diff options
author | Daniel Salzman <daniel.salzman@nic.cz> | 2018-03-02 14:39:03 +0100 |
---|---|---|
committer | Daniel Salzman <daniel.salzman@nic.cz> | 2018-03-02 15:49:27 +0100 |
commit | 2c9c7bd68ee3082c051cf5aeafc02006171290a1 (patch) | |
tree | 484bc831eead3805ebf277eca66da9b680446ffd | |
parent | tests-fuzz: add AFL detection to fuzz_packet and fuzz_zscanner (diff) | |
download | knot-2c9c7bd68ee3082c051cf5aeafc02006171290a1.tar.xz knot-2c9c7bd68ee3082c051cf5aeafc02006171290a1.zip |
tests-fuzz: replace asserts with regular checks to mute warnings
-rw-r--r-- | tests-fuzz/fuzz_packet.c | 8 | ||||
-rw-r--r-- | tests-fuzz/fuzz_zscanner.c | 14 | ||||
-rw-r--r-- | tests-fuzz/main.c | 19 |
3 files changed, 24 insertions, 17 deletions
diff --git a/tests-fuzz/fuzz_packet.c b/tests-fuzz/fuzz_packet.c index ad9c086ab..61362c2f1 100644 --- a/tests-fuzz/fuzz_packet.c +++ b/tests-fuzz/fuzz_packet.c @@ -14,7 +14,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include <assert.h> #include <stdint.h> #include "libknot/libknot.h" @@ -25,9 +24,10 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) memcpy(copy, data, size); knot_pkt_t *pkt = knot_pkt_new(copy, size, NULL); - assert(pkt); - knot_pkt_parse(pkt, 0); - knot_pkt_free(pkt); + if (pkt != NULL) { + knot_pkt_parse(pkt, 0); + knot_pkt_free(pkt); + } return 0; } diff --git a/tests-fuzz/fuzz_zscanner.c b/tests-fuzz/fuzz_zscanner.c index baccde2cb..4e664a37f 100644 --- a/tests-fuzz/fuzz_zscanner.c +++ b/tests-fuzz/fuzz_zscanner.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> +/* 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 @@ -14,19 +14,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include <assert.h> #include <stdint.h> #include "zscanner/scanner.h" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - zs_scanner_t s = { 0 }; - assert(zs_init(&s, ".", 1, 0) == 0); - assert(zs_set_input_string(&s, (const char *)data, size) == 0); - - zs_parse_all(&s); - + zs_scanner_t s; + if (zs_init(&s, ".", 1, 0) == 0 && + zs_set_input_string(&s, (const char *)data, size) == 0) { + zs_parse_all(&s); + } zs_deinit(&s); return 0; diff --git a/tests-fuzz/main.c b/tests-fuzz/main.c index 55694e34e..e8eb42883 100644 --- a/tests-fuzz/main.c +++ b/tests-fuzz/main.c @@ -20,7 +20,6 @@ * DEALINGS IN THE SOFTWARE. */ -#include <assert.h> #include <stdio.h> #include <unistd.h> #include <stdlib.h> @@ -51,7 +50,9 @@ static void test_all_from(const char *dirname) char fname[strlen(dirname) + strlen(dp->d_name) + 2]; int ret = snprintf(fname, sizeof(fname), "%s/%s", dirname, dp->d_name); - assert(ret > 0 && ret < sizeof(fname)); + if (ret < 0 || ret >= sizeof(fname)) { + fprintf(stderr, "Invalid path %s/%s\n", dirname, dp->d_name); + } int fd; if ((fd = open(fname, O_RDONLY)) == -1) { @@ -67,7 +68,11 @@ static void test_all_from(const char *dirname) } uint8_t *data = malloc(st.st_size); - assert(data); + if (data == NULL) { + fprintf(stderr, "Failed to stat %d (%d)\n", fd, ENOMEM); + close(fd); + continue; + } ssize_t n; if ((n = read(fd, data, st.st_size)) == st.st_size) { @@ -98,12 +103,16 @@ int main(int argc, char **argv) } int ret = snprintf(corporadir, sizeof(corporadir), SRCDIR "/%s.in", target); - assert(ret > 0 && ret < sizeof(corporadir)); + if (ret < 0 || ret >= sizeof(corporadir)) { + fprintf(stderr, "Invalid path %s/%s\n", SRCDIR "/%s.in", target); + } test_all_from(corporadir); ret = snprintf(corporadir, sizeof(corporadir), SRCDIR "/%s.repro", target); - assert(ret > 0 && ret < sizeof(corporadir)); + if (ret < 0 || ret >= sizeof(corporadir)) { + fprintf(stderr, "Invalid path %s/%s\n", SRCDIR "/%s.repro", target); + } test_all_from(corporadir); |