From: George Dunlap Date: Fri, 13 Oct 2017 08:36:00 +0000 (+0100) Subject: fuzz/x86_emulate: Fix afl-harness batch mode file pointer leak X-Git-Tag: archive/raspbian/4.11.1-1+rpi1~1^2~66^2~1058 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=d525519bedbcb3fb7b9cc297e352a35124681850;p=xen.git fuzz/x86_emulate: Fix afl-harness batch mode file pointer leak Changeset 2b1cde7783 introduced "batch mode" to afl-harness, which allowed the handling of several inputs in sequence. Unfortunately, it introduced a file pointer leak when the file was larger than the maximum size. Restructure the code to always close fp if we opened it. Signed-off-by: George Dunlap Reviewed-by: Jan Beulich Release-acked-by: Julien Grall --- diff --git a/tools/fuzz/x86_instruction_emulator/afl-harness.c b/tools/fuzz/x86_instruction_emulator/afl-harness.c index d514468dd2..a2bae46d98 100644 --- a/tools/fuzz/x86_instruction_emulator/afl-harness.c +++ b/tools/fuzz/x86_instruction_emulator/afl-harness.c @@ -99,13 +99,17 @@ int main(int argc, char **argv) exit(-1); } - if ( !feof(fp) ) + /* Only run the test if the input file was smaller than INPUT_SIZE */ + if ( feof(fp) ) + { + LLVMFuzzerTestOneInput(input, size); + } + else { printf("Input too large\n"); /* Don't exit if we're doing batch processing */ if ( max == 1 ) exit(-1); - continue; } if ( fp != stdin ) @@ -113,8 +117,6 @@ int main(int argc, char **argv) fclose(fp); fp = NULL; } - - LLVMFuzzerTestOneInput(input, size); } return 0;