LLVMFuzzerInitialize:
   46|      2|int LLVMFuzzerInitialize(int *argc, char ***argv) {
   47|      2|  (void)argc;
   48|      2|  (void)argv;
   49|       |
   50|      2|#if defined(OPENSSL_INIT_NO_LOAD_CONFIG) && !defined(LIBRESSL_VERSION_NUMBER)
   51|       |  /*
   52|       |   * Keep fuzzing deterministic and avoid MSan reports from OpenSSL's
   53|       |   * environment-dependent config file loading in unsanitized libcrypto.
   54|       |   */
   55|      2|  OPENSSL_init_crypto(OPENSSL_INIT_NO_LOAD_CONFIG, NULL);
   56|      2|#endif
   57|       |
   58|      2|  seed_addr_mappings();
   59|       |
   60|      2|  return 0;
   61|      2|}
FuzzOpenSSLInit.c:seed_addr_mappings:
   29|      2|static void seed_addr_mappings(void) {
   30|      2|  ioa_addr pub4 = {0};
   31|      2|  ioa_addr priv4 = {0};
   32|      2|  ioa_addr pub6 = {0};
   33|      2|  ioa_addr priv6 = {0};
   34|       |
   35|      2|  if (make_ioa_addr((const uint8_t *)"192.0.2.1", 0, &pub4) == 0 &&
  ------------------
  |  Branch (35:7): [True: 2, False: 0]
  ------------------
   36|      2|      make_ioa_addr((const uint8_t *)"10.0.0.1", 0, &priv4) == 0) {
  ------------------
  |  Branch (36:7): [True: 2, False: 0]
  ------------------
   37|      2|    ioa_addr_add_mapping(&pub4, &priv4);
   38|      2|  }
   39|       |
   40|      2|  if (make_ioa_addr((const uint8_t *)"2001:db8::1", 0, &pub6) == 0 &&
  ------------------
  |  Branch (40:7): [True: 2, False: 0]
  ------------------
   41|      2|      make_ioa_addr((const uint8_t *)"fd00::1", 0, &priv6) == 0) {
  ------------------
  |  Branch (41:7): [True: 2, False: 0]
  ------------------
   42|      2|    ioa_addr_add_mapping(&pub6, &priv6);
   43|      2|  }
   44|      2|}

LLVMFuzzerTestOneInput:
  598|  1.76k|extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
  599|  1.76k|  harness_integrity_sha1(Data, Size);
  600|  1.76k|  harness_integrity_multi(Data, Size);
  601|  1.76k|  harness_attr_iter(Data, Size);
  602|  1.76k|  harness_attr_add(Data, Size);
  603|  1.76k|  harness_old_stun(Data, Size);
  604|  1.76k|  harness_challenge_response_builder(Data, Size);
  605|  1.76k|  harness_full_addr_parser(Data, Size);
  606|  1.76k|  harness_integrity_attr_add(Data, Size);
  607|  1.76k|  return 0;
  608|  1.76k|}
FuzzStun.c:harness_integrity_sha1:
   49|  1.76k|static void harness_integrity_sha1(const uint8_t *Data, size_t Size) {
   50|  1.76k|  if (Size < 10 || Size > 5120) {
  ------------------
  |  Branch (50:7): [True: 71, False: 1.69k]
  |  Branch (50:20): [True: 110, False: 1.58k]
  ------------------
   51|    181|    return;
   52|    181|  }
   53|       |
   54|  1.58k|  stun_is_command_message_full_check_str((uint8_t *)Data, Size, true, NULL);
   55|       |
   56|  1.58k|  uint8_t uname[STUN_MAX_USERNAME_SIZE + 1] = "fuzzuser";
   57|  1.58k|  uint8_t realm[STUN_MAX_REALM_SIZE + 1] = "fuzz.realm";
   58|  1.58k|  uint8_t upwd[STUN_MAX_PWD_SIZE + 1] = "VOkJxbRl1RmTxUk/WvJxBt";
   59|       |
   60|  1.58k|  stun_check_message_integrity_str(TURN_CREDENTIALS_SHORT_TERM, (uint8_t *)Data, Size, uname, realm, upwd,
   61|  1.58k|                                   SHATYPE_SHA1);
   62|  1.58k|  stun_check_message_integrity_str(TURN_CREDENTIALS_LONG_TERM, (uint8_t *)Data, Size, uname, realm, upwd,
   63|  1.58k|                                   SHATYPE_SHA256);
   64|  1.58k|}
FuzzStun.c:harness_integrity_multi:
   69|  1.76k|static void harness_integrity_multi(const uint8_t *Data, size_t Size) {
   70|  1.76k|  if (Size < STUN_HEADER_LENGTH || Size > 5120) {
  ------------------
  |  |   46|  3.53k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (70:7): [True: 81, False: 1.68k]
  |  Branch (70:36): [True: 110, False: 1.57k]
  ------------------
   71|    191|    return;
   72|    191|  }
   73|       |
   74|  1.57k|  uint8_t buf[5120];
   75|  1.57k|  uint8_t uname[STUN_MAX_USERNAME_SIZE + 1] = "fuzzuser";
   76|  1.57k|  uint8_t realm[STUN_MAX_REALM_SIZE + 1] = "fuzz.realm";
   77|  1.57k|  uint8_t upwd[STUN_MAX_PWD_SIZE + 1] = "VOkJxbRl1RmTxUk/WvJxBt";
   78|       |
   79|  1.57k|  static const SHATYPE sha_types[] = {SHATYPE_SHA1, SHATYPE_SHA256, SHATYPE_SHA384, SHATYPE_SHA512};
   80|  1.57k|  const size_t num_sha = sizeof(sha_types) / sizeof(sha_types[0]);
   81|       |
   82|  7.88k|  for (size_t s = 0; s < num_sha; s++) {
  ------------------
  |  Branch (82:22): [True: 6.30k, False: 1.57k]
  ------------------
   83|  6.30k|    memcpy(buf, Data, Size);
   84|  6.30k|    stun_is_command_message_full_check_str(buf, Size, true, NULL);
   85|  6.30k|    stun_check_message_integrity_str(TURN_CREDENTIALS_SHORT_TERM, buf, Size, uname, realm, upwd, sha_types[s]);
   86|       |
   87|  6.30k|    memcpy(buf, Data, Size);
   88|  6.30k|    stun_check_message_integrity_str(TURN_CREDENTIALS_LONG_TERM, buf, Size, uname, realm, upwd, sha_types[s]);
   89|  6.30k|  }
   90|  1.57k|}
FuzzStun.c:harness_attr_iter:
  148|  1.76k|static void harness_attr_iter(const uint8_t *Data, size_t Size) {
  149|  1.76k|  if (Size < STUN_HEADER_LENGTH || Size > 8192) {
  ------------------
  |  |   46|  3.53k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (149:7): [True: 81, False: 1.68k]
  |  Branch (149:36): [True: 84, False: 1.60k]
  ------------------
  150|    165|    return;
  151|    165|  }
  152|       |
  153|  1.60k|  uint8_t buf[8192];
  154|  1.60k|  memcpy(buf, Data, Size);
  155|       |
  156|  1.60k|  if (!stun_is_command_message_str(buf, Size)) {
  ------------------
  |  Branch (156:7): [True: 466, False: 1.13k]
  ------------------
  157|    466|    return;
  158|    466|  }
  159|       |
  160|  1.13k|  stun_attr_ref sar = stun_attr_get_first_str(buf, Size);
  161|  15.9k|  while (sar) {
  ------------------
  |  Branch (161:10): [True: 14.8k, False: 1.13k]
  ------------------
  162|  14.8k|    (void)stun_attr_get_type(sar);
  163|  14.8k|    (void)stun_attr_get_len(sar);
  164|  14.8k|    (void)stun_attr_get_value(sar);
  165|  14.8k|    (void)stun_attr_is_addr(sar);
  166|  14.8k|    sar = stun_attr_get_next_str(buf, Size, sar);
  167|  14.8k|  }
  168|       |
  169|  1.13k|  ioa_addr addr;
  170|  1.13k|  const size_t num_addr_attrs = sizeof(kAddrAttrs) / sizeof(kAddrAttrs[0]);
  171|  10.2k|  for (size_t i = 0; i < num_addr_attrs; i++) {
  ------------------
  |  Branch (171:22): [True: 9.09k, False: 1.13k]
  ------------------
  172|  9.09k|    sar = stun_attr_get_first_by_type_str(buf, Size, kAddrAttrs[i]);
  173|  9.09k|    if (sar) {
  ------------------
  |  Branch (173:9): [True: 1.15k, False: 7.94k]
  ------------------
  174|  1.15k|      memset(&addr, 0, sizeof(addr));
  175|  1.15k|      stun_attr_get_addr_str(buf, Size, sar, &addr, NULL);
  176|  1.15k|    }
  177|  9.09k|    memset(&addr, 0, sizeof(addr));
  178|  9.09k|    stun_attr_get_first_addr_str(buf, Size, kAddrAttrs[i], &addr, NULL);
  179|  9.09k|  }
  180|       |
  181|  1.13k|  sar = stun_attr_get_first_by_type_str(buf, Size, STUN_ATTRIBUTE_CHANNEL_NUMBER);
  ------------------
  |  |  117|  1.13k|#define STUN_ATTRIBUTE_CHANNEL_NUMBER (0x000C)
  ------------------
  182|  1.13k|  if (sar) {
  ------------------
  |  Branch (182:7): [True: 173, False: 964]
  ------------------
  183|    173|    (void)stun_attr_get_channel_number(sar);
  184|    173|  }
  185|  1.13k|  (void)stun_attr_get_first_channel_number_str(buf, Size);
  186|       |
  187|  1.13k|  sar = stun_attr_get_first_by_type_str(buf, Size, STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY);
  ------------------
  |  |  108|  1.13k|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY (0x0017)
  ------------------
  188|  1.13k|  if (sar) {
  ------------------
  |  Branch (188:7): [True: 21, False: 1.11k]
  ------------------
  189|     21|    (void)stun_get_requested_address_family(sar);
  190|     21|  }
  191|       |
  192|  1.13k|  sar = stun_attr_get_first_by_type_str(buf, Size, STUN_ATTRIBUTE_ADDITIONAL_ADDRESS_FAMILY);
  ------------------
  |  |  144|  1.13k|#define STUN_ATTRIBUTE_ADDITIONAL_ADDRESS_FAMILY (0x8000)
  ------------------
  193|  1.13k|  if (sar) {
  ------------------
  |  Branch (193:7): [True: 40, False: 1.09k]
  ------------------
  194|     40|    (void)stun_get_requested_address_family(sar);
  195|     40|  }
  196|       |
  197|  1.13k|  sar = stun_attr_get_first_by_type_str(buf, Size, STUN_ATTRIBUTE_EVEN_PORT);
  ------------------
  |  |  123|  1.13k|#define STUN_ATTRIBUTE_EVEN_PORT (0x0018)
  ------------------
  198|  1.13k|  if (sar) {
  ------------------
  |  Branch (198:7): [True: 40, False: 1.09k]
  ------------------
  199|     40|    (void)stun_attr_get_even_port(sar);
  200|     40|  }
  201|       |
  202|  1.13k|  sar = stun_attr_get_first_by_type_str(buf, Size, STUN_ATTRIBUTE_BANDWIDTH);
  ------------------
  |  |  119|  1.13k|#define STUN_ATTRIBUTE_BANDWIDTH (0x0010)
  ------------------
  203|  1.13k|  if (sar) {
  ------------------
  |  Branch (203:7): [True: 57, False: 1.08k]
  ------------------
  204|     57|    (void)stun_attr_get_bandwidth(sar);
  205|     57|  }
  206|       |
  207|  1.13k|  sar = stun_attr_get_first_by_type_str(buf, Size, STUN_ATTRIBUTE_NEW_BANDWIDTH);
  ------------------
  |  |   52|  1.13k|#define STUN_ATTRIBUTE_NEW_BANDWIDTH (0x8000 + STUN_ATTRIBUTE_BANDWIDTH)
  |  |  ------------------
  |  |  |  |  119|  1.13k|#define STUN_ATTRIBUTE_BANDWIDTH (0x0010)
  |  |  ------------------
  ------------------
  208|  1.13k|  if (sar) {
  ------------------
  |  Branch (208:7): [True: 26, False: 1.11k]
  ------------------
  209|     26|    (void)stun_attr_get_bandwidth(sar);
  210|     26|  }
  211|       |
  212|  1.13k|  sar = stun_attr_get_first_by_type_str(buf, Size, STUN_ATTRIBUTE_RESERVATION_TOKEN);
  ------------------
  |  |  127|  1.13k|#define STUN_ATTRIBUTE_RESERVATION_TOKEN (0x0022)
  ------------------
  213|  1.13k|  if (sar) {
  ------------------
  |  Branch (213:7): [True: 55, False: 1.08k]
  ------------------
  214|     55|    (void)stun_attr_get_reservation_token_value(sar);
  215|     55|  }
  216|       |
  217|  1.13k|  sar = stun_attr_get_first_by_type_str(buf, Size, STUN_ATTRIBUTE_CHANGE_REQUEST);
  ------------------
  |  |   97|  1.13k|#define STUN_ATTRIBUTE_CHANGE_REQUEST (0x0003)
  ------------------
  218|  1.13k|  if (sar) {
  ------------------
  |  Branch (218:7): [True: 34, False: 1.10k]
  ------------------
  219|     34|    bool change_ip = false, change_port = false;
  220|     34|    stun_attr_get_change_request_str(sar, &change_ip, &change_port);
  221|     34|  }
  222|       |
  223|  1.13k|  sar = stun_attr_get_first_by_type_str(buf, Size, STUN_ATTRIBUTE_RESPONSE_PORT);
  ------------------
  |  |  135|  1.13k|#define STUN_ATTRIBUTE_RESPONSE_PORT (0x0027)
  ------------------
  224|  1.13k|  if (sar) {
  ------------------
  |  Branch (224:7): [True: 34, False: 1.10k]
  ------------------
  225|     34|    (void)stun_attr_get_response_port_str(sar);
  226|     34|  }
  227|       |
  228|  1.13k|  sar = stun_attr_get_first_by_type_str(buf, Size, STUN_ATTRIBUTE_PADDING);
  ------------------
  |  |  134|  1.13k|#define STUN_ATTRIBUTE_PADDING (0x0026)
  ------------------
  229|  1.13k|  if (sar) {
  ------------------
  |  Branch (229:7): [True: 28, False: 1.10k]
  ------------------
  230|     28|    (void)stun_attr_get_padding_len_str(sar);
  231|     28|  }
  232|       |
  233|  1.13k|  {
  234|  1.13k|    int err_code = 0;
  235|  1.13k|    uint8_t err_msg[1024] = {0};
  236|  1.13k|    stun_is_error_response_str(buf, Size, &err_code, err_msg, sizeof(err_msg));
  237|  1.13k|  }
  238|  1.13k|  {
  239|  1.13k|    int err_code = 0;
  240|  1.13k|    uint8_t err_msg[1024] = {0};
  241|  1.13k|    uint8_t chal_realm[STUN_MAX_REALM_SIZE + 1] = {0};
  242|  1.13k|    uint8_t chal_nonce[STUN_MAX_NONCE_SIZE + 1] = {0};
  243|  1.13k|    uint8_t server_name[STUN_MAX_SERVER_NAME_SIZE + 1] = {0};
  244|  1.13k|    bool oauth = false;
  245|  1.13k|    stun_is_challenge_response_str(buf, Size, &err_code, err_msg, sizeof(err_msg), chal_realm, chal_nonce, server_name,
  246|  1.13k|                                   &oauth);
  247|  1.13k|  }
  248|       |
  249|  1.13k|  const size_t num_all_attrs = sizeof(kAllAttrTypes) / sizeof(kAllAttrTypes[0]);
  250|  51.1k|  for (size_t i = 0; i < num_all_attrs; i++) {
  ------------------
  |  Branch (250:22): [True: 50.0k, False: 1.13k]
  ------------------
  251|  50.0k|    sar = stun_attr_get_first_by_type_str(buf, Size, kAllAttrTypes[i]);
  252|  50.0k|    if (sar) {
  ------------------
  |  Branch (252:9): [True: 2.49k, False: 47.5k]
  ------------------
  253|  2.49k|      (void)stun_attr_get_type(sar);
  254|  2.49k|      (void)stun_attr_get_len(sar);
  255|  2.49k|      (void)stun_attr_get_value(sar);
  256|  2.49k|    }
  257|  50.0k|  }
  258|  1.13k|}
FuzzStun.c:harness_attr_add:
  263|  1.76k|static void harness_attr_add(const uint8_t *Data, size_t Size) {
  264|  1.76k|  if (Size < STUN_HEADER_LENGTH || Size > 4096) {
  ------------------
  |  |   46|  3.53k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (264:7): [True: 81, False: 1.68k]
  |  Branch (264:36): [True: 149, False: 1.53k]
  ------------------
  265|    230|    return;
  266|    230|  }
  267|       |
  268|  1.53k|  uint8_t buf[MAX_STUN_MESSAGE_SIZE] = {0};
  269|  1.53k|  memcpy(buf, Data, Size);
  270|  1.53k|  size_t len = Size;
  271|       |
  272|  1.53k|  if (!stun_is_command_message_str(buf, len)) {
  ------------------
  |  Branch (272:7): [True: 420, False: 1.11k]
  ------------------
  273|    420|    return;
  274|    420|  }
  275|       |
  276|  1.11k|  uint8_t test_uname[] = "fuzzuser@fuzz.realm";
  277|  1.11k|  stun_attr_add_str(buf, &len, STUN_ATTRIBUTE_USERNAME, test_uname, (int)(sizeof(test_uname) - 1));
  ------------------
  |  |  100|  1.11k|#define STUN_ATTRIBUTE_USERNAME (0x0006)
  ------------------
  278|       |
  279|  1.11k|  uint8_t test_realm[] = "fuzz.realm";
  280|  1.11k|  stun_attr_add_str(buf, &len, STUN_ATTRIBUTE_REALM, test_realm, (int)(sizeof(test_realm) - 1));
  ------------------
  |  |  106|  1.11k|#define STUN_ATTRIBUTE_REALM (0x0014)
  ------------------
  281|       |
  282|  1.11k|  uint8_t test_nonce[] = "fuzznonce0123456789abcdef";
  283|  1.11k|  stun_attr_add_str(buf, &len, STUN_ATTRIBUTE_NONCE, test_nonce, (int)(sizeof(test_nonce) - 1));
  ------------------
  |  |  107|  1.11k|#define STUN_ATTRIBUTE_NONCE (0x0015)
  ------------------
  284|       |
  285|  1.11k|  uint8_t test_sw[] = "coturn-fuzz/1.0";
  286|  1.11k|  stun_attr_add_str(buf, &len, STUN_ATTRIBUTE_SOFTWARE, test_sw, (int)(sizeof(test_sw) - 1));
  ------------------
  |  |  112|  1.11k|#define STUN_ATTRIBUTE_SOFTWARE (0x8022)
  ------------------
  287|       |
  288|  1.11k|  uint8_t lifetime_val[4] = {0x00, 0x00, 0x02, 0x58};
  289|  1.11k|  stun_attr_add_str(buf, &len, STUN_ATTRIBUTE_LIFETIME, lifetime_val, 4);
  ------------------
  |  |  118|  1.11k|#define STUN_ATTRIBUTE_LIFETIME (0x000D)
  ------------------
  290|       |
  291|  1.11k|  uint8_t transport_val[4] = {STUN_ATTRIBUTE_TRANSPORT_UDP_VALUE, 0x00, 0x00, 0x00};
  ------------------
  |  |  176|  1.11k|#define STUN_ATTRIBUTE_TRANSPORT_UDP_VALUE (17)
  ------------------
  292|  1.11k|  stun_attr_add_str(buf, &len, STUN_ATTRIBUTE_REQUESTED_TRANSPORT, transport_val, 4);
  ------------------
  |  |  124|  1.11k|#define STUN_ATTRIBUTE_REQUESTED_TRANSPORT (0x0019)
  ------------------
  293|       |
  294|  1.11k|  uint8_t af_val[4] = {STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV4, 0x00, 0x00, 0x00};
  ------------------
  |  |  168|  1.11k|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV4 (0x01)
  ------------------
  295|  1.11k|  stun_attr_add_str(buf, &len, STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY, af_val, 4);
  ------------------
  |  |  108|  1.11k|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY (0x0017)
  ------------------
  296|       |
  297|  1.11k|  uint8_t even_port_val[1] = {0x80};
  298|  1.11k|  stun_attr_add_str(buf, &len, STUN_ATTRIBUTE_EVEN_PORT, even_port_val, 1);
  ------------------
  |  |  123|  1.11k|#define STUN_ATTRIBUTE_EVEN_PORT (0x0018)
  ------------------
  299|       |
  300|  1.11k|  stun_attr_add_str(buf, &len, STUN_ATTRIBUTE_DONT_FRAGMENT, NULL, 0);
  ------------------
  |  |  125|  1.11k|#define STUN_ATTRIBUTE_DONT_FRAGMENT (0x001A)
  ------------------
  301|       |
  302|  1.11k|  stun_attr_add_channel_number_str(buf, &len, 0x4001);
  303|       |
  304|  1.11k|  stun_attr_add_bandwidth_str(buf, &len, 1000000);
  305|       |
  306|  1.11k|  ioa_addr addr4 = {0};
  307|  1.11k|  addr4.s4.sin_family = AF_INET;
  308|  1.11k|  addr4.s4.sin_port = htons(12345);
  309|  1.11k|  addr4.s4.sin_addr.s_addr = htonl(0xC0A80001);
  310|  1.11k|  stun_attr_add_addr_str(buf, &len, STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS, &addr4);
  ------------------
  |  |  109|  1.11k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  311|  1.11k|  stun_attr_add_addr_str(buf, &len, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &addr4);
  ------------------
  |  |  120|  1.11k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  312|  1.11k|  stun_attr_add_addr_str(buf, &len, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, &addr4);
  ------------------
  |  |  122|  1.11k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  313|  1.11k|  stun_attr_add_addr_str(buf, &len, STUN_ATTRIBUTE_MAPPED_ADDRESS, &addr4);
  ------------------
  |  |   95|  1.11k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
  314|       |
  315|  1.11k|  ioa_addr addr6 = {0};
  316|  1.11k|  addr6.s6.sin6_family = AF_INET6;
  317|  1.11k|  addr6.s6.sin6_port = htons(54321);
  318|  1.11k|  addr6.s6.sin6_addr.s6_addr[15] = 1;
  319|  1.11k|  stun_attr_add_addr_str(buf, &len, STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS, &addr6);
  ------------------
  |  |  109|  1.11k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  320|  1.11k|  stun_attr_add_addr_str(buf, &len, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, &addr6);
  ------------------
  |  |  122|  1.11k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  321|       |
  322|  1.11k|  stun_attr_add_address_error_code(buf, &len, STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6, 440);
  ------------------
  |  |  169|  1.11k|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6 (0x02)
  ------------------
  323|       |
  324|  1.11k|  stun_attr_add_change_request_str(buf, &len, true, true);
  325|  1.11k|  stun_attr_add_response_port_str(buf, &len, 3479);
  326|  1.11k|  stun_attr_add_padding_str(buf, &len, 64);
  327|       |
  328|  1.11k|  if (Size > STUN_HEADER_LENGTH + 4) {
  ------------------
  |  |   46|  1.11k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (328:7): [True: 1.00k, False: 117]
  ------------------
  329|  1.00k|    int data_len = (int)(Size - STUN_HEADER_LENGTH);
  ------------------
  |  |   46|  1.00k|#define STUN_HEADER_LENGTH (20)
  ------------------
  330|  1.00k|    if (data_len > 1024) {
  ------------------
  |  Branch (330:9): [True: 94, False: 907]
  ------------------
  331|     94|      data_len = 1024;
  332|     94|    }
  333|  1.00k|    stun_attr_add_str(buf, &len, STUN_ATTRIBUTE_DATA, Data + STUN_HEADER_LENGTH, data_len);
  ------------------
  |  |  121|  1.00k|#define STUN_ATTRIBUTE_DATA (0x0013)
  ------------------
                  stun_attr_add_str(buf, &len, STUN_ATTRIBUTE_DATA, Data + STUN_HEADER_LENGTH, data_len);
  ------------------
  |  |   46|  1.00k|#define STUN_HEADER_LENGTH (20)
  ------------------
  334|  1.00k|  }
  335|       |
  336|  1.11k|  stun_attr_add_fingerprint_str(buf, &len);
  337|  1.11k|}
