mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 02:01:24 +01:00
tools/insn-fuzz: Don't hit memcpy() for zero-length reads
For control-flow changes, the emulator needs to perform a zero-length instruction fetch at the target offset. It also passes NULL for the destination buffer, as there is no instruction stream to collect. This trips up UBSAN when passed to memcpy(), as passing NULL is undefined behaviour per the C spec (irrespective of passing a size of 0). Special case these fetches in fuzz_insn_fetch() before reaching data_read(). Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com> Acked-by: George Dunlap <george.dunlap@citrix.com> Reviewed-by: Jan Beulich <jbeulich@suse.com>
This commit is contained in:
1 parent
66c9436008
commit
654740b4bd
1 file changed
+10
@@ -117,6 +117,16 @@ static int fuzz_insn_fetch(
|
||||
unsigned int bytes,
|
||||
struct x86_emulate_ctxt *ctxt)
|
||||
{
|
||||
/*
|
||||
* Zero-length instruction fetches are made at the destination of jumps,
|
||||
* to perform segmentation checks. No data needs returning.
|
||||
*/
|
||||
if ( bytes == 0 )
|
||||
{
|
||||
assert(p_data == NULL);
|
||||
return maybe_fail("insn_fetch", true);
|
||||
}
|
||||
|
||||
return data_read("insn_fetch", p_data, bytes);
|
||||
}
|
||||
|
||||
|
||||