LCOV - code coverage report
Current view: top level - src/test/fuzz - http_request.cpp (source / functions) Coverage Total Hit
Test: fuzz_coverage.info Lines: 100.0 % 26 26
Test Date: 2026-06-29 07:05:34 Functions: 100.0 % 2 2
Branches: 58.3 % 48 28

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2020-present The Bitcoin Core developers
       2                 :             : // Distributed under the MIT software license, see the accompanying
       3                 :             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4                 :             : 
       5                 :             : #include <httpserver.h>
       6                 :             : #include <netaddress.h>
       7                 :             : #include <test/fuzz/FuzzedDataProvider.h>
       8                 :             : #include <test/fuzz/fuzz.h>
       9                 :             : #include <test/fuzz/util.h>
      10                 :             : #include <util/signalinterrupt.h>
      11                 :             : #include <util/strencodings.h>
      12                 :             : 
      13                 :             : #include <cassert>
      14                 :             : #include <cstdint>
      15                 :             : #include <string>
      16                 :             : #include <vector>
      17                 :             : 
      18                 :             : 
      19                 :             : std::string_view RequestMethodString(HTTPRequestMethod m);
      20                 :             : 
      21         [ +  - ]:         658 : FUZZ_TARGET(http_request)
      22                 :             : {
      23                 :         192 :     using http_bitcoin::HTTPRequest;
      24                 :         192 :     using http_bitcoin::MAX_HEADERS_SIZE;
      25                 :         192 :     using util::LineReader;
      26                 :             : 
      27                 :         192 :     FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
      28                 :         192 :     const std::vector<std::byte> http_buffer{ConsumeRandomLengthByteVector<std::byte>(fuzzed_data_provider, 4096)};
      29                 :             : 
      30         [ -  + ]:         192 :     HTTPRequest http_request;
      31   [ -  +  +  - ]:         192 :     LineReader reader(http_buffer, MAX_HEADERS_SIZE);
      32                 :         192 :     try {
      33   [ +  +  +  + ]:         192 :         if (!http_request.LoadControlData(reader)) return;
      34   [ +  +  +  + ]:          88 :         if (!http_request.LoadHeaders(reader)) return;
      35   [ +  -  +  - ]:          55 :         if (!http_request.LoadBody(reader)) return;
      36         [ -  + ]:          95 :     } catch (const std::runtime_error&) {
      37                 :          95 :         return;
      38                 :          95 :     }
      39                 :             : 
      40         [ +  - ]:          55 :     const HTTPRequestMethod request_method = http_request.GetRequestMethod();
      41         [ +  - ]:          55 :     (void)RequestMethodString(request_method);
      42         [ -  + ]:         110 :     (void)http_request.GetURI();
      43         [ +  - ]:          55 :     (void)http_request.GetHeader("Host");
      44         [ +  - ]:          55 :     std::string header = fuzzed_data_provider.ConsumeRandomLengthString(16);
      45   [ -  +  +  - ]:          55 :     (void)http_request.GetHeader(header);
      46   [ +  -  +  - ]:         165 :     (void)http_request.WriteHeader(std::string(header), fuzzed_data_provider.ConsumeRandomLengthString(16));
      47   [ -  +  +  - ]:          55 :     (void)http_request.GetHeader(header);
      48         [ -  + ]:          55 :     const std::string body = http_request.ReadBody();
      49         [ -  + ]:          55 :     assert(body.empty());
      50                 :         192 : }
        

Generated by: LCOV version 2.0-1