FuzzStun.c:harness_old_stun:
  342|  1.76k|static void harness_old_stun(const uint8_t *Data, size_t Size) {
  343|  1.76k|  if (Size < STUN_HEADER_LENGTH || Size > 5120) {
  ------------------
  |  |   46|  3.53k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (343:7): [True: 81, False: 1.68k]
  |  Branch (343:36): [True: 110, False: 1.57k]
  ------------------
  344|    191|    return;
  345|    191|  }
  346|       |
  347|  1.57k|  uint8_t buf[5120];
  348|  1.57k|  memcpy(buf, Data, Size);
  349|       |
  350|  1.57k|  uint32_t cookie = 0;
  351|  1.57k|  bool is_old = old_stun_is_command_message_str(buf, Size, &cookie);
  352|  1.57k|  (void)stun_is_command_message_str(buf, Size);
  353|       |
  354|  1.57k|  if (is_old) {
  ------------------
  |  Branch (354:7): [True: 172, False: 1.40k]
  ------------------
  355|    172|    (void)stun_get_msg_type_str(buf, Size);
  356|    172|    (void)stun_get_method_str(buf, Size);
  357|       |
  358|    172|    stun_is_request_str(buf, Size);
  359|    172|    stun_is_indication_str(buf, Size);
  360|    172|    stun_is_success_response_str(buf, Size);
  361|       |
  362|    172|    int err_code = 0;
  363|    172|    uint8_t err_msg[256] = {0};
  364|    172|    stun_is_error_response_str(buf, Size, &err_code, err_msg, sizeof(err_msg));
  365|       |
  366|    172|    bool fp_present = false;
  367|    172|    stun_is_command_message_full_check_str(buf, Size, true, &fp_present);
  368|    172|    stun_is_command_message_full_check_str(buf, Size, false, &fp_present);
  369|       |
  370|    172|    stun_is_binding_request_str(buf, Size, 0);
  371|    172|    stun_is_binding_response_str(buf, Size);
  372|       |
  373|    172|    stun_attr_ref sar = stun_attr_get_first_str(buf, Size);
  374|    809|    while (sar) {
  ------------------
  |  Branch (374:12): [True: 637, False: 172]
  ------------------
  375|    637|      (void)stun_attr_get_type(sar);
  376|    637|      (void)stun_attr_get_len(sar);
  377|    637|      sar = stun_attr_get_next_str(buf, Size, sar);
  378|    637|    }
  379|    172|  }
  380|  1.57k|}
FuzzStun.c:harness_challenge_response_builder:
  404|  1.76k|static void harness_challenge_response_builder(const uint8_t *Data, size_t Size) {
  405|  1.76k|  if (!Size) {
  ------------------
  |  Branch (405:7): [True: 0, False: 1.76k]
  ------------------
  406|      0|    return;
  407|      0|  }
  408|       |
  409|  1.76k|  static const uint16_t kMethods[] = {
  410|  1.76k|      STUN_METHOD_ALLOCATE,
  ------------------
  |  |   82|  1.76k|#define STUN_METHOD_ALLOCATE (0x0003)
  ------------------
  411|  1.76k|      STUN_METHOD_BINDING,
  ------------------
  |  |   81|  1.76k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
  412|  1.76k|      STUN_METHOD_REFRESH,
  ------------------
  |  |   83|  1.76k|#define STUN_METHOD_REFRESH (0x0004)
  ------------------
  413|  1.76k|      STUN_METHOD_CHANNEL_BIND,
  ------------------
  |  |   87|  1.76k|#define STUN_METHOD_CHANNEL_BIND (0x0009)
  ------------------
  414|  1.76k|  };
  415|  1.76k|  const uint16_t method = kMethods[Data[0] % (sizeof(kMethods) / sizeof(kMethods[0]))];
  416|       |
  417|       |  /* Length of each variable-length string is taken from a single fuzz byte
  418|       |   * so libFuzzer still varies the inputs across iterations. Floors keep the
  419|       |   * attribute non-empty so the inner copies in stun_is_challenge_response_str
  420|       |   * actually populate the output buffers. */
  421|  1.76k|  const size_t realm_len = 1 + (Size > 1 ? (Data[1] % 16) : 0);
  ------------------
  |  Branch (421:33): [True: 1.73k, False: 32]
  ------------------
  422|  1.76k|  const size_t nonce_len = 1 + (Size > 2 ? (Data[2] % 16) : 0);
  ------------------
  |  Branch (422:33): [True: 1.72k, False: 47]
  ------------------
  423|  1.76k|  const size_t server_len = 1 + (Size > 3 ? (Data[3] % 16) : 0);
  ------------------
  |  Branch (423:34): [True: 1.71k, False: 56]
  ------------------
  424|       |
  425|  1.76k|  uint8_t realm_buf[STUN_MAX_REALM_SIZE + 1] = {0};
  426|  1.76k|  uint8_t nonce_buf[STUN_MAX_NONCE_SIZE + 1] = {0};
  427|  1.76k|  uint8_t server_buf[STUN_MAX_SERVER_NAME_SIZE + 1] = {0};
  428|  13.3k|  for (size_t i = 0; i < realm_len; ++i) {
  ------------------
  |  Branch (428:22): [True: 11.5k, False: 1.76k]
  ------------------
  429|  11.5k|    realm_buf[i] = (uint8_t)('a' + (i % 26));
  430|  11.5k|  }
  431|  6.39k|  for (size_t i = 0; i < nonce_len; ++i) {
  ------------------
  |  Branch (431:22): [True: 4.63k, False: 1.76k]
  ------------------
  432|  4.63k|    nonce_buf[i] = (uint8_t)('0' + (i % 10));
  433|  4.63k|  }
  434|  13.0k|  for (size_t i = 0; i < server_len; ++i) {
  ------------------
  |  Branch (434:22): [True: 11.2k, False: 1.76k]
  ------------------
  435|  11.2k|    server_buf[i] = (uint8_t)('A' + (i % 26));
  436|  11.2k|  }
  437|       |
  438|  1.76k|  stun_tid tid = {0};
  439|  22.9k|  for (size_t i = 0; i < STUN_TID_SIZE; ++i) {
  ------------------
  |  |   53|  22.9k|#define STUN_TID_SIZE (12)
  ------------------
  |  Branch (439:22): [True: 21.2k, False: 1.76k]
  ------------------
  440|  21.2k|    tid.tsx_id[i] = (uint8_t)(Size > i + 4 ? Data[i + 4] : (uint8_t)i);
  ------------------
  |  Branch (440:31): [True: 20.3k, False: 858]
  ------------------
  441|  21.2k|  }
  442|       |
  443|       |  /* Each variant builds a fresh error response and runs it through the
  444|       |   * predicate so the inner attribute lookups fire. */
  445|  1.76k|  static const struct {
  446|  1.76k|    uint16_t err_code;
  447|  1.76k|    bool include_realm;
  448|  1.76k|    bool include_nonce;
  449|  1.76k|    bool include_third_party_auth;
  450|  1.76k|  } kVariants[] = {
  451|  1.76k|      {401, true, true, false},   /* canonical 401 challenge: REALM + NONCE */
  452|  1.76k|      {401, true, true, true},    /* same + THIRD-PARTY-AUTHORIZATION (OAuth branch) */
  453|  1.76k|      {438, true, true, false},   /* covers the (*err_code) == 438 disjunct */
  454|  1.76k|      {401, true, false, false},  /* REALM present, NONCE missing — negative inner path */
  455|  1.76k|      {401, false, false, false}, /* err_code matches but no REALM — outer negative path */
  456|  1.76k|      {400, true, true, false},   /* err_code does not match 401/438 — early-out path */
  457|  1.76k|  };
  458|       |
  459|  12.3k|  for (size_t v = 0; v < sizeof(kVariants) / sizeof(kVariants[0]); ++v) {
  ------------------
  |  Branch (459:22): [True: 10.6k, False: 1.76k]
  ------------------
  460|  10.6k|    uint8_t buf[MAX_STUN_MESSAGE_SIZE] = {0};
  461|  10.6k|    size_t len = 0;
  462|  10.6k|    stun_init_error_response_str(method, buf, &len, kVariants[v].err_code, (const uint8_t *)"unauthorized", &tid, true);
  463|       |
  464|  10.6k|    if (kVariants[v].include_realm) {
  ------------------
  |  Branch (464:9): [True: 8.84k, False: 1.76k]
  ------------------
  465|  8.84k|      stun_attr_add_str(buf, &len, STUN_ATTRIBUTE_REALM, realm_buf, (int)realm_len);
  ------------------
  |  |  106|  8.84k|#define STUN_ATTRIBUTE_REALM (0x0014)
  ------------------
  466|  8.84k|    }
  467|  10.6k|    if (kVariants[v].include_third_party_auth) {
  ------------------
  |  Branch (467:9): [True: 1.76k, False: 8.84k]
  ------------------
  468|  1.76k|      stun_attr_add_str(buf, &len, STUN_ATTRIBUTE_THIRD_PARTY_AUTHORIZATION, server_buf, (int)server_len);
  ------------------
  |  |  227|  1.76k|#define STUN_ATTRIBUTE_THIRD_PARTY_AUTHORIZATION (0x802E)
  ------------------
  469|  1.76k|    }
  470|  10.6k|    if (kVariants[v].include_nonce) {
  ------------------
  |  Branch (470:9): [True: 7.07k, False: 3.53k]
  ------------------
  471|  7.07k|      stun_attr_add_str(buf, &len, STUN_ATTRIBUTE_NONCE, nonce_buf, (int)nonce_len);
  ------------------
  |  |  107|  7.07k|#define STUN_ATTRIBUTE_NONCE (0x0015)
  ------------------
  472|  7.07k|    }
  473|       |
  474|  10.6k|    int err_code = 0;
  475|  10.6k|    uint8_t err_msg[1024] = {0};
  476|  10.6k|    uint8_t out_realm[STUN_MAX_REALM_SIZE + 1] = {0};
  477|  10.6k|    uint8_t out_nonce[STUN_MAX_NONCE_SIZE + 1] = {0};
  478|  10.6k|    uint8_t out_server[STUN_MAX_SERVER_NAME_SIZE + 1] = {0};
  479|  10.6k|    bool oauth = false;
  480|  10.6k|    (void)stun_is_challenge_response_str(buf, len, &err_code, err_msg, sizeof(err_msg), out_realm, out_nonce,
  481|  10.6k|                                         out_server, &oauth);
  482|       |
  483|       |    /* Also exercise the NULL-oauth-pointer branch, which is reachable from
  484|       |     * other call sites in the codebase. */
  485|  10.6k|    (void)stun_is_challenge_response_str(buf, len, &err_code, err_msg, sizeof(err_msg), out_realm, out_nonce,
  486|       |                                         out_server, NULL);
  487|  10.6k|  }
  488|  1.76k|}
FuzzStun.c:harness_full_addr_parser:
  493|  1.76k|static void harness_full_addr_parser(const uint8_t *Data, size_t Size) {
  494|  1.76k|  ioa_addr addr;
  495|  1.76k|  const uint16_t default_port = fuzz_u16(Data, Size, 0);
  496|  1.76k|  const uint16_t explicit_port = fuzz_u16(Data, Size, 2);
  497|       |
  498|  1.76k|  char ipv4_plain[MAX_IOA_ADDR_STRING];
  499|  1.76k|  char ipv4_with_port[MAX_IOA_ADDR_STRING];
  500|  1.76k|  char ipv6_bracketed[MAX_IOA_ADDR_STRING];
  501|  1.76k|  char ipv6_with_port[MAX_IOA_ADDR_STRING];
  502|  1.76k|  char ipv4_spaced[MAX_IOA_ADDR_STRING];
  503|       |
  504|  1.76k|  snprintf(ipv4_plain, sizeof(ipv4_plain), "%u.%u.%u.%u", fuzz_byte(Data, Size, 4), fuzz_byte(Data, Size, 5),
  505|  1.76k|           fuzz_byte(Data, Size, 6), fuzz_byte(Data, Size, 7));
  506|  1.76k|  snprintf(ipv4_with_port, sizeof(ipv4_with_port), "%u.%u.%u.%u:%u", fuzz_byte(Data, Size, 8), fuzz_byte(Data, Size, 9),
  507|  1.76k|           fuzz_byte(Data, Size, 10), fuzz_byte(Data, Size, 11), explicit_port);
  508|  1.76k|  snprintf(ipv6_bracketed, sizeof(ipv6_bracketed), "[2001:db8:%x:%x::%x]", fuzz_u16(Data, Size, 12),
  509|  1.76k|           fuzz_u16(Data, Size, 14), fuzz_u16(Data, Size, 16));
  510|  1.76k|  snprintf(ipv6_with_port, sizeof(ipv6_with_port), "[2001:db8:%x:%x::%x]:%u", fuzz_u16(Data, Size, 18),
  511|  1.76k|           fuzz_u16(Data, Size, 20), fuzz_u16(Data, Size, 22), explicit_port);
  512|  1.76k|  snprintf(ipv4_spaced, sizeof(ipv4_spaced), "  %u.%u.%u.%u:%u", fuzz_byte(Data, Size, 24), fuzz_byte(Data, Size, 25),
  513|  1.76k|           fuzz_byte(Data, Size, 26), fuzz_byte(Data, Size, 27), explicit_port);
  514|       |
  515|  1.76k|  static const char *kFixedInputs[] = {
  516|  1.76k|      "", "0.0.0.0", "127.0.0.1:3478", "192.0.2.1:", "[::1]", "[::1]:5349", "[2001:db8::1]  ", "::1",
  517|  1.76k|  };
  518|       |
  519|  15.9k|  for (size_t i = 0; i < sizeof(kFixedInputs) / sizeof(kFixedInputs[0]); ++i) {
  ------------------
  |  Branch (519:22): [True: 14.1k, False: 1.76k]
  ------------------
  520|  14.1k|    memset(&addr, 0, sizeof(addr));
  521|  14.1k|    (void)make_ioa_addr_from_full_string((const uint8_t *)kFixedInputs[i], default_port, &addr);
  522|  14.1k|  }
  523|       |
  524|  1.76k|  const char *generated[] = {ipv4_plain, ipv4_with_port, ipv6_bracketed, ipv6_with_port, ipv4_spaced};
  525|  10.6k|  for (size_t i = 0; i < sizeof(generated) / sizeof(generated[0]); ++i) {
  ------------------
  |  Branch (525:22): [True: 8.84k, False: 1.76k]
  ------------------
  526|  8.84k|    memset(&addr, 0, sizeof(addr));
  527|  8.84k|    (void)make_ioa_addr_from_full_string((const uint8_t *)generated[i], default_port, &addr);
  528|  8.84k|  }
  529|       |
  530|       |  (void)make_ioa_addr_from_full_string((const uint8_t *)ipv4_plain, default_port, NULL);
  531|  1.76k|}
FuzzStun.c:fuzz_u16:
   29|  14.1k|static uint16_t fuzz_u16(const uint8_t *Data, size_t Size, size_t idx) {
   30|  14.1k|  return (uint16_t)(((uint16_t)fuzz_byte(Data, Size, idx) << 8) | (uint16_t)fuzz_byte(Data, Size, idx + 1));
   31|  14.1k|}
FuzzStun.c:fuzz_byte:
   27|   772k|static uint8_t fuzz_byte(const uint8_t *Data, size_t Size, size_t idx) { return Size ? Data[idx % Size] : 0; }
  ------------------
  |  Branch (27:81): [True: 772k, False: 0]
  ------------------
FuzzStun.c:harness_integrity_attr_add:
  536|  1.76k|static void harness_integrity_attr_add(const uint8_t *Data, size_t Size) {
  537|  1.76k|  static const SHATYPE kShaTypes[] = {SHATYPE_SHA1, SHATYPE_SHA256, SHATYPE_SHA384, SHATYPE_SHA512};
  538|  1.76k|  const SHATYPE shatype = kShaTypes[fuzz_byte(Data, Size, 0) % (sizeof(kShaTypes) / sizeof(kShaTypes[0]))];
  539|       |
  540|  1.76k|  uint8_t uname[STUN_MAX_USERNAME_SIZE + 1] = {0};
  541|  1.76k|  uint8_t realm[STUN_MAX_REALM_SIZE + 1] = {0};
  542|  1.76k|  uint8_t nonce[STUN_MAX_NONCE_SIZE + 1] = {0};
  543|  1.76k|  uint8_t upwd[STUN_MAX_PWD_SIZE + 1] = {0};
  544|  1.76k|  password_t pwd = {0};
  545|  1.76k|  hmackey_t key = {0};
  546|       |
  547|  1.76k|  fuzz_printable_string(Data, Size, 1, uname, sizeof(uname));
  548|  1.76k|  fuzz_printable_string(Data, Size, 1 + sizeof(uname), realm, sizeof(realm));
  549|  1.76k|  fuzz_printable_string(Data, Size, 1 + sizeof(uname) + sizeof(realm), nonce, sizeof(nonce));
  550|  1.76k|  fuzz_printable_string(Data, Size, 1 + sizeof(uname) + sizeof(realm) + sizeof(nonce), upwd, sizeof(upwd));
  551|  1.76k|  fuzz_printable_string(Data, Size, 1 + sizeof(uname) + sizeof(realm) + sizeof(nonce) + sizeof(upwd), pwd, sizeof(pwd));
  552|       |
  553|  1.76k|  if (!uname[0]) {
  ------------------
  |  Branch (553:7): [True: 196, False: 1.57k]
  ------------------
  554|    196|    memcpy(uname, "fuzzuser", sizeof("fuzzuser"));
  555|    196|  }
  556|  1.76k|  if (!realm[0]) {
  ------------------
  |  Branch (556:7): [True: 580, False: 1.18k]
  ------------------
  557|    580|    memcpy(realm, "fuzz.realm", sizeof("fuzz.realm"));
  558|    580|  }
  559|  1.76k|  if (!nonce[0]) {
  ------------------
  |  Branch (559:7): [True: 822, False: 946]
  ------------------
  560|    822|    memcpy(nonce, "fuzznonce", sizeof("fuzznonce"));
  561|    822|  }
  562|  1.76k|  if (!upwd[0]) {
  ------------------
  |  Branch (562:7): [True: 1.16k, False: 604]
  ------------------
  563|  1.16k|    memcpy(upwd, "fuzzpassword", sizeof("fuzzpassword"));
  564|  1.16k|  }
  565|  1.76k|  if (!pwd[0]) {
  ------------------
  |  Branch (565:7): [True: 576, False: 1.19k]
  ------------------
  566|    576|    memcpy(pwd, "shortterm", sizeof("shortterm"));
  567|    576|  }
  568|       |
  569|   114k|  for (size_t i = 0; i < sizeof(key); ++i) {
  ------------------
  |  Branch (569:22): [True: 113k, False: 1.76k]
  ------------------
  570|   113k|    key[i] = fuzz_byte(Data, Size, 32 + i);
  571|   113k|  }
  572|       |
  573|  1.76k|  uint8_t buf[MAX_STUN_MESSAGE_SIZE];
  574|  1.76k|  size_t len = 0;
  575|  1.76k|  stun_init_request_str(STUN_METHOD_BINDING, buf, &len);
  ------------------
  |  |   81|  1.76k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
  576|  1.76k|  (void)stun_attr_add_integrity_by_key_str(buf, &len, uname, realm, key, nonce, shatype);
  577|       |
  578|  1.76k|  len = 0;
  579|  1.76k|  stun_init_request_str(STUN_METHOD_ALLOCATE, buf, &len);
  ------------------
  |  |   82|  1.76k|#define STUN_METHOD_ALLOCATE (0x0003)
  ------------------
  580|  1.76k|  (void)stun_attr_add_integrity_by_user_str(buf, &len, uname, realm, upwd, nonce, shatype);
  581|       |
  582|  1.76k|  len = 0;
  583|  1.76k|  stun_init_request_str(STUN_METHOD_REFRESH, buf, &len);
  ------------------
  |  |   83|  1.76k|#define STUN_METHOD_REFRESH (0x0004)
  ------------------
  584|  1.76k|  (void)stun_attr_add_integrity_by_user_short_term_str(buf, &len, uname, pwd, shatype);
  585|       |
  586|  1.76k|  len = 0;
  587|  1.76k|  stun_init_request_str(STUN_METHOD_CHANNEL_BIND, buf, &len);
  ------------------
  |  |   87|  1.76k|#define STUN_METHOD_CHANNEL_BIND (0x0009)
  ------------------
  588|  1.76k|  (void)stun_attr_add_integrity_str(TURN_CREDENTIALS_SHORT_TERM, buf, &len, key, pwd, shatype);
  589|       |
  590|  1.76k|  len = 0;
  591|  1.76k|  stun_init_request_str(STUN_METHOD_BINDING, buf, &len);
  ------------------
  |  |   81|  1.76k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
  592|  1.76k|  (void)stun_attr_add_integrity_str(TURN_CREDENTIALS_LONG_TERM, buf, &len, key, pwd, shatype);
  593|  1.76k|}
