From 2963fcf0839035a36944679523fe0bc7c3ec7c5e Mon Sep 17 00:00:00 2001 From: semarie Date: Tue, 23 Jun 2015 18:03:09 +0000 Subject: [PATCH] add regress tests for httpd - this testsuite covers patterns --- regress/usr.sbin/httpd/Makefile | 5 + regress/usr.sbin/httpd/patterns/Makefile | 31 +++++ .../usr.sbin/httpd/patterns/patterns-tester.c | 98 ++++++++++++++ .../httpd/patterns/patterns-tester.lua | 3 + .../httpd/patterns/test-patterns-lua.out | 128 ++++++++++++++++++ .../usr.sbin/httpd/patterns/test-patterns.in | 27 ++++ .../usr.sbin/httpd/patterns/test-patterns.out | 99 ++++++++++++++ 7 files changed, 391 insertions(+) create mode 100644 regress/usr.sbin/httpd/Makefile create mode 100644 regress/usr.sbin/httpd/patterns/Makefile create mode 100644 regress/usr.sbin/httpd/patterns/patterns-tester.c create mode 100644 regress/usr.sbin/httpd/patterns/patterns-tester.lua create mode 100644 regress/usr.sbin/httpd/patterns/test-patterns-lua.out create mode 100644 regress/usr.sbin/httpd/patterns/test-patterns.in create mode 100644 regress/usr.sbin/httpd/patterns/test-patterns.out diff --git a/regress/usr.sbin/httpd/Makefile b/regress/usr.sbin/httpd/Makefile new file mode 100644 index 00000000000..94c29fc20f2 --- /dev/null +++ b/regress/usr.sbin/httpd/Makefile @@ -0,0 +1,5 @@ +# $OpenBSD: Makefile,v 1.1 2015/06/23 18:03:09 semarie Exp $ + +SUBDIR += patterns + +.include diff --git a/regress/usr.sbin/httpd/patterns/Makefile b/regress/usr.sbin/httpd/patterns/Makefile new file mode 100644 index 00000000000..912d0d54bf6 --- /dev/null +++ b/regress/usr.sbin/httpd/patterns/Makefile @@ -0,0 +1,31 @@ +# $OpenBSD: Makefile,v 1.1 2015/06/23 18:03:09 semarie Exp $ + +HTTPDSRC = ${.CURDIR}/../../../../usr.sbin/httpd + +.PATH: ${HTTPDSRC} + +REGRESS_TARGETS= test-patterns + +CLEANFILES += patterns-tester + +#LUA?= lua53 +.ifdef LUA +REGRESS_TARGETS+= test-patterns-lua +.endif + +patterns-tester: patterns-tester.c patterns.c patterns.h + ${CC} -o $@ ${CFLAGS} ${.CURDIR}/patterns-tester.c ${HTTPDSRC}/patterns.c -I${HTTPDSRC} + +test-patterns: patterns-tester test-patterns.out test-patterns.in + cat ${.CURDIR}/test-patterns.in | grep -v '^#' | \ + while IFS=' ' read string pattern comments ; do \ + ./patterns-tester "$${string}" "$${pattern}" 2>&1 || true; \ + done | diff -I 'OpenBSD' -u ${.CURDIR}/test-patterns.out - + +test-patterns-lua: patterns-tester.lua test-patterns-lua.out test-patterns.in + cat ${.CURDIR}/test-patterns.in | grep -v '^#' | \ + while IFS=' ' read string pattern comments ; do \ + ${LUA} ./patterns-tester.lua "$${string}" "$${pattern}" 2>&1 || true; \ + done | diff -I 'OpenBSD' -u ${.CURDIR}/test-patterns-lua.out - + +.include diff --git a/regress/usr.sbin/httpd/patterns/patterns-tester.c b/regress/usr.sbin/httpd/patterns/patterns-tester.c new file mode 100644 index 00000000000..54f145620a5 --- /dev/null +++ b/regress/usr.sbin/httpd/patterns/patterns-tester.c @@ -0,0 +1,98 @@ +/* $OpenBSD: patterns-tester.c,v 1.1 2015/06/23 18:03:09 semarie Exp $ */ +/* + * Copyright (c) 2015 Sebastien Marie + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include +#include + +#include "patterns.h" + +extern char * malloc_options; + +static void read_string(char *, size_t); +static void read_string_stop(void); + +static void +read_string(char *buf, size_t len) +{ + size_t i; + + /* init */ + bzero(buf, len); + + /* read */ + if (fgets(buf, len, stdin) == NULL) + err(1, "fgets"); + + /* strip '\n' */ + i = strnlen(buf, len); + if (i != 0) + buf[i-1] = '\0'; +} + +static void +read_string_stop() +{ + if (getchar() != EOF) + errx(1, "read_string_stop: too many input"); +} + +int +main(int argc, char *argv[]) +{ + char string[1024]; + char pattern[1024]; + struct str_match m; + const char *errstr = NULL; + int ret; + size_t i; + + /* configure malloc */ + malloc_options = "S"; + + /* read testcase */ + if (argc != 3) { + /* from stdin (useful for afl) */ + read_string(string, sizeof(string)); + read_string(pattern, sizeof(pattern)); + read_string_stop(); + } else { + /* from arguments */ + strlcpy(string, argv[1], sizeof(string)); + strlcpy(pattern, argv[2], sizeof(pattern)); + } + + /* print testcase */ + printf("string='%s'\n", string); + printf("pattern='%s'\n", pattern); + + /* test it ! */ + ret = str_match(string, pattern, &m, &errstr); + if (errstr != NULL) + errx(1, "str_match: %s", errstr); + + /* print result */ + printf("ret=%d num=%d\n", ret, m.sm_nmatch); + for (i=0; i