LLVMFuzzerTestOneInput:
   30|    409|{
   31|       |
   32|    409|  std::vector<ProxyProtocolValue> values;
   33|    409|  ComboAddress source;
   34|    409|  ComboAddress destination;
   35|    409|  bool proxy = false;
   36|    409|  bool tcp = false;
   37|       |
   38|    409|  try {
   39|    409|    parseProxyHeader(std::string(reinterpret_cast<const char*>(data), size), proxy, source, destination, tcp, values);
   40|    409|  }
   41|    409|  catch (const std::exception& e) {
   42|      0|  }
   43|    409|  catch (const PDNSException& e) {
   44|      0|  }
   45|       |
   46|    409|  return 0;
   47|    409|}

_ZN12ComboAddressC2Ev:
  212|    838|  {
  213|       |    sin4.sin_family = AF_INET;
  214|    838|    sin4.sin_addr.s_addr = 0;
  215|    838|    sin4.sin_port = 0;
  216|    838|    sin6.sin6_scope_id = 0;
  217|    838|    sin6.sin6_flowinfo = 0;
  218|    838|  }
_ZN12ComboAddress7setPortEt:
  427|     20|  {
  428|       |    sin4.sin_port = htons(port);
  429|     20|  }
_Z23makeComboAddressFromRawhPKcm:
  659|     20|{
  660|     20|  ComboAddress address;
  661|       |
  662|     20|  if (version == 4) {
  ------------------
  |  Branch (662:7): [True: 4, False: 16]
  ------------------
  663|      4|    address.sin4.sin_family = AF_INET;
  664|      4|    if (len != sizeof(address.sin4.sin_addr)) {
  ------------------
  |  Branch (664:9): [True: 0, False: 4]
  ------------------
  665|      0|      throw NetmaskException("invalid raw address length");
  666|      0|    }
  667|      4|    memcpy(&address.sin4.sin_addr, raw, sizeof(address.sin4.sin_addr));
  668|      4|  }
  669|     16|  else if (version == 6) {
  ------------------
  |  Branch (669:12): [True: 16, False: 0]
  ------------------
  670|     16|    address.sin6.sin6_family = AF_INET6;
  671|     16|    if (len != sizeof(address.sin6.sin6_addr)) {
  ------------------
  |  Branch (671:9): [True: 0, False: 16]
  ------------------
  672|      0|      throw NetmaskException("invalid raw address length");
  673|      0|    }
  674|     16|    memcpy(&address.sin6.sin6_addr, raw, sizeof(address.sin6.sin6_addr));
  675|     16|  }
  676|      0|  else {
  677|      0|    throw NetmaskException("invalid address family");
  678|      0|  }
  679|       |
  680|     20|  return address;
  681|     20|}

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