FuzzStun.c:fuzz_printable_string:
   33|  8.84k|static void fuzz_printable_string(const uint8_t *Data, size_t Size, size_t idx, uint8_t *out, size_t out_size) {
   34|  8.84k|  if (!out_size) {
  ------------------
  |  Branch (34:7): [True: 0, False: 8.84k]
  ------------------
   35|      0|    return;
   36|      0|  }
   37|       |
   38|  8.84k|  const size_t max_len = out_size - 1;
   39|  8.84k|  const size_t len = max_len ? (size_t)(fuzz_byte(Data, Size, idx) % (max_len + 1)) : 0;
  ------------------
  |  Branch (39:22): [True: 8.84k, False: 0]
  ------------------
   40|   607k|  for (size_t i = 0; i < len; ++i) {
  ------------------
  |  Branch (40:22): [True: 599k, False: 8.84k]
  ------------------
   41|   599k|    out[i] = (uint8_t)(33 + (fuzz_byte(Data, Size, idx + 1 + i) % 94));
   42|   599k|  }
   43|  8.84k|  out[len] = 0;
   44|  8.84k|}

turn_malloc_impl:
  938|  9.67k|void *turn_malloc_impl(size_t sz, const char *file, int line) {
  939|  9.67k|  void *ptr = malloc(sz);
  940|  9.67k|  if (!ptr && sz) {
  ------------------
  |  Branch (940:7): [True: 0, False: 9.67k]
  |  Branch (940:15): [True: 0, False: 0]
  ------------------
  941|      0|    turn_out_of_memory(file, line, "malloc", sz);
  942|      0|  }
  943|  9.67k|  return ptr;
  944|  9.67k|}
turn_calloc_impl:
  946|  1.11k|void *turn_calloc_impl(size_t number, size_t size, const char *file, int line) {
  947|  1.11k|  void *ptr = calloc(number, size);
  948|  1.11k|  if (!ptr && number && size) {
  ------------------
  |  Branch (948:7): [True: 0, False: 1.11k]
  |  Branch (948:15): [True: 0, False: 0]
  |  Branch (948:25): [True: 0, False: 0]
  ------------------
  949|      0|    turn_out_of_memory(file, line, "calloc", number * size);
  950|      0|  }
  951|  1.11k|  return ptr;
  952|  1.11k|}
turn_realloc_impl:
  954|      8|void *turn_realloc_impl(void *ptr, size_t sz, const char *file, int line) {
  955|      8|  void *newptr = realloc(ptr, sz);
  956|      8|  if (!newptr && sz) {
  ------------------
  |  Branch (956:7): [True: 0, False: 8]
  |  Branch (956:18): [True: 0, False: 0]
  ------------------
  957|      0|    turn_out_of_memory(file, line, "realloc", sz);
  958|      0|  }
  959|      8|  return newptr;
  960|      8|}
turn_strdup_impl:
  962|  22.9k|char *turn_strdup_impl(const char *s, const char *file, int line) {
  963|  22.9k|  if (!s) {
  ------------------
  |  Branch (963:7): [True: 0, False: 22.9k]
  ------------------
  964|      0|    return NULL;
  965|      0|  }
  966|  22.9k|  char *ptr = strdup(s);
  967|  22.9k|  if (!ptr) {
  ------------------
  |  Branch (967:7): [True: 0, False: 22.9k]
  ------------------
  968|      0|    turn_out_of_memory(file, line, "strdup", strlen(s) + 1);
  969|      0|  }
  970|  22.9k|  return ptr;
  971|  22.9k|}

addr_set_any:
   48|  15.5k|void addr_set_any(ioa_addr *addr) {
   49|  15.5k|  if (addr) {
  ------------------
  |  Branch (49:7): [True: 15.5k, False: 0]
  ------------------
   50|  15.5k|    memset(addr, 0, sizeof(ioa_addr));
   51|  15.5k|  }
   52|  15.5k|}
addr_eq_no_port:
  180|  15.3k|int addr_eq_no_port(const ioa_addr *a1, const ioa_addr *a2) {
  181|       |
  182|  15.3k|  if (!a1) {
  ------------------
  |  Branch (182:7): [True: 0, False: 15.3k]
  ------------------
  183|      0|    return (!a2);
  184|  15.3k|  } else if (!a2) {
  ------------------
  |  Branch (184:14): [True: 0, False: 15.3k]
  ------------------
  185|      0|    return (!a1);
  186|      0|  }
  187|       |
  188|  15.3k|  if (a1->ss.sa_family == a2->ss.sa_family) {
  ------------------
  |  Branch (188:7): [True: 7.68k, False: 7.65k]
  ------------------
  189|  7.68k|    if (a1->ss.sa_family == AF_INET) {
  ------------------
  |  Branch (189:9): [True: 5.18k, False: 2.50k]
  ------------------
  190|  5.18k|      if ((int)a1->s4.sin_addr.s_addr == (int)a2->s4.sin_addr.s_addr) {
  ------------------
  |  Branch (190:11): [True: 28, False: 5.15k]
  ------------------
  191|     28|        return 1;
  192|     28|      }
  193|  5.18k|    } else if (a1->ss.sa_family == AF_INET6) {
  ------------------
  |  Branch (193:16): [True: 2.50k, False: 0]
  ------------------
  194|  2.50k|      if (memcmp(&(a1->s6.sin6_addr), &(a2->s6.sin6_addr), sizeof(struct in6_addr)) == 0) {
  ------------------
  |  Branch (194:11): [True: 24, False: 2.47k]
  ------------------
  195|     24|        return 1;
  196|     24|      }
  197|  2.50k|    }
  198|  7.68k|  }
  199|  15.2k|  return 0;
  200|  15.3k|}
