Skip to content
Snippets Groups Projects
Commit 2c9c7bd6 authored by Daniel Salzman's avatar Daniel Salzman
Browse files

tests-fuzz: replace asserts with regular checks to mute warnings

parent 09dbbd94
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -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;
}
/* 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;
......
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment