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

_ZN12ComboAddressC2Ev:
  200|    760|  {
  201|    760|    sin4.sin_family=AF_INET;
  202|    760|    sin4.sin_addr.s_addr=0;
  203|    760|    sin4.sin_port=0;
  204|    760|    sin6.sin6_scope_id = 0;
  205|    760|    sin6.sin6_flowinfo = 0;
  206|    760|  }
_ZN12ComboAddress7setPortEt:
  378|      8|  {
  379|      8|    sin4.sin_port = htons(port);
  380|      8|  }
_Z23makeComboAddressFromRawhPKcm:
  474|      8|{
  475|      8|  ComboAddress address;
  476|       |
  477|      8|  if (version == 4) {
  ------------------
  |  Branch (477:7): [True: 2, False: 6]
  ------------------
  478|      2|    address.sin4.sin_family = AF_INET;
  479|      2|    if (len != sizeof(address.sin4.sin_addr)) throw NetmaskException("invalid raw address length");
  ------------------
  |  Branch (479:9): [True: 0, False: 2]
  ------------------
  480|      2|    memcpy(&address.sin4.sin_addr, raw, sizeof(address.sin4.sin_addr));
  481|      2|  }
  482|      6|  else if (version == 6) {
  ------------------
  |  Branch (482:12): [True: 6, False: 0]
  ------------------
  483|      6|    address.sin6.sin6_family = AF_INET6;
  484|      6|    if (len != sizeof(address.sin6.sin6_addr)) throw NetmaskException("invalid raw address length");
  ------------------
  |  Branch (484:9): [True: 0, False: 6]
  ------------------
  485|      6|    memcpy(&address.sin6.sin6_addr, raw, sizeof(address.sin6.sin6_addr));
  486|      6|  }
  487|      0|  else throw NetmaskException("invalid address family");
  488|       |
  489|      8|  return address;
  490|      8|}

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

