diff options
author | Omar Polo <op@omarpolo.com> | 2024-07-02 17:47:49 +0000 |
---|---|---|
committer | Omar Polo <op@omarpolo.com> | 2024-07-02 17:47:49 +0000 |
commit | d0fed6eb088ab7f0eec876aea0bb98327c77c2bb (patch) | |
tree | 713c7372ed8f253920410f4f417cb42d44e6140e | |
parent | bdfea70f305cae0cee71d79f097aff93a69bccf7 (diff) |
initial support for fuzzying
-rw-r--r-- | .gitignore | 5 | ||||
-rw-r--r-- | regress/fuzz/Makefile | 38 | ||||
-rw-r--r-- | regress/fuzz/iri.c | 35 |
3 files changed, 78 insertions, 0 deletions
@@ -33,5 +33,10 @@ regress/iri_test regress/puny-test regress/gmid.pid +regress/fuzz/in +regress/fuzz/out +regress/fuzz/min +regress/fuzz/iri + site/gemini site/www diff --git a/regress/fuzz/Makefile b/regress/fuzz/Makefile new file mode 100644 index 0000000..88bffca --- /dev/null +++ b/regress/fuzz/Makefile @@ -0,0 +1,38 @@ +DISTFILES = Makefile \ + iri.c + +include ../../config.mk + +CC = afl-clang + +COBJS = ${COMPATS:.c=.o} +REG_COMPATS = ${COBJS:%=../../%} + +IRI_SRCS = iri.c ../../iri.c ../../utf8.c ../../log.c +IRI_OBJS = ${IRI_SRCS:.c=.o} ${REG_COMPATS} + +.PHONY: all data clean dist + +all: fuzz + +fuzz: iri + mkdir -p in out + echo 'gemini://omarpolo.com/' > in/simple + echo 'https://op:123@omarpolo.com/' > in/auth + echo 'ftp://op@omarpolo.com/a/bb/c' > in/path + echo 'gemini://omarpolo.com/?some=val' > in/query + echo 'gemini://omarpolo.com/b/#xyz' > in/fragment + echo 'gemini://omarpolo.com/b/?x=y#xyz' > in/qf + echo 'ssh://omarpolo.com/%2F/' > in/enc + echo 'http://omarpolo.com/foo/.././' > in/dots + echo 'http://omarpolo.com/////././' > in/slash + afl-fuzz -i in -o out -- ./iri + +iri: ${IRI_OBJS} + ${CC} ${IRI_OBJS} -o $@ ${LIBS} ${LDFLAGS} + +.c.o: + ${CC} -I../.. ${CFLAGS} -c $< -o $@ + +clean: + rm -f *.o iri diff --git a/regress/fuzz/iri.c b/regress/fuzz/iri.c new file mode 100644 index 0000000..c9672f4 --- /dev/null +++ b/regress/fuzz/iri.c @@ -0,0 +1,35 @@ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include "iri.h" + +int +main(void) +{ + struct iri iri; + const char *errstr = NULL; + char buf[64]; + char *line = NULL; + size_t linesize = 0; + ssize_t linelen; + + if ((linelen = getline(&line, &linesize, stdin)) == -1) + return (1); + + if (line[linelen-1] == '\n') + line[--linelen] = '\0'; + + if (parse_iri(line, &iri, &errstr)) { + if (serialize_iri(&iri, buf, sizeof(buf))) + puts(buf); + } + + free(line); + if (ferror(stdin)) { + perror("getline"); + return (1); + } + + return (0); +} |