]> xenbits.xensource.com Git - people/iwj/xen.git/commitdiff
fuzz/x86_emulate: Fix afl-harness batch mode file pointer leak
authorGeorge Dunlap <george.dunlap@citrix.com>
Fri, 13 Oct 2017 08:36:00 +0000 (09:36 +0100)
committerGeorge Dunlap <george.dunlap@citrix.com>
Fri, 27 Oct 2017 13:44:05 +0000 (14:44 +0100)
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 <george.dunlap@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Release-acked-by: Julien Grall <julien.grall@linaro.org>
tools/fuzz/x86_instruction_emulator/afl-harness.c

index d514468dd297424f26a9b415321baf5161a1efff..a2bae46d98617a50e910e79e9b5bbece3adf8923 100644 (file)
@@ -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;