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

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

_Z21isProxyHeaderCompleteINSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEElRKT_PbSA_PmPh:
  119|    402|{
  120|    402|  static const size_t addr4Size = sizeof(ComboAddress::sin4.sin_addr.s_addr);
  121|    402|  static const size_t addr6Size = sizeof(ComboAddress::sin6.sin6_addr.s6_addr);
  122|    402|  size_t addrSize = 0;
  123|    402|  uint8_t versioncommand;
  124|    402|  uint8_t protocol;
  125|       |
  126|    402|  if (header.size() < s_proxyProtocolMinimumHeaderSize) {
  ------------------
  |  Branch (126:7): [True: 11, False: 391]
  ------------------
  127|       |    // this is too short to be a complete proxy header
  128|     11|    return -(s_proxyProtocolMinimumHeaderSize - header.size());
  129|     11|  }
  130|       |
  131|    391|  if (std::memcmp(&header.at(0), &proxymagic.at(0), proxymagic.size()) != 0) {
  ------------------
  |  Branch (131:7): [True: 128, False: 263]
  ------------------
  132|       |    // wrong magic, can not be a proxy header
  133|    128|    return 0;
  134|    128|  }
  135|       |
  136|    263|  versioncommand = header.at(12);
  137|       |  /* check version */
  138|    263|  if (!(versioncommand & 0x20)) {
  ------------------
  |  Branch (138:7): [True: 3, False: 260]
  ------------------
  139|      3|    return 0;
  140|      3|  }
  141|       |
  142|       |  /* remove the version to get the command */
  143|    260|  uint8_t command = versioncommand & ~0x20;
  144|       |
  145|    260|  if (command == 0x01) {
  ------------------
  |  Branch (145:7): [True: 31, False: 229]
  ------------------
  146|     31|    protocol = header.at(13);
  147|     31|    if ((protocol & 0xf) == 1) {
  ------------------
  |  Branch (147:9): [True: 14, False: 17]
  ------------------
  148|     14|      if (tcp) {
  ------------------
  |  Branch (148:11): [True: 14, False: 0]
  ------------------
  149|     14|        *tcp = true;
  150|     14|      }
  151|     17|    } else if ((protocol & 0xf) == 2) {
  ------------------
  |  Branch (151:16): [True: 12, False: 5]
  ------------------
  152|     12|      if (tcp) {
  ------------------
  |  Branch (152:11): [True: 12, False: 0]
  ------------------
  153|     12|        *tcp = false;
  154|     12|      }
  155|     12|    } else {
  156|      5|      return 0;
  157|      5|    }
  158|       |
  159|     26|    protocol = protocol >> 4;
  160|       |
  161|     26|    if (protocol == 1) {
  ------------------
  |  Branch (161:9): [True: 9, False: 17]
  ------------------
  162|      9|      if (protocolOut) {
  ------------------
  |  Branch (162:11): [True: 9, False: 0]
  ------------------
  163|      9|        *protocolOut = 4;
  164|      9|      }
  165|      9|      addrSize = addr4Size; // IPv4
  166|     17|    } else if (protocol == 2) {
  ------------------
  |  Branch (166:16): [True: 11, False: 6]
  ------------------
  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|      6|      return 0;
  174|      6|    }
  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|    229|  else if (command == 0x00) {
  ------------------
  |  Branch (184:12): [True: 219, False: 10]
  ------------------
  185|    219|    if (proxy) {
  ------------------
  |  Branch (185:9): [True: 219, False: 0]
  ------------------
  186|    219|      *proxy = false;
  187|    219|    }
  188|    219|  }
  189|     10|  else {
  190|       |    /* unsupported command */
  191|     10|    return 0;
  192|     10|  }
  193|       |
  194|    239|  uint16_t contentlen = (static_cast<uint8_t>(header.at(14)) << 8) + static_cast<uint8_t>(header.at(15));
  195|    239|  uint16_t expectedlen = 0;
  196|    239|  if (command != 0x00) {
  ------------------
  |  Branch (196:7): [True: 20, False: 219]
  ------------------
  197|     20|    expectedlen = (addrSize * 2) + sizeof(ComboAddress::sin4.sin_port) + sizeof(ComboAddress::sin4.sin_port);
  198|     20|  }
  199|       |
  200|    239|  if (contentlen < expectedlen) {
  ------------------
  |  Branch (200:7): [True: 6, False: 233]
  ------------------
  201|      6|    return 0;
  202|      6|  }
  203|       |
  204|    233|  if (header.size() < s_proxyProtocolMinimumHeaderSize + contentlen) {
  ------------------
  |  Branch (204:7): [True: 40, False: 193]
  ------------------
  205|     40|    return -((s_proxyProtocolMinimumHeaderSize + contentlen) - header.size());
  206|     40|  }
  207|       |
  208|    193|  return s_proxyProtocolMinimumHeaderSize + contentlen;
  209|    233|}
_Z16parseProxyHeaderINSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEElRKT_RbR12ComboAddressSC_SA_RNS0_6vectorI18ProxyProtocolValueNS4_ISE_EEEE:
  215|    402|{
  216|    402|  size_t addrSize = 0;
  217|    402|  uint8_t protocol = 0;
  218|    402|  ssize_t got = isProxyHeaderComplete(header, &proxy, &tcp, &addrSize, &protocol);
  219|    402|  if (got <= 0) {
  ------------------
  |  Branch (219:7): [True: 209, False: 193]
  ------------------
  220|    209|    return got;
  221|    209|  }
  222|       |
  223|    193|  size_t pos = s_proxyProtocolMinimumHeaderSize;
  224|       |
  225|    193|  if (proxy) {
  ------------------
  |  Branch (225:7): [True: 8, False: 185]
  ------------------
  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|    193|  size_t remaining = got - pos;
  237|  48.6k|  while (remaining >= (sizeof(uint8_t) + sizeof(uint16_t))) {
  ------------------
  |  Branch (237:10): [True: 48.5k, False: 115]
  ------------------
  238|       |    /* we still have TLV values to parse */
  239|  48.5k|    uint8_t type = static_cast<uint8_t>(header.at(pos));
  240|  48.5k|    pos += sizeof(uint8_t);
  241|  48.5k|    uint16_t len = (static_cast<uint8_t>(header.at(pos)) << 8) + static_cast<uint8_t>(header.at(pos + 1));
  242|  48.5k|    pos += sizeof(uint16_t);
  243|       |
  244|  48.5k|    if (len > 0) {
  ------------------
  |  Branch (244:9): [True: 1.19k, False: 47.3k]
  ------------------
  245|  1.19k|      if (len > (got - pos)) {
  ------------------
  |  Branch (245:11): [True: 78, False: 1.11k]
  ------------------
  246|     78|        return 0;
  247|     78|      }
  248|       |
  249|  1.11k|      values.push_back({std::string(reinterpret_cast<const char*>(&header.at(pos)), len), type});
  250|  1.11k|      pos += len;
  251|  1.11k|    }
  252|  47.3k|    else {
  253|  47.3k|      values.push_back({"", type});
  254|  47.3k|    }
  255|       |
  256|  48.4k|    remaining = got - pos;
  257|  48.4k|  }
  258|       |
  259|    115|  return pos;
  260|    193|}