make_ioa_addr:
  202|  22.9k|int make_ioa_addr(const uint8_t *saddr0, uint16_t port, ioa_addr *addr) {
  203|       |
  204|  22.9k|  if (!saddr0 || !addr) {
  ------------------
  |  Branch (204:7): [True: 0, False: 22.9k]
  |  Branch (204:18): [True: 0, False: 22.9k]
  ------------------
  205|      0|    return -1;
  206|      0|  }
  207|       |
  208|  22.9k|  char ssaddr[257];
  209|  22.9k|  STRCPY(ssaddr, saddr0);
  ------------------
  |  |  242|  22.9k|  do {                                                                                                                 \
  |  |  243|  22.9k|    if ((const char *)(dst) != (const char *)(src)) {                                                                  \
  |  |  ------------------
  |  |  |  Branch (243:9): [True: 22.9k, False: 0]
  |  |  ------------------
  |  |  244|  22.9k|      if (sizeof(dst) == sizeof(char *))                                                                               \
  |  |  ------------------
  |  |  |  Branch (244:11): [Folded, False: 22.9k]
  |  |  ------------------
  |  |  245|  22.9k|        strcpy(((char *)(dst)), (const char *)(src));                                                                  \
  |  |  246|  22.9k|      else {                                                                                                           \
  |  |  247|  22.9k|        size_t szdst = sizeof((dst));                                                                                  \
  |  |  248|  22.9k|        strncpy((char *)(dst), (const char *)(src), szdst);                                                            \
  |  |  249|  22.9k|        ((char *)(dst))[szdst - 1] = 0;                                                                                \
  |  |  250|  22.9k|      }                                                                                                                \
  |  |  251|  22.9k|    }                                                                                                                  \
  |  |  252|  22.9k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (252:12): [Folded, False: 22.9k]
  |  |  ------------------
  ------------------
  210|       |
  211|  22.9k|  char *saddr = ssaddr;
  212|  22.9k|  while (*saddr == ' ') {
  ------------------
  |  Branch (212:10): [True: 0, False: 22.9k]
  ------------------
  213|      0|    ++saddr;
  214|      0|  }
  215|       |
  216|  22.9k|  size_t len = strlen(saddr);
  217|  22.9k|  while (len > 0) {
  ------------------
  |  Branch (217:10): [True: 19.4k, False: 3.53k]
  ------------------
  218|  19.4k|    if (saddr[len - 1] == ' ') {
  ------------------
  |  Branch (218:9): [True: 0, False: 19.4k]
  ------------------
  219|      0|      saddr[len - 1] = 0;
  220|      0|      --len;
  221|  19.4k|    } else {
  222|  19.4k|      break;
  223|  19.4k|    }
  224|  19.4k|  }
  225|       |
  226|  22.9k|  memset(addr, 0, sizeof(ioa_addr));
  227|  22.9k|  if ((len == 0) || (inet_pton(AF_INET, saddr, &addr->s4.sin_addr) == 1)) {
  ------------------
  |  Branch (227:7): [True: 3.53k, False: 19.4k]
  |  Branch (227:21): [True: 10.6k, False: 8.84k]
  ------------------
  228|  14.1k|    addr->s4.sin_family = AF_INET;
  229|       |#if defined(TURN_HAS_SIN_LEN) /* tested when configured */
  230|       |    addr->s4.sin_len = sizeof(struct sockaddr_in);
  231|       |#endif
  232|  14.1k|    addr->s4.sin_port = nswap16(port);
  ------------------
  |  |   86|  14.1k|#define nswap16(s) ntohs(s)
  ------------------
  233|  14.1k|  } else if (inet_pton(AF_INET6, saddr, &addr->s6.sin6_addr) == 1) {
  ------------------
  |  Branch (233:14): [True: 8.84k, False: 0]
  ------------------
  234|  8.84k|    addr->s6.sin6_family = AF_INET6;
  235|       |#if defined(SIN6_LEN) /* this define is required by IPv6 if used */
  236|       |    addr->s6.sin6_len = sizeof(struct sockaddr_in6);
  237|       |#endif
  238|  8.84k|    addr->s6.sin6_port = nswap16(port);
  ------------------
  |  |   86|  8.84k|#define nswap16(s) ntohs(s)
  ------------------
  239|  8.84k|  } else {
  240|      0|    struct addrinfo addr_hints;
  241|      0|    struct addrinfo *addr_result = NULL;
  242|      0|    int err;
  243|       |
  244|      0|    memset(&addr_hints, 0, sizeof(struct addrinfo));
  245|      0|    addr_hints.ai_family = AF_UNSPEC;    /* Allow IPv4 or IPv6 */
  246|      0|    addr_hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */
  247|      0|    addr_hints.ai_flags = AI_PASSIVE;    /* For wildcard IP address */
  248|      0|    addr_hints.ai_protocol = 0;          /* Any protocol */
  249|      0|    addr_hints.ai_canonname = NULL;
  250|      0|    addr_hints.ai_addr = NULL;
  251|      0|    addr_hints.ai_next = NULL;
  252|       |
  253|      0|    err = getaddrinfo(saddr, NULL, &addr_hints, &addr_result);
  254|      0|    if ((err != 0) || (!addr_result)) {
  ------------------
  |  Branch (254:9): [True: 0, False: 0]
  |  Branch (254:23): [True: 0, False: 0]
  ------------------
  255|      0|      fprintf(stderr, "error resolving '%s' hostname: %s\n", saddr, gai_strerror(err));
  256|      0|      return -1;
  257|      0|    }
  258|       |
  259|      0|    int family = AF_INET;
  260|      0|    struct addrinfo *addr_result_orig = addr_result;
  261|      0|    int found = 0;
  262|       |
  263|      0|  beg_af:
  264|       |
  265|      0|    while (addr_result) {
  ------------------
  |  Branch (265:12): [True: 0, False: 0]
  ------------------
  266|       |
  267|      0|      if (addr_result->ai_family == family) {
  ------------------
  |  Branch (267:11): [True: 0, False: 0]
  ------------------
  268|      0|        if (addr_result->ai_family == AF_INET) {
  ------------------
  |  Branch (268:13): [True: 0, False: 0]
  ------------------
  269|      0|          memcpy(addr, addr_result->ai_addr, addr_result->ai_addrlen);
  270|      0|          addr->s4.sin_port = nswap16(port);
  ------------------
  |  |   86|      0|#define nswap16(s) ntohs(s)
  ------------------
  271|       |#if defined(TURN_HAS_SIN_LEN) /* tested when configured */
  272|       |          addr->s4.sin_len = sizeof(struct sockaddr_in);
  273|       |#endif
  274|      0|          found = 1;
  275|      0|          break;
  276|      0|        } else if (addr_result->ai_family == AF_INET6) {
  ------------------
  |  Branch (276:20): [True: 0, False: 0]
  ------------------
  277|      0|          memcpy(addr, addr_result->ai_addr, addr_result->ai_addrlen);
  278|      0|          addr->s6.sin6_port = nswap16(port);
  ------------------
  |  |   86|      0|#define nswap16(s) ntohs(s)
  ------------------
  279|       |#if defined(SIN6_LEN) /* this define is required by IPv6 if used */
  280|       |          addr->s6.sin6_len = sizeof(struct sockaddr_in6);
  281|       |#endif
  282|      0|          found = 1;
  283|      0|          break;
  284|      0|        }
  285|      0|      }
  286|       |
  287|      0|      addr_result = addr_result->ai_next;
  288|      0|    }
  289|       |
  290|      0|    if (!found && family == AF_INET) {
  ------------------
  |  Branch (290:9): [True: 0, False: 0]
  |  Branch (290:19): [True: 0, False: 0]
  ------------------
  291|      0|      family = AF_INET6;
  292|      0|      addr_result = addr_result_orig;
  293|      0|      goto beg_af;
  294|      0|    }
  295|       |
  296|      0|    freeaddrinfo(addr_result_orig);
  297|      0|  }
  298|       |
  299|  22.9k|  return 0;
  300|  22.9k|}
make_ioa_addr_from_full_string:
  340|  24.7k|int make_ioa_addr_from_full_string(const uint8_t *saddr, uint16_t default_port, ioa_addr *addr) {
  341|  24.7k|  if (!addr) {
  ------------------
  |  Branch (341:7): [True: 1.76k, False: 22.9k]
  ------------------
  342|  1.76k|    return -1;
  343|  1.76k|  }
  344|       |
  345|  22.9k|  int ret = -1;
  346|  22.9k|  uint16_t port = 0;
  347|  22.9k|  char *s = turn_strdup((const char *)saddr);
  ------------------
  |  |  122|  22.9k|#define turn_strdup(s) turn_strdup_impl((s), __FILE__, __LINE__)
  ------------------
  348|  22.9k|  char *sa = get_addr_string_and_port(s, &port);
  349|  22.9k|  if (sa) {
  ------------------
  |  Branch (349:7): [True: 22.9k, False: 0]
  ------------------
  350|  22.9k|    if (port < 1) {
  ------------------
  |  Branch (350:9): [True: 14.5k, False: 8.46k]
  ------------------
  351|  14.5k|      port = default_port;
  352|  14.5k|    }
  353|  22.9k|    ret = make_ioa_addr((uint8_t *)sa, port, addr);
  354|  22.9k|  }
  355|  22.9k|  free(s);
  356|  22.9k|  return ret;
  357|  24.7k|}
addr_set_port:
  407|     52|void addr_set_port(ioa_addr *addr, uint16_t port) {
  408|     52|  if (addr) {
  ------------------
  |  Branch (408:7): [True: 52, False: 0]
  ------------------
  409|     52|    if (addr->s4.sin_family == AF_INET) {
  ------------------
  |  Branch (409:9): [True: 28, False: 24]
  ------------------
  410|     28|      addr->s4.sin_port = nswap16(port);
  ------------------
  |  |   86|     28|#define nswap16(s) ntohs(s)
  ------------------
  411|     28|    } else if (addr->s6.sin6_family == AF_INET6) {
  ------------------
  |  Branch (411:16): [True: 24, False: 0]
  ------------------
  412|       |      addr->s6.sin6_port = nswap16(port);
  ------------------
  |  |   86|     24|#define nswap16(s) ntohs(s)
  ------------------
  413|     24|    }
  414|     52|  }
  415|     52|}
addr_get_port:
  417|     52|uint16_t addr_get_port(const ioa_addr *addr) {
  418|     52|  if (!addr) {
  ------------------
  |  Branch (418:7): [True: 0, False: 52]
  ------------------
  419|      0|    return 0;
  420|      0|  }
  421|       |
  422|     52|  if (addr->s4.sin_family == AF_INET) {
  ------------------
  |  Branch (422:7): [True: 28, False: 24]
  ------------------
  423|     28|    return nswap16(addr->s4.sin_port);
  ------------------
  |  |   86|     28|#define nswap16(s) ntohs(s)
  ------------------
  424|     28|  } else if (addr->s6.sin6_family == AF_INET6) {
  ------------------
  |  Branch (424:14): [True: 24, False: 0]
  ------------------
  425|     24|    return nswap16(addr->s6.sin6_port);
  ------------------
  |  |   86|     24|#define nswap16(s) ntohs(s)
  ------------------
  426|     24|  }
  427|      0|  return 0;
  428|     52|}
ioa_addr_add_mapping:
  676|      4|void ioa_addr_add_mapping(ioa_addr *apub, ioa_addr *apriv) {
  677|      4|  const size_t new_size = msz + sizeof(ioa_addr *);
  678|      4|  public_addrs = (ioa_addr **)turn_realloc(public_addrs, new_size);
  ------------------
  |  |  121|      4|#define turn_realloc(ptr, sz) turn_realloc_impl((ptr), (sz), __FILE__, __LINE__)
  ------------------
  679|      4|  private_addrs = (ioa_addr **)turn_realloc(private_addrs, new_size);
  ------------------
  |  |  121|      4|#define turn_realloc(ptr, sz) turn_realloc_impl((ptr), (sz), __FILE__, __LINE__)
  ------------------
  680|      4|  public_addrs[mcount] = (ioa_addr *)turn_malloc(sizeof(ioa_addr));
  ------------------
  |  |  119|      4|#define turn_malloc(sz) turn_malloc_impl((sz), __FILE__, __LINE__)
  ------------------
  681|      4|  private_addrs[mcount] = (ioa_addr *)turn_malloc(sizeof(ioa_addr));
  ------------------
  |  |  119|      4|#define turn_malloc(sz) turn_malloc_impl((sz), __FILE__, __LINE__)
  ------------------
  682|      4|  addr_cpy(public_addrs[mcount], apub);
  683|      4|  addr_cpy(private_addrs[mcount], apriv);
  684|      4|  ++mcount;
  685|      4|  msz += sizeof(ioa_addr *);
  686|      4|}
map_addr_from_public_to_private:
  688|    977|void map_addr_from_public_to_private(const ioa_addr *public_addr, ioa_addr *private_addr) {
  689|    977|  size_t i;
  690|  2.85k|  for (i = 0; i < mcount; ++i) {
  ------------------
  |  Branch (690:15): [True: 1.92k, False: 925]
  ------------------
  691|  1.92k|    if (addr_eq_no_port(public_addr, public_addrs[i])) {
  ------------------
  |  Branch (691:9): [True: 52, False: 1.87k]
  ------------------
  692|     52|      addr_cpy(private_addr, private_addrs[i]);
  693|     52|      addr_set_port(private_addr, addr_get_port(public_addr));
  694|     52|      return;
  695|     52|    }
  696|  1.92k|  }
  697|    925|  addr_cpy(private_addr, public_addr);
  698|    925|}
map_addr_from_private_to_public:
  700|  6.70k|void map_addr_from_private_to_public(const ioa_addr *private_addr, ioa_addr *public_addr) {
  701|  6.70k|  size_t i;
  702|  20.1k|  for (i = 0; i < mcount; ++i) {
  ------------------
  |  Branch (702:15): [True: 13.4k, False: 6.70k]
  ------------------
  703|  13.4k|    if (addr_eq_no_port(private_addr, private_addrs[i])) {
  ------------------
  |  Branch (703:9): [True: 0, False: 13.4k]
  ------------------
  704|      0|      addr_cpy(public_addr, public_addrs[i]);
  705|      0|      addr_set_port(public_addr, addr_get_port(private_addr));
  706|      0|      return;
  707|      0|    }
  708|  13.4k|  }
  709|  6.70k|  addr_cpy(public_addr, private_addr);
  710|  6.70k|}
ns_turn_ioaddr.c:get_addr_string_and_port:
  302|  22.9k|static char *get_addr_string_and_port(char *s0, uint16_t *port) {
  303|  22.9k|  char *s = s0;
  304|  26.5k|  while (*s && (*s == ' ')) {
  ------------------
  |  Branch (304:10): [True: 24.7k, False: 1.76k]
  |  Branch (304:16): [True: 3.53k, False: 21.2k]
  ------------------
  305|  3.53k|    ++s;
  306|  3.53k|  }
  307|  22.9k|  if (*s == '[') {
  ------------------
  |  Branch (307:7): [True: 8.84k, False: 14.1k]
  ------------------
  308|  8.84k|    ++s;
  309|  8.84k|    char *tail = strstr(s, "]");
  310|  8.84k|    if (tail) {
  ------------------
  |  Branch (310:9): [True: 8.84k, False: 0]
  ------------------
  311|  8.84k|      *tail = 0;
  312|  8.84k|      ++tail;
  313|  12.3k|      while (*tail && (*tail == ' ')) {
  ------------------
  |  Branch (313:14): [True: 7.07k, False: 5.30k]
  |  Branch (313:23): [True: 3.53k, False: 3.53k]
  ------------------
  314|  3.53k|        ++tail;
  315|  3.53k|      }
  316|  8.84k|      if (*tail == ':') {
  ------------------
  |  Branch (316:11): [True: 3.53k, False: 5.30k]
  ------------------
  317|  3.53k|        ++tail;
  318|  3.53k|        *port = atoi(tail);
  319|  3.53k|        return s;
  320|  5.30k|      } else if (*tail == 0) {
  ------------------
  |  Branch (320:18): [True: 5.30k, False: 0]
  ------------------
  321|  5.30k|        *port = 0;
  322|  5.30k|        return s;
  323|  5.30k|      }
  324|  8.84k|    }
  325|  14.1k|  } else {
  326|  14.1k|    char *tail = strstr(s, ":");
  327|  14.1k|    if (tail) {
  ------------------
  |  Branch (327:9): [True: 8.84k, False: 5.30k]
  ------------------
  328|  8.84k|      *tail = 0;
  329|  8.84k|      ++tail;
  330|  8.84k|      *port = atoi(tail);
  331|  8.84k|      return s;
  332|  8.84k|    } else {
  333|  5.30k|      *port = 0;
  334|  5.30k|      return s;
  335|  5.30k|    }
  336|  14.1k|  }
  337|      0|  return NULL;
  338|  22.9k|}

ns_turn_ioaddr.c:addr_cpy:
   87|  7.69k|static inline void addr_cpy(ioa_addr *dst, const ioa_addr *src) {
   88|  7.69k|  if (dst && src) {
  ------------------
  |  Branch (88:7): [True: 7.69k, False: 0]
  |  Branch (88:14): [True: 7.69k, False: 0]
  ------------------
   89|  7.69k|    memcpy(dst, src, sizeof(ioa_addr));
   90|  7.69k|  }
   91|  7.69k|}

turn_random_number:
  123|  58.3k|long turn_random_number(void) {
  124|  58.3k|  long ret = 0;
  125|  58.3k|#if defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
  126|  58.3k|  ret = (long)fuzz_prng_next();
  127|       |#else
  128|       |  if (!RAND_bytes((unsigned char *)&ret, sizeof(ret)))
  129|       |#if defined(WINDOWS)
  130|       |    ret = rand();
  131|       |#else
  132|       |    ret = random();
  133|       |#endif
  134|       |#endif
  135|  58.3k|  return ret;
  136|  58.3k|}
stun_calculate_hmac:
  174|  9.15k|                         unsigned int *hmac_len, SHATYPE shatype) {
  175|  9.15k|  ERR_clear_error();
  176|  9.15k|  UNUSED_ARG(shatype);
  ------------------
  |  |  218|  9.15k|  do {                                                                                                                 \
  |  |  219|  9.15k|    A = A;                                                                                                             \
  |  |  220|  9.15k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (220:12): [Folded, False: 9.15k]
  |  |  ------------------
  ------------------
  177|       |
  178|  9.15k|  if (shatype == SHATYPE_SHA256) {
  ------------------
  |  Branch (178:7): [True: 3.76k, False: 5.38k]
  ------------------
  179|  3.76k|#if !defined(OPENSSL_NO_SHA256) && defined(SHA256_DIGEST_LENGTH)
  180|  3.76k|    if (!HMAC(EVP_sha256(), key, (int)keylen, buf, len, hmac, hmac_len)) {
  ------------------
  |  Branch (180:9): [True: 0, False: 3.76k]
  ------------------
  181|      0|      return false;
  182|      0|    }
  183|       |#else
  184|       |    fprintf(stderr, "SHA256 is not supported\n");
  185|       |    return false;
  186|       |#endif
  187|  5.38k|  } else if (shatype == SHATYPE_SHA384) {
  ------------------
  |  Branch (187:14): [True: 1.40k, False: 3.98k]
  ------------------
  188|  1.40k|#if !defined(OPENSSL_NO_SHA384) && defined(SHA384_DIGEST_LENGTH)
  189|  1.40k|    if (!HMAC(EVP_sha384(), key, (int)keylen, buf, len, hmac, hmac_len)) {
  ------------------
  |  Branch (189:9): [True: 0, False: 1.40k]
  ------------------
  190|      0|      return false;
  191|      0|    }
  192|       |#else
  193|       |    fprintf(stderr, "SHA384 is not supported\n");
  194|       |    return false;
  195|       |#endif
  196|  3.98k|  } else if (shatype == SHATYPE_SHA512) {
  ------------------
  |  Branch (196:14): [True: 1.94k, False: 2.04k]
  ------------------
  197|  1.94k|#if !defined(OPENSSL_NO_SHA512) && defined(SHA512_DIGEST_LENGTH)
  198|  1.94k|    if (!HMAC(EVP_sha512(), key, (int)keylen, buf, len, hmac, hmac_len)) {
  ------------------
  |  Branch (198:9): [True: 0, False: 1.94k]
  ------------------
  199|      0|      return false;
  200|      0|    }
  201|       |#else
  202|       |    fprintf(stderr, "SHA512 is not supported\n");
  203|       |    return false;
  204|       |#endif
  205|  2.04k|  } else if (!HMAC(EVP_sha1(), key, (int)keylen, buf, len, hmac, hmac_len)) {
  ------------------
  |  Branch (205:14): [True: 0, False: 2.04k]
  ------------------
  206|      0|    return false;
  207|      0|  }
  208|       |
  209|  9.15k|  return true;
  210|  9.15k|}
stun_produce_integrity_key_str:
  340|  9.66k|                                    SHATYPE shatype) {
  341|  9.66k|  bool ret;
  342|       |
  343|  9.66k|  ERR_clear_error();
  344|  9.66k|  UNUSED_ARG(shatype);
  ------------------
  |  |  218|  9.66k|  do {                                                                                                                 \
  |  |  219|  9.66k|    A = A;                                                                                                             \
  |  |  220|  9.66k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (220:12): [Folded, False: 9.66k]
  |  |  ------------------
  ------------------
  345|       |
  346|  9.66k|  const size_t ulen = strlen((const char *)uname);
  347|  9.66k|  const size_t rlen = strlen((const char *)realm);
  348|  9.66k|  const size_t plen = strlen((const char *)upwd);
  349|  9.66k|  const size_t sz = ulen + 1 + rlen + 1 + plen + 1 + 10;
  350|  9.66k|  const size_t strl = ulen + 1 + rlen + 1 + plen;
  351|  9.66k|  uint8_t *str = (uint8_t *)turn_malloc(sz + 1);
  ------------------
  |  |  119|  9.66k|#define turn_malloc(sz) turn_malloc_impl((sz), __FILE__, __LINE__)
  ------------------
  352|       |
  353|  9.66k|  strncpy((char *)str, (const char *)uname, sz);
  354|  9.66k|  str[ulen] = ':';
  355|  9.66k|  strncpy((char *)str + ulen + 1, (const char *)realm, sz - ulen - 1);
  356|  9.66k|  str[ulen + 1 + rlen] = ':';
  357|  9.66k|  strncpy((char *)str + ulen + 1 + rlen + 1, (const char *)upwd, sz - ulen - 1 - rlen - 1);
  358|  9.66k|  str[strl] = 0;
  359|       |
  360|  9.66k|  if (shatype == SHATYPE_SHA256) {
  ------------------
  |  Branch (360:7): [True: 3.89k, False: 5.77k]
  ------------------
  361|  3.89k|#if !defined(OPENSSL_NO_SHA256) && defined(SHA256_DIGEST_LENGTH)
  362|  3.89k|    unsigned int keylen = 0;
  363|  3.89k|    EVP_MD_CTX *ctx = EVP_MD_CTX_new();
  364|  3.89k|    EVP_DigestInit(ctx, EVP_sha256());
  365|  3.89k|    EVP_DigestUpdate(ctx, str, strl);
  366|  3.89k|    EVP_DigestFinal(ctx, key, &keylen);
  367|  3.89k|    EVP_MD_CTX_free(ctx);
  368|  3.89k|    ret = true;
  369|       |#else
  370|       |    fprintf(stderr, "SHA256 is not supported\n");
  371|       |    ret = false;
  372|       |#endif
  373|  5.77k|  } else if (shatype == SHATYPE_SHA384) {
  ------------------
  |  Branch (373:14): [True: 1.85k, False: 3.91k]
  ------------------
  374|  1.85k|#if !defined(OPENSSL_NO_SHA384) && defined(SHA384_DIGEST_LENGTH)
  375|  1.85k|    unsigned int keylen = 0;
  376|  1.85k|    EVP_MD_CTX *ctx = EVP_MD_CTX_new();
  377|  1.85k|    EVP_DigestInit(ctx, EVP_sha384());
  378|  1.85k|    EVP_DigestUpdate(ctx, str, strl);
  379|  1.85k|    EVP_DigestFinal(ctx, key, &keylen);
  380|  1.85k|    EVP_MD_CTX_free(ctx);
  381|  1.85k|    ret = true;
  382|       |#else
  383|       |    fprintf(stderr, "SHA384 is not supported\n");
  384|       |    ret = false;
  385|       |#endif
  386|  3.91k|  } else if (shatype == SHATYPE_SHA512) {
  ------------------
  |  Branch (386:14): [True: 1.96k, False: 1.95k]
  ------------------
  387|  1.96k|#if !defined(OPENSSL_NO_SHA512) && defined(SHA512_DIGEST_LENGTH)
  388|  1.96k|    unsigned int keylen = 0;
  389|  1.96k|    EVP_MD_CTX *ctx = EVP_MD_CTX_new();
  390|  1.96k|    EVP_DigestInit(ctx, EVP_sha512());
  391|  1.96k|    EVP_DigestUpdate(ctx, str, strl);
  392|  1.96k|    EVP_DigestFinal(ctx, key, &keylen);
  393|  1.96k|    EVP_MD_CTX_free(ctx);
  394|  1.96k|    ret = true;
  395|       |#else
  396|       |    fprintf(stderr, "SHA512 is not supported\n");
  397|       |    ret = false;
  398|       |#endif
  399|  1.96k|  } else {
  400|  1.95k|#if OPENSSL_VERSION_NUMBER >= 0x30000000L
  401|       |    /* Long-term keys need MD5: fetch it with "-fips" rather than clearing the
  402|       |     * process-wide FIPS default, which every other thread shares. */
  403|  1.95k|    EVP_MD_CTX *ctx = EVP_MD_CTX_new();
  404|  1.95k|    EVP_MD *md5 = EVP_MD_fetch(NULL, "MD5", "-fips");
  405|  1.95k|    unsigned int keylen = 0;
  406|  1.95k|    const bool digested = ctx && md5 && EVP_DigestInit_ex(ctx, md5, NULL) == 1 &&
  ------------------
  |  Branch (406:27): [True: 1.95k, False: 0]
  |  Branch (406:34): [True: 1.95k, False: 0]
  |  Branch (406:41): [True: 1.95k, False: 0]
  ------------------
  407|  1.95k|                          EVP_DigestUpdate(ctx, str, strl) == 1 && EVP_DigestFinal_ex(ctx, key, &keylen) == 1;
  ------------------
  |  Branch (407:27): [True: 1.95k, False: 0]
  |  Branch (407:68): [True: 1.95k, False: 0]
  ------------------
  408|  1.95k|    EVP_MD_free(md5);
  409|  1.95k|    EVP_MD_CTX_free(ctx);
  410|  1.95k|    if (!digested) {
  ------------------
  |  Branch (410:9): [True: 0, False: 1.95k]
  ------------------
  411|      0|      memset(key, 0, sizeof(hmackey_t));
  412|      0|      ret = false;
  413|  1.95k|    } else {
  414|  1.95k|      ret = true;
  415|  1.95k|    }
  416|       |#else // OPENSSL_VERSION_NUMBER < 0x30000000L
  417|       |    unsigned int keylen = 0;
  418|       |    EVP_MD_CTX *ctx = EVP_MD_CTX_new();
  419|       |#if defined EVP_MD_CTX_FLAG_NON_FIPS_ALLOW && !defined(LIBRESSL_VERSION_NUMBER)
  420|       |    if (ctx && FIPS_mode()) {
  421|       |      EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
  422|       |    }
  423|       |#endif
  424|       |    const bool digested = ctx && EVP_DigestInit_ex(ctx, EVP_md5(), NULL) == 1 &&
  425|       |                          EVP_DigestUpdate(ctx, str, strl) == 1 && EVP_DigestFinal_ex(ctx, key, &keylen) == 1;
  426|       |    EVP_MD_CTX_free(ctx);
  427|       |    if (!digested) {
  428|       |      memset(key, 0, sizeof(hmackey_t));
  429|       |      ret = false;
  430|       |    } else {
  431|       |      ret = true;
  432|       |    }
  433|       |#endif // OPENSSL_VERSION_NUMBER >= 0X30000000L
  434|  1.95k|  }
  435|       |
  436|  9.66k|  free(str);
  437|       |
  438|  9.66k|  return ret;
  439|  9.66k|}
stun_get_command_message_len_str:
  533|  1.50M|int stun_get_command_message_len_str(const uint8_t *buf, size_t len) {
  534|  1.50M|  if (len < STUN_HEADER_LENGTH) {
  ------------------
  |  |   46|  1.50M|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (534:7): [True: 20, False: 1.50M]
  ------------------
  535|     20|    return -1;
  536|     20|  }
  537|       |
  538|       |  /* Validate the size the buffer claims to be */
  539|  1.50M|  const size_t bufLen = (size_t)(turn_read_u16(buf + 2) + STUN_HEADER_LENGTH);
  ------------------
  |  |   46|  1.50M|#define STUN_HEADER_LENGTH (20)
  ------------------
  540|  1.50M|  if (bufLen > len) {
  ------------------
  |  Branch (540:7): [True: 1.03k, False: 1.50M]
  ------------------
  541|  1.03k|    return -1;
  542|  1.03k|  }
  543|       |
  544|  1.50M|  return bufLen;
  545|  1.50M|}
stun_make_type:
  557|  19.4k|uint16_t stun_make_type(uint16_t method) {
  558|  19.4k|  method = method & 0x0FFF;
  559|  19.4k|  return ((method & 0x000F) | ((method & 0x0070) << 1) | ((method & 0x0380) << 2) | ((method & 0x0C00) << 2));
  560|  19.4k|}
stun_get_method_str:
  562|  5.37k|uint16_t stun_get_method_str(const uint8_t *buf, size_t len) {
  563|  5.37k|  if (!buf || len < 2) {
  ------------------
  |  Branch (563:7): [True: 0, False: 5.37k]
  |  Branch (563:15): [True: 0, False: 5.37k]
  ------------------
  564|      0|    return (uint16_t)-1;
  565|      0|  }
  566|       |
  567|  5.37k|  const uint16_t tt = turn_read_u16(buf);
  568|       |
  569|  5.37k|  return (tt & 0x000F) | ((tt & 0x00E0) >> 1) | ((tt & 0x0E00) >> 2) | ((tt & 0x3000) >> 2);
  570|  5.37k|}
stun_get_msg_type_str:
  572|  24.3k|uint16_t stun_get_msg_type_str(const uint8_t *buf, size_t len) {
  573|  24.3k|  if (!buf || len < 2) {
  ------------------
  |  Branch (573:7): [True: 0, False: 24.3k]
  |  Branch (573:15): [True: 0, False: 24.3k]
  ------------------
  574|      0|    return (uint16_t)-1;
  575|      0|  }
  576|  24.3k|  return (turn_read_u16(buf) & 0x3FFF);
  577|  24.3k|}
is_channel_msg_str:
  579|  24.1k|bool is_channel_msg_str(const uint8_t *buf, size_t blen) {
  580|  24.1k|  return (buf && blen >= 4 && STUN_VALID_CHANNEL(turn_read_u16(buf)));
  ------------------
  |  |  163|  24.1k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (163:34): [True: 0, False: 24.1k]
  |  |  |  Branch (163:53): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (580:11): [True: 24.1k, False: 0]
  |  Branch (580:18): [True: 24.1k, False: 0]
  ------------------
  581|  24.1k|}
stun_is_command_message_str:
  585|  13.3k|bool stun_is_command_message_str(const uint8_t *buf, size_t blen) {
  586|  13.3k|  if (buf && blen >= STUN_HEADER_LENGTH) {
  ------------------
  |  |   46|  13.3k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (586:7): [True: 13.3k, False: 0]
  |  Branch (586:14): [True: 13.2k, False: 10]
  ------------------
  587|  13.2k|    if (!STUN_VALID_CHANNEL(turn_read_u16(buf))) {
  ------------------
  |  |  163|  13.2k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (163:34): [True: 361, False: 12.9k]
  |  |  |  Branch (163:53): [True: 50, False: 311]
  |  |  ------------------
  ------------------
  588|  13.2k|      if ((((uint8_t)buf[0]) & ((uint8_t)(0xC0))) == 0) {
  ------------------
  |  Branch (588:11): [True: 12.9k, False: 311]
  ------------------
  589|  12.9k|        if (turn_read_u32(buf + 4) == STUN_MAGIC_COOKIE) {
  ------------------
  |  |   60|  12.9k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (589:13): [True: 9.64k, False: 3.28k]
  ------------------
  590|  9.64k|          const uint16_t len = turn_read_u16(buf + 2);
  591|  9.64k|          if ((len & 0x0003) == 0) {
  ------------------
  |  Branch (591:15): [True: 9.50k, False: 143]
  ------------------
  592|  9.50k|            if ((size_t)(len + STUN_HEADER_LENGTH) == blen) {
  ------------------
  |  |   46|  9.50k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (592:17): [True: 9.05k, False: 445]
  ------------------
  593|  9.05k|              return true;
  594|  9.05k|            }
  595|  9.50k|          }
  596|  9.64k|        }
  597|  12.9k|      }
  598|  13.2k|    }
  599|  13.2k|  }
  600|  4.24k|  return false;
  601|  13.3k|}
old_stun_is_command_message_str:
  603|  1.57k|bool old_stun_is_command_message_str(const uint8_t *buf, size_t blen, uint32_t *cookie) {
  604|  1.57k|  if (buf && blen >= STUN_HEADER_LENGTH) {
  ------------------
  |  |   46|  1.57k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (604:7): [True: 1.57k, False: 0]
  |  Branch (604:14): [True: 1.57k, False: 0]
  ------------------
  605|  1.57k|    if (!STUN_VALID_CHANNEL(turn_read_u16(buf))) {
  ------------------
  |  |  163|  1.57k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (163:34): [True: 45, False: 1.53k]
  |  |  |  Branch (163:53): [True: 6, False: 39]
  |  |  ------------------
  ------------------
  606|  1.57k|      if ((((uint8_t)buf[0]) & ((uint8_t)(0xC0))) == 0) {
  ------------------
  |  Branch (606:11): [True: 1.53k, False: 39]
  ------------------
  607|  1.53k|        const uint32_t msg_cookie = turn_read_u32(buf + 4);
  608|  1.53k|        if (msg_cookie != STUN_MAGIC_COOKIE) {
  ------------------
  |  |   60|  1.53k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (608:13): [True: 325, False: 1.20k]
  ------------------
  609|    325|          const uint16_t len = turn_read_u16(buf + 2);
  610|    325|          if ((len & 0x0003) == 0) {
  ------------------
  |  Branch (610:15): [True: 259, False: 66]
  ------------------
  611|    259|            if ((size_t)(len + STUN_HEADER_LENGTH) == blen) {
  ------------------
  |  |   46|    259|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (611:17): [True: 172, False: 87]
  ------------------
  612|    172|              *cookie = msg_cookie;
  613|    172|              return true;
  614|    172|            }
  615|    259|          }
  616|    325|        }
  617|  1.53k|      }
  618|  1.57k|    }
  619|  1.57k|  }
  620|  1.40k|  return false;
  621|  1.57k|}
stun_is_command_message_full_check_str:
  624|  8.23k|                                            bool *fingerprint_present) {
  625|  8.23k|  if (!stun_is_command_message_str(buf, blen)) {
  ------------------
  |  Branch (625:7): [True: 2.56k, False: 5.67k]
  ------------------
  626|  2.56k|    return false;
  627|  2.56k|  }
  628|  5.67k|  stun_attr_ref sar = stun_attr_get_first_by_type_str(buf, blen, STUN_ATTRIBUTE_FINGERPRINT);
  ------------------
  |  |  115|  5.67k|#define STUN_ATTRIBUTE_FINGERPRINT (0x8028)
  ------------------
  629|  5.67k|  if (!sar) {
  ------------------
  |  Branch (629:7): [True: 5.20k, False: 470]
  ------------------
  630|  5.20k|    if (fingerprint_present) {
  ------------------
  |  Branch (630:9): [True: 0, False: 5.20k]
  ------------------
  631|      0|      *fingerprint_present = false;
  632|      0|    }
  633|  5.20k|    if (stun_get_method_str(buf, blen) == STUN_METHOD_BINDING) {
  ------------------
  |  |   81|  5.20k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
  |  Branch (633:9): [True: 230, False: 4.97k]
  ------------------
  634|    230|      return true;
  635|    230|    }
  636|  4.97k|    return !must_check_fingerprint;
  637|  5.20k|  }
  638|    470|  if (stun_attr_get_len(sar) != 4) {
  ------------------
  |  Branch (638:7): [True: 115, False: 355]
  ------------------
  639|    115|    return false;
  640|    115|  }
  641|    355|  const uint8_t *fingerprint = stun_attr_get_value(sar);
  642|    355|  if (!fingerprint) {
  ------------------
  |  Branch (642:7): [True: 0, False: 355]
  ------------------
  643|      0|    return !must_check_fingerprint;
  644|      0|  }
  645|    355|  const uint32_t crc32len = (uint32_t)((fingerprint - buf) - 4);
  646|    355|  const bool ret = (turn_read_u32(fingerprint) == (ns_crc32(buf, crc32len) ^ ((uint32_t)FINGERPRINT_XOR)));
  ------------------
  |  |   53|    355|#define FINGERPRINT_XOR 0x5354554e
  ------------------
  647|    355|  if (ret && fingerprint_present) {
  ------------------
  |  Branch (647:7): [True: 5, False: 350]
  |  Branch (647:14): [True: 0, False: 5]
  ------------------
  648|      0|    *fingerprint_present = ret;
  649|      0|  }
  650|    355|  return ret;
  651|    355|}
stun_is_request_str:
  653|    172|bool stun_is_request_str(const uint8_t *buf, size_t len) {
  654|    172|  if (is_channel_msg_str(buf, len)) {
  ------------------
  |  Branch (654:7): [True: 0, False: 172]
  ------------------
  655|      0|    return false;
  656|      0|  }
  657|    172|  return IS_STUN_REQUEST(stun_get_msg_type_str(buf, len));
  ------------------
  |  |   62|    172|#define IS_STUN_REQUEST(msg_type) (((msg_type)&0x0110) == 0x0000)
  ------------------
  658|    172|}
stun_is_success_response_str:
  660|    172|bool stun_is_success_response_str(const uint8_t *buf, size_t len) {
  661|    172|  if (is_channel_msg_str(buf, len)) {
  ------------------
  |  Branch (661:7): [True: 0, False: 172]
  ------------------
  662|      0|    return false;
  663|      0|  }
  664|    172|  return IS_STUN_SUCCESS_RESP(stun_get_msg_type_str(buf, len));
  ------------------
  |  |   64|    172|#define IS_STUN_SUCCESS_RESP(msg_type) (((msg_type)&0x0110) == 0x0100)
  ------------------
  665|    172|}
