Commit 6536d71b authored by Filip Široký's avatar Filip Široký Committed by Daniel Salzman

tests-fuzz: add tests for dname to/from string operations

parent 816c475c
......@@ -423,6 +423,8 @@ src/utils/knsupdate/knsupdate_params.h
src/utils/kzonecheck/main.c
src/utils/kzonecheck/zone_check.c
src/utils/kzonecheck/zone_check.h
tests-fuzz/fuzz_dname_from_str.c
tests-fuzz/fuzz_dname_to_str.c
tests-fuzz/fuzz_packet.c
tests-fuzz/fuzz_zscanner.c
tests-fuzz/knotd_wrap/afl-loop.h
......
......@@ -8,3 +8,5 @@
*.log
/fuzz_packet
/fuzz_zscanner
/fuzz_dname_to_str
/fuzz_dname_from_str
\ No newline at end of file
......@@ -7,8 +7,10 @@ AM_CPPFLAGS = \
-DSRCDIR=\"$(abs_srcdir)\"
FUZZERS = \
fuzz_packet \
fuzz_zscanner
fuzz_packet \
fuzz_zscanner \
fuzz_dname_to_str \
fuzz_dname_from_str
check_PROGRAMS = $(FUZZERS)
......@@ -45,13 +47,23 @@ fuzz_zscanner_SOURCES = fuzz_zscanner.c
fuzz_zscanner_CPPFLAGS = $(AM_CPPFLAGS)
fuzz_zscanner_LDADD = $(top_builddir)/src/libzscanner.la
fuzz_dname_to_str_SOURCES = fuzz_dname_to_str.c
fuzz_dname_to_str_CPPFLAGS = $(AM_CPPFLAGS)
fuzz_dname_to_str_LDADD = $(top_builddir)/src/libknot.la
fuzz_dname_from_str_SOURCES = fuzz_dname_from_str.c
fuzz_dname_from_str_CPPFLAGS = $(AM_CPPFLAGS)
fuzz_dname_from_str_LDADD = $(top_builddir)/src/libknot.la
if OSS_FUZZ
# CFLAGS, LDFLAGS, etc. are defined by the oss-fuzz environment; just link
# in the fuzzing engine
fuzz_packet_LDADD += ${LIB_FUZZING_ENGINE} -lc++
fuzz_zscanner_LDADD += ${LIB_FUZZING_ENGINE} -lc++
fuzz_packet_LDADD += ${LIB_FUZZING_ENGINE} -lc++
fuzz_zscanner_LDADD += ${LIB_FUZZING_ENGINE} -lc++
fuzz_dname_to_str_LDADD += ${LIB_FUZZING_ENGINE} -lc++
fuzz_dname_from_str_LDADD += ${LIB_FUZZING_ENGINE} -lc++
else
......@@ -63,6 +75,12 @@ fuzz_packet_LDFLAGS = ${fuzzer_LDFLAGS}
fuzz_zscanner_CPPFLAGS += ${fuzzer_CFLAGS}
fuzz_zscanner_LDFLAGS = ${fuzzer_LDFLAGS}
fuzz_dname_to_str_CPPFLAGS += ${fuzzer_CFLAGS}
fuzz_dname_to_str_LDFLAGS = ${fuzzer_LDFLAGS}
fuzz_dname_from_str_CPPFLAGS += ${fuzzer_CFLAGS}
fuzz_dname_from_str_LDFLAGS = ${fuzzer_LDFLAGS}
# Ensure that fuzzers execute successfully with a benign input
TESTS = check/check_fuzzers.test
......@@ -70,8 +88,10 @@ EXTRA_DIST = check/check_fuzzers.test
else
fuzz_packet_SOURCES += main.c
fuzz_zscanner_SOURCES += main.c
fuzz_packet_SOURCES += main.c
fuzz_zscanner_SOURCES += main.c
fuzz_dname_to_str_SOURCES += main.c
fuzz_dname_from_str_SOURCES += main.c
TESTS = $(FUZZERS)
......
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <string.h>
#include "libknot/dname.h"
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
// Prepare 0-terminated dname string.
char *txt = malloc(size + 1);
if (txt == NULL) {
return 0;
}
memcpy(txt, data, size);
txt[size] = '\0';
// Transform the input.
uint8_t dname[KNOT_DNAME_MAXLEN];
(void)knot_dname_from_str(dname, txt, sizeof(dname));
free(txt);
return 0;
}
*.*a.a*a.**.
\ No newline at end of file
\000\0320\ \\\"\.\@\*.
\ No newline at end of file
_a.b-c./d.
\ No newline at end of file
\000\001\002\003\004\005\006\007\008\009\010\011\012\013\014\015\016\017\018\019
\ No newline at end of file
\020\021\022\023\024\025\026\027\028\029\030\031\032\033\034\035\036\037\038\039
\ No newline at end of file
\040\041\042\043\044\045\046\047\048\049\050\051\052\053\054\055\056\057\058\059
\ No newline at end of file
\060\061\062\063\064\065\066\067\068\069\070\071\072\073\074\075\076\077\078\079
\ No newline at end of file
\080\081\082\083\084\085\086\087\088\089\090\091\092\093\094\095\096\097\098\099
\ No newline at end of file
\100\101\102\103\104\105\106\107\108\109\110\111\112\113\114\115\116\117\118\119
\ No newline at end of file
\120\121\122\123\124\125\126\127\128\129\130\131\132\133\134\135\136\137\138\139
\ No newline at end of file
\140\141\142\143\144\145\146\147\148\149\150\151\152\153\154\155\156\157\158\159
\ No newline at end of file
\160\161\162\163\164\165\166\167\168\169\170\171\172\173\174\175\176\177\178\179
\ No newline at end of file
\180\181\182\183\184\185\186\187\188\189\190\191\192\193\194\195\196\197\198\199
\ No newline at end of file
\200\201\202\203\204\205\206\207\208\209\210\211\212\213\214\215\216\217\218\219
\ No newline at end of file
\220\221\222\223\224\225\226\227\228\229\230\231\232\233\234\235\236\237\238\239
\ No newline at end of file
\240\241\242\243\244\245\246\247\248\249\250\251\252\253\254\255
\ No newline at end of file
12345678901234567890123456789012345678901234567890123456789012\063
\ No newline at end of file
1234567890123456789012345678901234567890123456789.1234567890123456789012345678901234567890123456789.1234567890123456789012345678901234567890123456789.1234567890123456789012345678901234567890123456789.\#234567890123456789012345678901234567890123456789012\063
\ No newline at end of file
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "libknot/dname.h"
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
// Skip invalid dnames.
if (knot_dname_wire_check(data, data + size, NULL) <= 0) {
return 0;
}
// Transform the input.
char txt[KNOT_DNAME_TXT_MAXLEN + 1];
(void)knot_dname_to_str(txt, (const knot_dname_t *)data, sizeof(txt));
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment