Support american fuzzy lop

When built with AFL_MODE set to true, whois will use the first line of
standard input as command line parameters and the rest as network input.
This commit is contained in:
Marco d'Itri 2015-12-08 08:38:50 +01:00
parent e143980234
commit 718ae61ae5
3 changed files with 38 additions and 0 deletions

View File

@ -96,6 +96,19 @@ tld_serv.h: tld_serv_list make_tld_serv.pl
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

View File

@ -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))

21
whois.c
View File

@ -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