stun_is_error_response_str:
  667|  23.6k|bool stun_is_error_response_str(const uint8_t *buf, size_t len, int *err_code, uint8_t *err_msg, size_t err_msg_size) {
  668|  23.6k|  if (is_channel_msg_str(buf, len)) {
  ------------------
  |  Branch (668:7): [True: 0, False: 23.6k]
  ------------------
  669|      0|    return false;
  670|      0|  }
  671|  23.6k|  if (IS_STUN_ERR_RESP(stun_get_msg_type_str(buf, len))) {
  ------------------
  |  |   65|  23.6k|#define IS_STUN_ERR_RESP(msg_type) (((msg_type)&0x0110) == 0x0110)
  |  |  ------------------
  |  |  |  Branch (65:36): [True: 22.0k, False: 1.62k]
  |  |  ------------------
  ------------------
  672|  22.0k|    if (err_code) {
  ------------------
  |  Branch (672:9): [True: 22.0k, False: 0]
  ------------------
  673|  22.0k|      stun_attr_ref sar = stun_attr_get_first_by_type_str(buf, len, STUN_ATTRIBUTE_ERROR_CODE);
  ------------------
  |  |  103|  22.0k|#define STUN_ATTRIBUTE_ERROR_CODE (0x0009)
  ------------------
  674|  22.0k|      if (sar) {
  ------------------
  |  Branch (674:11): [True: 21.4k, False: 583]
  ------------------
  675|  21.4k|        if (stun_attr_get_len(sar) >= 4) {
  ------------------
  |  Branch (675:13): [True: 21.4k, False: 27]
  ------------------
  676|  21.4k|          const uint8_t *val = (const uint8_t *)stun_attr_get_value(sar);
  677|  21.4k|          *err_code = (int)(val[2] * 100 + val[3]);
  678|  21.4k|          if (err_msg && err_msg_size > 0) {
  ------------------
  |  Branch (678:15): [True: 21.4k, False: 0]
  |  Branch (678:26): [True: 21.4k, False: 0]
  ------------------
  679|  21.4k|            err_msg[0] = 0;
  680|  21.4k|            if (stun_attr_get_len(sar) > 4) {
  ------------------
  |  Branch (680:17): [True: 21.3k, False: 113]
  ------------------
  681|  21.3k|              size_t msg_len = stun_attr_get_len(sar) - 4;
  682|  21.3k|              if (msg_len > (err_msg_size - 1)) {
  ------------------
  |  Branch (682:19): [True: 17, False: 21.2k]
  ------------------
  683|     17|                msg_len = err_msg_size - 1;
  684|     17|              }
  685|  21.3k|              memcpy(err_msg, val + 4, msg_len);
  686|  21.3k|              err_msg[msg_len] = 0;
  687|  21.3k|            }
  688|  21.4k|          }
  689|  21.4k|        }
  690|  21.4k|      }
  691|  22.0k|    }
  692|  22.0k|    return true;
  693|  22.0k|  }
  694|  1.62k|  return false;
  695|  23.6k|}
stun_is_challenge_response_str:
  699|  22.3k|                                    bool *oauth) {
  700|  22.3k|  const bool ret = stun_is_error_response_str(buf, len, err_code, err_msg, err_msg_size);
  701|       |
  702|  22.3k|  if (ret && (((*err_code) == 401) || ((*err_code) == 438))) {
  ------------------
  |  Branch (702:7): [True: 21.5k, False: 764]
  |  Branch (702:15): [True: 14.1k, False: 7.40k]
  |  Branch (702:39): [True: 3.55k, False: 3.84k]
  ------------------
  703|  17.7k|    stun_attr_ref sar = stun_attr_get_first_by_type_str(buf, len, STUN_ATTRIBUTE_REALM);
  ------------------
  |  |  106|  17.7k|#define STUN_ATTRIBUTE_REALM (0x0014)
  ------------------
  704|  17.7k|    if (sar) {
  ------------------
  |  Branch (704:9): [True: 14.2k, False: 3.53k]
  ------------------
  705|  14.2k|      bool found_oauth = false;
  706|       |
  707|  14.2k|      const uint8_t *value = stun_attr_get_value(sar);
  708|  14.2k|      if (value) {
  ------------------
  |  Branch (708:11): [True: 14.2k, False: 1]
  ------------------
  709|  14.2k|        size_t vlen = (size_t)stun_attr_get_len(sar);
  710|       |        /* Truncating would corrupt the realm mid-codepoint and fail the integrity
  711|       |         * check later with an unrelated error; reject the challenge instead. */
  712|  14.2k|        if (vlen > (size_t)STUN_MAX_REALM_SIZE) {
  ------------------
  |  |   54|  14.2k|#define STUN_MAX_REALM_SIZE (763)
  ------------------
  |  Branch (712:13): [True: 5, False: 14.1k]
  ------------------
  713|      5|          return false;
  714|      5|        }
  715|  14.1k|        memcpy(realm, value, vlen);
  716|  14.1k|        realm[vlen] = 0;
  717|  14.1k|        {
  718|  14.1k|          sar = stun_attr_get_first_by_type_str(buf, len, STUN_ATTRIBUTE_THIRD_PARTY_AUTHORIZATION);
  ------------------
  |  |  227|  14.1k|#define STUN_ATTRIBUTE_THIRD_PARTY_AUTHORIZATION (0x802E)
  ------------------
  719|  14.1k|          if (sar) {
  ------------------
  |  Branch (719:15): [True: 3.56k, False: 10.6k]
  ------------------
  720|  3.56k|            value = stun_attr_get_value(sar);
  721|  3.56k|            if (value) {
  ------------------
  |  Branch (721:17): [True: 3.56k, False: 2]
  ------------------
  722|  3.56k|              vlen = (size_t)stun_attr_get_len(sar);
  723|  3.56k|              vlen = min(vlen, (size_t)STUN_MAX_SERVER_NAME_SIZE);
  ------------------
  |  |  138|  3.56k|#define min(a, b) ((a) <= (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (138:20): [True: 3.55k, False: 3]
  |  |  ------------------
  ------------------
  724|  3.56k|              if (vlen > 0) {
  ------------------
  |  Branch (724:19): [True: 3.56k, False: 0]
  ------------------
  725|  3.56k|                if (server_name) {
  ------------------
  |  Branch (725:21): [True: 3.56k, False: 0]
  ------------------
  726|  3.56k|                  memcpy(server_name, value, vlen);
  727|  3.56k|                  server_name[vlen] = 0;
  728|  3.56k|                }
  729|  3.56k|                found_oauth = true;
  730|  3.56k|              }
  731|  3.56k|            }
  732|  3.56k|          }
  733|  14.1k|        }
  734|       |
  735|  14.1k|        sar = stun_attr_get_first_by_type_str(buf, len, STUN_ATTRIBUTE_NONCE);
  ------------------
  |  |  107|  14.1k|#define STUN_ATTRIBUTE_NONCE (0x0015)
  ------------------
  736|  14.1k|        if (sar) {
  ------------------
  |  Branch (736:13): [True: 10.6k, False: 3.57k]
  ------------------
  737|  10.6k|          value = stun_attr_get_value(sar);
  738|  10.6k|          if (value) {
  ------------------
  |  Branch (738:15): [True: 10.6k, False: 2]
  ------------------
  739|  10.6k|            vlen = (size_t)stun_attr_get_len(sar);
  740|  10.6k|            if (vlen > (size_t)STUN_MAX_NONCE_SIZE) {
  ------------------
  |  |   55|  10.6k|#define STUN_MAX_NONCE_SIZE (763)
  ------------------
  |  Branch (740:17): [True: 4, False: 10.6k]
  ------------------
  741|      4|              return false;
  742|      4|            }
  743|  10.6k|            memcpy(nonce, value, vlen);
  744|  10.6k|            nonce[vlen] = 0;
  745|  10.6k|            if (oauth) {
  ------------------
  |  Branch (745:17): [True: 5.31k, False: 5.30k]
  ------------------
  746|  5.31k|              *oauth = found_oauth;
  747|  5.31k|            }
  748|  10.6k|            return true;
  749|  10.6k|          }
  750|  10.6k|        }
  751|  14.1k|      }
  752|  14.2k|    }
  753|  17.7k|  }
  754|       |
  755|  11.7k|  return false;
  756|  22.3k|}
stun_is_indication_str:
  771|    172|bool stun_is_indication_str(const uint8_t *buf, size_t len) {
  772|    172|  if (is_channel_msg_str(buf, len)) {
  ------------------
  |  Branch (772:7): [True: 0, False: 172]
  ------------------
  773|      0|    return false;
  774|      0|  }
  775|    172|  return IS_STUN_INDICATION(stun_get_msg_type_str(buf, len));
  ------------------
  |  |   63|    172|#define IS_STUN_INDICATION(msg_type) (((msg_type)&0x0110) == 0x0010)
  ------------------
  776|    172|}
stun_make_request:
  778|  8.84k|uint16_t stun_make_request(uint16_t method) { return GET_STUN_REQUEST(stun_make_type(method)); }
  ------------------
  |  |   67|  8.84k|#define GET_STUN_REQUEST(msg_type) (msg_type & 0xFEEF)
  ------------------
stun_make_error_response:
  784|  10.6k|uint16_t stun_make_error_response(uint16_t method) { return GET_STUN_ERR_RESP(stun_make_type(method)); }
  ------------------
  |  |   70|  10.6k|#define GET_STUN_ERR_RESP(msg_type) (msg_type | 0x0110)
  ------------------
stun_init_buffer_str:
  788|  19.4k|void stun_init_buffer_str(uint8_t *buf, size_t *len) {
  789|  19.4k|  *len = STUN_HEADER_LENGTH;
  ------------------
  |  |   46|  19.4k|#define STUN_HEADER_LENGTH (20)
  ------------------
  790|  19.4k|  memset(buf, 0, *len);
  791|  19.4k|}
stun_init_command_str:
  793|  19.4k|void stun_init_command_str(uint16_t message_type, uint8_t *buf, size_t *len) {
  794|  19.4k|  stun_init_buffer_str(buf, len);
  795|  19.4k|  message_type &= (uint16_t)(0x3FFF);
  796|  19.4k|  turn_write_u16(buf, message_type);
  797|  19.4k|  turn_write_u16(buf + 2, 0);
  798|  19.4k|  turn_write_u32(buf + 4, STUN_MAGIC_COOKIE);
  ------------------
  |  |   60|  19.4k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  799|       |  stun_tid_generate_in_message_str(buf, NULL);
  800|  19.4k|}
stun_init_request_str:
  811|  8.84k|void stun_init_request_str(uint16_t method, uint8_t *buf, size_t *len) {
  812|  8.84k|  stun_init_command_str(stun_make_request(method), buf, len);
  813|  8.84k|}
get_default_reason:
  833|  1.11k|const uint8_t *get_default_reason(int error_code) {
  834|  1.11k|  const char *reason = "Unknown error";
  835|       |
  836|  1.11k|  switch (error_code) {
  837|      0|  case 300:
  ------------------
  |  Branch (837:3): [True: 0, False: 1.11k]
  ------------------
  838|      0|    reason = "Try Alternate";
  839|      0|    break;
  840|      0|  case 400:
  ------------------
  |  Branch (840:3): [True: 0, False: 1.11k]
  ------------------
  841|      0|    reason = "Bad Request";
  842|      0|    break;
  843|      0|  case 401:
  ------------------
  |  Branch (843:3): [True: 0, False: 1.11k]
  ------------------
  844|      0|    reason = "Unauthorized";
  845|      0|    break;
  846|      0|  case 403:
  ------------------
  |  Branch (846:3): [True: 0, False: 1.11k]
  ------------------
  847|      0|    reason = "Forbidden";
  848|      0|    break;
  849|      0|  case 404:
  ------------------
  |  Branch (849:3): [True: 0, False: 1.11k]
  ------------------
  850|      0|    reason = "Not Found";
  851|      0|    break;
  852|      0|  case 420:
  ------------------
  |  Branch (852:3): [True: 0, False: 1.11k]
  ------------------
  853|      0|    reason = "Unknown Attribute";
  854|      0|    break;
  855|      0|  case 437:
  ------------------
  |  Branch (855:3): [True: 0, False: 1.11k]
  ------------------
  856|      0|    reason = "Allocation Mismatch";
  857|      0|    break;
  858|      0|  case 438:
  ------------------
  |  Branch (858:3): [True: 0, False: 1.11k]
  ------------------
  859|      0|    reason = "Stale Nonce";
  860|      0|    break;
  861|  1.11k|  case 440:
  ------------------
  |  Branch (861:3): [True: 1.11k, False: 0]
  ------------------
  862|  1.11k|    reason = "Address Family not Supported";
  863|  1.11k|    break;
  864|      0|  case 441:
  ------------------
  |  Branch (864:3): [True: 0, False: 1.11k]
  ------------------
  865|      0|    reason = "Wrong Credentials";
  866|      0|    break;
  867|      0|  case 442:
  ------------------
  |  Branch (867:3): [True: 0, False: 1.11k]
  ------------------
  868|      0|    reason = "Unsupported Transport Protocol";
  869|      0|    break;
  870|      0|  case 443:
  ------------------
  |  Branch (870:3): [True: 0, False: 1.11k]
  ------------------
  871|      0|    reason = "Peer Address Family Mismatch";
  872|      0|    break;
  873|      0|  case 446:
  ------------------
  |  Branch (873:3): [True: 0, False: 1.11k]
  ------------------
  874|      0|    reason = "Connection Already Exists";
  875|      0|    break;
  876|      0|  case 447:
  ------------------
  |  Branch (876:3): [True: 0, False: 1.11k]
  ------------------
  877|      0|    reason = "Connection Timeout or Failure";
  878|      0|    break;
  879|      0|  case 486:
  ------------------
  |  Branch (879:3): [True: 0, False: 1.11k]
  ------------------
  880|      0|    reason = "Allocation Quota Reached";
  881|      0|    break;
  882|      0|  case 487:
  ------------------
  |  Branch (882:3): [True: 0, False: 1.11k]
  ------------------
  883|      0|    reason = "Role Conflict";
  884|      0|    break;
  885|      0|  case 500:
  ------------------
  |  Branch (885:3): [True: 0, False: 1.11k]
  ------------------
  886|      0|    reason = "Server Error";
  887|      0|    break;
  888|      0|  case 508:
  ------------------
  |  Branch (888:3): [True: 0, False: 1.11k]
  ------------------
  889|      0|    reason = "Insufficient Capacity";
  890|      0|    break;
  891|      0|  default:;
  ------------------
  |  Branch (891:3): [True: 0, False: 1.11k]
  ------------------
  892|  1.11k|  };
  893|       |
  894|  1.11k|  return (const uint8_t *)reason;
  895|  1.11k|}
stun_init_error_response_str:
  941|  10.6k|                                  const uint8_t *reason, stun_tid *id, bool include_reason_string) {
  942|       |
  943|  10.6k|  stun_init_command_str(stun_make_error_response(method), buf, len);
  944|       |
  945|       |  stun_init_error_response_common_str(buf, len, error_code, reason, id, include_reason_string, false);
  946|  10.6k|}
stun_is_binding_request_str:
 1408|    172|bool stun_is_binding_request_str(const uint8_t *buf, size_t len, size_t offset) {
 1409|    172|  if (offset < len) {
  ------------------
  |  Branch (1409:7): [True: 172, False: 0]
  ------------------
 1410|    172|    buf += offset;
 1411|    172|    len -= offset;
 1412|    172|    if (stun_is_command_message_str(buf, len)) {
  ------------------
  |  Branch (1412:9): [True: 0, False: 172]
  ------------------
 1413|      0|      if (stun_is_request_str(buf, len) && (stun_get_method_str(buf, len) == STUN_METHOD_BINDING)) {
  ------------------
  |  |   81|      0|#define STUN_METHOD_BINDING (0x0001)
  ------------------
  |  Branch (1413:11): [True: 0, False: 0]
  |  Branch (1413:44): [True: 0, False: 0]
  ------------------
 1414|      0|        return true;
 1415|      0|      }
 1416|      0|    }
 1417|    172|  }
 1418|    172|  return false;
 1419|    172|}
stun_is_binding_response_str:
 1421|    172|bool stun_is_binding_response_str(const uint8_t *buf, size_t len) {
 1422|    172|  if (stun_is_command_message_str(buf, len) && (stun_get_method_str(buf, len) == STUN_METHOD_BINDING)) {
  ------------------
  |  |   81|      0|#define STUN_METHOD_BINDING (0x0001)
  ------------------
  |  Branch (1422:7): [True: 0, False: 172]
  |  Branch (1422:48): [True: 0, False: 0]
  ------------------
 1423|      0|    if (stun_is_response_str(buf, len)) {
  ------------------
  |  Branch (1423:9): [True: 0, False: 0]
  ------------------
 1424|      0|      return true;
 1425|      0|    }
 1426|      0|  }
 1427|    172|  return false;
 1428|    172|}
