summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile13
-rw-r--r--utils.h4
-rw-r--r--whois.c21
3 files changed, 38 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 8d8f69b..2634a9a 100644
--- a/Makefile
+++ b/Makefile
@@ -97,6 +97,19 @@ servers_charset.h: servers_charset_list make_servers_charset.pl
$(PERL) make_servers_charset.pl < $< > $@
##############################################################################
+afl:
+ $(MAKE) whois \
+ CC=afl-gcc AFL_HARDEN=1 \
+ HAVE_LIBIDN=1 HAVE_ICONV=1 DEFS=-DAFL_MODE=1
+
+afl2:
+ $(MAKE) whois \
+ HAVE_LIBIDN=1 HAVE_ICONV=1 DEFS=-DAFL_MODE=1
+
+afl-run:
+ nice afl-fuzz -i ../afl_in -o ../afl_out -- ./whois
+
+##############################################################################
install: install-whois install-mkpasswd install-pos
install-whois: whois
diff --git a/utils.h b/utils.h
index 0f226ae..4523266 100644
--- a/utils.h
+++ b/utils.h
@@ -9,6 +9,10 @@
#define NOFAIL(ptr) do_nofail((ptr), __FILE__, __LINE__)
+#ifndef AFL_MODE
+# define AFL_MODE 0
+#endif
+
/* Portability macros */
#ifdef __GNUC__
# define NORETURN __attribute__((noreturn))
diff --git a/whois.c b/whois.c
index 49df0ad..7262bea 100644
--- a/whois.c
+++ b/whois.c
@@ -140,6 +140,20 @@ int main(int argc, char *argv[])
fstring = malloc(fstringlen + 1);
*fstring = '\0';
+ /* interface for American Fuzzy Lop */
+ if (AFL_MODE) {
+ FILE *fp = fdopen(0, "r");
+ char *buf = NULL;
+ size_t len = 0;
+
+ /* read one line from stdin */
+ if (getline(&buf, &len, fp) < 0)
+ err_sys("getline");
+ fflush(fp);
+ /* and use it as command line arguments */
+ argv = merge_args(buf, argv, &argc);
+ }
+
/* prepend options from environment */
argv = merge_args(getenv("WHOIS_OPTIONS"), argv, &argc);
@@ -907,6 +921,13 @@ int openconn(const char *server, const char *port)
struct sockaddr_in saddr;
#endif
+ /*
+ * When using American Fuzzy Lop get the data from it using stdin
+ * instead of connecting to the actual whois server.
+ */
+ if (AFL_MODE)
+ return (dup(0));
+
alarm(60);
#ifdef HAVE_GETADDRINFO