Fuzzing: db_dump alternate option fuzz targets

pull/2756/head
Roger A. Light 3 years ago
parent 8c98a6ded4
commit d8bc5df102

@ -2,7 +2,9 @@ R=../..
.PHONY: all clean
FUZZERS:= \
db_dump_fuzz_load
db_dump_fuzz_load \
db_dump_fuzz_load_client_stats \
db_dump_fuzz_load_stats
LOCAL_CPPFLAGS:=$(CPPFLAGS)
LOCAL_CXXFLAGS:=$(CXXFLAGS) -g -Wall -Werror -pthread
@ -14,7 +16,17 @@ all: $(FUZZERS)
db_dump_fuzz_load : db_dump_fuzz_load.cpp
$(CXX) $(LOCAL_CXXFLAGS) $(LOCAL_CPPFLAGS) $(LOCAL_LDFLAGS) -o $@ $^ $(LOCAL_LIBADD)
install $@ ${OUT}/$@
cp ${R}/fuzzing/corpora/db_dump_seed_corpus.zip ${OUT}/
cp ${R}/fuzzing/corpora/db_dump_seed_corpus.zip ${OUT}/$@_seed_corpus.zip
db_dump_fuzz_load_client_stats : db_dump_fuzz_load_client_stats.cpp
$(CXX) $(LOCAL_CXXFLAGS) $(LOCAL_CPPFLAGS) $(LOCAL_LDFLAGS) -o $@ $^ $(LOCAL_LIBADD)
install $@ ${OUT}/$@
cp ${R}/fuzzing/corpora/db_dump_seed_corpus.zip ${OUT}/$@_seed_corpus.zip
db_dump_fuzz_load_stats : db_dump_fuzz_load_stats.cpp
$(CXX) $(LOCAL_CXXFLAGS) $(LOCAL_CPPFLAGS) $(LOCAL_LDFLAGS) -o $@ $^ $(LOCAL_LIBADD)
install $@ ${OUT}/$@
cp ${R}/fuzzing/corpora/db_dump_seed_corpus.zip ${OUT}/$@_seed_corpus.zip
clean:
rm -f *.o $(FUZZERS)

@ -0,0 +1,64 @@
/*
Copyright (c) 2023 Cedalo GmbH
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License 2.0
and Eclipse Distribution License v1.0 which accompany this distribution.
The Eclipse Public License is available at
https://www.eclipse.org/legal/epl-2.0/
and the Eclipse Distribution License is available at
http://www.eclipse.org/org/documents/edl-v10.php.
SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
Contributors:
Roger Light - initial implementation and documentation.
*/
#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <unistd.h>
/*
* Test loading a file, with client stats
*/
/* The fuzz-only main function. */
extern "C" int db_dump_fuzz_main(int argc, char *argv[]);
void run_db_dump(char *filename)
{
char *argv[3];
int argc = 3;
argv[0] = strdup("mosquitto_db_dump");
argv[1] = strdup("--client-stats");
argv[2] = filename;
db_dump_fuzz_main(argc, argv);
free(argv[0]);
free(argv[1]);
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
char filename[100];
FILE *fptr;
snprintf(filename, sizeof(filename), "/tmp/db_dump_client_stats_%d.db", getpid());
fptr = fopen(filename, "wb");
if(!fptr) return 1;
fwrite(data, 1, size, fptr);
fclose(fptr);
run_db_dump(filename);
unlink(filename);
return 0;
}

@ -0,0 +1,64 @@
/*
Copyright (c) 2023 Cedalo GmbH
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License 2.0
and Eclipse Distribution License v1.0 which accompany this distribution.
The Eclipse Public License is available at
https://www.eclipse.org/legal/epl-2.0/
and the Eclipse Distribution License is available at
http://www.eclipse.org/org/documents/edl-v10.php.
SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
Contributors:
Roger Light - initial implementation and documentation.
*/
#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <unistd.h>
/*
* Test loading a file
*/
/* The fuzz-only main function. */
extern "C" int db_dump_fuzz_main(int argc, char *argv[]);
void run_db_dump(char *filename)
{
char *argv[3];
int argc = 3;
argv[0] = strdup("mosquitto_db_dump");
argv[1] = strdup("--stats");
argv[2] = filename;
db_dump_fuzz_main(argc, argv);
free(argv[0]);
free(argv[1]);
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
char filename[100];
FILE *fptr;
snprintf(filename, sizeof(filename), "/tmp/db_dump_stats_%d.db", getpid());
fptr = fopen(filename, "wb");
if(!fptr) return 1;
fwrite(data, 1, size, fptr);
fclose(fptr);
run_db_dump(filename);
unlink(filename);
return 0;
}
Loading…
Cancel
Save