]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3605] use server listener
authorRazvan Becheriu <razvan@isc.org>
Tue, 22 Oct 2024 14:39:57 +0000 (17:39 +0300)
committerAndrei Pavel <andrei@isc.org>
Wed, 23 Oct 2024 13:40:37 +0000 (16:40 +0300)
fuzz/fuzz_http_endpoint_kea_dhcp4.cc
fuzz/fuzz_http_endpoint_kea_dhcp6.cc
fuzz/fuzz_unix_socket_kea_dhcp4.cc
fuzz/fuzz_unix_socket_kea_dhcp6.cc
src/lib/config/http_command_mgr.cc

index 5fae753fd827a1352e09d4f725bf9eca3a157a00..d17107e392f0074de6ad7694e16775d539b1a1a7 100644 (file)
@@ -45,14 +45,10 @@ static pid_t const PID(getpid());
 static int const PORT(getpid() % 1000 + 2000);
 static string const PID_STR(to_string(PID));
 static string const PORT_STR(to_string(PORT));
+static string const ADDRESS("0.0.0.0");
 static string const KEA_DHCP4_CONF(KEA_FUZZ_DIR + "/kea-dhcp4-" + PID_STR + ".conf");
 static string const KEA_DHCP4_CSV(KEA_FUZZ_DIR + "/kea-dhcp4-" + PID_STR + ".csv");
 
-void timeoutHandler() {
-    cerr << "Timeout occurred while fuzzing!" << endl;
-    abort();
-}
-
 /// @brief Represents HTTP POST request with JSON body.
 ///
 /// In addition to the requirements specified by the @ref PostHttpRequest
