LLVMFuzzerTestOneInput:
   27|    369|extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
   28|       |
   29|    369|  std::vector<ProxyProtocolValue> values;
   30|    369|  ComboAddress source;
   31|    369|  ComboAddress destination;
   32|    369|  bool proxy = false;
   33|    369|  bool tcp = false;  
   34|       |
   35|    369|  try {
   36|    369|    parseProxyHeader(std::string(reinterpret_cast<const char*>(data), size), proxy, source, destination, tcp, values);
   37|    369|  }
   38|    369|  catch(const std::exception& e) {
   39|      0|  }
   40|    369|  catch(const PDNSException& e) {
   41|      0|  }
   42|       |
   43|    369|  return 0;
   44|    369|}

_ZN12ComboAddressC2Ev:
  182|    754|  {
  183|    754|    sin4.sin_family=AF_INET;
  184|    754|    sin4.sin_addr.s_addr=0;
  185|    754|    sin4.sin_port=0;
  186|    754|    sin6.sin6_scope_id = 0;
  187|    754|    sin6.sin6_flowinfo = 0;
  188|    754|  }
_ZN12ComboAddress7setPortEt:
  351|     16|  {
  352|     16|    sin4.sin_port = htons(port);
  353|     16|  }
_Z23makeComboAddressFromRawhPKcm:
  447|     16|{
  448|     16|  ComboAddress address;
  449|       |
  450|     16|  if (version == 4) {
  ------------------
  |  Branch (450:7): [True: 10, False: 6]
  ------------------
  451|     10|    address.sin4.sin_family = AF_INET;
  452|     10|    if (len != sizeof(address.sin4.sin_addr)) throw NetmaskException("invalid raw address length");
  ------------------
  |  Branch (452:9): [True: 0, False: 10]
  ------------------
  453|     10|    memcpy(&address.sin4.sin_addr, raw, sizeof(address.sin4.sin_addr));
  454|     10|  }
  455|      6|  else if (version == 6) {
  ------------------
  |  Branch (455:12): [True: 6, False: 0]
  ------------------
  456|      6|    address.sin6.sin6_family = AF_INET6;
  457|      6|    if (len != sizeof(address.sin6.sin6_addr)) throw NetmaskException("invalid raw address length");
  ------------------
  |  Branch (457:9): [True: 0, False: 6]
  ------------------
  458|      6|    memcpy(&address.sin6.sin6_addr, raw, sizeof(address.sin6.sin6_addr));
  459|      6|  }
  460|      0|  else throw NetmaskException("invalid address family");
  461|       |
  462|     16|  return address;
  463|     16|}

_Z21isProxyHeaderCompleteINSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEElRKT_PbSA_PmPh:
  119|    369|{
  120|    369|  static const size_t addr4Size = sizeof(ComboAddress::sin4.sin_addr.s_addr);
  121|    369|  static const size_t addr6Size = sizeof(ComboAddress::sin6.sin6_addr.s6_addr);
  122|    369|  size_t addrSize = 0;
  123|    369|  uint8_t versioncommand;
  124|    369|  uint8_t protocol;
  125|       |
  126|    369|  if (header.size() < s_proxyProtocolMinimumHeaderSize) {
  ------------------
  |  Branch (126:7): [True: 11, False: 358]
  ------------------
  127|       |    // this is too short to be a complete proxy header
  128|     11|    return -(s_proxyProtocolMinimumHeaderSize - header.size());
  129|     11|  }
  130|       |
  131|    358|  if (std::memcmp(&header.at(0), &proxymagic.at(0), proxymagic.size()) != 0) {
  ------------------
  |  Branch (131:7): [True: 115, False: 243]
  ------------------
  132|       |    // wrong magic, can not be a proxy header
  133|    115|    return 0;
  134|    115|  }
  135|       |
  136|    243|  versioncommand = header.at(12);
  137|       |  /* check version */
  138|    243|  if (!(versioncommand & 0x20)) {
  ------------------
  |  Branch (138:7): [True: 1, False: 242]
  ------------------
  139|      1|    return 0;
  140|      1|  }
  141|       |
  142|       |  /* remove the version to get the command */
  143|    242|  uint8_t command = versioncommand & ~0x20;
  144|       |
  145|    242|  if (command == 0x01) {
  ------------------
  |  Branch (145:7): [True: 34, False: 208]
  ------------------
  146|     34|    protocol = header.at(13);
  147|     34|    if ((protocol & 0xf) == 1) {
  ------------------
  |  Branch (147:9): [True: 19, False: 15]
  ------------------
  148|     19|      if (tcp) {
  ------------------
  |  Branch (148:11): [True: 19, False: 0]
  ------------------
  149|     19|        *tcp = true;
  150|     19|      }
  151|     19|    } else if ((protocol & 0xf) == 2) {
  ------------------
  |  Branch (151:16): [True: 10, False: 5]
  ------------------
  152|     10|      if (tcp) {
  ------------------
  |  Branch (152:11): [True: 10, False: 0]
  ------------------
  153|     10|        *tcp = false;
  154|     10|      }
  155|     10|    } else {
  156|      5|      return 0;
  157|      5|    }
  158|       |
  159|     29|    protocol = protocol >> 4;
  160|       |
  161|     29|    if (protocol == 1) {
  ------------------
  |  Branch (161:9): [True: 15, False: 14]
  ------------------
  162|     15|      if (protocolOut) {
  ------------------
  |  Branch (162:11): [True: 15, False: 0]
  ------------------
  163|     15|        *protocolOut = 4;
  164|     15|      }
  165|     15|      addrSize = addr4Size; // IPv4
  166|     15|    } else if (protocol == 2) {
  ------------------
  |  Branch (166:16): [True: 9, False: 5]
  ------------------
  167|      9|      if (protocolOut) {
  ------------------
  |  Branch (167:11): [True: 9, False: 0]
  ------------------
  168|      9|        *protocolOut = 6;
  169|      9|      }
  170|      9|      addrSize = addr6Size; // IPv6
  171|      9|    } else {
  172|       |      // invalid protocol
  173|      5|      return 0;
  174|      5|    }
  175|       |
  176|     24|    if (addrSizeOut) {
  ------------------
  |  Branch (176:9): [True: 24, False: 0]
  ------------------
  177|     24|      *addrSizeOut = addrSize;
  178|     24|    }
  179|       |
  180|     24|    if (proxy) {
  ------------------
  |  Branch (180:9): [True: 24, False: 0]
  ------------------
  181|     24|      *proxy = true;
  182|     24|    }
  183|     24|  }
  184|    208|  else if (command == 0x00) {
  ------------------
  |  Branch (184:12): [True: 199, False: 9]
  ------------------
  185|    199|    if (proxy) {
  ------------------
  |  Branch (185:9): [True: 199, False: 0]
  ------------------
  186|    199|      *proxy = false;
  187|    199|    }
  188|    199|  }
  189|      9|  else {
  190|       |    /* unsupported command */
  191|      9|    return 0;
  192|      9|  }
  193|       |
  194|    223|  uint16_t contentlen = (static_cast<uint8_t>(header.at(14)) << 8) + static_cast<uint8_t>(header.at(15));
  195|    223|  uint16_t expectedlen = 0;
  196|    223|  if (command != 0x00) {
  ------------------
  |  Branch (196:7): [True: 24, False: 199]
  ------------------
  197|     24|    expectedlen = (addrSize * 2) + sizeof(ComboAddress::sin4.sin_port) + sizeof(ComboAddress::sin4.sin_port);
  198|     24|  }
  199|       |
  200|    223|  if (contentlen < expectedlen) {
  ------------------
  |  Branch (200:7): [True: 7, False: 216]
  ------------------
  201|      7|    return 0;
  202|      7|  }
  203|       |
  204|    216|  if (header.size() < s_proxyProtocolMinimumHeaderSize + contentlen) {
  ------------------
  |  Branch (204:7): [True: 46, False: 170]
  ------------------
  205|     46|    return -((s_proxyProtocolMinimumHeaderSize + contentlen) - header.size());
  206|     46|  }
  207|       |
  208|    170|  return s_proxyProtocolMinimumHeaderSize + contentlen;
  209|    216|}
