[build-path-prefix-map-spec] 04/50: Run C examples through afl-fuzz
Ximin Luo
infinity0 at debian.org
Fri Mar 10 15:17:18 UTC 2017
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch master
in repository build-path-prefix-map-spec.
commit 4cb90ad907a73e4f49d4a14131a1dd076aa77008
Author: Ximin Luo <infinity0 at debian.org>
Date: Tue Jan 17 19:24:47 2017 +0100
Run C examples through afl-fuzz
---
.gitignore | 1 +
Makefile | 49 +++++++++++++++++++++++++++++++++-------
afl-in-split/1.in | Bin 0 -> 65 bytes
source_prefix_map.h | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++
split.c | 23 ++-----------------
5 files changed, 108 insertions(+), 29 deletions(-)
diff --git a/.gitignore b/.gitignore
index 8f893d3..c48c113 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
/split
+/afl-out-*
diff --git a/Makefile b/Makefile
index 039bacf..945d9ff 100644
--- a/Makefile
+++ b/Makefile
@@ -1,22 +1,55 @@
+TMPDIR = /run/shm/rb-prefix-map
+
ALL = split
-ALL_CHECK = split split.py
+
+ALLCHECK_split = split split.py
+envvar_1_split = /a/b=yyy=ERROR /a=lol /b=foo /a/b=yyy=secreteh
+
+ALLCHECK_urlencode = urlencode.py
+envvar_1_urlencode = /a/b%3Dyyy=ERROR&/a=lol&/b=foo&/a/b%3Dyyy=secreteh
.PHONY: all
all: $(ALL)
-%: %.c
- gcc -o "$@" "$<"
+%: %.c source_prefix_map.h
+ $(CC) -o "$@" "$<"
-.PHONY: check-apply
-check-apply: apply.out.1 apply.out.2 $(ALL_CHECK)
- set -ex; for i in $(ALL_CHECK); do \
- SOURCE_PREFIX_MAP='/a/b=yyy=ERROR /a=lol /b=foo /a/b=yyy=secreteh' \
+check-apply-generic = \
+ set -ex; for i in $(1); do \
+ SOURCE_PREFIX_MAP='$(2)' \
./$$i /a/d /b/1234 /a/b=yyy/xxx | diff -ru - apply.out.1; \
done
- set -ex; for i in $(ALL_CHECK); do \
+
+check-apply-none = \
+ set -ex; for i in $(1); do \
./$$i /a/d /b/1234 /a/b=yyy/xxx | diff -ru - apply.out.2; \
done
+.PHONY: check
+check: check-apply-split check-apply-urlencode
+
+.PHONY: check-apply-%
+check-apply-%: apply.out.1 apply.out.2
+ $(MAKE) $(ALLCHECK_$*)
+ $(call check-apply-generic,$(ALLCHECK_$*),$(envvar_1_$*))
+ $(call check-apply-none,$(ALLCHECK_$*))
+
+.PHONY: fuzz-%
+fuzz-%: %
+ @echo "$(CC)" | grep -i afl || \
+ echo >&2 "warning: you didn't set CC=afl-gcc, fuzzing might not work"
+ @set -e; if test -d "afl-out-$*"; then \
+ echo >&2 "afl-out-$* exists, reusing. run 'make reset-fuzz-$* to delete it."; \
+ afl-fuzz -i - -o "afl-out-$*" -- "./$*" -; else \
+ mkdir -p $(TMPDIR); \
+ ln -s "$$(mktemp -d -p $(TMPDIR))" "afl-out-$*"; \
+ afl-fuzz -i "afl-in-$(basename $*)" -o "afl-out-$*" -- "./$*" -; fi
+
+.PHONY: reset-fuzz-%
+reset-fuzz-%: %
+ rm -rf "$$(readlink -f "afl-out-$*")" && rm -rf "afl-out-$*"
+ rmdir -p "$(TMPDIR)" 2>/dev/null || true
+
.PHONY: clean
clean:
rm -f $(ALL)
diff --git a/afl-in-split/1.in b/afl-in-split/1.in
new file mode 100644
index 0000000..c61b632
Binary files /dev/null and b/afl-in-split/1.in differ
diff --git a/source_prefix_map.h b/source_prefix_map.h
index b256095..702aaa9 100644
--- a/source_prefix_map.h
+++ b/source_prefix_map.h
@@ -107,3 +107,67 @@ remap_prefix (const char *filename, struct prefix_maps *maps)
{
return remap_prefix_alloc (filename, maps, malloc);
}
+
+#include <stdlib.h>
+#include <stdio.h>
+
+/*
+ * Run as one of:
+ *
+ * $ SOURCE_PREFIX_MAP=${map} ./main ${path0} ${path1} ${path2}
+ * $ printf "${map}\0${path0}\0${path1}\0${path2}\0" | ./main -
+ */
+int
+generic_main (int (*parse_prefix_maps) (const char *, struct prefix_maps *), int argc, char *argv[])
+{
+ struct prefix_maps source_prefix_map = { NULL, 0 };
+
+ int using_stdin = 0; // 0 = SOURCE_PREFIX_MAP envvar, 1 = stdin (for afl)
+ char *mapstr = NULL;
+ if (argc > 1 && strncmp (argv[1], "-", 1) == 0)
+ {
+ size_t len = 0;
+ getdelim (&mapstr, &len, 0, stdin);
+ if (ferror (stdin))
+ goto err_stdin;
+ using_stdin = 1;
+ }
+ else
+ mapstr = getenv ("SOURCE_PREFIX_MAP");
+
+ if (mapstr)
+ if (!parse_prefix_maps (mapstr, &source_prefix_map))
+ {
+ fprintf (stderr, "parse_prefix_maps failed\n");
+ return 1;
+ }
+
+ if (using_stdin)
+ {
+ free (mapstr); // as per contract of getdelim()
+
+ char *arg = NULL;
+ size_t len = 0;
+ while (getdelim (&arg, &len, 0, stdin) != -1)
+ {
+ printf ("%s\n", remap_prefix (arg, &source_prefix_map));
+ }
+
+ if (ferror (stdin))
+ goto err_stdin;
+ }
+ else
+ {
+ for (int i = using_stdin ? 2 : 1; i < argc; i++)
+ {
+ //fprintf (stderr, "%s", argv[i]);
+ printf ("%s\n", remap_prefix (argv[i], &source_prefix_map));
+ }
+ }
+
+ return 0;
+
+err_stdin:
+ perror ("failed to read from stdin");
+ return 1;
+}
diff --git a/split.c b/split.c
index a9c92e1..2a7a52d 100644
--- a/split.c
+++ b/split.c
@@ -1,6 +1,4 @@
#include "source_prefix_map.h"
-#include <stdlib.h>
-#include <stdio.h>
/* Parsing the variable. */
/* For Applying the variable, see source_prefix_map.h. */
@@ -34,7 +32,7 @@ parse_prefix_maps (const char *arg, struct prefix_maps *maps)
struct prefix_map *map = XNEW (struct prefix_map);
if (!parse_prefix_map (tok, map))
{
- fprintf (stderr, "invalid value for prefix-map: %s\n", tok);
+ fprintf (stderr, "invalid value for prefix-map: '%s'\n", tok);
free (map);
return 0;
}
@@ -49,22 +47,5 @@ parse_prefix_maps (const char *arg, struct prefix_maps *maps)
int
main (int argc, char *argv[])
{
- struct prefix_maps source_prefix_map = { NULL, 0 };
-
- const char *arg;
- arg = getenv ("SOURCE_PREFIX_MAP");
- if (arg)
- if (!parse_prefix_maps (arg, &source_prefix_map))
- {
- fprintf (stderr, "parse_prefix_map failed\n");
- return 1;
- }
-
- for (int i = 1; i < argc; i++)
- {
- fprintf (stderr, "%s", argv[i]);
- printf ("%s\n", remap_prefix (argv[i], &source_prefix_map));
- }
-
- return 0;
+ return generic_main (parse_prefix_maps, argc, argv);
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/build-path-prefix-map-spec.git
More information about the Reproducible-commits
mailing list