diff --git a/.github/workflows/ci-gcc48.yml b/.github/workflows/ci-gcc48.yml deleted file mode 100644 index 8f117fff..00000000 --- a/.github/workflows/ci-gcc48.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: g++ 4.8 build - -on: - push: - branches: [ '**' ] - pull_request: - branches: [ '**' ] - -permissions: - contents: read - -jobs: - build: - - runs-on: ci-gcc48 - if: ${{ github.repository != 'intel/pcm' }} - - steps: - - name: Harden Runner - uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1 - with: - egress-policy: audit - - - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 - - name: install simdjson - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 - with: - repository: simdjson/simdjson - path: src/simdjson - - name: Configure CMake - run: | - cmake --version - rm -rf ${{ github.workspace }}/build && mkdir ${{ github.workspace }}/build - cd ${{ github.workspace }}/build - cmake -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/build .. - - name: Build - run: | - g++ --version - cd ${{ github.workspace }}/build - make -j$(nproc) - - name: Install - run: | - cd ${{ github.workspace }}/build - make install -j$(nproc) diff --git a/.github/workflows/ci-gcc5.yml b/.github/workflows/ci-gcc5.yml deleted file mode 100644 index 109d620c..00000000 --- a/.github/workflows/ci-gcc5.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: g++ 5 build - -on: - push: - branches: [ '**' ] - pull_request: - branches: [ '**' ] - -permissions: - contents: read - -jobs: - build: - - runs-on: ci-gcc5 - if: ${{ github.repository != 'intel/pcm' }} - - steps: - - name: Harden Runner - uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1 - with: - egress-policy: audit - - - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 - - name: install simdjson - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 - with: - repository: simdjson/simdjson - path: src/simdjson - - name: Configure CMake - run: | - cmake --version - rm -rf ${{ github.workspace }}/build && mkdir ${{ github.workspace }}/build - cd ${{ github.workspace }}/build - cmake -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/build .. - - name: Build - run: | - g++ --version - cd ${{ github.workspace }}/build - make -j$(nproc) - - name: Install - run: | - cd ${{ github.workspace }}/build - make install -j$(nproc) - - name: upload-artifact - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3 - with: - name: PCMforLinuxGCC5 - path: build/bin/* diff --git a/.github/workflows/ci-gcc7.yml b/.github/workflows/ci-gcc7.yml index b58b097a..1cb4c54e 100644 --- a/.github/workflows/ci-gcc7.yml +++ b/.github/workflows/ci-gcc7.yml @@ -12,7 +12,7 @@ permissions: jobs: build: - runs-on: ci-gcc7 + runs-on: ci-gcc9 if: ${{ github.repository != 'intel/pcm' }} steps: @@ -21,26 +21,16 @@ jobs: with: egress-policy: audit - - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 - - name: install simdjson - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: - repository: simdjson/simdjson - path: src/simdjson + submodules: recursive - name: Configure CMake run: | cmake --version - rm -rf ${{ github.workspace }}/build && mkdir ${{ github.workspace }}/build - cd ${{ github.workspace }}/build - cmake -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/build .. - - name: Build - run: | - g++ --version - cd ${{ github.workspace }}/build - make -j$(nproc) - - name: Install + rm -rf ${{ github.workspace }}/build + CXX=g++-7 CC=gcc-7 cmake -B ${{ github.workspace }}/build -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/build + - name: Build and Install run: | + g++-7 --version cd ${{ github.workspace }}/build make install -j$(nproc) - - name: Diagnostic - run: date \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a7db0e4b..3002d81c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -50,8 +50,6 @@ if(UNIX) # LINUX, FREE_BSD, APPLE add_subdirectory(MacMSRDriver) include_directories("${CMAKE_SOURCE_DIR}/src/MacMSRDriver") # target_include_directories doesn't work target_link_libraries(PCM_SHARED PRIVATE PCM_STATIC_SILENT PcmMsr Threads::Threads) - elseif(LINUX) - target_link_libraries(PCM_SHARED PRIVATE PCM_STATIC_SILENT Threads::Threads asan) else() target_link_libraries(PCM_SHARED PRIVATE PCM_STATIC_SILENT Threads::Threads) endif() @@ -66,14 +64,21 @@ if(MSVC) file(GLOB WINDOWS_SOURCES winpmem/winpmem.cpp windows/stdafx.cpp freegetopt/getopt.cpp) add_library(PCM_STATIC STATIC ${COMMON_SOURCES} ${WINDOWS_SOURCES}) target_compile_definitions(PCM_STATIC PRIVATE UNICODE _UNICODE _CONSOLE) - target_compile_options(PCM_STATIC PRIVATE "/MT$<$:d>") + if (NO_STATIC_MSVC_RUNTIME_LIBRARY) + set(PCM_MSVC_RUNTIME_LIBRARY_OPTIONS "") + else() + set(PCM_MSVC_RUNTIME_LIBRARY_OPTIONS "/MT$<$:d>") + message(STATUS "Using static MSVC runtime library") + message(STATUS "To use default/dynamic MSVC runtime library, use -DNO_STATIC_MSVC_RUNTIME_LIBRARY=1 option") + endif() + target_compile_options(PCM_STATIC PRIVATE "${PCM_MSVC_RUNTIME_LIBRARY_OPTIONS}") # Graphical perfmon front-end: pcm-lib, pcm-service # Files: COMMON_FILES() + pcm-lib.cpp winpmem\winpmem.cpp dllmain.cpp file(GLOB PCM_LIB_SOURCES winpmem/winpmem.cpp dllmain.cpp pcm-lib.cpp ) add_library(pcm-lib SHARED ${COMMON_SOURCES} ${PCM_LIB_SOURCES}) target_compile_definitions(pcm-lib PRIVATE _WINDOWS _USRDLL PCM_EXPORTS _WINDLL _UNICODE UNICODE) - target_compile_options(pcm-lib PRIVATE "/MT$<$:d>") + target_compile_options(pcm-lib PRIVATE "${PCM_MSVC_RUNTIME_LIBRARY_OPTIONS}") # Pcm-service files: PCM_SHARED + AssemblyInfo.cpp PCMInstaller.cpp PCMService.cpp file(GLOB PCM_SERVICE_SOURCES windows/PCMInstaller.cpp windows/PCMService.cpp windows/AssemblyInfo.cpp winddows/utils.cpp) @@ -139,9 +144,13 @@ foreach(PROJECT_NAME ${PROJECT_NAMES}) add_executable(${PROJECT_NAME} ${PROJECT_FILE}) if(MSVC) - target_compile_options(${PROJECT_NAME} PRIVATE "/MT$<$:d>") + target_compile_options(${PROJECT_NAME} PRIVATE "${PCM_MSVC_RUNTIME_LIBRARY_OPTIONS}") endif(MSVC) + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-static-libasan") + endif() + # specific file for pcm-raw project if(${PROJECT_NAME} STREQUAL pcm-raw) set(LIBS ${LIBS} PCM_SIMDJSON) diff --git a/src/cpucounters.cpp b/src/cpucounters.cpp index 22afedff..470f9916 100644 --- a/src/cpucounters.cpp +++ b/src/cpucounters.cpp @@ -8712,18 +8712,16 @@ void ServerUncorePMUs::programServerUncoreMemoryMetrics(const ServerUncoreMemory std::cerr << "PCM Error: invalid rankA value: " << rankA << "\n"; return; } - if (rankB < 0 || rankB > 7) - { - std::cerr << "PCM Error: invalid rankB value: " << rankB << "\n"; - return; - } switch(cpu_model) { case PCM::IVYTOWN: MCCntConfig[EventPosition::READ_RANK_A] = MC_CH_PCI_PMON_CTL_EVENT((0xb0 + rankA)) + MC_CH_PCI_PMON_CTL_UMASK(0xff); // RD_CAS_RANK(rankA) all banks MCCntConfig[EventPosition::WRITE_RANK_A] = MC_CH_PCI_PMON_CTL_EVENT((0xb8 + rankA)) + MC_CH_PCI_PMON_CTL_UMASK(0xff); // WR_CAS_RANK(rankA) all banks - MCCntConfig[EventPosition::READ_RANK_B] = MC_CH_PCI_PMON_CTL_EVENT((0xb0 + rankB)) + MC_CH_PCI_PMON_CTL_UMASK(0xff); // RD_CAS_RANK(rankB) all banks - MCCntConfig[EventPosition::WRITE_RANK_B] = MC_CH_PCI_PMON_CTL_EVENT((0xb8 + rankB)) + MC_CH_PCI_PMON_CTL_UMASK(0xff); // WR_CAS_RANK(rankB) all banks + if (rankB >= 0 && rankB <= 7) + { + MCCntConfig[EventPosition::READ_RANK_B] = MC_CH_PCI_PMON_CTL_EVENT((0xb0 + rankB)) + MC_CH_PCI_PMON_CTL_UMASK(0xff); // RD_CAS_RANK(rankB) all banks + MCCntConfig[EventPosition::WRITE_RANK_B] = MC_CH_PCI_PMON_CTL_EVENT((0xb8 + rankB)) + MC_CH_PCI_PMON_CTL_UMASK(0xff); // WR_CAS_RANK(rankB) all banks + } break; case PCM::HASWELLX: case PCM::BDX_DE: @@ -8731,8 +8729,11 @@ void ServerUncorePMUs::programServerUncoreMemoryMetrics(const ServerUncoreMemory case PCM::SKX: MCCntConfig[EventPosition::READ_RANK_A] = MC_CH_PCI_PMON_CTL_EVENT((0xb0 + rankA)) + MC_CH_PCI_PMON_CTL_UMASK(16); // RD_CAS_RANK(rankA) all banks MCCntConfig[EventPosition::WRITE_RANK_A] = MC_CH_PCI_PMON_CTL_EVENT((0xb8 + rankA)) + MC_CH_PCI_PMON_CTL_UMASK(16); // WR_CAS_RANK(rankA) all banks - MCCntConfig[EventPosition::READ_RANK_B] = MC_CH_PCI_PMON_CTL_EVENT((0xb0 + rankB)) + MC_CH_PCI_PMON_CTL_UMASK(16); // RD_CAS_RANK(rankB) all banks - MCCntConfig[EventPosition::WRITE_RANK_B] = MC_CH_PCI_PMON_CTL_EVENT((0xb8 + rankB)) + MC_CH_PCI_PMON_CTL_UMASK(16); // WR_CAS_RANK(rankB) all banks + if (rankB >= 0 && rankB <= 7) + { + MCCntConfig[EventPosition::READ_RANK_B] = MC_CH_PCI_PMON_CTL_EVENT((0xb0 + rankB)) + MC_CH_PCI_PMON_CTL_UMASK(16); // RD_CAS_RANK(rankB) all banks + MCCntConfig[EventPosition::WRITE_RANK_B] = MC_CH_PCI_PMON_CTL_EVENT((0xb8 + rankB)) + MC_CH_PCI_PMON_CTL_UMASK(16); // WR_CAS_RANK(rankB) all banks + } break; case PCM::KNL: MCCntConfig[EventPosition::READ] = MC_CH_PCI_PMON_CTL_EVENT(0x03) + MC_CH_PCI_PMON_CTL_UMASK(1); // monitor reads on counter 0: CAS.RD diff --git a/src/pcm-sensor-server.cpp b/src/pcm-sensor-server.cpp index 9c68c3d8..b17e7d64 100644 --- a/src/pcm-sensor-server.cpp +++ b/src/pcm-sensor-server.cpp @@ -1017,6 +1017,7 @@ class basic_socketbuf : public std::basic_streambuf { bytesReceived = SSL_read( ssl_, static_cast(inputBuffer_), SIZE * sizeof( char_type ) ); if ( 0 >= bytesReceived ) { int sslError = SSL_get_error( ssl_, bytesReceived ); + ERR_print_errors_fp(stderr); switch ( sslError ) { case SSL_ERROR_WANT_READ: case SSL_ERROR_WANT_WRITE: diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index eb78bb67..c7a507de 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -19,12 +19,18 @@ if(UNIX) endif(UNIX) if(FUZZ) + find_package(OpenSSL REQUIRED) + set(SSL_LIBS OpenSSL::SSL OpenSSL::Crypto) add_executable(urltest-fuzz urltest-fuzz.cpp) add_executable(pcm-sensor-server-fuzz pcm-sensor-server-fuzz.cpp) + add_executable(pcm-sensor-server-ssl-fuzz pcm-sensor-server-fuzz.cpp) + target_compile_options(pcm-sensor-server-fuzz PRIVATE -DUSE_SSL=1) + target_compile_options(pcm-sensor-server-ssl-fuzz PRIVATE -DUSE_SSL=1 -DFUZZ_USE_SSL=1) add_executable(pcm-fuzz pcm-fuzz.cpp) add_executable(pcm-memory-fuzz pcm-memory-fuzz.cpp) target_link_libraries(urltest-fuzz Threads::Threads PCM_STATIC) - target_link_libraries(pcm-sensor-server-fuzz Threads::Threads PCM_STATIC) + target_link_libraries(pcm-sensor-server-fuzz Threads::Threads PCM_STATIC ${SSL_LIBS}) + target_link_libraries(pcm-sensor-server-ssl-fuzz Threads::Threads PCM_STATIC ${SSL_LIBS}) target_link_libraries(pcm-fuzz Threads::Threads PCM_STATIC) target_link_libraries(pcm-memory-fuzz Threads::Threads PCM_STATIC) endif() diff --git a/tests/fuzz.sh b/tests/fuzz.sh index 3172d1a1..1b9d4062 100644 --- a/tests/fuzz.sh +++ b/tests/fuzz.sh @@ -7,6 +7,12 @@ if [ "$#" -eq 1 ]; then factor=$1 fi +# Suppress leaks in libcrypto +# Below is caused by openssl leaks +# similar to https://github.com/spdk/spdk/issues/2947 +echo leak:libcrypto.so >> pcm_asan_suppression_file +export LSAN_OPTIONS=suppressions="pcm_asan_suppression_file" + echo "Running fuzz tests with running time multiplier $factor" CC=`which clang` CXX=`which clang++` cmake .. -DCMAKE_BUILD_TYPE=Debug -DFUZZ=1 && mkdir -p corpus && @@ -14,6 +20,7 @@ make urltest-fuzz \ pcm-fuzz \ pcm-memory-fuzz \ pcm-sensor-server-fuzz \ + pcm-sensor-server-ssl-fuzz \ -j && rm -rf corpus/* && printf '%b' "GET / HTTP/1.1\r\nHost: localhost\r\nAccept: */*\r\n\r\n" > corpus/1 && @@ -34,6 +41,26 @@ printf '%b' "GET /dashboard/prometheus HTTP/1.1\r\nHost: localhost\r\nAccept: */ printf '%b' "GET /dashboard/prometheus/default HTTP/1.1\r\nHost: localhost\r\nAccept: */*\r\n\r\n" > corpus/10 && printf '%b' "GET /dashboard HTTP/1.1\r\nHost: localhost\r\nAccept: */*\r\n\r\n" > corpus/11 && printf '%b' "GET /favicon.ico HTTP/1.1\r\nHost: localhost\r\nAccept: */*\r\n\r\n" > corpus/12 && +LLVM_PROFILE_FILE="pcm-sensor-server-ssl.profraw" bin/tests/pcm-sensor-server-ssl-fuzz -detect_leaks=0 -max_total_time=$((10 * $factor)) -rss_limit_mb=10000 corpus > /dev/null && +rm -rf corpus/* && +printf '%b' "GET / HTTP/1.1\r\nHost: localhost\r\nAccept: */*\r\n\r\n" > corpus/1 && +printf '%b' "GET /metrics HTTP/1.1\r\nHost: localhost\r\nAccept: */*\r\n\r\n" > corpus/2 && +printf '%b' "GET /persecond HTTP/1.1\r\nHost: localhost\r\nAccept: */*\r\n\r\n" > corpus/3 && +printf '%b' "GET /persecond HTTP/1.1\r\nHost: localhost\r\nAccept: application/json\r\n\r\n" > corpus/3.1 && +printf '%b' "GET /persecond HTTP/1.1\r\nHost: localhost\r\nAccept: text/plain; version=0.0.4\r\n\r\n" > corpus/3.2 && +printf '%b' "GET /persecond/1 HTTP/1.1\r\nHost: localhost\r\nAccept: */*\r\n\r\n" > corpus/4 && +printf '%b' "GET /persecond/1 HTTP/1.1\r\nHost: localhost\r\nAccept: application/json\r\n\r\n" > corpus/4.1 && +printf '%b' "GET /persecond/1 HTTP/1.1\r\nHost: localhost\r\nAccept: text/plain; version=0.0.4\r\n\r\n" > corpus/4.2 && +printf '%b' "GET /persecond/10 HTTP/1.1\r\nHost: localhost\r\nAccept: */*\r\n\r\n" > corpus/5 && +printf '%b' "GET /persecond/10 HTTP/1.1\r\nHost: localhost\r\nAccept: application/json\r\n\r\n" > corpus/5.1 && +printf '%b' "GET /persecond/10 HTTP/1.1\r\nHost: localhost\r\nAccept: text/plain; version=0.0.4\r\n\r\n" > corpus/5.2 && +printf '%b' "GET /persecond/100 HTTP/1.1\r\nHost: localhost\r\nAccept: application/json\r\n\r\n" > corpus/6 && +printf '%b' "GET /metrics HTTP/1.1\r\nHost: localhost\r\nAccept: */*\r\n\r\n" > corpus/7 && +printf '%b' "GET /dashboard/influxdb HTTP/1.1\r\nHost: localhost\r\nAccept: */*\r\n\r\n" > corpus/8 && +printf '%b' "GET /dashboard/prometheus HTTP/1.1\r\nHost: localhost\r\nAccept: */*\r\n\r\n" > corpus/9 && +printf '%b' "GET /dashboard/prometheus/default HTTP/1.1\r\nHost: localhost\r\nAccept: */*\r\n\r\n" > corpus/10 && +printf '%b' "GET /dashboard HTTP/1.1\r\nHost: localhost\r\nAccept: */*\r\n\r\n" > corpus/11 && +printf '%b' "GET /favicon.ico HTTP/1.1\r\nHost: localhost\r\nAccept: */*\r\n\r\n" > corpus/12 && LLVM_PROFILE_FILE="pcm-sensor-server.profraw" bin/tests/pcm-sensor-server-fuzz -detect_leaks=0 -rss_limit_mb=10000 -max_total_time=$((10 * $factor)) corpus > /dev/null && rm -rf corpus/* && printf '%b' "http://otto:test@www.intel.com/~otto/file1.txt" > corpus/1 && @@ -71,11 +98,13 @@ llvm-profdata merge -sparse \ pcm.nmi_watchdog.profraw \ pcm-memory.profraw \ pcm-sensor-server.profraw \ + pcm-sensor-server-ssl.profraw \ -o all.profdata && llvm-cov report --summary-only \ -object ./bin/tests/pcm-fuzz \ -object ./bin/tests/urltest-fuzz \ -object ./bin/tests/pcm-memory-fuzz \ -object ./bin/tests/pcm-sensor-server-fuzz \ + -object ./bin/tests/pcm-sensor-server-ssl-fuzz \ -instr-profile=all.profdata | tee report.txt diff --git a/tests/pcm-sensor-server-fuzz.cpp b/tests/pcm-sensor-server-fuzz.cpp index 141a3887..05a85630 100644 --- a/tests/pcm-sensor-server-fuzz.cpp +++ b/tests/pcm-sensor-server-fuzz.cpp @@ -77,14 +77,25 @@ bool init() exit(1); } debug::dyn_debug_level(0); + #ifdef FUZZ_USE_SSL + std::cerr << "Starting SSL enabled server on https://localhost:" << port << "/\n"; + auto httpsServer = new HTTPSServer( "", port ); + httpsServer->setPrivateKeyFile ( "/private.key" ); + httpsServer->setCertificateFile( "/certificate.crt" ); + httpsServer->initialiseSSL(); + httpServer = httpsServer; + #else std::cerr << "Starting plain HTTP server on http://localhost:" << port << "/\n"; httpServer = new HTTPServer( "", port ); + #endif // HEAD is GET without body, we will remove the body in execute() httpServer->registerCallback( HTTPRequestMethod::GET, my_get_callback ); httpServer->registerCallback( HTTPRequestMethod::HEAD, my_get_callback ); httpServer->run(); }); int timeout = 60; // Timeout in seconds + std::cout << "Waiting for port " << port << " to be bound with timeout of " << timeout << " seconds..." << std::endl; + std::cout.flush(); if (waitForPort(port, timeout)) { std::cout << "Port " << port << " is now bound." << std::endl; } else { @@ -99,10 +110,20 @@ bool init() std::vector buffer(1024*1024*16); std::string make_request(const std::string& request) { +#ifdef FUZZ_USE_SSL + const SSL_METHOD* method = TLS_client_method(); + SSL_CTX* ctx = SSL_CTX_new(method); + if (!ctx) { + throw std::runtime_error("Unable to create SSL context"); + } +#endif std::string server = "127.0.0.1"; // Resolve the host struct hostent* host = gethostbyname(server.c_str()); if (!host) { +#ifdef FUZZ_USE_SSL + SSL_CTX_free(ctx); +#endif std::cerr << "Failed to resolve host. Error: " << strerror(errno) << std::endl; throw std::runtime_error("Failed to resolve host: " + server); } @@ -110,6 +131,9 @@ std::string make_request(const std::string& request) { // Create socket int sock = socket(AF_INET, SOCK_STREAM, 0); if (sock < 0) { +#ifdef FUZZ_USE_SSL + SSL_CTX_free(ctx); +#endif std::cerr << "Failed to create socket. Error: " << strerror(errno) << std::endl; throw std::runtime_error("Failed to create socket"); } @@ -125,12 +149,40 @@ std::string make_request(const std::string& request) { if (connect(sock, (struct sockaddr*)&server_addr, sizeof(server_addr)) < 0) { std::cerr << "Failed to connect to server. Error: " << strerror(errno) << std::endl; close(sock); +#ifdef FUZZ_USE_SSL + SSL_CTX_free(ctx); +#endif throw std::runtime_error("Failed to connect to server"); } - // Form the request +#ifdef FUZZ_USE_SSL + // Create SSL structure + SSL* ssl = SSL_new(ctx); + SSL_set_fd(ssl, sock); + if (SSL_connect(ssl) <= 0) { + SSL_free(ssl); + close(sock); + SSL_CTX_free(ctx); + throw std::runtime_error("Failed to establish SSL connection"); + } +#endif + std::cout << "Sending request: " << request << "\n=====\n"; + std::string response; + int bytes_received = -1; +#ifdef FUZZ_USE_SSL + // Send the request + if (SSL_write(ssl, request.c_str(), request.length()) <= 0) { + SSL_free(ssl); + close(sock); + SSL_CTX_free(ctx); + return "Failed to send request, no response"; + } + + // Receive the response + bytes_received = SSL_read(ssl, &(buffer[0]), buffer.size()); +#else // Send the request if (send(sock, request.c_str(), request.length(), 0) < 0) { std::cerr << "Failed to send request. Error: " << strerror(errno) << std::endl; @@ -140,23 +192,35 @@ std::string make_request(const std::string& request) { } // Receive the response - std::string response; - ssize_t bytes_received; bytes_received = recv(sock, &(buffer[0]), buffer.size(), 0); +#endif if (bytes_received > 0) { response.append(&(buffer[0]), bytes_received); } if (bytes_received < 0) { +#ifdef FUZZ_USE_SSL + SSL_free(ssl); +#endif std::cerr << "Failed to receive response. Error: " << strerror(errno) << std::endl; close(sock); +#ifdef FUZZ_USE_SSL + SSL_CTX_free(ctx); +#endif // throw std::runtime_error("Failed to receive response"); return "Failed to receive response"; // expected to happen sometimes } - // Close the socket + // clean up +#ifdef FUZZ_USE_SSL + SSL_shutdown(ssl); + SSL_free(ssl); +#endif close(sock); +#ifdef FUZZ_USE_SSL + SSL_CTX_free(ctx); +#endif return response; }