From c7918378631992d874c99736272ed342d5d77b2c Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sat, 8 Dec 2018 19:03:09 +0100 Subject: 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. --- pkg/csource/generated.go | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'pkg/csource/generated.go') diff --git a/pkg/csource/generated.go b/pkg/csource/generated.go index a7bfe74d0..0c3ecb4e8 100644 --- a/pkg/csource/generated.go +++ b/pkg/csource/generated.go @@ -310,19 +310,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 @@ -3945,7 +3936,10 @@ static long syz_compare(long want, long want_len, long got, long got_len) return -1; } if (memcmp((void*)want, (void*)got, want_len)) { - debug("syz_compare: data differs\n"); + debug("syz_compare: data differs, want:\n"); + debug_dump_data((char*)want, want_len); + debug("got:\n"); + debug_dump_data((char*)got, got_len); errno = EINVAL; return -1; } @@ -4106,7 +4100,10 @@ static long syz_compare(long want, long want_len, long got, long got_len) return -1; } if (memcmp((void*)want, (void*)got, want_len)) { - debug("syz_compare: data differs\n"); + debug("syz_compare: data differs, want:\n"); + debug_dump_data((char*)want, want_len); + debug("got:\n"); + debug_dump_data((char*)got, got_len); errno = EINVAL; return -1; } -- cgit mrf-deployment