diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2018-12-08 19:03:09 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2018-12-08 19:08:08 +0100 |
| commit | c7918378631992d874c99736272ed342d5d77b2c (patch) | |
| tree | 5e67097471fda876d532c270dc4b7f3db0e850c5 /executor/common.h | |
| parent | 33508266251f6db13ef34741e36b1dce2c9e1b49 (diff) | |
executor: fix handling of big-endian bitfields
Currently we apply big-endian-ness and bitfield-ness in the wrong order in copyin.
This leads to totally bogus result. Fix this.
Diffstat (limited to 'executor/common.h')
| -rw-r--r-- | executor/common.h | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/executor/common.h b/executor/common.h index 49a2cbd67..7e855b91c 100644 --- a/executor/common.h +++ b/executor/common.h @@ -325,19 +325,10 @@ static int event_timedwait(event_t* ev, uint64 timeout) #endif #if SYZ_EXECUTOR || SYZ_USE_BITMASKS -#define BITMASK_LEN(type, bf_len) (type)((1ull << (bf_len)) - 1) - -#define BITMASK_LEN_OFF(type, bf_off, bf_len) (type)(BITMASK_LEN(type, (bf_len)) << (bf_off)) - -#define STORE_BY_BITMASK(type, addr, val, bf_off, bf_len) \ - if ((bf_off) == 0 && (bf_len) == 0) { \ - *(type*)(addr) = (type)(val); \ - } else { \ - type new_val = *(type*)(addr); \ - new_val &= ~BITMASK_LEN_OFF(type, (bf_off), (bf_len)); \ - new_val |= ((type)(val)&BITMASK_LEN(type, (bf_len))) << (bf_off); \ - *(type*)(addr) = new_val; \ - } +#define BITMASK(bf_off, bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) +#define STORE_BY_BITMASK(type, htobe, addr, val, bf_off, bf_len) \ + *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | \ + (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) #endif #if SYZ_EXECUTOR || SYZ_USE_CHECKSUMS |