_Z16parseProxyHeaderINSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEElRKT_RbR12ComboAddressSC_SA_RNS0_6vectorI18ProxyProtocolValueNS4_ISE_EEEE:
  215|    369|{
  216|    369|  size_t addrSize = 0;
  217|    369|  uint8_t protocol = 0;
  218|    369|  ssize_t got = isProxyHeaderComplete(header, &proxy, &tcp, &addrSize, &protocol);
  219|    369|  if (got <= 0) {
  ------------------
  |  Branch (219:7): [True: 199, False: 170]
  ------------------
  220|    199|    return got;
  221|    199|  }
  222|       |
  223|    170|  size_t pos = s_proxyProtocolMinimumHeaderSize;
  224|       |
  225|    170|  if (proxy) {
  ------------------
  |  Branch (225:7): [True: 8, False: 162]
  ------------------
  226|      8|    source = makeComboAddressFromRaw(protocol, reinterpret_cast<const char*>(&header.at(pos)), addrSize);
  227|      8|    pos = pos + addrSize;
  228|      8|    destination = makeComboAddressFromRaw(protocol, reinterpret_cast<const char*>(&header.at(pos)), addrSize);
  229|      8|    pos = pos + addrSize;
  230|      8|    source.setPort((static_cast<uint8_t>(header.at(pos)) << 8) + static_cast<uint8_t>(header.at(pos+1)));
  231|      8|    pos = pos + sizeof(uint16_t);
  232|      8|    destination.setPort((static_cast<uint8_t>(header.at(pos)) << 8) + static_cast<uint8_t>(header.at(pos+1)));
  233|      8|    pos = pos + sizeof(uint16_t);
  234|      8|  }
  235|       |
  236|    170|  size_t remaining = got - pos;
  237|  35.8k|  while (remaining >= (sizeof(uint8_t) + sizeof(uint16_t))) {
  ------------------
  |  Branch (237:10): [True: 35.7k, False: 101]
  ------------------
  238|       |    /* we still have TLV values to parse */
  239|  35.7k|    uint8_t type = static_cast<uint8_t>(header.at(pos));
  240|  35.7k|    pos += sizeof(uint8_t);
  241|  35.7k|    uint16_t len = (static_cast<uint8_t>(header.at(pos)) << 8) + static_cast<uint8_t>(header.at(pos + 1));
  242|  35.7k|    pos += sizeof(uint16_t);
  243|       |
  244|  35.7k|    if (len > 0) {
  ------------------
  |  Branch (244:9): [True: 1.00k, False: 34.7k]
  ------------------
  245|  1.00k|      if (len > (got - pos)) {
  ------------------
  |  Branch (245:11): [True: 69, False: 933]
  ------------------
  246|     69|        return 0;
  247|     69|      }
  248|       |
  249|    933|      values.push_back({std::string(reinterpret_cast<const char*>(&header.at(pos)), len), type});
  250|    933|      pos += len;
  251|    933|    }
  252|  34.7k|    else {
  253|  34.7k|      values.push_back({"", type});
  254|  34.7k|    }
  255|       |
  256|  35.7k|    remaining = got - pos;
  257|  35.7k|  }
  258|       |
  259|    101|  return pos;
  260|    170|}