@@ -97,8 +93,6 @@ struct PostHttpRequestBytes : PostHttpRequest {
 
 using PostHttpRequestBytesPtr = boost::shared_ptr<PostHttpRequestBytes>;
 
-ThreadPool<function<void()>> THREAD_POOL;
-
 }  // namespace
 
 extern "C" {
@@ -113,13 +107,14 @@ LLVMFuzzerInitialize() {
         "Dhcp4": {
           "control-sockets": [
             {
-              "socket-address": "0.0.0.0",
+              "socket-address": ")" + ADDRESS + R"(",
               "socket-port": )" + PORT_STR + R"(,
               "socket-type": "http"
             }
           ],
           "lease-database": {
             "name": ")" + KEA_DHCP4_CSV + R"(",
+            "persist": false,
             "type": "memfile"
           }
         }
@@ -148,22 +143,9 @@ LLVMFuzzerTestOneInput(uint8_t const* data, size_t size) {
     ControlledDhcpv4Srv server;
     server.init(KEA_DHCP4_CONF);
 
-    string const address("127.0.0.1");
-    int const port(18000);
-    int const timeout(100000);
-
-    CmdHttpListener listener(IOAddress(address), port);
-    MultiThreadingMgr::instance().setMode(true);
-
-    // Start the server.
-    listener.start();
-
-    // Create a client and specify the URL on which the server can be reached.
-    IOServicePtr io_service(new IOService());
-    IntervalTimer run_io_service_timer(io_service);
-    HttpClient client(io_service, false);
+    HttpClient client(ControlledDhcpv4Srv::getInstance()->getIOService(), false);
     stringstream ss;
-    ss << "http://" << address << ":" << port;
+    ss << "http://" << ADDRESS << ":" << PORT_STR;
     Url url(ss.str());
 
     // Initiate request to the server.
@@ -182,14 +164,7 @@ LLVMFuzzerTestOneInput(uint8_t const* data, size_t size) {
            string const&) {
         });
 
-    // Actually trigger the requests. The requests should be handlded by the
-    // server one after another. While the first request is being processed
-    // the server should queue another one.
-    io_service->getInternalIOService().reset();
-    run_io_service_timer.setup(&timeoutHandler, timeout, IntervalTimer::ONE_SHOT);
-    io_service->runOne();
-    io_service->getInternalIOService().reset();
-    io_service->poll();
+    ControlledDhcpv4Srv::getInstance()->getIOService()->poll();
 
     // Make sure that the received responses are different. We check that by
     // comparing value of the sequence parameters.
@@ -200,10 +175,8 @@ LLVMFuzzerTestOneInput(uint8_t const* data, size_t size) {
             cout << "no response" << endl;
         }
     }
-    listener.stop();
     client.stop();
-    run_io_service_timer.cancel();
-    io_service->poll();
+    ControlledDhcpv4Srv::getInstance()->getIOService()->poll();
     MultiThreadingMgr::instance().setMode(false);
 
     return 0;
index be2c78dbb159bbf8de42c8f878258e2774de1908..08f4f7e79614b0f28eca8b98290135b6ff92ce9e 100644 (file)
@@ -45,14 +45,10 @@ static pid_t const PID(getpid());
 static int const PORT(getpid() % 1000 + 2000);
 static string const PID_STR(to_string(PID));
 static string const PORT_STR(to_string(PORT));
+static string const ADDRESS("::");
 static string const KEA_DHCP6_CONF(KEA_FUZZ_DIR + "/kea-dhcp6-" + PID_STR + ".conf");
 static string const KEA_DHCP6_CSV(KEA_FUZZ_DIR + "/kea-dhcp6-" + PID_STR + ".csv");
 
-void timeoutHandler() {
-    cerr << "Timeout occurred while fuzzing!" << endl;
-    abort();
-}
-
 /// @brief Represents HTTP POST request with JSON body.
 ///
 /// In addition to the requirements specified by the @ref PostHttpRequest
@@ -97,8 +93,6 @@ struct PostHttpRequestBytes : PostHttpRequest {
 
 using PostHttpRequestBytesPtr = boost::shared_ptr<PostHttpRequestBytes>;
 
-ThreadPool<function<void()>> THREAD_POOL;
-
 }  // namespace
 
 extern "C" {
@@ -113,13 +107,14 @@ LLVMFuzzerInitialize() {
         "Dhcp6": {
           "control-sockets": [
             {
-              "socket-address": "0.0.0.0",
+              "socket-address": ")" + ADDRESS + R"(",
               "socket-port": )" + PORT_STR + R"(,
               "socket-type": "http"
             }
           ],
           "lease-database": {
             "name": ")" + KEA_DHCP6_CSV + R"(",
+            "persist": false,
             "type": "memfile"
           },
           "server-id": {
@@ -154,22 +149,9 @@ LLVMFuzzerTestOneInput(uint8_t const* data, size_t size) {
     ControlledDhcpv6Srv server;
     server.init(KEA_DHCP6_CONF);
 
-    string const address("127.0.0.1");
-    int const port(18000);
-    int const timeout(100000);
-
-    CmdHttpListener listener(IOAddress(address), port);
-    MultiThreadingMgr::instance().setMode(true);
-
-    // Start the server.
-    listener.start();
-
-    // Create a client and specify the URL on which the server can be reached.
-    IOServicePtr io_service(new IOService());
-    IntervalTimer run_io_service_timer(io_service);
-    HttpClient client(io_service, false);
+    HttpClient client(ControlledDhcpv6Srv::getInstance()->getIOService(), false);
     stringstream ss;
-    ss << "http://" << address << ":" << port;
+    ss << "http://[" << ADDRESS << "]:" << PORT_STR;
     Url url(ss.str());
 
     // Initiate request to the server.
@@ -188,14 +170,7 @@ LLVMFuzzerTestOneInput(uint8_t const* data, size_t size) {
            string const&) {
         });
 
-    // Actually trigger the requests. The requests should be handlded by the
-    // server one after another. While the first request is being processed
-    // the server should queue another one.
-    io_service->getInternalIOService().reset();
-    run_io_service_timer.setup(&timeoutHandler, timeout, IntervalTimer::ONE_SHOT);
-    io_service->runOne();
-    io_service->getInternalIOService().reset();
-    io_service->poll();
+    ControlledDhcpv6Srv::getInstance()->getIOService()->poll();
 
     // Make sure that the received responses are different. We check that by
     // comparing value of the sequence parameters.
@@ -206,10 +181,8 @@ LLVMFuzzerTestOneInput(uint8_t const* data, size_t size) {
             cout << "no response" << endl;
         }
     }
-    listener.stop();
     client.stop();
-    run_io_service_timer.cancel();
-    io_service->poll();
+    ControlledDhcpv6Srv::getInstance()->getIOService()->poll();
     MultiThreadingMgr::instance().setMode(false);
 
     return 0;
index c87124d5bca2ab637e7f724d3bd2e31a8ed22dac..2f0f0d5404d299ab30f00f8a9d95240b8a5f6c0d 100644 (file)
@@ -37,7 +37,6 @@ static string const KEA_DHCP4_CSV(KEA_FUZZ_DIR + "/kea-dhcp4-" + PID_STR + ".csv
 static string const SOCKET(KEA_FUZZ_DIR + "/kea-dhcp4-ctrl-" + PID_STR + ".sock");
 
 static UnixControlClient CLIENT;
-static IOServicePtr IO_SERVICE(new IOService());
 
 }  // namespace
 
@@ -60,6 +59,7 @@ LLVMFuzzerInitialize() {
           },
           "lease-database": {
             "name": ")" + KEA_DHCP4_CSV + R"(",
+            "persist": false,
             "type": "memfile"
           }
         }
index 021dcf48db5e130cea7772b400ece78ac0ee9b72..837aa27ba9e55f3adac11d4c18220a28cbca33dd 100644 (file)
@@ -37,7 +37,6 @@ static string const KEA_DHCP6_CSV(KEA_FUZZ_DIR + "/kea-dhcp6-" + PID_STR + ".csv
 static string const SOCKET(KEA_FUZZ_DIR + "/kea-dhcp6-ctrl-" + PID_STR + ".sock");
 
 static UnixControlClient CLIENT;
-static IOServicePtr IO_SERVICE(new IOService());
 
 }  // namespace
 
@@ -60,6 +59,7 @@ LLVMFuzzerInitialize() {
           },
           "lease-database": {
             "name": ")" + KEA_DHCP6_CSV + R"(",
+            "persist": false,
             "type": "memfile"
           },
           "server-id": {
index 2f396ae83e333e67832d5655eb5c44d3e92aedfe..e13cadebe8a0aecc70a71a58262e0335453616e4 100644 (file)
@@ -165,7 +165,7 @@ HttpCommandMgrImpl::close(bool remove) {
     ostringstream ep;
     if (current_config_) {
         use_https = !current_config_->getCertFile().empty();
-        ep << " bound to address " << current_config_->getSocketAddress()
+        ep << "bound to address " << current_config_->getSocketAddress()
            << " port " << current_config_->getSocketPort();
     }
     LOG_INFO(command_logger, HTTP_COMMAND_MGR_SERVICE_STOPPING)