0
0
mirror of https://github.com/zeromq/libzmq.git synced 2025-01-14 17:58:01 +08:00

Problem: test_socket_options_fuzzer does not work

Solution: fix it
This commit is contained in:
Luca Boccassi 2020-08-21 18:07:00 +01:00
parent 2fb04c1018
commit 5b0956c381

View File

@ -31,31 +31,36 @@
#include <fuzzer/FuzzedDataProvider.h> #include <fuzzer/FuzzedDataProvider.h>
#endif #endif
#include <string>
#include <stdlib.h>
#include "testutil.hpp" #include "testutil.hpp"
#include "testutil_unity.hpp" #include "testutil_unity.hpp"
#ifdef ZMQ_DISCONNECT_MSG
#define LAST_OPTION ZMQ_DISCONNECT_MSG
#else
#define LAST_OPTION ZMQ_BINDTODEVICE
#endif
extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
{ {
setup_test_context ();
void *s = test_context_socket (ZMQ_XPUB);
int option; int option;
void *ctx = zmq_ctx_new ();
TEST_ASSERT_NOT_NULL (ctx);
void *server = zmq_socket (ctx, ZMQ_XPUB);
TEST_ASSERT_NOT_NULL (server);
// A lot of options expect a well-formatted string if (!size)
((uint8_t *)data)[size - 1] = 0; return 0;
for (option = ZMQ_AFFINITY; option < ZMQ_BINDTODEVICE + 1; ++option) { for (option = ZMQ_AFFINITY; option <= LAST_OPTION; ++option) {
uint8_t out[512]; uint8_t out[8192];
size_t out_size = 512; size_t out_size = 8192;
zmq_setsockopt(s, option, data, size); zmq_setsockopt (server, option, data, size);
zmq_getsockopt(s, option, out, &out_size); zmq_getsockopt (server, option, out, &out_size);
} }
test_context_socket_close_zero_linger (s); zmq_close (server);
teardown_test_context (); zmq_ctx_term (ctx);
return 0; return 0;
} }
@ -66,8 +71,8 @@ void test_socket_options_fuzzer ()
uint8_t **data; uint8_t **data;
size_t *len, num_cases = 0; size_t *len, num_cases = 0;
if (fuzzer_corpus_encode ( if (fuzzer_corpus_encode (
"tests/libzmq-fuzz-corpora/test_socket_options_fuzzer_seed_corpus", &data, "tests/libzmq-fuzz-corpora/test_socket_options_fuzzer_seed_corpus",
&len, &num_cases) &data, &len, &num_cases)
!= 0) != 0)
exit (77); exit (77);