stun_tid_from_message_str:
 1466|  14.4k|void stun_tid_from_message_str(const uint8_t *buf, size_t len, stun_tid *id) {
 1467|  14.4k|  UNUSED_ARG(len);
  ------------------
  |  |  218|  14.4k|  do {                                                                                                                 \
  |  |  219|  14.4k|    A = A;                                                                                                             \
  |  |  220|  14.4k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (220:12): [Folded, False: 14.4k]
  |  |  ------------------
  ------------------
 1468|  14.4k|  stun_tid_from_string(buf + 8, id);
 1469|  14.4k|}
stun_tid_message_cpy:
 1471|  30.0k|void stun_tid_message_cpy(uint8_t *buf, const stun_tid *id) {
 1472|  30.0k|  if (buf && id) {
  ------------------
  |  Branch (1472:7): [True: 30.0k, False: 0]
  |  Branch (1472:14): [True: 30.0k, False: 0]
  ------------------
 1473|  30.0k|    stun_tid_string_cpy(buf + 8, id);
 1474|  30.0k|  }
 1475|  30.0k|}
stun_tid_generate:
 1477|  19.4k|void stun_tid_generate(stun_tid *id) {
 1478|  19.4k|  if (id) {
  ------------------
  |  Branch (1478:7): [True: 19.4k, False: 0]
  ------------------
 1479|  19.4k|    turn_random_tid_size(id->tsx_id);
 1480|  19.4k|  }
 1481|  19.4k|}
stun_tid_generate_in_message_str:
 1483|  19.4k|void stun_tid_generate_in_message_str(uint8_t *buf, stun_tid *id) {
 1484|  19.4k|  stun_tid tmp;
 1485|  19.4k|  if (!id) {
  ------------------
  |  Branch (1485:7): [True: 19.4k, False: 0]
  ------------------
 1486|  19.4k|    id = &tmp;
 1487|  19.4k|  }
 1488|  19.4k|  stun_tid_generate(id);
 1489|  19.4k|  stun_tid_message_cpy(buf, id);
 1490|  19.4k|}
stun_attr_get_type:
 1514|  1.40M|int stun_attr_get_type(stun_attr_ref attr) {
 1515|  1.40M|  if (attr) {
  ------------------
  |  Branch (1515:7): [True: 1.40M, False: 0]
  ------------------
 1516|  1.40M|    return (int)turn_read_u16(attr);
 1517|  1.40M|  }
 1518|      0|  return -1;
 1519|  1.40M|}
stun_attr_get_len:
 1521|  2.70M|int stun_attr_get_len(stun_attr_ref attr) {
 1522|  2.70M|  if (attr) {
  ------------------
  |  Branch (1522:7): [True: 2.70M, False: 0]
  ------------------
 1523|  2.70M|    return (int)turn_read_u16((const uint8_t *)attr + 2);
 1524|  2.70M|  }
 1525|      0|  return -1;
 1526|  2.70M|}
stun_attr_get_value:
 1528|  77.7k|const uint8_t *stun_attr_get_value(stun_attr_ref attr) {
 1529|  77.7k|  if (attr) {
  ------------------
  |  Branch (1529:7): [True: 77.7k, False: 0]
  ------------------
 1530|  77.7k|    const int len = (int)turn_read_u16((const uint8_t *)attr + 2);
 1531|  77.7k|    if (len < 1) {
  ------------------
  |  Branch (1531:9): [True: 15.5k, False: 62.2k]
  ------------------
 1532|  15.5k|      return NULL;
 1533|  15.5k|    }
 1534|  62.2k|    return ((const uint8_t *)attr) + 4;
 1535|  77.7k|  }
 1536|      0|  return NULL;
 1537|  77.7k|}
stun_get_requested_address_family:
 1539|     61|int stun_get_requested_address_family(stun_attr_ref attr) {
 1540|     61|  if (attr) {
  ------------------
  |  Branch (1540:7): [True: 61, False: 0]
  ------------------
 1541|     61|    const int len = (int)turn_read_u16((const uint8_t *)attr + 2);
 1542|     61|    if (len != 4) {
  ------------------
  |  Branch (1542:9): [True: 45, False: 16]
  ------------------
 1543|     45|      return STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_INVALID;
  ------------------
  |  |  171|     45|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_INVALID (-1)
  ------------------
 1544|     45|    }
 1545|     16|    const int val = ((const uint8_t *)attr)[4];
 1546|     16|    switch (val) {
 1547|      3|    case STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV4:
  ------------------
  |  |  168|      3|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV4 (0x01)
  ------------------
  |  Branch (1547:5): [True: 3, False: 13]
  ------------------
 1548|      4|    case STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6:
  ------------------
  |  |  169|      4|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6 (0x02)
  ------------------
  |  Branch (1548:5): [True: 1, False: 15]
  ------------------
 1549|      4|      return val;
 1550|     12|    default:
  ------------------
  |  Branch (1550:5): [True: 12, False: 4]
  ------------------
 1551|     12|      return STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_INVALID;
  ------------------
  |  |  171|     12|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_INVALID (-1)
  ------------------
 1552|     16|    };
 1553|      0|  }
 1554|      0|  return STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_DEFAULT;
  ------------------
  |  |  170|      0|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_DEFAULT (0x00)
  ------------------
 1555|     61|}
stun_attr_get_channel_number:
 1557|  1.98k|uint16_t stun_attr_get_channel_number(stun_attr_ref attr) {
 1558|  1.98k|  if (attr) {
  ------------------
  |  Branch (1558:7): [True: 1.98k, False: 0]
  ------------------
 1559|  1.98k|    const uint8_t *value = stun_attr_get_value(attr);
 1560|  1.98k|    if (value && (stun_attr_get_len(attr) >= 2)) {
  ------------------
  |  Branch (1560:9): [True: 1.30k, False: 686]
  |  Branch (1560:18): [True: 829, False: 473]
  ------------------
 1561|    829|      const uint16_t cn = turn_read_u16(value);
 1562|    829|      if (STUN_VALID_CHANNEL(cn)) {
  ------------------
  |  |  163|    829|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (163:34): [True: 419, False: 410]
  |  |  |  Branch (163:53): [True: 40, False: 379]
  |  |  ------------------
  ------------------
 1563|     40|        return cn;
 1564|     40|      }
 1565|    829|    }
 1566|  1.98k|  }
 1567|  1.94k|  return 0;
 1568|  1.98k|}
stun_attr_get_bandwidth:
 1570|     83|band_limit_t stun_attr_get_bandwidth(stun_attr_ref attr) {
 1571|     83|  if (attr) {
  ------------------
  |  Branch (1571:7): [True: 83, False: 0]
  ------------------
 1572|     83|    const uint8_t *value = stun_attr_get_value(attr);
 1573|     83|    if (value && (stun_attr_get_len(attr) >= 4)) {
  ------------------
  |  Branch (1573:9): [True: 55, False: 28]
  |  Branch (1573:18): [True: 35, False: 20]
  ------------------
 1574|     35|      const uint32_t bps = turn_read_u32(value);
 1575|     35|      return (band_limit_t)(bps << 7);
 1576|     35|    }
 1577|     83|  }
 1578|     48|  return 0;
 1579|     83|}
stun_attr_get_reservation_token_value:
 1581|     55|uint64_t stun_attr_get_reservation_token_value(stun_attr_ref attr) {
 1582|     55|  if (attr) {
  ------------------
  |  Branch (1582:7): [True: 55, False: 0]
  ------------------
 1583|     55|    const uint8_t *value = stun_attr_get_value(attr);
 1584|     55|    if (value && (stun_attr_get_len(attr) == 8)) {
  ------------------
  |  Branch (1584:9): [True: 39, False: 16]
  |  Branch (1584:18): [True: 4, False: 35]
  ------------------
 1585|      4|      return turn_read_u64(value);
 1586|      4|    }
 1587|     55|  }
 1588|     51|  return 0;
 1589|     55|}
stun_attr_is_addr:
 1591|   130k|bool stun_attr_is_addr(stun_attr_ref attr) {
 1592|       |
 1593|   130k|  if (attr) {
  ------------------
  |  Branch (1593:7): [True: 130k, False: 0]
  ------------------
 1594|   130k|    switch (stun_attr_get_type(attr)) {
 1595|  14.4k|    case STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS:
  ------------------
  |  |  109|  14.4k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (1595:5): [True: 14.4k, False: 116k]
  ------------------
 1596|  23.4k|    case STUN_ATTRIBUTE_XOR_PEER_ADDRESS:
  ------------------
  |  |  120|  23.4k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  |  Branch (1596:5): [True: 8.95k, False: 121k]
  ------------------
 1597|  33.5k|    case STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS:
  ------------------
  |  |  122|  33.5k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  |  Branch (1597:5): [True: 10.0k, False: 120k]
  ------------------
 1598|  43.9k|    case STUN_ATTRIBUTE_MAPPED_ADDRESS:
  ------------------
  |  |   95|  43.9k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
  |  Branch (1598:5): [True: 10.4k, False: 120k]
  ------------------
 1599|  49.2k|    case STUN_ATTRIBUTE_ALTERNATE_SERVER:
  ------------------
  |  |  114|  49.2k|#define STUN_ATTRIBUTE_ALTERNATE_SERVER (0x8023)
  ------------------
  |  Branch (1599:5): [True: 5.29k, False: 125k]
  ------------------
 1600|  52.7k|    case OLD_STUN_ATTRIBUTE_RESPONSE_ADDRESS:
  ------------------
  |  |   96|  52.7k|#define OLD_STUN_ATTRIBUTE_RESPONSE_ADDRESS (0x0002)
  ------------------
  |  Branch (1600:5): [True: 3.51k, False: 127k]
  ------------------
 1601|  55.9k|    case OLD_STUN_ATTRIBUTE_SOURCE_ADDRESS:
  ------------------
  |  |   98|  55.9k|#define OLD_STUN_ATTRIBUTE_SOURCE_ADDRESS (0x0004)
  ------------------
  |  Branch (1601:5): [True: 3.23k, False: 127k]
  ------------------
 1602|  59.2k|    case OLD_STUN_ATTRIBUTE_CHANGED_ADDRESS:
  ------------------
  |  |   99|  59.2k|#define OLD_STUN_ATTRIBUTE_CHANGED_ADDRESS (0x0005)
  ------------------
  |  Branch (1602:5): [True: 3.23k, False: 127k]
  ------------------
 1603|  63.4k|    case OLD_STUN_ATTRIBUTE_REFLECTED_FROM:
  ------------------
  |  |  105|  63.4k|#define OLD_STUN_ATTRIBUTE_REFLECTED_FROM (0x000B)
  ------------------
  |  Branch (1603:5): [True: 4.25k, False: 126k]
  ------------------
 1604|  68.5k|    case STUN_ATTRIBUTE_RESPONSE_ORIGIN:
  ------------------
  |  |  136|  68.5k|#define STUN_ATTRIBUTE_RESPONSE_ORIGIN (0x802B)
  ------------------
  |  Branch (1604:5): [True: 5.07k, False: 125k]
  ------------------
 1605|  74.3k|    case STUN_ATTRIBUTE_OTHER_ADDRESS:
  ------------------
  |  |  137|  74.3k|#define STUN_ATTRIBUTE_OTHER_ADDRESS (0x802C)
  ------------------
  |  Branch (1605:5): [True: 5.76k, False: 124k]
  ------------------
 1606|  74.3k|      return true;
 1607|      0|      break;
 1608|  56.3k|    default:;
  ------------------
  |  Branch (1608:5): [True: 56.3k, False: 74.3k]
  ------------------
 1609|   130k|    };
 1610|  56.3k|  }
 1611|  56.3k|  return false;
 1612|   130k|}
stun_attr_get_even_port:
 1614|     40|uint8_t stun_attr_get_even_port(stun_attr_ref attr) {
 1615|     40|  if (attr) {
  ------------------
  |  Branch (1615:7): [True: 40, False: 0]
  ------------------
 1616|     40|    const uint8_t *value = stun_attr_get_value(attr);
 1617|     40|    if (value) {
  ------------------
  |  Branch (1617:9): [True: 28, False: 12]
  ------------------
 1618|     28|      if ((uint8_t)(value[0]) > 0x7F) {
  ------------------
  |  Branch (1618:11): [True: 11, False: 17]
  ------------------
 1619|     11|        return 1;
 1620|     11|      }
 1621|     28|    }
 1622|     40|  }
 1623|     29|  return 0;
 1624|     40|}
stun_attr_get_first_by_type_str:
 1634|   160k|stun_attr_ref stun_attr_get_first_by_type_str(const uint8_t *buf, size_t len, uint16_t attr_type) {
 1635|   160k|  stun_attr_ref attr = stun_attr_get_first_str(buf, len);
 1636|  1.26M|  while (attr) {
  ------------------
  |  Branch (1636:10): [True: 1.16M, False: 104k]
  ------------------
 1637|  1.16M|    if (stun_attr_get_type(attr) == attr_type) {
  ------------------
  |  Branch (1637:9): [True: 55.9k, False: 1.10M]
  ------------------
 1638|  55.9k|      return attr;
 1639|  55.9k|    }
 1640|  1.10M|    attr = stun_attr_get_next_str(buf, len, attr);
 1641|  1.10M|  }
 1642|       |
 1643|   104k|  return NULL;
 1644|   160k|}
stun_attr_get_first_str:
 1679|   171k|stun_attr_ref stun_attr_get_first_str(const uint8_t *buf, size_t len) {
 1680|   171k|  const int bufLen = stun_get_command_message_len_str(buf, len);
 1681|   171k|  if (bufLen > STUN_HEADER_LENGTH) {
  ------------------
  |  |   46|   171k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (1681:7): [True: 168k, False: 3.41k]
  ------------------
 1682|   168k|    stun_attr_ref attr = (stun_attr_ref)(buf + STUN_HEADER_LENGTH);
  ------------------
  |  |   46|   168k|#define STUN_HEADER_LENGTH (20)
  ------------------
 1683|   168k|    return stun_attr_check_valid(attr, bufLen - STUN_HEADER_LENGTH);
  ------------------
  |  |   46|   168k|#define STUN_HEADER_LENGTH (20)
  ------------------
 1684|   168k|  }
 1685|       |
 1686|  3.41k|  return NULL;
 1687|   171k|}
stun_attr_get_next_str:
 1689|  1.25M|stun_attr_ref stun_attr_get_next_str(const uint8_t *buf, size_t len, stun_attr_ref prev) {
 1690|  1.25M|  if (!prev) {
  ------------------
  |  Branch (1690:7): [True: 0, False: 1.25M]
  ------------------
 1691|      0|    return stun_attr_get_first_str(buf, len);
 1692|  1.25M|  } else {
 1693|  1.25M|    const uint8_t *end = buf + stun_get_command_message_len_str(buf, len);
 1694|  1.25M|    int attrlen = stun_attr_get_len(prev);
 1695|  1.25M|    const uint16_t rem4 = ((uint16_t)attrlen) & 0x0003;
 1696|  1.25M|    if (rem4) {
  ------------------
  |  Branch (1696:9): [True: 237k, False: 1.01M]
  ------------------
 1697|   237k|      attrlen = attrlen + 4 - (int)rem4;
 1698|   237k|    }
 1699|       |    /* Note the order here: operations on attrlen are untrusted as they may overflow */
 1700|  1.25M|    if (attrlen < end - (const uint8_t *)prev - 4) {
  ------------------
  |  Branch (1700:9): [True: 1.16M, False: 88.2k]
  ------------------
 1701|  1.16M|      const uint8_t *attr_end = (const uint8_t *)prev + 4 + attrlen;
 1702|  1.16M|      return stun_attr_check_valid(attr_end, end - attr_end);
 1703|  1.16M|    }
 1704|  88.2k|    return NULL;
 1705|  1.25M|  }
 1706|  1.25M|}
stun_attr_add_str:
 1708|  75.1k|bool stun_attr_add_str(uint8_t *buf, size_t *len, uint16_t attr, const uint8_t *avalue, int alen) {
 1709|  75.1k|  if (alen < 0) {
  ------------------
  |  Branch (1709:7): [True: 0, False: 75.1k]
  ------------------
 1710|      0|    alen = 0;
 1711|      0|  }
 1712|  75.1k|  uint8_t tmp[1];
 1713|  75.1k|  if (!avalue) {
  ------------------
  |  Branch (1713:7): [True: 1.11k, False: 73.9k]
  ------------------
 1714|  1.11k|    alen = 0;
 1715|  1.11k|    avalue = tmp;
 1716|  1.11k|  }
 1717|  75.1k|  const int clen = stun_get_command_message_len_str(buf, *len);
 1718|  75.1k|  int newlen = clen + 4 + alen;
 1719|  75.1k|  const int newlenrem4 = newlen & 0x00000003;
 1720|  75.1k|  int paddinglen = 0;
 1721|  75.1k|  if (newlenrem4) {
  ------------------
  |  Branch (1721:7): [True: 29.8k, False: 45.2k]
  ------------------
 1722|  29.8k|    paddinglen = 4 - newlenrem4;
 1723|  29.8k|    newlen = newlen + paddinglen;
 1724|  29.8k|  }
 1725|       |
 1726|  75.1k|  if (newlen >= MAX_STUN_MESSAGE_SIZE) {
  ------------------
  |  |  223|  75.1k|#define MAX_STUN_MESSAGE_SIZE (65507)
  ------------------
  |  Branch (1726:7): [True: 0, False: 75.1k]
  ------------------
 1727|      0|    return false;
 1728|      0|  }
 1729|       |
 1730|  75.1k|  uint8_t *attr_start = buf + clen;
 1731|       |
 1732|  75.1k|  stun_set_command_message_len_str(buf, newlen);
 1733|  75.1k|  *len = newlen;
 1734|       |
 1735|  75.1k|  turn_write_u16(attr_start, attr);
 1736|  75.1k|  turn_write_u16(attr_start + 2, (uint16_t)alen);
 1737|  75.1k|  if (alen > 0) {
  ------------------
  |  Branch (1737:7): [True: 73.9k, False: 1.11k]
  ------------------
 1738|  73.9k|    memcpy(attr_start + 4, avalue, alen);
 1739|  73.9k|  }
 1740|       |
 1741|       |  // Write 0 padding to not leak data
 1742|  75.1k|  memset(attr_start + 4 + alen, 0, paddinglen);
 1743|       |
 1744|       |  return true;
 1745|  75.1k|}
stun_attr_add_addr_str:
 1747|  6.70k|bool stun_attr_add_addr_str(uint8_t *buf, size_t *len, uint16_t attr_type, const ioa_addr *ca) {
 1748|       |
 1749|  6.70k|  stun_tid tid;
 1750|  6.70k|  stun_tid_from_message_str(buf, *len, &tid);
 1751|       |
 1752|  6.70k|  int xor_ed = 0;
 1753|  6.70k|  switch (attr_type) {
 1754|  2.23k|  case STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS:
  ------------------
  |  |  109|  2.23k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (1754:3): [True: 2.23k, False: 4.47k]
  ------------------
 1755|  3.35k|  case STUN_ATTRIBUTE_XOR_PEER_ADDRESS:
  ------------------
  |  |  120|  3.35k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  |  Branch (1755:3): [True: 1.11k, False: 5.59k]
  ------------------
 1756|  5.59k|  case STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS:
  ------------------
  |  |  122|  5.59k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  |  Branch (1756:3): [True: 2.23k, False: 4.47k]
  ------------------
 1757|  5.59k|    xor_ed = 1;
 1758|  5.59k|    break;
 1759|  1.11k|  default:;
  ------------------
  |  Branch (1759:3): [True: 1.11k, False: 5.59k]
  ------------------
 1760|  6.70k|  };
 1761|       |
 1762|  6.70k|  ioa_addr public_addr;
 1763|  6.70k|  map_addr_from_private_to_public(ca, &public_addr);
 1764|       |
 1765|  6.70k|  uint8_t cfield[64];
 1766|  6.70k|  int clen = 0;
 1767|  6.70k|  if (stun_addr_encode(&public_addr, cfield, &clen, xor_ed, STUN_MAGIC_COOKIE, tid.tsx_id) < 0) {
  ------------------
  |  |   60|  6.70k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (1767:7): [True: 0, False: 6.70k]
  ------------------
 1768|      0|    return false;
 1769|      0|  }
 1770|       |
 1771|  6.70k|  if (!stun_attr_add_str(buf, len, attr_type, (uint8_t *)(&cfield), clen)) {
  ------------------
  |  Branch (1771:7): [True: 0, False: 6.70k]
  ------------------
 1772|      0|    return false;
 1773|      0|  }
 1774|       |
 1775|  6.70k|  return true;
 1776|  6.70k|}
stun_attr_get_addr_str:
 1779|  7.77k|                            const ioa_addr *default_addr) {
 1780|  7.77k|  stun_tid tid;
 1781|  7.77k|  stun_tid_from_message_str(buf, len, &tid);
 1782|  7.77k|  ioa_addr public_addr;
 1783|       |
 1784|  7.77k|  addr_set_any(ca);
 1785|  7.77k|  addr_set_any(&public_addr);
 1786|       |
 1787|  7.77k|  const int attr_type = stun_attr_get_type(attr);
 1788|  7.77k|  if (attr_type < 0) {
  ------------------
  |  Branch (1788:7): [True: 0, False: 7.77k]
  ------------------
 1789|      0|    return false;
 1790|      0|  }
 1791|       |
 1792|  7.77k|  int xor_ed = 0;
 1793|  7.77k|  switch (attr_type) {
 1794|  1.68k|  case STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS:
  ------------------
  |  |  109|  1.68k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (1794:3): [True: 1.68k, False: 6.08k]
  ------------------
 1795|  2.91k|  case STUN_ATTRIBUTE_XOR_PEER_ADDRESS:
  ------------------
  |  |  120|  2.91k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  |  Branch (1795:3): [True: 1.22k, False: 6.54k]
  ------------------
 1796|  4.16k|  case STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS:
  ------------------
  |  |  122|  4.16k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  |  Branch (1796:3): [True: 1.25k, False: 6.52k]
  ------------------
 1797|  4.16k|    xor_ed = 1;
 1798|  4.16k|    break;
 1799|  3.60k|  default:;
  ------------------
  |  Branch (1799:3): [True: 3.60k, False: 4.16k]
  ------------------
 1800|  7.77k|  };
 1801|       |
 1802|  7.77k|  const uint8_t *cfield = stun_attr_get_value(attr);
 1803|  7.77k|  if (!cfield) {
  ------------------
  |  Branch (1803:7): [True: 4.47k, False: 3.29k]
  ------------------
 1804|  4.47k|    return false;
 1805|  4.47k|  }
 1806|       |
 1807|  3.29k|  if (stun_addr_decode(&public_addr, cfield, stun_attr_get_len(attr), xor_ed, STUN_MAGIC_COOKIE, tid.tsx_id) < 0) {
  ------------------
  |  |   60|  3.29k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (1807:7): [True: 2.32k, False: 977]
  ------------------
 1808|  2.32k|    return false;
 1809|  2.32k|  }
 1810|       |
 1811|    977|  map_addr_from_public_to_private(&public_addr, ca);
 1812|       |
 1813|    977|  if (default_addr && addr_any_no_port(ca) && !addr_any_no_port(default_addr)) {
  ------------------
  |  Branch (1813:7): [True: 0, False: 977]
  |  Branch (1813:23): [True: 0, False: 0]
  |  Branch (1813:47): [True: 0, False: 0]
  ------------------
 1814|      0|    const uint16_t port = addr_get_port(ca);
 1815|      0|    addr_cpy(ca, default_addr);
 1816|      0|    addr_set_port(ca, port);
 1817|      0|  }
 1818|       |
 1819|       |  return true;
 1820|  3.29k|}
stun_attr_get_first_addr_str:
 1823|  9.09k|                                  const ioa_addr *default_addr) {
 1824|  9.09k|  stun_attr_ref attr = stun_attr_get_first_str(buf, len);
 1825|       |
 1826|   124k|  while (attr) {
  ------------------
  |  Branch (1826:10): [True: 115k, False: 8.60k]
  ------------------
 1827|   115k|    if (stun_attr_is_addr(attr) && (attr_type == stun_attr_get_type(attr))) {
  ------------------
  |  Branch (1827:9): [True: 65.8k, False: 49.9k]
  |  Branch (1827:36): [True: 6.61k, False: 59.2k]
  ------------------
 1828|  6.61k|      if (stun_attr_get_addr_str(buf, len, attr, ca, default_addr)) {
  ------------------
  |  Branch (1828:11): [True: 492, False: 6.12k]
  ------------------
 1829|    492|        return true;
 1830|    492|      }
 1831|  6.61k|    }
 1832|   115k|    attr = stun_attr_get_next_str(buf, len, attr);
 1833|   115k|  }
 1834|       |
 1835|  8.60k|  return false;
 1836|  9.09k|}
stun_attr_add_channel_number_str:
 1838|  1.11k|bool stun_attr_add_channel_number_str(uint8_t *buf, size_t *len, uint16_t chnumber) {
 1839|       |
 1840|  1.11k|  uint16_t field[2];
 1841|  1.11k|  field[0] = nswap16(chnumber);
  ------------------
  |  |   86|  1.11k|#define nswap16(s) ntohs(s)
  ------------------
 1842|  1.11k|  field[1] = 0;
 1843|       |
 1844|  1.11k|  return stun_attr_add_str(buf, len, STUN_ATTRIBUTE_CHANNEL_NUMBER, (uint8_t *)(field), sizeof(field));
  ------------------
  |  |  117|  1.11k|#define STUN_ATTRIBUTE_CHANNEL_NUMBER (0x000C)
  ------------------
 1845|  1.11k|}
stun_attr_add_bandwidth_str:
 1847|  1.11k|bool stun_attr_add_bandwidth_str(uint8_t *buf, size_t *len, band_limit_t bps0) {
 1848|       |
 1849|  1.11k|  const uint32_t bps = (uint32_t)(band_limit_t)(bps0 >> 7);
 1850|       |
 1851|  1.11k|  uint32_t field = nswap32(bps);
  ------------------
  |  |   87|  1.11k|#define nswap32(ul) ntohl(ul)
  ------------------
 1852|       |
 1853|  1.11k|  return stun_attr_add_str(buf, len, STUN_ATTRIBUTE_NEW_BANDWIDTH, (uint8_t *)(&field), sizeof(field));
  ------------------
  |  |   52|  1.11k|#define STUN_ATTRIBUTE_NEW_BANDWIDTH (0x8000 + STUN_ATTRIBUTE_BANDWIDTH)
  |  |  ------------------
  |  |  |  |  119|  1.11k|#define STUN_ATTRIBUTE_BANDWIDTH (0x0010)
  |  |  ------------------
  ------------------
 1854|  1.11k|}
stun_attr_add_address_error_code:
 1856|  1.11k|bool stun_attr_add_address_error_code(uint8_t *buf, size_t *len, int requested_address_family, int error_code) {
 1857|  1.11k|  const uint8_t *reason = get_default_reason(error_code);
 1858|       |
 1859|  1.11k|  uint8_t avalue[513] = {0};
 1860|  1.11k|  avalue[0] = (uint8_t)requested_address_family;
 1861|  1.11k|  avalue[1] = 0;
 1862|  1.11k|  avalue[2] = (uint8_t)(error_code / 100);
 1863|  1.11k|  avalue[3] = (uint8_t)(error_code % 100);
 1864|  1.11k|  strncpy((char *)(avalue + 4), (const char *)reason, sizeof(avalue) - 4);
 1865|  1.11k|  avalue[sizeof(avalue) - 1] = 0;
 1866|       |
 1867|       |  /* RFC 8489 Section 14: the declared length excludes padding. */
 1868|  1.11k|  const int alen = 4 + (int)strlen((const char *)(avalue + 4));
 1869|       |
 1870|  1.11k|  return stun_attr_add_str(buf, len, STUN_ATTRIBUTE_ADDRESS_ERROR_CODE, (uint8_t *)avalue, alen);
  ------------------
  |  |  145|  1.11k|#define STUN_ATTRIBUTE_ADDRESS_ERROR_CODE (0x8001)
  ------------------
 1871|  1.11k|}
