Commit 53054c4c authored by Ondřej Surý's avatar Ondřej Surý

Adapt to the new afl to use __AFL_LOOP

parent 44f7f034
......@@ -4,3 +4,4 @@
/knotd_stdio
/packet
/packet_libfuzzer
/wrap/main.c
AM_CPPFLAGS = \
-include $(top_builddir)/src/config.h \
-I$(top_srcdir)/src \
-I$(top_srcdir)/src/dnssec/lib
-include $(top_builddir)/src/config.h \
-I$(top_srcdir)/src \
-I$(top_srcdir)/src/dnssec/lib \
-DCONFIG_DIR='"${config_dir}"' \
-DSTORAGE_DIR='"${storage_dir}"' \
-DRUN_DIR='"${run_dir}"'
LDADD = \
$(top_builddir)/src/libknot.la
......@@ -15,11 +18,17 @@ check_PROGRAMS += packet_libfuzzer
packet_libfuzzer_LDADD = $(LDADD) $(libfuzzer_LIBS) -lstdc++
endif
knotd_stdio_SOURCES = wrap/server.c wrap/tcp-handler.c wrap/udp-handler.c
packet_SOURCES = packet.c afl-loop.h
knotd_stdio_SOURCES = wrap/server.c wrap/tcp-handler.c wrap/udp-handler.c afl-loop.h
nodist_knotd_stdio_SOURCES = wrap/main.c
knotd_stdio_CPPFLAGS = $(AM_CPPFLAGS) $(liburcu_CFLAGS)
knotd_stdio_LDADD = \
$(top_builddir)/src/utils/knotd/knotd-main.o \
$(top_builddir)/src/libknotd.la $(top_builddir)/src/libcontrib.la \
$(liburcu_LIBS)
BUILT_SOURCES = wrap/main.c
CLEANFILES = wrap/main.c
wrap/main.c: Makefile $(top_builddir)/src/utils/knotd/main.c
echo '#include "afl-loop.h"' > $@
sed -e 's/for (;;)/while (__AFL_LOOP(1000))/' $(top_builddir)/src/utils/knotd/main.c >>$@
check-compile: $(check_PROGRAMS)
#ifndef __AFL_COMPILER
#define __AFL_LOOP(x) (0)
#endif
......@@ -20,10 +20,11 @@
#include <signal.h>
#include "libknot/libknot.h"
#include "afl-loop.h"
int main(void)
{
for(;;) {
while (__AFL_LOOP(1000)) {
uint8_t buffer[UINT16_MAX + 1] = { 0 };
size_t len = fread(buffer, 1, sizeof(buffer), stdin);
......@@ -32,10 +33,6 @@ int main(void)
int r = knot_pkt_parse(pkt, 0);
knot_pkt_free(&pkt);
if (getenv("AFL_PERSISTENT")) {
raise(SIGSTOP);
} else {
return (r == KNOT_EOK ? 0 : 1);
}
return (r == KNOT_EOK ? 0 : 1);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment