]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
fuzz/x86_emulate: Clear errors in the officially sanctioned way
authorGeorge Dunlap <george.dunlap@citrix.com>
Wed, 11 Oct 2017 17:49:37 +0000 (18:49 +0100)
committerGeorge Dunlap <george.dunlap@citrix.com>
Wed, 11 Oct 2017 22:35:21 +0000 (23:35 +0100)
Commit 849a1f10c9 was checked in inappropriately; review flagged up
that clearerr() was too big a hammer, as it would clear both the EOF
flag and stream errors.

Stream errors shouldn't be cleared; we only want the EOF and other
stream-related state reset.  To do this, it is sufficient to fseek()
to zero.

Signed-off-by: George Dunlap <george.dunlap@citrix.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
tools/fuzz/x86_instruction_emulator/afl-harness.c

index b4d15451b5786c526786e509557104c4f435a30b..31ae1daef10f838f7da8c4e1fcb610345cbee303 100644 (file)
@@ -77,6 +77,17 @@ int main(int argc, char **argv)
                 exit(-1);
             }
         }
+#ifdef __AFL_HAVE_MANUAL_CONTROL
+        else
+        {
+            /* 
+             * This will ensure we're dealing with a clean stream
+             * state after the afl-fuzz process messes with the open
+             * file handle.
+             */
+            fseek(fp, 0, SEEK_SET);
+        }
+#endif
 
         size = fread(input, 1, INPUT_SIZE, fp);
 
@@ -97,8 +108,6 @@ int main(int argc, char **argv)
             fclose(fp);
             fp = NULL;
         }
-        else
-            clearerr(fp);
 
         LLVMFuzzerTestOneInput(input, size);
     }