mirror of
https://github.com/zeromq/libzmq.git
synced 2025-01-31 14:39:55 +01:00
Problem: we want to have multiple seed corpora per fuzzer binary
Solution: store them each as a single line in the text file and convert them at install time
This commit is contained in:
parent
c4fd6dfea7
commit
9ab3fbeee2
27
Makefile.am
27
Makefile.am
@ -1186,22 +1186,30 @@ install-data-hook:
|
||||
$(LN_S) -r -f $(DESTDIR)/$(FUZZINGdir)/zmtp.dict $(DESTDIR)/$(FUZZINGdir)/test_bind_null_fuzzer.dict
|
||||
$(LN_S) -r -f $(DESTDIR)/$(FUZZINGdir)/zmtp.dict $(DESTDIR)/$(FUZZINGdir)/test_connect_curve_fuzzer.dict
|
||||
$(LN_S) -r -f $(DESTDIR)/$(FUZZINGdir)/zmtp.dict $(DESTDIR)/$(FUZZINGdir)/test_connect_null_fuzzer.dict
|
||||
$(shell cat $(DESTDIR)/$(FUZZINGdir)/test_bind_curve_fuzzer.txt | perl -e 'print pack "H*", <STDIN>' > $(DESTDIR)/$(FUZZINGdir)/test_bind_curve_fuzzer.seed; \
|
||||
$(shell while read -r test; do \
|
||||
echo -n $$test | perl -e 'print pack "H*", <STDIN>' > $(DESTDIR)/$(FUZZINGdir)/test_bind_curve_fuzzer.seed; \
|
||||
export fn=$$(cat $(DESTDIR)/$(FUZZINGdir)/test_bind_curve_fuzzer.seed | sha1sum | awk '{print $$1}'); \
|
||||
mv $(DESTDIR)/$(FUZZINGdir)/test_bind_curve_fuzzer.seed $(DESTDIR)/$(FUZZINGdir)/$$fn; \
|
||||
zip -j -m --quiet $(DESTDIR)/$(FUZZINGdir)/test_bind_curve_fuzzer_seed_corpus.zip $(DESTDIR)/$(FUZZINGdir)/$$fn)
|
||||
$(shell cat $(DESTDIR)/$(FUZZINGdir)/test_bind_null_fuzzer.txt | perl -e 'print pack "H*", <STDIN>' > $(DESTDIR)/$(FUZZINGdir)/test_bind_null_fuzzer.seed; \
|
||||
zip -j -m -g --quiet $(DESTDIR)/$(FUZZINGdir)/test_bind_curve_fuzzer_seed_corpus.zip $(DESTDIR)/$(FUZZINGdir)/$$fn; \
|
||||
done < $(DESTDIR)/$(FUZZINGdir)/test_bind_curve_fuzzer.txt)
|
||||
$(shell while read -r test; do \
|
||||
echo -n $$test | perl -e 'print pack "H*", <STDIN>' > $(DESTDIR)/$(FUZZINGdir)/test_bind_null_fuzzer.seed; \
|
||||
export fn=$$(cat $(DESTDIR)/$(FUZZINGdir)/test_bind_null_fuzzer.seed | sha1sum | awk '{print $$1}'); \
|
||||
mv $(DESTDIR)/$(FUZZINGdir)/test_bind_null_fuzzer.seed $(DESTDIR)/$(FUZZINGdir)/$$fn; \
|
||||
zip -j -m --quiet $(DESTDIR)/$(FUZZINGdir)/test_bind_null_fuzzer_seed_corpus.zip $(DESTDIR)/$(FUZZINGdir)/$$fn)
|
||||
$(shell cat $(DESTDIR)/$(FUZZINGdir)/test_connect_curve_fuzzer.txt | perl -e 'print pack "H*", <STDIN>' > $(DESTDIR)/$(FUZZINGdir)/test_connect_curve_fuzzer.seed; \
|
||||
zip -j -m -g --quiet $(DESTDIR)/$(FUZZINGdir)/test_bind_null_fuzzer_seed_corpus.zip $(DESTDIR)/$(FUZZINGdir)/$$fn; \
|
||||
done < $(DESTDIR)/$(FUZZINGdir)/test_bind_null_fuzzer.txt)
|
||||
$(shell while read -r test; do \
|
||||
echo -n $$test | perl -e 'print pack "H*", <STDIN>' > $(DESTDIR)/$(FUZZINGdir)/test_connect_curve_fuzzer.seed; \
|
||||
export fn=$$(cat $(DESTDIR)/$(FUZZINGdir)/test_connect_curve_fuzzer.seed | sha1sum | awk '{print $$1}'); \
|
||||
mv $(DESTDIR)/$(FUZZINGdir)/test_connect_curve_fuzzer.seed $(DESTDIR)/$(FUZZINGdir)/$$fn; \
|
||||
zip -j -m --quiet $(DESTDIR)/$(FUZZINGdir)/test_connect_curve_fuzzer_seed_corpus.zip $(DESTDIR)/$(FUZZINGdir)/$$fn)
|
||||
$(shell cat $(DESTDIR)/$(FUZZINGdir)/test_connect_null_fuzzer.txt | perl -e 'print pack "H*", <STDIN>' > $(DESTDIR)/$(FUZZINGdir)/test_connect_null_fuzzer.seed; \
|
||||
zip -j -m -g --quiet $(DESTDIR)/$(FUZZINGdir)/test_connect_curve_fuzzer_seed_corpus.zip $(DESTDIR)/$(FUZZINGdir)/$$fn; \
|
||||
done < $(DESTDIR)/$(FUZZINGdir)/test_connect_curve_fuzzer.txt)
|
||||
$(shell while read -r test; do \
|
||||
echo -n $$test | perl -e 'print pack "H*", <STDIN>' > $(DESTDIR)/$(FUZZINGdir)/test_connect_null_fuzzer.seed; \
|
||||
export fn=$$(cat $(DESTDIR)/$(FUZZINGdir)/test_connect_null_fuzzer.seed | sha1sum | awk '{print $$1}'); \
|
||||
mv $(DESTDIR)/$(FUZZINGdir)/test_connect_null_fuzzer.seed $(DESTDIR)/$(FUZZINGdir)/$$fn; \
|
||||
zip -j -m --quiet $(DESTDIR)/$(FUZZINGdir)/test_connect_null_fuzzer_seed_corpus.zip $(DESTDIR)/$(FUZZINGdir)/$$fn)
|
||||
zip -j -m -g --quiet $(DESTDIR)/$(FUZZINGdir)/test_connect_null_fuzzer_seed_corpus.zip $(DESTDIR)/$(FUZZINGdir)/$$fn; \
|
||||
done < $(DESTDIR)/$(FUZZINGdir)/test_connect_null_fuzzer.txt)
|
||||
rm -f $(DESTDIR)/$(FUZZINGdir)/*.txt
|
||||
else
|
||||
test_apps += tests/test_bind_null_fuzzer \
|
||||
@ -1353,6 +1361,9 @@ EXTRA_DIST = \
|
||||
src/version.rc.in \
|
||||
tests/CMakeLists.txt \
|
||||
tests/test_pair_tcp_cap_net_admin.cpp \
|
||||
tests/fuzzer_corpora/endpoint.dict tests/fuzzer_corpora/zmtp.dict \
|
||||
tests/fuzzer_corpora/test_bind_curve_fuzzer.txt tests/fuzzer_corpora/test_bind_null_fuzzer.txt \
|
||||
tests/fuzzer_corpora/test_connect_curve_fuzzer.txt tests/fuzzer_corpora/test_connect_null_fuzzer.txt \
|
||||
unittests/CMakeLists.txt \
|
||||
tools/curve_keygen.cpp
|
||||
|
||||
|
@ -14,6 +14,7 @@ if [ $BUILD_TYPE == "default" ]; then
|
||||
CONFIG_OPTS+=("LDFLAGS=-L${BUILD_PREFIX}/lib")
|
||||
CONFIG_OPTS+=("PKG_CONFIG_PATH=${BUILD_PREFIX}/lib/pkgconfig")
|
||||
CONFIG_OPTS+=("--prefix=${BUILD_PREFIX}")
|
||||
CHECK="distcheck"
|
||||
|
||||
if [ -n "$ADDRESS_SANITIZER" ] && [ "$ADDRESS_SANITIZER" == "enabled" ]; then
|
||||
CONFIG_OPTS+=("--enable-address-sanitizer=yes")
|
||||
@ -22,6 +23,8 @@ if [ $BUILD_TYPE == "default" ]; then
|
||||
# workaround for linker problem with ASAN options in GCC
|
||||
# http://stackoverflow.com/questions/37603238/fsanitize-not-using-gold-linker-in-gcc-6-1
|
||||
CONFIG_OPTS+=("LDFLAGS=-fuse-ld=gold")
|
||||
# distcheck does an out-of-tree build, and the fuzzer tests use a hard-coded relative path for simplicity
|
||||
CHECK="check"
|
||||
fi
|
||||
|
||||
if [ $USE_NSS == "yes" ]; then
|
||||
@ -79,7 +82,7 @@ if [ $BUILD_TYPE == "default" ]; then
|
||||
./autogen.sh &&
|
||||
./configure "${CONFIG_OPTS[@]}" &&
|
||||
export DISTCHECK_CONFIGURE_FLAGS="${CONFIG_OPTS[@]}" &&
|
||||
make VERBOSE=1 -j5 distcheck
|
||||
make VERBOSE=1 -j5 ${CHECK}
|
||||
) || exit 1
|
||||
else
|
||||
cd ./builds/${BUILD_TYPE} && ./ci_build.sh
|
||||
|
@ -1 +1 @@
|
||||
ff00000000000000017f03014355525645000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004c80548454c4c4f0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a5af606a040b3eb749b38aad3c43ea22f18b1659de5c3db1996b6f880d48e30e000000000000000108706d93931262db2e66acd402ecbe67b85aba0e696fe5d5ada13b14d2ab50917301acbb09f29f85b24c470915951d1ce2973288aca89cda8c484389bba97271a0ded05860f152a5c757b7bdd5849fa206000000000000011408494e495449415445e3d3dd23298ecbdc31d3b471a56f9235701b35296117c8f798a4013f1d3a11d4c4c254b1785ad9cc6f3e01b9387f95468fabe11bd45d73704a9653165e045c2a2baa48130e8d9d9745975fc7600c23679cc044b396a4a7f91c946acf744d072a00000000000000020e56c8aebfb1f9f33f989e76c2cebbe45e0fef500717436e64b53da90ac7d2af3ca8ebd5edbdfb896ed18126d2a4c2836861a935e089503cc5efbfc166b94e504a0cfff64c0410689fd669aa4c1b041cadb21910fe7af4323258461960d969d8c481b47959430732bdb6126d62ddf801b3db7d32c146e5b10bc83cd503fd75badad67e6370c7adb2996a3242b0210e82ef1947ab563a5333a60aaeae9fc7c968c6264a002b074d4553534147450000000000000003cc90b40b5bc78bcb00f8ad69dc162c4b387cf8b9ab2d334455b3a9
|
||||
ff00000000000000017f03014355525645000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004c80548454c4c4f0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a5af606a040b3eb749b38aad3c43ea22f18b1659de5c3db1996b6f880d48e30e000000000000000108706d93931262db2e66acd402ecbe67b85aba0e696fe5d5ada13b14d2ab50917301acbb09f29f85b24c470915951d1ce2973288aca89cda8c484389bba97271a0ded05860f152a5c757b7bdd5849fa206000000000000011408494e495449415445e3d3dd23298ecbdc31d3b471a56f9235701b35296117c8f798a4013f1d3a11d4c4c254b1785ad9cc6f3e01b9387f95468fabe11bd45d73704a9653165e045c2a2baa48130e8d9d9745975fc7600c23679cc044b396a4a7f91c946acf744d072a00000000000000020e56c8aebfb1f9f33f989e76c2cebbe45e0fef500717436e64b53da90ac7d2af3ca8ebd5edbdfb896ed18126d2a4c2836861a935e089503cc5efbfc166b94e504a0cfff64c0410689fd669aa4c1b041cadb21910fe7af4323258461960d969d8c481b47959430732bdb6126d62ddf801b3db7d32c146e5b10bc83cd503fd75badad67e6370c7adb2996a3242b0210e82ef1947ab563a5333a60aaeae9fc7c968c6264a002b074d4553534147450000000000000003cc90b40b5bc78bcb00f8ad69dc162c4b387cf8b9ab2d334455b3a9
|
||||
|
@ -1 +1 @@
|
||||
ff00000000000000017f03014e554c4c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004190552454144590b536f636b65742d5479706500000003535542040a09535542534352494245
|
||||
ff00000000000000017f03014e554c4c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004190552454144590b536f636b65742d5479706500000003535542040a09535542534352494245
|
||||
|
@ -1 +1 @@
|
||||
ff00000000000000017f03014355525645000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004a80757454c434f4d45b82e58be6c89e876fd91e236488b8d4bb37846d2cd38e739264ea8ff66ca06f5930d70920b8429505844f064be5d8c977078b8dd135e340cd8c7f276293ebf9c45bd6b240c0d9c15b8fde2defb11f4f49c864695f07c3456e855dd7eef6ee371dbda86b05f3db853781ce741ecacffcc50a7a8176ec8ebd3c2692beb79977b143f90c77a13eee6ed5282ee27ad45f36fd08a31ecd205dfa9e7b6887fe2ea1ccc0432055245414459000000000000000171f53d3270589095cd304baeedfe0a326ed8488d0173dded2dca5b996d0d31e6469d5f4e0026074d4553534147450000000000000002fbb1f34c99e8d2f5a2cb37dfb01b0a74f2d1c0439f5c0026074d455353414745000000000000000388166e23cf25cda98b8b3f635039b468bb222cbfec30
|
||||
ff00000000000000017f03014355525645000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004a80757454c434f4d45b82e58be6c89e876fd91e236488b8d4bb37846d2cd38e739264ea8ff66ca06f5930d70920b8429505844f064be5d8c977078b8dd135e340cd8c7f276293ebf9c45bd6b240c0d9c15b8fde2defb11f4f49c864695f07c3456e855dd7eef6ee371dbda86b05f3db853781ce741ecacffcc50a7a8176ec8ebd3c2692beb79977b143f90c77a13eee6ed5282ee27ad45f36fd08a31ecd205dfa9e7b6887fe2ea1ccc0432055245414459000000000000000171f53d3270589095cd304baeedfe0a326ed8488d0173dded2dca5b996d0d31e6469d5f4e0026074d4553534147450000000000000002fbb1f34c99e8d2f5a2cb37dfb01b0a74f2d1c0439f5c0026074d455353414745000000000000000388166e23cf25cda98b8b3f635039b468bb222cbfec30
|
||||
|
@ -1 +1 @@
|
||||
ff00000000000000017f03014e554c4c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041a0552454144590b536f636b65742d547970650000000458505542000568656c6c6f0005776f726c64
|
||||
ff00000000000000017f03014e554c4c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041a0552454144590b536f636b65742d547970650000000458505542000568656c6c6f0005776f726c64
|
||||
|
@ -82,16 +82,21 @@ extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
|
||||
#ifndef ZMQ_USE_FUZZING_ENGINE
|
||||
void test_bind_curve_fuzzer ()
|
||||
{
|
||||
uint8_t *data;
|
||||
size_t len;
|
||||
uint8_t **data;
|
||||
size_t *len, num_cases = 0;
|
||||
if (fuzzer_corpus_encode ("tests/fuzzer_corpora/test_bind_curve_fuzzer.txt",
|
||||
&data, &len)
|
||||
&data, &len, &num_cases)
|
||||
!= 0)
|
||||
exit (77);
|
||||
|
||||
TEST_ASSERT_SUCCESS_ERRNO (LLVMFuzzerTestOneInput (data, len));
|
||||
while (num_cases-- > 0) {
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
LLVMFuzzerTestOneInput (data[num_cases], len[num_cases]));
|
||||
free (data[num_cases]);
|
||||
}
|
||||
|
||||
free (data);
|
||||
free (len);
|
||||
}
|
||||
|
||||
int main (int argc, char **argv)
|
||||
|
@ -75,21 +75,26 @@ extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
|
||||
#ifndef ZMQ_USE_FUZZING_ENGINE
|
||||
void test_bind_null_fuzzer ()
|
||||
{
|
||||
uint8_t *data;
|
||||
size_t len;
|
||||
uint8_t **data;
|
||||
size_t *len, num_cases = 0;
|
||||
if (fuzzer_corpus_encode ("tests/fuzzer_corpora/test_bind_null_fuzzer.txt",
|
||||
&data, &len)
|
||||
&data, &len, &num_cases)
|
||||
!= 0)
|
||||
exit (77);
|
||||
|
||||
TEST_ASSERT_SUCCESS_ERRNO (LLVMFuzzerTestOneInput (data, len));
|
||||
while (num_cases-- > 0) {
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
LLVMFuzzerTestOneInput (data[num_cases], len[num_cases]));
|
||||
free (data[num_cases]);
|
||||
}
|
||||
|
||||
free (data);
|
||||
free (len);
|
||||
}
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
setup_test_environment ();
|
||||
setup_test_environment (0);
|
||||
|
||||
UNITY_BEGIN ();
|
||||
RUN_TEST (test_bind_null_fuzzer);
|
||||
|
@ -86,16 +86,22 @@ extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
|
||||
#ifndef ZMQ_USE_FUZZING_ENGINE
|
||||
void test_connect_curve_fuzzer ()
|
||||
{
|
||||
uint8_t *data;
|
||||
size_t len;
|
||||
uint8_t **data;
|
||||
size_t *len, num_cases = 0;
|
||||
if (fuzzer_corpus_encode (
|
||||
"tests/fuzzer_corpora/test_connect_curve_fuzzer.txt", &data, &len)
|
||||
"tests/fuzzer_corpora/test_connect_curve_fuzzer.txt", &data, &len,
|
||||
&num_cases)
|
||||
!= 0)
|
||||
exit (77);
|
||||
|
||||
TEST_ASSERT_SUCCESS_ERRNO (LLVMFuzzerTestOneInput (data, len));
|
||||
while (num_cases-- > 0) {
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
LLVMFuzzerTestOneInput (data[num_cases], len[num_cases]));
|
||||
free (data[num_cases]);
|
||||
}
|
||||
|
||||
free (data);
|
||||
free (len);
|
||||
}
|
||||
|
||||
int main (int argc, char **argv)
|
||||
|
@ -86,16 +86,22 @@ extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
|
||||
#ifndef ZMQ_USE_FUZZING_ENGINE
|
||||
void test_connect_null_fuzzer ()
|
||||
{
|
||||
uint8_t *data;
|
||||
size_t len;
|
||||
uint8_t **data;
|
||||
size_t *len, num_cases = 0;
|
||||
if (fuzzer_corpus_encode (
|
||||
"tests/fuzzer_corpora/test_connect_null_fuzzer.txt", &data, &len)
|
||||
"tests/fuzzer_corpora/test_connect_null_fuzzer.txt", &data, &len,
|
||||
&num_cases)
|
||||
!= 0)
|
||||
exit (77);
|
||||
|
||||
TEST_ASSERT_SUCCESS_ERRNO (LLVMFuzzerTestOneInput (data, len));
|
||||
while (num_cases-- > 0) {
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
LLVMFuzzerTestOneInput (data[num_cases], len[num_cases]));
|
||||
free (data[num_cases]);
|
||||
}
|
||||
|
||||
free (data);
|
||||
free (len);
|
||||
}
|
||||
|
||||
int main (int argc, char **argv)
|
||||
|
@ -523,7 +523,10 @@ bool strneq (const char *lhs_, const char *rhs_)
|
||||
return strcmp (lhs_, rhs_) != 0;
|
||||
}
|
||||
|
||||
int fuzzer_corpus_encode (const char *filename, uint8_t **data, size_t *len)
|
||||
int fuzzer_corpus_encode (const char *filename,
|
||||
uint8_t ***data,
|
||||
size_t **len,
|
||||
size_t *num_cases)
|
||||
{
|
||||
TEST_ASSERT_NOT_NULL (filename);
|
||||
TEST_ASSERT_NOT_NULL (data);
|
||||
@ -532,24 +535,38 @@ int fuzzer_corpus_encode (const char *filename, uint8_t **data, size_t *len)
|
||||
if (!f)
|
||||
return -1;
|
||||
fseek (f, 0, SEEK_END);
|
||||
size_t text_len = ftell (f);
|
||||
size_t text_len = ftell (f) + 1;
|
||||
fseek (f, 0, SEEK_SET);
|
||||
char *buf = (char *) malloc (text_len);
|
||||
TEST_ASSERT_NOT_NULL (buf);
|
||||
size_t read = fread (buf, 1, text_len, f);
|
||||
fclose (f);
|
||||
TEST_ASSERT_EQUAL_INT (read, text_len);
|
||||
|
||||
*len = NULL;
|
||||
*data = NULL;
|
||||
*num_cases = 0;
|
||||
// Convert to binary format, corpus is stored in ascii (hex)
|
||||
*len = text_len / 2;
|
||||
*data = (unsigned char *) malloc (*len);
|
||||
TEST_ASSERT_NOT_NULL (*data);
|
||||
const char *pos = buf;
|
||||
for (size_t count = 0; count < *len; ++count, pos += 2) {
|
||||
char tmp[3] = {pos[0], pos[1], 0};
|
||||
(*data)[count] = (uint8_t) strtol (tmp, NULL, 16);
|
||||
while (fgets (buf, (int) text_len, f)) {
|
||||
*len = (size_t *) realloc (*len, (*num_cases + 1) * sizeof (size_t));
|
||||
TEST_ASSERT_NOT_NULL (*len);
|
||||
*(*len + *num_cases) = strlen (buf) / 2;
|
||||
*data =
|
||||
(uint8_t **) realloc (*data, (*num_cases + 1) * sizeof (uint8_t *));
|
||||
TEST_ASSERT_NOT_NULL (*data);
|
||||
*(*data + *num_cases) =
|
||||
(uint8_t *) malloc (*(*len + *num_cases) * sizeof (uint8_t));
|
||||
TEST_ASSERT_NOT_NULL (*(*data + *num_cases));
|
||||
|
||||
const char *pos = buf;
|
||||
for (size_t count = 0; count < *(*len + *num_cases);
|
||||
++count, pos += 2) {
|
||||
char tmp[3] = {pos[0], pos[1], 0};
|
||||
*(*(*data + *num_cases) + count) = (uint8_t) strtol (tmp, NULL, 16);
|
||||
}
|
||||
(*num_cases)++;
|
||||
}
|
||||
|
||||
|
||||
free (buf);
|
||||
fclose (f);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -228,6 +228,9 @@ fd_t bind_socket_resolve_port (const char *address_,
|
||||
const int af_ = AF_INET,
|
||||
const int protocol_ = IPPROTO_TCP);
|
||||
|
||||
int fuzzer_corpus_encode (const char *filename, uint8_t **data, size_t *len);
|
||||
int fuzzer_corpus_encode (const char *filename,
|
||||
uint8_t ***data,
|
||||
size_t **len,
|
||||
size_t *num_cases);
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user