stun_attr_get_first_channel_number_str:
 1873|  1.13k|uint16_t stun_attr_get_first_channel_number_str(const uint8_t *buf, size_t len) {
 1874|       |
 1875|  1.13k|  stun_attr_ref attr = stun_attr_get_first_str(buf, len);
 1876|  15.7k|  while (attr) {
  ------------------
  |  Branch (1876:10): [True: 14.6k, False: 1.11k]
  ------------------
 1877|  14.6k|    if (stun_attr_get_type(attr) == STUN_ATTRIBUTE_CHANNEL_NUMBER) {
  ------------------
  |  |  117|  14.6k|#define STUN_ATTRIBUTE_CHANNEL_NUMBER (0x000C)
  ------------------
  |  Branch (1877:9): [True: 1.81k, False: 12.8k]
  ------------------
 1878|  1.81k|      const uint16_t ret = stun_attr_get_channel_number(attr);
 1879|  1.81k|      if (STUN_VALID_CHANNEL(ret)) {
  ------------------
  |  |  163|  1.81k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (163:34): [True: 21, False: 1.79k]
  |  |  |  Branch (163:53): [True: 21, False: 0]
  |  |  ------------------
  ------------------
 1880|     21|        return ret;
 1881|     21|      }
 1882|  1.81k|    }
 1883|  14.6k|    attr = stun_attr_get_next_str(buf, len, attr);
 1884|  14.6k|  }
 1885|       |
 1886|  1.11k|  return 0;
 1887|  1.13k|}
stun_attr_add_fingerprint_str:
 1891|  1.11k|bool stun_attr_add_fingerprint_str(uint8_t *buf, size_t *len) {
 1892|  1.11k|  uint32_t crc32 = 0;
 1893|  1.11k|  if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_FINGERPRINT, (uint8_t *)&crc32, 4)) {
  ------------------
  |  |  115|  1.11k|#define STUN_ATTRIBUTE_FINGERPRINT (0x8028)
  ------------------
  |  Branch (1893:7): [True: 0, False: 1.11k]
  ------------------
 1894|      0|    return false;
 1895|      0|  }
 1896|  1.11k|  crc32 = ns_crc32(buf, (int)*len - 8);
 1897|  1.11k|  turn_write_u32(buf + *len - 4, crc32 ^ ((uint32_t)FINGERPRINT_XOR));
  ------------------
  |  |   53|  1.11k|#define FINGERPRINT_XOR 0x5354554e
  ------------------
 1898|       |  return true;
 1899|  1.11k|}
get_hmackey_size:
 1994|  24.6k|size_t get_hmackey_size(SHATYPE shatype) {
 1995|  24.6k|  if (shatype == SHATYPE_SHA256) {
  ------------------
  |  Branch (1995:7): [True: 8.37k, False: 16.2k]
  ------------------
 1996|  8.37k|    return 32;
 1997|  8.37k|  }
 1998|  16.2k|  if (shatype == SHATYPE_SHA384) {
  ------------------
  |  Branch (1998:7): [True: 4.54k, False: 11.7k]
  ------------------
 1999|  4.54k|    return 48;
 2000|  4.54k|  }
 2001|  11.7k|  if (shatype == SHATYPE_SHA512) {
  ------------------
  |  Branch (2001:7): [True: 5.08k, False: 6.62k]
  ------------------
 2002|  5.08k|    return 64;
 2003|  5.08k|  }
 2004|  6.62k|  return 16;
 2005|  11.7k|}
stun_attr_add_integrity_str:
 2020|  5.30k|                                 SHATYPE shatype) {
 2021|  5.30k|  return turn_attr_add_integrity_key_len_str(ct, buf, len, key, get_hmackey_size(shatype), pwd, shatype);
 2022|  5.30k|}
turn_attr_add_integrity_key_len_str:
 2025|  8.84k|                                         size_t key_len, password_t pwd, SHATYPE shatype) {
 2026|  8.84k|  if (ct != TURN_CREDENTIALS_SHORT_TERM && (key_len == 0 || key_len > sizeof(hmackey_t))) {
  ------------------
  |  Branch (2026:7): [True: 5.30k, False: 3.53k]
  |  Branch (2026:45): [True: 0, False: 5.30k]
  |  Branch (2026:61): [True: 0, False: 5.30k]
  ------------------
 2027|      0|    return false;
 2028|      0|  }
 2029|       |
 2030|  8.84k|  uint8_t hmac[MAXSHASIZE] = {0};
 2031|       |
 2032|  8.84k|  unsigned int shasize;
 2033|       |
 2034|  8.84k|  switch (shatype) {
 2035|  3.63k|  case SHATYPE_SHA256:
  ------------------
  |  Branch (2035:3): [True: 3.63k, False: 5.20k]
  ------------------
 2036|  3.63k|    shasize = SHA256SIZEBYTES;
  ------------------
  |  |  184|  3.63k|#define SHA256SIZEBYTES (32)
  ------------------
 2037|  3.63k|    break;
 2038|  1.39k|  case SHATYPE_SHA384:
  ------------------
  |  Branch (2038:3): [True: 1.39k, False: 7.45k]
  ------------------
 2039|  1.39k|    shasize = SHA384SIZEBYTES;
  ------------------
  |  |  185|  1.39k|#define SHA384SIZEBYTES (48)
  ------------------
 2040|  1.39k|    break;
 2041|  1.93k|  case SHATYPE_SHA512:
  ------------------
  |  Branch (2041:3): [True: 1.93k, False: 6.90k]
  ------------------
 2042|  1.93k|    shasize = SHA512SIZEBYTES;
  ------------------
  |  |  186|  1.93k|#define SHA512SIZEBYTES (64)
  ------------------
 2043|  1.93k|    break;
 2044|  1.88k|  default:
  ------------------
  |  Branch (2044:3): [True: 1.88k, False: 6.96k]
  ------------------
 2045|  1.88k|    shasize = SHA1SIZEBYTES;
  ------------------
  |  |  183|  1.88k|#define SHA1SIZEBYTES (20)
  ------------------
 2046|  8.84k|  };
 2047|       |
 2048|  8.84k|  if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_MESSAGE_INTEGRITY, hmac, shasize)) {
  ------------------
  |  |  102|  8.84k|#define STUN_ATTRIBUTE_MESSAGE_INTEGRITY (0x0008)
  ------------------
  |  Branch (2048:7): [True: 0, False: 8.84k]
  ------------------
 2049|      0|    return false;
 2050|      0|  }
 2051|       |
 2052|  8.84k|  if (ct == TURN_CREDENTIALS_SHORT_TERM) {
  ------------------
  |  Branch (2052:7): [True: 3.53k, False: 5.30k]
  ------------------
 2053|  3.53k|    return stun_calculate_hmac(buf, *len - 4 - shasize, pwd, strlen((char *)pwd), buf + *len - shasize, &shasize,
 2054|  3.53k|                               shatype);
 2055|  5.30k|  } else {
 2056|  5.30k|    return stun_calculate_hmac(buf, *len - 4 - shasize, key, key_len, buf + *len - shasize, &shasize, shatype);
 2057|  5.30k|  }
 2058|  8.84k|}
stun_attr_add_integrity_by_key_str:
 2061|  3.53k|                                        hmackey_t key, const uint8_t *nonce, SHATYPE shatype) {
 2062|  3.53k|  return turn_attr_add_integrity_by_key_len_str(buf, len, uname, realm, key, get_hmackey_size(shatype), nonce, shatype);
 2063|  3.53k|}
turn_attr_add_integrity_by_key_len_str:
 2066|  3.53k|                                            const uint8_t *key, size_t key_len, const uint8_t *nonce, SHATYPE shatype) {
 2067|  3.53k|  if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_USERNAME, uname, (int)strlen((const char *)uname))) {
  ------------------
  |  |  100|  3.53k|#define STUN_ATTRIBUTE_USERNAME (0x0006)
  ------------------
  |  Branch (2067:7): [True: 0, False: 3.53k]
  ------------------
 2068|      0|    return false;
 2069|      0|  }
 2070|       |
 2071|  3.53k|  if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_NONCE, nonce, (int)strlen((const char *)nonce))) {
  ------------------
  |  |  107|  3.53k|#define STUN_ATTRIBUTE_NONCE (0x0015)
  ------------------
  |  Branch (2071:7): [True: 0, False: 3.53k]
  ------------------
 2072|      0|    return false;
 2073|      0|  }
 2074|       |
 2075|  3.53k|  if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_REALM, realm, (int)strlen((const char *)realm))) {
  ------------------
  |  |  106|  3.53k|#define STUN_ATTRIBUTE_REALM (0x0014)
  ------------------
  |  Branch (2075:7): [True: 0, False: 3.53k]
  ------------------
 2076|      0|    return false;
 2077|      0|  }
 2078|       |
 2079|  3.53k|  password_t p;
 2080|  3.53k|  return turn_attr_add_integrity_key_len_str(TURN_CREDENTIALS_LONG_TERM, buf, len, key, key_len, p, shatype);
 2081|  3.53k|}
stun_attr_add_integrity_by_user_str:
 2084|  1.76k|                                         const uint8_t *upwd, const uint8_t *nonce, SHATYPE shatype) {
 2085|  1.76k|  hmackey_t key;
 2086|       |
 2087|  1.76k|  if (!stun_produce_integrity_key_str(uname, realm, upwd, key, shatype)) {
  ------------------
  |  Branch (2087:7): [True: 0, False: 1.76k]
  ------------------
 2088|      0|    return false;
 2089|      0|  }
 2090|       |
 2091|  1.76k|  return stun_attr_add_integrity_by_key_str(buf, len, uname, realm, key, nonce, shatype);
 2092|  1.76k|}
stun_attr_add_integrity_by_user_short_term_str:
 2095|  1.76k|                                                    SHATYPE shatype) {
 2096|  1.76k|  if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_USERNAME, uname, (int)strlen((const char *)uname))) {
  ------------------
  |  |  100|  1.76k|#define STUN_ATTRIBUTE_USERNAME (0x0006)
  ------------------
  |  Branch (2096:7): [True: 0, False: 1.76k]
  ------------------
 2097|      0|    return false;
 2098|      0|  }
 2099|       |
 2100|  1.76k|  hmackey_t key;
 2101|  1.76k|  return stun_attr_add_integrity_str(TURN_CREDENTIALS_SHORT_TERM, buf, len, key, pwd, shatype);
 2102|  1.76k|}
stun_check_message_integrity_by_key_str:
 2108|  15.7k|                                            password_t pwd, SHATYPE shatype) {
 2109|  15.7k|  return turn_check_message_integrity_by_key_len_str(ct, buf, len, key, get_hmackey_size(shatype), pwd, shatype);
 2110|  15.7k|}
turn_check_message_integrity_by_key_len_str:
 2116|  15.7k|                                                size_t key_len, password_t pwd, SHATYPE shatype) {
 2117|  15.7k|  if (ct != TURN_CREDENTIALS_SHORT_TERM && (key_len == 0 || key_len > sizeof(hmackey_t))) {
  ------------------
  |  Branch (2117:7): [True: 7.89k, False: 7.89k]
  |  Branch (2117:45): [True: 0, False: 7.89k]
  |  Branch (2117:61): [True: 0, False: 7.89k]
  ------------------
 2118|      0|    return -1;
 2119|      0|  }
 2120|       |
 2121|  15.7k|  stun_attr_ref sar = stun_attr_get_first_by_type_str(buf, len, STUN_ATTRIBUTE_MESSAGE_INTEGRITY);
  ------------------
  |  |  102|  15.7k|#define STUN_ATTRIBUTE_MESSAGE_INTEGRITY (0x0008)
  ------------------
 2122|  15.7k|  if (!sar) {
  ------------------
  |  Branch (2122:7): [True: 14.3k, False: 1.43k]
  ------------------
 2123|  14.3k|    return -1;
 2124|  14.3k|  }
 2125|       |
 2126|  1.43k|  unsigned int shasize = 0;
 2127|  1.43k|  switch (stun_attr_get_len(sar)) {
 2128|    440|  case SHA256SIZEBYTES:
  ------------------
  |  |  184|    440|#define SHA256SIZEBYTES (32)
  ------------------
  |  Branch (2128:3): [True: 440, False: 990]
  ------------------
 2129|    440|    shasize = SHA256SIZEBYTES;
  ------------------
  |  |  184|    440|#define SHA256SIZEBYTES (32)
  ------------------
 2130|    440|    if (shatype != SHATYPE_SHA256) {
  ------------------
  |  Branch (2130:9): [True: 308, False: 132]
  ------------------
 2131|    308|      return -1;
 2132|    308|    }
 2133|    132|    break;
 2134|    132|  case SHA384SIZEBYTES:
  ------------------
  |  |  185|     50|#define SHA384SIZEBYTES (48)
  ------------------
  |  Branch (2134:3): [True: 50, False: 1.38k]
  ------------------
 2135|     50|    shasize = SHA384SIZEBYTES;
  ------------------
  |  |  185|     50|#define SHA384SIZEBYTES (48)
  ------------------
 2136|     50|    if (shatype != SHATYPE_SHA384) {
  ------------------
  |  Branch (2136:9): [True: 40, False: 10]
  ------------------
 2137|     40|      return -1;
 2138|     40|    }
 2139|     10|    break;
 2140|     50|  case SHA512SIZEBYTES:
  ------------------
  |  |  186|     50|#define SHA512SIZEBYTES (64)
  ------------------
  |  Branch (2140:3): [True: 50, False: 1.38k]
  ------------------
 2141|     50|    shasize = SHA512SIZEBYTES;
  ------------------
  |  |  186|     50|#define SHA512SIZEBYTES (64)
  ------------------
 2142|     50|    if (shatype != SHATYPE_SHA512) {
  ------------------
  |  Branch (2142:9): [True: 40, False: 10]
  ------------------
 2143|     40|      return -1;
 2144|     40|    }
 2145|     10|    break;
 2146|    540|  case SHA1SIZEBYTES:
  ------------------
  |  |  183|    540|#define SHA1SIZEBYTES (20)
  ------------------
  |  Branch (2146:3): [True: 540, False: 890]
  ------------------
 2147|    540|    shasize = SHA1SIZEBYTES;
  ------------------
  |  |  183|    540|#define SHA1SIZEBYTES (20)
  ------------------
 2148|    540|    if (shatype != SHATYPE_SHA1) {
  ------------------
  |  Branch (2148:9): [True: 378, False: 162]
  ------------------
 2149|    378|      return -1;
 2150|    378|    }
 2151|    162|    break;
 2152|    350|  default:
  ------------------
  |  Branch (2152:3): [True: 350, False: 1.08k]
  ------------------
 2153|    350|    return -1;
 2154|  1.43k|  };
 2155|       |
 2156|    314|  const int orig_len = stun_get_command_message_len_str(buf, len);
 2157|    314|  if (orig_len < 0) {
  ------------------
  |  Branch (2157:7): [True: 0, False: 314]
  ------------------
 2158|      0|    return -1;
 2159|      0|  }
 2160|       |
 2161|    314|  const int new_len = (int)((const uint8_t *)sar - buf) + 4 + shasize;
 2162|    314|  if (new_len > orig_len) {
  ------------------
  |  Branch (2162:7): [True: 0, False: 314]
  ------------------
 2163|      0|    return -1;
 2164|      0|  }
 2165|       |
 2166|    314|  if (!stun_set_command_message_len_str(buf, new_len)) {
  ------------------
  |  Branch (2166:7): [True: 0, False: 314]
  ------------------
 2167|      0|    return -1;
 2168|      0|  }
 2169|       |
 2170|    314|  int res = 0;
 2171|    314|  uint8_t new_hmac[MAXSHASIZE] = {0};
 2172|    314|  if (ct == TURN_CREDENTIALS_SHORT_TERM) {
  ------------------
  |  Branch (2172:7): [True: 162, False: 152]
  ------------------
 2173|    162|    if (!stun_calculate_hmac(buf, (size_t)new_len - 4 - shasize, pwd, strlen((char *)pwd), new_hmac, &shasize,
  ------------------
  |  Branch (2173:9): [True: 0, False: 162]
  ------------------
 2174|    162|                             shatype)) {
 2175|      0|      res = -1;
 2176|    162|    } else {
 2177|    162|      res = 0;
 2178|    162|    }
 2179|    162|  } else {
 2180|    152|    if (!stun_calculate_hmac(buf, (size_t)new_len - 4 - shasize, key, key_len, new_hmac, &shasize, shatype)) {
  ------------------
  |  Branch (2180:9): [True: 0, False: 152]
  ------------------
 2181|      0|      res = -1;
 2182|    152|    } else {
 2183|    152|      res = 0;
 2184|    152|    }
 2185|    152|  }
 2186|       |
 2187|    314|  stun_set_command_message_len_str(buf, orig_len);
 2188|    314|  if (res < 0) {
  ------------------
  |  Branch (2188:7): [True: 0, False: 314]
  ------------------
 2189|      0|    return -1;
 2190|      0|  }
 2191|       |
 2192|    314|  const uint8_t *old_hmac = stun_attr_get_value(sar);
 2193|    314|  if (!old_hmac) {
  ------------------
  |  Branch (2193:7): [True: 0, False: 314]
  ------------------
 2194|      0|    return -1;
 2195|      0|  }
 2196|       |
 2197|       |  /* Use constant-time comparison: a short-circuiting memcmp leaks the matching prefix
 2198|       |     length via response timing, allowing byte-by-byte HMAC recovery. */
 2199|    314|  if (0 != CRYPTO_memcmp(old_hmac, new_hmac, shasize)) {
  ------------------
  |  Branch (2199:7): [True: 312, False: 2]
  ------------------
 2200|    312|    return 0;
 2201|    312|  }
 2202|       |
 2203|      2|  return +1;
 2204|    314|}
stun_check_message_integrity_str:
 2210|  15.7k|                                     const uint8_t *realm, const uint8_t *upwd, SHATYPE shatype) {
 2211|  15.7k|  hmackey_t key;
 2212|  15.7k|  password_t pwd;
 2213|       |
 2214|  15.7k|  if (ct == TURN_CREDENTIALS_SHORT_TERM) {
  ------------------
  |  Branch (2214:7): [True: 7.89k, False: 7.89k]
  ------------------
 2215|  7.89k|    strncpy((char *)pwd, (const char *)upwd, sizeof(password_t) - 1);
 2216|  7.89k|    pwd[sizeof(password_t) - 1] = 0;
 2217|  7.89k|  } else if (!stun_produce_integrity_key_str(uname, realm, upwd, key, shatype)) {
  ------------------
  |  Branch (2217:14): [True: 0, False: 7.89k]
  ------------------
 2218|      0|    return -1;
 2219|      0|  }
 2220|       |
 2221|  15.7k|  return stun_check_message_integrity_by_key_str(ct, buf, len, key, pwd, shatype);
 2222|  15.7k|}
stun_attr_get_change_request_str:
 2226|     34|bool stun_attr_get_change_request_str(stun_attr_ref attr, bool *change_ip, bool *change_port) {
 2227|     34|  if (stun_attr_get_len(attr) == 4) {
  ------------------
  |  Branch (2227:7): [True: 5, False: 29]
  ------------------
 2228|      5|    const uint8_t *value = stun_attr_get_value(attr);
 2229|      5|    if (value) {
  ------------------
  |  Branch (2229:9): [True: 5, False: 0]
  ------------------
 2230|      5|      *change_ip = (value[3] & 0x04);
 2231|      5|      *change_port = (value[3] & 0x02);
 2232|      5|      return true;
 2233|      5|    }
 2234|      5|  }
 2235|     29|  return false;
 2236|     34|}
stun_attr_add_change_request_str:
 2238|  1.11k|bool stun_attr_add_change_request_str(uint8_t *buf, size_t *len, bool change_ip, bool change_port) {
 2239|  1.11k|  uint8_t avalue[4] = {0, 0, 0, 0};
 2240|       |
 2241|  1.11k|  if (change_ip) {
  ------------------
  |  Branch (2241:7): [True: 1.11k, False: 0]
  ------------------
 2242|  1.11k|    if (change_port) {
  ------------------
  |  Branch (2242:9): [True: 1.11k, False: 0]
  ------------------
 2243|  1.11k|      avalue[3] = 0x06;
 2244|  1.11k|    } else {
 2245|      0|      avalue[3] = 0x04;
 2246|      0|    }
 2247|  1.11k|  } else if (change_port) {
  ------------------
  |  Branch (2247:14): [True: 0, False: 0]
  ------------------
 2248|      0|    avalue[3] = 0x02;
 2249|      0|  }
 2250|       |
 2251|  1.11k|  return stun_attr_add_str(buf, len, STUN_ATTRIBUTE_CHANGE_REQUEST, avalue, 4);
  ------------------
  |  |   97|  1.11k|#define STUN_ATTRIBUTE_CHANGE_REQUEST (0x0003)
  ------------------
 2252|  1.11k|}
stun_attr_get_response_port_str:
 2254|     34|int stun_attr_get_response_port_str(stun_attr_ref attr) {
 2255|     34|  if (stun_attr_get_len(attr) >= 2) {
  ------------------
  |  Branch (2255:7): [True: 19, False: 15]
  ------------------
 2256|     19|    const uint8_t *value = stun_attr_get_value(attr);
 2257|     19|    if (value) {
  ------------------
  |  Branch (2257:9): [True: 19, False: 0]
  ------------------
 2258|     19|      return turn_read_u16(value);
 2259|     19|    }
 2260|     19|  }
 2261|     15|  return -1;
 2262|     34|}
stun_attr_add_response_port_str:
 2264|  1.11k|bool stun_attr_add_response_port_str(uint8_t *buf, size_t *len, uint16_t port) {
 2265|  1.11k|  uint8_t avalue[4] = {0, 0, 0, 0};
 2266|  1.11k|  turn_write_u16(avalue, port);
 2267|       |
 2268|  1.11k|  return stun_attr_add_str(buf, len, STUN_ATTRIBUTE_RESPONSE_PORT, avalue, 4);
  ------------------
  |  |  135|  1.11k|#define STUN_ATTRIBUTE_RESPONSE_PORT (0x0027)
  ------------------
 2269|  1.11k|}
stun_attr_get_padding_len_str:
 2271|     28|int stun_attr_get_padding_len_str(stun_attr_ref attr) {
 2272|     28|  const int len = stun_attr_get_len(attr);
 2273|     28|  if (len < 0) {
  ------------------
  |  Branch (2273:7): [True: 0, False: 28]
  ------------------
 2274|      0|    return -1;
 2275|      0|  }
 2276|     28|  return (uint16_t)len;
 2277|     28|}
