]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add a TCL script that can be run to generate the fuzzdata1.txt file.
authordrh <drh@noemail.net>
Tue, 28 Apr 2015 00:53:26 +0000 (00:53 +0000)
committerdrh <drh@noemail.net>
Tue, 28 Apr 2015 00:53:26 +0000 (00:53 +0000)
FossilOrigin-Name: fdc79fd14af8e05d1d5b4665303715b391f2e402

manifest
manifest.uuid
test/mkfuzzdata1.tcl [new file with mode: 0644]

index 3d1499a25be7cc36997ce54f73f182f746aa1506..a79fb89411c52cc2e6ab272f76a3f6358db0ae67 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\sfault-injection\stests\sfor\sthe\scode\sin\stest_stat.c.
-D 2015-04-27T19:53:55.422
+C Add\sa\sTCL\sscript\sthat\scan\sbe\srun\sto\sgenerate\sthe\sfuzzdata1.txt\sfile.
+D 2015-04-28T00:53:26.193
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in e3268d234210842b4be0a6e2e1c5990999f1d9f4
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -754,6 +754,7 @@ F test/misc6.test 953cc693924d88e6117aeba16f46f0bf5abede91
 F test/misc7.test edd0b63e2ee29a256900b0514f6fff27e19e9bb2
 F test/misc8.test fc2754d38892f7dac30c22db3616c2764f117d66
 F test/misuse.test 3c34719944ba045cc6c188a4852ba04680728912
+F test/mkfuzzdata1.tcl a2d0a8d07c957c637ab3c258cbd618ca72faf8c6
 F test/mmap1.test 1bfd611b9841eafb44f7d83c0788e146d84a33c9
 F test/mmap2.test 9d6dd9ddb4ad2379f29cc78f38ce1e63ed418022
 F test/mmap3.test c92273e16eb8d23c1d55c9815b446bb72ef0512e
@@ -1254,7 +1255,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 8134d41b964428b3af022735bce9d07c6ad28b21
-R 92d658e0b96ed36e187e832049d255ac
-U dan
-Z 90302e8af97f1cb8a317f09e966de90f
+P ea5e0b74c997492025225cd86e65e8a8c86ca4a0
+R 665c35450ac2eba500934043a45f4d8f
+U drh
+Z 3f98585e47e8d7e97d7cf0e6cce74567
index 7df52eda81f2bd87e8e5361c66bac6db55b2cc17..203f908ac205585981acd419fc3a943944294586 100644 (file)
@@ -1 +1 @@
-ea5e0b74c997492025225cd86e65e8a8c86ca4a0
\ No newline at end of file
+fdc79fd14af8e05d1d5b4665303715b391f2e402
\ No newline at end of file
diff --git a/test/mkfuzzdata1.tcl b/test/mkfuzzdata1.tcl
new file mode 100644 (file)
index 0000000..766757b
--- /dev/null
@@ -0,0 +1,112 @@
+#!/usr/bin/tclsh
+#
+# Run this script in order to rebuild the fuzzdata1.txt file containing
+# fuzzer data for the fuzzershell utility that is create by afl-fuzz.
+#
+# This script gathers all of the test cases identified by afl-fuzz and
+# runs afl-cmin and afl-tmin over them all to try to generate a mimimum
+# set of tests that cover all observed behavior.
+# 
+# Options:
+#
+#    --afl-bin DIR1             DIR1 contains the AFL binaries
+#    --fuzzershell PATH         Full pathname of instrumented fuzzershell
+#    --afl-data DIR3            DIR3 is the "-o" directory from afl-fuzz
+#    -o FILE                    Write results into FILE
+#
+set AFLBIN {}
+set FUZZERSHELL {}
+set AFLDATA {}
+set OUTFILE {}
+
+proc usage {} {
+  puts stderr "Usage: $::argv0 --afl-bin DIR --fuzzershell PATH\
+                  --afl-data DIR -o FILE"
+  exit 1
+}
+proc cmdlineerr {msg} {
+  puts stderr $msg
+  usage
+}
+
+for {set i 0} {$i<[llength $argv]} {incr i} {
+  set x [lindex $argv $i]
+  if {[string index $x 0]!="-"} {cmdlineerr "illegal argument: $x"}
+  set x [string trimleft $x -]
+  incr i
+  if {$i>=[llength $argv]} {cmdlineerr "no argument on --$x"}
+  set a [lindex $argv $i]
+  switch -- $x {
+     afl-bin {set AFLBIN $a}
+     afl-data {set AFLDATA $a}
+     fuzzershell {set FUZZERSHELL $a}
+     o {set OUTFILE $a}
+     default {cmdlineerr "unknown option: --$x"}
+  }
+}
+proc checkarg {varname option} {
+  set val [set ::$varname]
+  if {$val==""} {cmdlineerr "required option missing: --$option"}
+}
+checkarg AFLBIN afl-bin
+checkarg AFLDATA afl-data
+checkarg FUZZERSHELL fuzzershell
+checkarg OUTFILE o
+proc checkexec {x} {
+  if {![file exec $x]} {cmdlineerr "cannot find $x"}
+}
+checkexec $AFLBIN/afl-cmin
+checkexec $AFLBIN/afl-tmin
+checkexec $FUZZERSHELL
+proc checkdir {x} {
+  if {![file isdir $x]} {cmdlineerr "no such directory: $x"}
+}
+checkdir $AFLDATA/queue
+
+proc progress {msg} {
+  puts "******** $msg"
+  flush stdout
+}
+progress "mkdir tmp1 tmp2"
+file mkdir tmp1 tmp2
+progress "copying test cases from $AFLDATA into tmp1..."
+set n 0
+foreach file [glob -nocomplain $AFLDATA/queue/id:*] {
+  incr n
+  file copy $file tmp1/$n
+}
+foreach file [glob -nocomplain $AFLDATA/crash*/id:*] {
+  incr n
+  file copy $file tmp1/$n
+}
+progress "total $n files copied."
+progress "running: $AFLBIN/afl-cmin -i tmp1 -o tmp2 $FUZZERSHELL"
+exec $AFLBIN/afl-cmin -i tmp1 -o tmp2 $FUZZERSHELL >&@ stdout
+progress "afl-cmin complete."
+#
+# Experiments show that running afl-tmin is too slow for this application.
+# And it doesn't really make the test cases that much smaller.  So let's
+# just skip it.
+#
+# foreach file [glob tmp2/*] {
+#   progress "$AFLBIN/afl-tmin -i $file -o tmp3/[file tail $file] $FUZZERSHELL"
+#   exec $AFLBIN/afl-tmin -i $file -o tmp3/[file tail $file] \
+#       $FUZZERSHELL >&@ stdout
+# }
+progress "generating final output into $OUTFILE"
+set out [open $OUTFILE wb]
+puts $out "# Test data for use with fuzzershell.  Automatically
+# generated using $argv0.  This file contains binary data
+#"
+set n 0
+foreach file [glob tmp2/*] {
+  incr n
+  puts -nonewline $out "/****<$n>****/"
+  set in [open $file rb]
+  puts -nonewline $out [read $in]
+  close $in
+}
+close $out
+progress "done.  $n test cases written to $OUTFILE"
+progress "clean-up..."
+file delete -force tmp1 tmp2