mirror of
https://github.com/zeromq/libzmq.git
synced 2025-03-12 09:06:26 +00:00
Merge pull request #4022 from bluca/fuzzers
Problem: test_socket_options_fuzzer does not work
This commit is contained in:
commit
8cc56d9f0f
@ -761,7 +761,8 @@ int zmq::options_t::setsockopt (int option_,
|
||||
|
||||
case ZMQ_METADATA:
|
||||
if (optvallen_ > 0 && !is_int) {
|
||||
const std::string s (static_cast<const char *> (optval_));
|
||||
const std::string s (static_cast<const char *> (optval_),
|
||||
optvallen_);
|
||||
const size_t pos = s.find (':');
|
||||
if (pos != std::string::npos && pos != 0
|
||||
&& pos != s.length () - 1) {
|
||||
|
@ -31,31 +31,36 @@
|
||||
#include <fuzzer/FuzzedDataProvider.h>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "testutil.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)
|
||||
{
|
||||
setup_test_context ();
|
||||
void *s = test_context_socket (ZMQ_XPUB);
|
||||
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
|
||||
((uint8_t *)data)[size - 1] = 0;
|
||||
if (!size)
|
||||
return 0;
|
||||
|
||||
for (option = ZMQ_AFFINITY; option < ZMQ_BINDTODEVICE + 1; ++option) {
|
||||
uint8_t out[512];
|
||||
size_t out_size = 512;
|
||||
for (option = ZMQ_AFFINITY; option <= LAST_OPTION; ++option) {
|
||||
uint8_t out[8192];
|
||||
size_t out_size = 8192;
|
||||
|
||||
zmq_setsockopt(s, option, data, size);
|
||||
zmq_getsockopt(s, option, out, &out_size);
|
||||
zmq_setsockopt (server, option, data, size);
|
||||
zmq_getsockopt (server, option, out, &out_size);
|
||||
}
|
||||
|
||||
test_context_socket_close_zero_linger (s);
|
||||
teardown_test_context ();
|
||||
zmq_close (server);
|
||||
zmq_ctx_term (ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -66,8 +71,8 @@ void test_socket_options_fuzzer ()
|
||||
uint8_t **data;
|
||||
size_t *len, num_cases = 0;
|
||||
if (fuzzer_corpus_encode (
|
||||
"tests/libzmq-fuzz-corpora/test_socket_options_fuzzer_seed_corpus", &data,
|
||||
&len, &num_cases)
|
||||
"tests/libzmq-fuzz-corpora/test_socket_options_fuzzer_seed_corpus",
|
||||
&data, &len, &num_cases)
|
||||
!= 0)
|
||||
exit (77);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user