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

_ZN12ComboAddressC2Ev:
  206|    774|  {
  207|    774|    sin4.sin_family = AF_INET;
  208|    774|    sin4.sin_addr.s_addr = 0;
  209|    774|    sin4.sin_port = 0;
  210|    774|    sin6.sin6_scope_id = 0;
  211|    774|    sin6.sin6_flowinfo = 0;
  212|    774|  }
_ZN12ComboAddress7setPortEt:
  420|     16|  {
  421|     16|    sin4.sin_port = htons(port);
  422|     16|  }
_Z23makeComboAddressFromRawhPKcm:
  652|     16|{
  653|     16|  ComboAddress address;
  654|       |
  655|     16|  if (version == 4) {
  ------------------
  |  Branch (655:7): [True: 10, False: 6]
  ------------------
  656|     10|    address.sin4.sin_family = AF_INET;
  657|     10|    if (len != sizeof(address.sin4.sin_addr)) {
  ------------------
  |  Branch (657:9): [True: 0, False: 10]
  ------------------
  658|      0|      throw NetmaskException("invalid raw address length");
  659|      0|    }
  660|     10|    memcpy(&address.sin4.sin_addr, raw, sizeof(address.sin4.sin_addr));
  661|     10|  }
  662|      6|  else if (version == 6) {
  ------------------
  |  Branch (662:12): [True: 6, False: 0]
  ------------------
  663|      6|    address.sin6.sin6_family = AF_INET6;
  664|      6|    if (len != sizeof(address.sin6.sin6_addr)) {
  ------------------
  |  Branch (664:9): [True: 0, False: 6]
  ------------------
  665|      0|      throw NetmaskException("invalid raw address length");
  666|      0|    }
  667|      6|    memcpy(&address.sin6.sin6_addr, raw, sizeof(address.sin6.sin6_addr));
  668|      6|  }
  669|      0|  else {
  670|      0|    throw NetmaskException("invalid address family");
  671|      0|  }
  672|       |
  673|     16|  return address;
  674|     16|}

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