stun_attr_add_padding_str:
 2279|  1.11k|bool stun_attr_add_padding_str(uint8_t *buf, size_t *len, uint16_t padding_len) {
 2280|       |  /* PADDING is all zeroes, so the scratch value is heap-allocated rather than a
 2281|       |   * 64 KB stack array: this runs on relay threads for RFC 5780 responses. */
 2282|  1.11k|  uint8_t *avalue = (uint8_t *)turn_calloc(1, padding_len);
  ------------------
  |  |  120|  1.11k|#define turn_calloc(number, size) turn_calloc_impl((number), (size), __FILE__, __LINE__)
  ------------------
 2283|       |
 2284|  1.11k|  const bool ret = stun_attr_add_str(buf, len, STUN_ATTRIBUTE_PADDING, avalue, padding_len);
  ------------------
  |  |  134|  1.11k|#define STUN_ATTRIBUTE_PADDING (0x0026)
  ------------------
 2285|       |
 2286|  1.11k|  free(avalue);
 2287|       |
 2288|  1.11k|  return ret;
 2289|  1.11k|}
ns_turn_msg.c:fuzz_prng_next:
  112|  58.3k|static uint64_t fuzz_prng_next(void) {
  113|  58.3k|  static uint64_t state = UINT64_C(0x9e3779b97f4a7c15);
  114|       |
  115|  58.3k|  state += UINT64_C(0x9e3779b97f4a7c15);
  116|  58.3k|  uint64_t z = state;
  117|  58.3k|  z = (z ^ (z >> 30)) * UINT64_C(0xbf58476d1ce4e5b9);
  118|       |  z = (z ^ (z >> 27)) * UINT64_C(0x94d049bb133111eb);
  119|  58.3k|  return z ^ (z >> 31);
  120|  58.3k|}
ns_turn_msg.c:stun_init_error_response_common_str:
  898|  10.6k|                                                stun_tid *id, bool include_reason_string, bool pad_reason_phrase) {
  899|       |
  900|  10.6k|  if (include_reason_string && (!reason || !strcmp((const char *)reason, "Unknown error"))) {
  ------------------
  |  Branch (900:7): [True: 10.6k, False: 0]
  |  Branch (900:33): [True: 0, False: 10.6k]
  |  Branch (900:44): [True: 0, False: 10.6k]
  ------------------
  901|      0|    reason = get_default_reason(error_code);
  902|      0|  }
  903|       |
  904|  10.6k|  uint8_t avalue[513];
  905|  10.6k|  memset(avalue, 0, sizeof(avalue));
  906|  10.6k|  avalue[0] = 0;
  907|  10.6k|  avalue[1] = 0;
  908|  10.6k|  avalue[2] = (uint8_t)(error_code / 100);
  909|  10.6k|  avalue[3] = (uint8_t)(error_code % 100);
  910|  10.6k|  if (include_reason_string) {
  ------------------
  |  Branch (910:7): [True: 10.6k, False: 0]
  ------------------
  911|  10.6k|    strncpy((char *)(avalue + 4), (const char *)reason, sizeof(avalue) - 4);
  912|  10.6k|  }
  913|  10.6k|  avalue[sizeof(avalue) - 1] = 0;
  914|  10.6k|  int alen = 4 + (int)strlen((const char *)(avalue + 4));
  915|       |
  916|       |  /* RFC 3489 Section 11.2.9 requires a reason phrase length that is a multiple of 4;
  917|       |   * RFC 8489 Section 14 requires the declared length to exclude padding. */
  918|  10.6k|  if (pad_reason_phrase) {
  ------------------
  |  Branch (918:7): [True: 0, False: 10.6k]
  ------------------
  919|      0|    const int rem = alen % 4;
  920|      0|    if (rem) {
  ------------------
  |  Branch (920:9): [True: 0, False: 0]
  ------------------
  921|      0|      alen += (4 - rem);
  922|      0|    }
  923|      0|  }
  924|       |
  925|  10.6k|  stun_attr_add_str(buf, len, STUN_ATTRIBUTE_ERROR_CODE, (uint8_t *)avalue, alen);
  ------------------
  |  |  103|  10.6k|#define STUN_ATTRIBUTE_ERROR_CODE (0x0009)
  ------------------
  926|  10.6k|  if (id) {
  ------------------
  |  Branch (926:7): [True: 10.6k, False: 0]
  ------------------
  927|  10.6k|    stun_tid_message_cpy(buf, id);
  928|  10.6k|  }
  929|  10.6k|}
ns_turn_msg.c:stun_tid_from_string:
 1460|  14.4k|static void stun_tid_from_string(const uint8_t *s, stun_tid *id) {
 1461|  14.4k|  if (s && id) {
  ------------------
  |  Branch (1461:7): [True: 14.4k, False: 0]
  |  Branch (1461:12): [True: 14.4k, False: 0]
  ------------------
 1462|  14.4k|    memcpy(id->tsx_id, s, STUN_TID_SIZE);
  ------------------
  |  |   53|  14.4k|#define STUN_TID_SIZE (12)
  ------------------
 1463|  14.4k|  }
 1464|  14.4k|}
ns_turn_msg.c:stun_tid_string_cpy:
 1454|  30.0k|static void stun_tid_string_cpy(uint8_t *s, const stun_tid *id) {
 1455|  30.0k|  if (s && id) {
  ------------------
  |  Branch (1455:7): [True: 30.0k, False: 0]
  |  Branch (1455:12): [True: 30.0k, False: 0]
  ------------------
 1456|  30.0k|    memcpy(s, id->tsx_id, STUN_TID_SIZE);
  ------------------
  |  |   53|  30.0k|#define STUN_TID_SIZE (12)
  ------------------
 1457|  30.0k|  }
 1458|  30.0k|}
ns_turn_msg.c:turn_random_tid_size:
  154|  19.4k|static void turn_random_tid_size(void *id) {
  155|  19.4k|  uint8_t *ar = (uint8_t *)id;
  156|  19.4k|#if defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
  157|  19.4k|  if (ar) {
  ------------------
  |  Branch (157:7): [True: 19.4k, False: 0]
  ------------------
  158|  77.7k|    for (size_t i = 0; i < 3; ++i) {
  ------------------
  |  Branch (158:24): [True: 58.3k, False: 19.4k]
  ------------------
  159|  58.3k|      const uint32_t r = (uint32_t)turn_random_number();
  160|  58.3k|      memcpy(ar + i * sizeof(r), &r, sizeof(r));
  161|  58.3k|    }
  162|  19.4k|  }
  163|       |#else
  164|       |  if (!RAND_bytes((unsigned char *)ar, 12)) {
  165|       |    for (size_t i = 0; i < 3; ++i) {
  166|       |      const uint32_t r = (uint32_t)turn_random_number();
  167|       |      memcpy(ar + i * sizeof(r), &r, sizeof(r));
  168|       |    }
  169|       |  }
  170|       |#endif
  171|  19.4k|}
ns_turn_msg.c:stun_attr_check_valid:
 1658|  1.33M|static stun_attr_ref stun_attr_check_valid(stun_attr_ref attr, size_t remaining) {
 1659|  1.33M|  if (remaining >= 4) {
  ------------------
  |  Branch (1659:7): [True: 1.33M, False: 100]
  ------------------
 1660|       |    /* Read the size of the attribute */
 1661|  1.33M|    size_t attrlen = stun_attr_get_len(attr);
 1662|  1.33M|    remaining -= 4;
 1663|       |
 1664|       |    /* Round to boundary */
 1665|  1.33M|    const uint16_t rem4 = ((uint16_t)attrlen) & 0x0003;
 1666|  1.33M|    if (rem4) {
  ------------------
  |  Branch (1666:9): [True: 277k, False: 1.05M]
  ------------------
 1667|   277k|      attrlen = attrlen + 4 - (int)rem4;
 1668|   277k|    }
 1669|       |
 1670|       |    /* Check that there's enough space remaining */
 1671|  1.33M|    if (attrlen <= remaining) {
  ------------------
  |  Branch (1671:9): [True: 1.31M, False: 23.5k]
  ------------------
 1672|  1.31M|      return attr;
 1673|  1.31M|    }
 1674|  1.33M|  }
 1675|       |
 1676|  23.6k|  return NULL;
 1677|  1.33M|}
ns_turn_msg.c:stun_set_command_message_len_str:
  547|  75.7k|static bool stun_set_command_message_len_str(uint8_t *buf, int len) {
  548|  75.7k|  if (len < STUN_HEADER_LENGTH) {
  ------------------
  |  |   46|  75.7k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (548:7): [True: 0, False: 75.7k]
  ------------------
  549|      0|    return false;
  550|      0|  }
  551|  75.7k|  turn_write_u16(buf + 2, (uint16_t)(len - STUN_HEADER_LENGTH));
  ------------------
  |  |   46|  75.7k|#define STUN_HEADER_LENGTH (20)
  ------------------
  552|       |  return true;
  553|  75.7k|}
ns_turn_msg.c:ns_crc32:
 1938|  1.47k|static uint32_t ns_crc32(const uint8_t *buffer, uint32_t len) {
 1939|  1.47k|  uint32_t crc = CRC_MASK;
  ------------------
  |  | 1902|  1.47k|#define CRC_MASK 0xFFFFFFFFUL
  ------------------
 1940|  1.01M|  while (len--) {
  ------------------
  |  Branch (1940:10): [True: 1.01M, False: 1.47k]
  ------------------
 1941|  1.01M|    UPDATE_CRC(crc, *buffer++);
  ------------------
  |  | 1904|  1.01M|#define UPDATE_CRC(crc, c) crc = crctable[(uint8_t)crc ^ (uint8_t)(c)] ^ (crc >> 8)
  ------------------
 1942|  1.01M|  }
 1943|  1.47k|  return (~crc);
 1944|  1.47k|}

stun_addr_encode:
   42|  6.70k|int stun_addr_encode(const ioa_addr *ca, uint8_t *cfield, int *clen, int xor_ed, uint32_t mc, const uint8_t *tsx_id) {
   43|       |
   44|  6.70k|  if (!cfield || !clen || !ca || !tsx_id) {
  ------------------
  |  Branch (44:7): [True: 0, False: 6.70k]
  |  Branch (44:18): [True: 0, False: 6.70k]
  |  Branch (44:27): [True: 0, False: 6.70k]
  |  Branch (44:34): [True: 0, False: 6.70k]
  ------------------
   45|      0|    return -1;
   46|      0|  }
   47|       |
   48|  6.70k|  if (ca->ss.sa_family == AF_INET || ca->ss.sa_family == 0) {
  ------------------
  |  Branch (48:7): [True: 4.47k, False: 2.23k]
  |  Branch (48:38): [True: 0, False: 2.23k]
  ------------------
   49|       |
   50|       |    /* IPv4 address */
   51|       |
   52|  4.47k|    *clen = 8;
   53|       |
   54|  4.47k|    cfield[0] = 0;
   55|  4.47k|    cfield[1] = 1; // IPv4 family
   56|       |
   57|  4.47k|    if (xor_ed) {
  ------------------
  |  Branch (57:9): [True: 3.35k, False: 1.11k]
  ------------------
   58|       |
   59|       |      /* Port */
   60|  3.35k|      const uint16_t port = (ca->s4.sin_port) ^ nswap16(mc >> 16);
  ------------------
  |  |   86|  3.35k|#define nswap16(s) ntohs(s)
  ------------------
   61|  3.35k|      memcpy(cfield + 2, &port, sizeof(port));
   62|       |
   63|       |      /* Address */
   64|  3.35k|      const uint32_t addr = (ca->s4.sin_addr.s_addr) ^ nswap32(mc);
  ------------------
  |  |   87|  3.35k|#define nswap32(ul) ntohl(ul)
  ------------------
   65|  3.35k|      memcpy(cfield + 4, &addr, sizeof(addr));
   66|       |
   67|  3.35k|    } else {
   68|       |
   69|       |      /* Port */
   70|  1.11k|      const uint16_t port = ca->s4.sin_port;
   71|  1.11k|      memcpy(cfield + 2, &port, sizeof(port));
   72|       |
   73|       |      /* Address */
   74|  1.11k|      const uint32_t addr = ca->s4.sin_addr.s_addr;
   75|  1.11k|      memcpy(cfield + 4, &addr, sizeof(addr));
   76|  1.11k|    }
   77|       |
   78|  4.47k|  } else if (ca->ss.sa_family == AF_INET6) {
  ------------------
  |  Branch (78:14): [True: 2.23k, False: 0]
  ------------------
   79|       |
   80|       |    /* IPv6 address */
   81|       |
   82|  2.23k|    *clen = 20;
   83|       |
   84|  2.23k|    cfield[0] = 0;
   85|  2.23k|    cfield[1] = 2; // IPv6 family
   86|       |
   87|  2.23k|    if (xor_ed) {
  ------------------
  |  Branch (87:9): [True: 2.23k, False: 0]
  ------------------
   88|       |
   89|  2.23k|      unsigned int i;
   90|  2.23k|      uint8_t *dst = ((uint8_t *)cfield) + 4;
   91|  2.23k|      const uint8_t *src = (const uint8_t *)&(ca->s6.sin6_addr);
   92|  2.23k|      uint32_t magic = nswap32(mc);
  ------------------
  |  |   87|  2.23k|#define nswap32(ul) ntohl(ul)
  ------------------
   93|       |
   94|       |      /* Port */
   95|  2.23k|      const uint16_t port = ca->s6.sin6_port ^ nswap16(mc >> 16);
  ------------------
  |  |   86|  2.23k|#define nswap16(s) ntohs(s)
  ------------------
   96|  2.23k|      memcpy(cfield + 2, &port, sizeof(port));
   97|       |
   98|       |      /* Address */
   99|       |
  100|  11.1k|      for (i = 0; i < 4; ++i) {
  ------------------
  |  Branch (100:19): [True: 8.94k, False: 2.23k]
  ------------------
  101|  8.94k|        dst[i] = (uint8_t)(src[i] ^ ((const uint8_t *)&magic)[i]);
  102|  8.94k|      }
  103|  29.0k|      for (i = 0; i < 12; ++i) {
  ------------------
  |  Branch (103:19): [True: 26.8k, False: 2.23k]
  ------------------
  104|  26.8k|        dst[i + 4] = (uint8_t)(src[i + 4] ^ tsx_id[i]);
  105|  26.8k|      }
  106|       |
  107|  2.23k|    } else {
  108|       |
  109|       |      /* Port */
  110|      0|      const uint16_t port = ca->s6.sin6_port;
  111|      0|      memcpy(cfield + 2, &port, sizeof(port));
  112|       |
  113|       |      /* Address */
  114|      0|      memcpy(((uint8_t *)cfield) + 4, &ca->s6.sin6_addr, 16);
  115|      0|    }
  116|       |
  117|  2.23k|  } else {
  118|      0|    return -1;
  119|      0|  }
  120|       |
  121|  6.70k|  return 0;
  122|  6.70k|}
stun_addr_decode:
  124|  3.29k|int stun_addr_decode(ioa_addr *ca, const uint8_t *cfield, int len, int xor_ed, uint32_t mc, const uint8_t *tsx_id) {
  125|       |
  126|  3.29k|  if (!cfield || !len || !ca || !tsx_id || (len < 8)) {
  ------------------
  |  Branch (126:7): [True: 0, False: 3.29k]
  |  Branch (126:18): [True: 0, False: 3.29k]
  |  Branch (126:26): [True: 0, False: 3.29k]
  |  Branch (126:33): [True: 0, False: 3.29k]
  |  Branch (126:44): [True: 784, False: 2.51k]
  ------------------
  127|    784|    return -1;
  128|    784|  }
  129|       |
  130|  2.51k|  if (cfield[0] != 0) {
  ------------------
  |  Branch (130:7): [True: 572, False: 1.94k]
  ------------------
  131|    572|    return -1;
  132|    572|  }
  133|       |
  134|  1.94k|  int sa_family;
  135|       |
  136|  1.94k|  if (cfield[1] == 1) {
  ------------------
  |  Branch (136:7): [True: 1.02k, False: 922]
  ------------------
  137|  1.02k|    sa_family = AF_INET;
  138|  1.02k|  } else if (cfield[1] == 2) {
  ------------------
  |  Branch (138:14): [True: 597, False: 325]
  ------------------
  139|    597|    sa_family = AF_INET6;
  140|    597|  } else {
  141|    325|    return -1;
  142|    325|  }
  143|       |
  144|  1.61k|  ca->ss.sa_family = sa_family;
  145|       |
  146|  1.61k|  if (sa_family == AF_INET) {
  ------------------
  |  Branch (146:7): [True: 1.02k, False: 597]
  ------------------
  147|       |
  148|  1.02k|    if (len != 8) {
  ------------------
  |  Branch (148:9): [True: 309, False: 711]
  ------------------
  149|    309|      return -1;
  150|    309|    }
  151|       |
  152|       |    /* IPv4 address */
  153|       |
  154|       |    /* Port */
  155|    711|    memcpy(&ca->s4.sin_port, cfield + 2, sizeof(ca->s4.sin_port));
  156|       |
  157|       |    /* Address */
  158|    711|    memcpy(&ca->s4.sin_addr.s_addr, cfield + 4, sizeof(ca->s4.sin_addr.s_addr));
  159|       |
  160|    711|    if (xor_ed) {
  ------------------
  |  Branch (160:9): [True: 248, False: 463]
  ------------------
  161|    248|      ca->s4.sin_port ^= nswap16(mc >> 16);
  ------------------
  |  |   86|    248|#define nswap16(s) ntohs(s)
  ------------------
  162|    248|      ca->s4.sin_addr.s_addr ^= nswap32(mc);
  ------------------
  |  |   87|    248|#define nswap32(ul) ntohl(ul)
  ------------------
  163|    248|    }
  164|       |
  165|    711|  } else if (sa_family == AF_INET6) {
  ------------------
  |  Branch (165:14): [True: 597, False: 0]
  ------------------
  166|       |
  167|       |    /* IPv6 address */
  168|       |
  169|    597|    if (len != 20) {
  ------------------
  |  Branch (169:9): [True: 331, False: 266]
  ------------------
  170|    331|      return -1;
  171|    331|    }
  172|       |
  173|       |    /* Port */
  174|    266|    memcpy(&ca->s6.sin6_port, cfield + 2, sizeof(ca->s6.sin6_port));
  175|       |
  176|       |    /* Address */
  177|    266|    memcpy(&ca->s6.sin6_addr, ((const uint8_t *)cfield) + 4, 16);
  178|       |
  179|    266|    if (xor_ed) {
  ------------------
  |  Branch (179:9): [True: 210, False: 56]
  ------------------
  180|       |
  181|    210|      unsigned int i;
  182|    210|      uint8_t *dst;
  183|    210|      const uint8_t *src;
  184|    210|      uint32_t magic = nswap32(mc);
  ------------------
  |  |   87|    210|#define nswap32(ul) ntohl(ul)
  ------------------
  185|       |
  186|       |      /* Port */
  187|    210|      ca->s6.sin6_port ^= nswap16(mc >> 16);
  ------------------
  |  |   86|    210|#define nswap16(s) ntohs(s)
  ------------------
  188|       |
  189|       |      /* Address */
  190|    210|      src = ((const uint8_t *)cfield) + 4;
  191|    210|      dst = (uint8_t *)&ca->s6.sin6_addr;
  192|  1.05k|      for (i = 0; i < 4; ++i) {
  ------------------
  |  Branch (192:19): [True: 840, False: 210]
  ------------------
  193|    840|        dst[i] = (uint8_t)(src[i] ^ ((const uint8_t *)&magic)[i]);
  194|    840|      }
  195|  2.73k|      for (i = 0; i < 12; ++i) {
  ------------------
  |  Branch (195:19): [True: 2.52k, False: 210]
  ------------------
  196|  2.52k|        dst[i + 4] = (uint8_t)(src[i + 4] ^ tsx_id[i]);
  197|  2.52k|      }
  198|    210|    }
  199|       |
  200|    266|  } else {
  201|      0|    return -1;
  202|      0|  }
  203|       |
  204|    977|  return 0;
  205|  1.61k|}

ns_turn_msg.c:turn_read_u16:
  127|  5.76M|static inline uint16_t turn_read_u16(const void *field) {
  128|  5.76M|  uint16_t v;
  129|  5.76M|  memcpy(&v, field, sizeof(v));
  130|       |  return nswap16(v);
  ------------------
  |  |   86|  5.76M|#define nswap16(s) ntohs(s)
  ------------------
  131|  5.76M|}
ns_turn_msg.c:turn_read_u32:
  133|  14.8k|static inline uint32_t turn_read_u32(const void *field) {
  134|  14.8k|  uint32_t v;
  135|  14.8k|  memcpy(&v, field, sizeof(v));
  136|       |  return nswap32(v);
  ------------------
  |  |   87|  14.8k|#define nswap32(ul) ntohl(ul)
  ------------------
  137|  14.8k|}
ns_turn_msg.c:turn_write_u16:
  145|   265k|static inline void turn_write_u16(void *field, uint16_t v) {
  146|       |  const uint16_t raw = nswap16(v);
  ------------------
  |  |   86|   265k|#define nswap16(s) ntohs(s)
  ------------------
  147|   265k|  memcpy(field, &raw, sizeof(raw));
  148|   265k|}
ns_turn_msg.c:turn_write_u32:
  150|  20.5k|static inline void turn_write_u32(void *field, uint32_t v) {
  151|       |  const uint32_t raw = nswap32(v);
  ------------------
  |  |   87|  20.5k|#define nswap32(ul) ntohl(ul)
  ------------------
  152|  20.5k|  memcpy(field, &raw, sizeof(raw));
  153|  20.5k|}
ns_turn_msg.c:_ioa_ntoh64:
   90|      4|static inline uint64_t _ioa_ntoh64(uint64_t v) {
   91|      4|#if BYTE_ORDER == LITTLE_ENDIAN
   92|      4|  uint8_t *src = (uint8_t *)&v;
   93|      4|  uint8_t *dst = src + 7;
   94|     20|  while (src < dst) {
  ------------------
  |  Branch (94:10): [True: 16, False: 4]
  ------------------
   95|     16|    uint8_t vdst = *dst;
   96|     16|    *(dst--) = *src;
   97|     16|    *(src++) = vdst;
   98|     16|  }
   99|       |#elif BYTE_ORDER == BIG_ENDIAN
  100|       |  /* OK */
  101|       |#else
  102|       |#error WRONG BYTE_ORDER SETTING
  103|       |#endif
  104|      4|  return v;
  105|      4|}
ns_turn_msg.c:turn_read_u64:
  139|      4|static inline uint64_t turn_read_u64(const void *field) {
  140|      4|  uint64_t v;
  141|      4|  memcpy(&v, field, sizeof(v));
  142|      4|  return nswap64(v);
  ------------------
  |  |   88|      4|#define nswap64(ull) ioa_ntoh64(ull)
  |  |  ------------------
  |  |  |  |  115|      4|#define ioa_ntoh64 _ioa_ntoh64
  |  |  ------------------
  ------------------
  143|      4|}

