commit - a1ef2acc86f58b0fd44ffd8ed6c5176fb500d45e
commit + 18ac3d0fd1fece16a142194f570c453f67e5b12f
blob - 01e731053dc0c5871f2108eae14a743c29d0300b
blob + d1641eda39d9be61f02da8b24ef6497d2e35464c
--- .gitignore
+++ .gitignore
regress/gmid.pid
regress/fuzz/in
-regress/fuzz/out
-regress/fuzz/min
regress/fuzz/iri
+regress/fuzz/min
+regress/fuzz/out
+regress/fuzz/proxy
site/gemini
site/www
blob - 88bffcaf6d2bc5e513bd72c81516167f6f286880
blob + e8906b3188e2dbe91ae8fc6007de0c60799edb98
--- regress/fuzz/Makefile
+++ regress/fuzz/Makefile
IRI_SRCS = iri.c ../../iri.c ../../utf8.c ../../log.c
IRI_OBJS = ${IRI_SRCS:.c=.o} ${REG_COMPATS}
+PROXY_SRCS = proxy.c ../../proxy-proto.c
+PROXY_OBJS = ${PROXY_SRCS:.c=.o} ${REG_COMPATS}
+
.PHONY: all data clean dist
-all: fuzz
+all:
+ @echo run ${MAKE} fuzz-iri to fuzz the IRI parser
+ @echo run ${MAKE} fuzz-proxy to fuzz the proxy v1 protocol parser
-fuzz: iri
+fuzz-iri: iri
+ rm -rf in out
mkdir -p in out
echo 'gemini://omarpolo.com/' > in/simple
echo 'https://op:123@omarpolo.com/' > in/auth
echo 'http://omarpolo.com/////././' > in/slash
afl-fuzz -i in -o out -- ./iri
+fuzz-proxy: proxy
+ rm -rf in out
+ mkdir -p in out
+ printf 'PROXY TCP4 255.255.255.255 255.255.255.255 65535 65535\r\n' >in/ipv4
+ printf 'PROXY TCP6 fe80::1 fd4b:b287:5c6f:1f4::2 65535 65535\r\n' >in/ipv6
+ printf 'PROXY UNKNOWN\r\n' > in/unknown
+ afl-fuzz -i in -o out -- ./proxy
+
iri: ${IRI_OBJS}
${CC} ${IRI_OBJS} -o $@ ${LIBS} ${LDFLAGS}
+proxy: ${PROXY_OBJS}
+ ${CC} ${PROXY_OBJS} -o $@ ${LIBS} ${LDFLAGS}
+
.c.o:
${CC} -I../.. ${CFLAGS} -c $< -o $@
blob - /dev/null
blob + 272332b4be0865d9706a0d06363aef6b14dd8ed6 (mode 644)
--- /dev/null
+++ regress/fuzz/proxy.c
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "gmid.h"
+
+int
+main(void)
+{
+ struct proxy_protocol_v1 pp1;
+ char buf[1024];
+ char *line = NULL;
+ size_t consumed, linesize = 0;
+ ssize_t linelen;
+
+ memset(&pp1, 0, sizeof(pp1));
+ memset(buf, 0, sizeof(buf));
+
+ if ((linelen = getline(&line, &linesize, stdin)) == -1)
+ return (1);
+
+ if (proxy_proto_v1_parse(&pp1, line, linelen, &consumed) != -1) {
+ switch (pp1.proto) {
+ case PROTO_V4:
+ inet_ntop(AF_INET, &pp1.srcaddr.v4, buf, sizeof(buf));
+ break;
+ case PROTO_V6:
+ inet_ntop(AF_INET6, &pp1.srcaddr.v6, buf, sizeof(buf));
+ break;
+ case PROTO_UNKNOWN:
+ strlcpy(buf, "UNKNOWN", sizeof(buf));
+ break;
+ default:
+ abort();
+ }
+ puts(buf);
+ }
+
+ free(line);
+ if (ferror(stdin)) {
+ perror("getline");
+ return (1);
+ }
+
+ return (0);
+}