Problem: test_bind_fuzzer clobbers working directory with random socket files

Solution: move to /tmp before running the test
This commit is contained in:
Luca Boccassi 2020-06-07 11:58:03 +01:00
parent b6bb3ef925
commit 1ffc21d378

View File

@ -39,6 +39,12 @@
// Test that zmq_bind can handle malformed strings // Test that zmq_bind can handle malformed strings
extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
{ {
// This test might create socket files, so move to /tmp to avoid clobbering
// the working directory with random filenames
char *pwd = get_current_dir_name ();
TEST_ASSERT_NOT_NULL (pwd);
TEST_ASSERT_SUCCESS_ERRNO (chdir ("/tmp"));
setup_test_context (); setup_test_context ();
std::string my_endpoint (reinterpret_cast<const char *> (data), size); std::string my_endpoint (reinterpret_cast<const char *> (data), size);
void *socket = test_context_socket (ZMQ_PUB); void *socket = test_context_socket (ZMQ_PUB);
@ -46,6 +52,8 @@ extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
test_context_socket_close_zero_linger (socket); test_context_socket_close_zero_linger (socket);
teardown_test_context (); teardown_test_context ();
TEST_ASSERT_SUCCESS_ERRNO (chdir (pwd));
free (pwd);
return 0; return 0;
} }