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

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

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

