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.72k|extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
  599|  1.72k|  harness_integrity_sha1(Data, Size);
  600|  1.72k|  harness_integrity_multi(Data, Size);
  601|  1.72k|  harness_attr_iter(Data, Size);
  602|  1.72k|  harness_attr_add(Data, Size);
  603|  1.72k|  harness_old_stun(Data, Size);
  604|  1.72k|  harness_challenge_response_builder(Data, Size);
  605|  1.72k|  harness_full_addr_parser(Data, Size);
  606|  1.72k|  harness_integrity_attr_add(Data, Size);
  607|  1.72k|  return 0;
  608|  1.72k|}
FuzzStun.c:harness_integrity_sha1:
   49|  1.72k|static void harness_integrity_sha1(const uint8_t *Data, size_t Size) {
   50|  1.72k|  if (Size < 10 || Size > 5120) {
  ------------------
  |  Branch (50:7): [True: 69, False: 1.65k]
  |  Branch (50:20): [True: 87, False: 1.57k]
  ------------------
   51|    156|    return;
   52|    156|  }
   53|       |
   54|  1.57k|  stun_is_command_message_full_check_str((uint8_t *)Data, Size, true, NULL);
   55|       |
   56|  1.57k|  uint8_t uname[STUN_MAX_USERNAME_SIZE + 1] = "fuzzuser";
   57|  1.57k|  uint8_t realm[STUN_MAX_REALM_SIZE + 1] = "fuzz.realm";
   58|  1.57k|  uint8_t upwd[STUN_MAX_PWD_SIZE + 1] = "VOkJxbRl1RmTxUk/WvJxBt";
   59|       |
   60|  1.57k|  stun_check_message_integrity_str(TURN_CREDENTIALS_SHORT_TERM, (uint8_t *)Data, Size, uname, realm, upwd,
   61|  1.57k|                                   SHATYPE_SHA1);
   62|  1.57k|  stun_check_message_integrity_str(TURN_CREDENTIALS_LONG_TERM, (uint8_t *)Data, Size, uname, realm, upwd,
   63|  1.57k|                                   SHATYPE_SHA256);
   64|  1.57k|}
FuzzStun.c:harness_integrity_multi:
   69|  1.72k|static void harness_integrity_multi(const uint8_t *Data, size_t Size) {
   70|  1.72k|  if (Size < STUN_HEADER_LENGTH || Size > 5120) {
  ------------------
  |  |   46|  3.45k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (70:7): [True: 80, False: 1.64k]
  |  Branch (70:36): [True: 87, False: 1.56k]
  ------------------
   71|    167|    return;
   72|    167|  }
   73|       |
   74|  1.56k|  uint8_t buf[5120];
   75|  1.56k|  uint8_t uname[STUN_MAX_USERNAME_SIZE + 1] = "fuzzuser";
   76|  1.56k|  uint8_t realm[STUN_MAX_REALM_SIZE + 1] = "fuzz.realm";
   77|  1.56k|  uint8_t upwd[STUN_MAX_PWD_SIZE + 1] = "VOkJxbRl1RmTxUk/WvJxBt";
   78|       |
   79|  1.56k|  static const SHATYPE sha_types[] = {SHATYPE_SHA1, SHATYPE_SHA256, SHATYPE_SHA384, SHATYPE_SHA512};
   80|  1.56k|  const size_t num_sha = sizeof(sha_types) / sizeof(sha_types[0]);
   81|       |
   82|  7.80k|  for (size_t s = 0; s < num_sha; s++) {
  ------------------
  |  Branch (82:22): [True: 6.24k, False: 1.56k]
  ------------------
   83|  6.24k|    memcpy(buf, Data, Size);
   84|  6.24k|    stun_is_command_message_full_check_str(buf, Size, true, NULL);
   85|  6.24k|    stun_check_message_integrity_str(TURN_CREDENTIALS_SHORT_TERM, buf, Size, uname, realm, upwd, sha_types[s]);
   86|       |
   87|  6.24k|    memcpy(buf, Data, Size);
   88|  6.24k|    stun_check_message_integrity_str(TURN_CREDENTIALS_LONG_TERM, buf, Size, uname, realm, upwd, sha_types[s]);
   89|  6.24k|  }
   90|  1.56k|}
FuzzStun.c:harness_attr_iter:
  148|  1.72k|static void harness_attr_iter(const uint8_t *Data, size_t Size) {
  149|  1.72k|  if (Size < STUN_HEADER_LENGTH || Size > 8192) {
  ------------------
  |  |   46|  3.45k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (149:7): [True: 80, False: 1.64k]
  |  Branch (149:36): [True: 72, False: 1.57k]
  ------------------
  150|    152|    return;
  151|    152|  }
  152|       |
  153|  1.57k|  uint8_t buf[8192];
  154|  1.57k|  memcpy(buf, Data, Size);
  155|       |
  156|  1.57k|  if (!stun_is_command_message_str(buf, Size)) {
  ------------------
  |  Branch (156:7): [True: 444, False: 1.13k]
  ------------------
  157|    444|    return;
  158|    444|  }
  159|       |
  160|  1.13k|  stun_attr_ref sar = stun_attr_get_first_str(buf, Size);
  161|  22.7k|  while (sar) {
  ------------------
  |  Branch (161:10): [True: 21.6k, False: 1.13k]
  ------------------
  162|  21.6k|    (void)stun_attr_get_type(sar);
  163|  21.6k|    (void)stun_attr_get_len(sar);
  164|  21.6k|    (void)stun_attr_get_value(sar);
  165|  21.6k|    (void)stun_attr_is_addr(sar);
  166|  21.6k|    sar = stun_attr_get_next_str(buf, Size, sar);
  167|  21.6k|  }
  168|       |
  169|  1.13k|  ioa_addr addr;
  170|  1.13k|  const size_t num_addr_attrs = sizeof(kAddrAttrs) / sizeof(kAddrAttrs[0]);
  171|  10.1k|  for (size_t i = 0; i < num_addr_attrs; i++) {
  ------------------
  |  Branch (171:22): [True: 9.04k, False: 1.13k]
  ------------------
  172|  9.04k|    sar = stun_attr_get_first_by_type_str(buf, Size, kAddrAttrs[i]);
  173|  9.04k|    if (sar) {
  ------------------
  |  Branch (173:9): [True: 1.29k, False: 7.75k]
  ------------------
  174|  1.29k|      memset(&addr, 0, sizeof(addr));
  175|  1.29k|      stun_attr_get_addr_str(buf, Size, sar, &addr, NULL);
  176|  1.29k|    }
  177|  9.04k|    memset(&addr, 0, sizeof(addr));
  178|  9.04k|    stun_attr_get_first_addr_str(buf, Size, kAddrAttrs[i], &addr, NULL);
  179|  9.04k|  }
  180|       |
  181|  1.13k|  sar = stun_attr_get_first_by_type_str(buf, Size, STUN_ATTRIBUTE_CHANNEL_NUMBER);
  ------------------
  |  |  113|  1.13k|#define STUN_ATTRIBUTE_CHANNEL_NUMBER (0x000C)
  ------------------
  182|  1.13k|  if (sar) {
  ------------------
  |  Branch (182:7): [True: 219, False: 912]
  ------------------
  183|    219|    (void)stun_attr_get_channel_number(sar);
  184|    219|  }
  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);
  ------------------
  |  |  104|  1.13k|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY (0x0017)
  ------------------
  188|  1.13k|  if (sar) {
  ------------------
  |  Branch (188:7): [True: 17, False: 1.11k]
  ------------------
  189|     17|    (void)stun_get_requested_address_family(sar);
  190|     17|  }
  191|       |
  192|  1.13k|  sar = stun_attr_get_first_by_type_str(buf, Size, STUN_ATTRIBUTE_ADDITIONAL_ADDRESS_FAMILY);
  ------------------
  |  |  140|  1.13k|#define STUN_ATTRIBUTE_ADDITIONAL_ADDRESS_FAMILY (0x8000)
  ------------------
  193|  1.13k|  if (sar) {
  ------------------
  |  Branch (193:7): [True: 91, False: 1.04k]
  ------------------
  194|     91|    (void)stun_get_requested_address_family(sar);
  195|     91|  }
  196|       |
  197|  1.13k|  sar = stun_attr_get_first_by_type_str(buf, Size, STUN_ATTRIBUTE_EVEN_PORT);
  ------------------
  |  |  119|  1.13k|#define STUN_ATTRIBUTE_EVEN_PORT (0x0018)
  ------------------
  198|  1.13k|  if (sar) {
  ------------------
  |  Branch (198:7): [True: 26, False: 1.10k]
  ------------------
  199|     26|    (void)stun_attr_get_even_port(sar);
  200|     26|  }
  201|       |
  202|  1.13k|  sar = stun_attr_get_first_by_type_str(buf, Size, STUN_ATTRIBUTE_BANDWIDTH);
  ------------------
  |  |  115|  1.13k|#define STUN_ATTRIBUTE_BANDWIDTH (0x0010)
  ------------------
  203|  1.13k|  if (sar) {
  ------------------
  |  Branch (203:7): [True: 52, False: 1.07k]
  ------------------
  204|     52|    (void)stun_attr_get_bandwidth(sar);
  205|     52|  }
  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)
  |  |  ------------------
  |  |  |  |  115|  1.13k|#define STUN_ATTRIBUTE_BANDWIDTH (0x0010)
  |  |  ------------------
  ------------------
  208|  1.13k|  if (sar) {
  ------------------
  |  Branch (208:7): [True: 16, False: 1.11k]
  ------------------
  209|     16|    (void)stun_attr_get_bandwidth(sar);
  210|     16|  }
  211|       |
  212|  1.13k|  sar = stun_attr_get_first_by_type_str(buf, Size, STUN_ATTRIBUTE_RESERVATION_TOKEN);
  ------------------
  |  |  123|  1.13k|#define STUN_ATTRIBUTE_RESERVATION_TOKEN (0x0022)
  ------------------
  213|  1.13k|  if (sar) {
  ------------------
  |  Branch (213:7): [True: 33, False: 1.09k]
  ------------------
  214|     33|    (void)stun_attr_get_reservation_token_value(sar);
  215|     33|  }
  216|       |
  217|  1.13k|  sar = stun_attr_get_first_by_type_str(buf, Size, STUN_ATTRIBUTE_CHANGE_REQUEST);
  ------------------
  |  |   93|  1.13k|#define STUN_ATTRIBUTE_CHANGE_REQUEST (0x0003)
  ------------------
  218|  1.13k|  if (sar) {
  ------------------
  |  Branch (218:7): [True: 39, False: 1.09k]
  ------------------
  219|     39|    bool change_ip = false, change_port = false;
  220|     39|    stun_attr_get_change_request_str(sar, &change_ip, &change_port);
  221|     39|  }
  222|       |
  223|  1.13k|  sar = stun_attr_get_first_by_type_str(buf, Size, STUN_ATTRIBUTE_RESPONSE_PORT);
  ------------------
  |  |  131|  1.13k|#define STUN_ATTRIBUTE_RESPONSE_PORT (0x0027)
  ------------------
  224|  1.13k|  if (sar) {
  ------------------
  |  Branch (224:7): [True: 35, False: 1.09k]
  ------------------
  225|     35|    (void)stun_attr_get_response_port_str(sar);
  226|     35|  }
  227|       |
  228|  1.13k|  sar = stun_attr_get_first_by_type_str(buf, Size, STUN_ATTRIBUTE_PADDING);
  ------------------
  |  |  130|  1.13k|#define STUN_ATTRIBUTE_PADDING (0x0026)
  ------------------
  229|  1.13k|  if (sar) {
  ------------------
  |  Branch (229:7): [True: 35, False: 1.09k]
  ------------------
  230|     35|    (void)stun_attr_get_padding_len_str(sar);
  231|     35|  }
  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|  50.8k|  for (size_t i = 0; i < num_all_attrs; i++) {
  ------------------
  |  Branch (250:22): [True: 49.7k, False: 1.13k]
  ------------------
  251|  49.7k|    sar = stun_attr_get_first_by_type_str(buf, Size, kAllAttrTypes[i]);
  252|  49.7k|    if (sar) {
  ------------------
  |  Branch (252:9): [True: 2.63k, False: 47.1k]
  ------------------
  253|  2.63k|      (void)stun_attr_get_type(sar);
  254|  2.63k|      (void)stun_attr_get_len(sar);
  255|  2.63k|      (void)stun_attr_get_value(sar);
  256|  2.63k|    }
  257|  49.7k|  }
  258|  1.13k|}
FuzzStun.c:harness_attr_add:
  263|  1.72k|static void harness_attr_add(const uint8_t *Data, size_t Size) {
  264|  1.72k|  if (Size < STUN_HEADER_LENGTH || Size > 4096) {
  ------------------
  |  |   46|  3.45k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (264:7): [True: 80, False: 1.64k]
  |  Branch (264:36): [True: 123, False: 1.52k]
  ------------------
  265|    203|    return;
  266|    203|  }
  267|       |
  268|  1.52k|  uint8_t buf[MAX_STUN_MESSAGE_SIZE] = {0};
  269|  1.52k|  memcpy(buf, Data, Size);
  270|  1.52k|  size_t len = Size;
  271|       |
  272|  1.52k|  if (!stun_is_command_message_str(buf, len)) {
  ------------------
  |  Branch (272:7): [True: 410, False: 1.11k]
  ------------------
  273|    410|    return;
  274|    410|  }
  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));
  ------------------
  |  |   96|  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));
  ------------------
  |  |  102|  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));
  ------------------
  |  |  103|  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));
  ------------------
  |  |  108|  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);
  ------------------
  |  |  114|  1.11k|#define STUN_ATTRIBUTE_LIFETIME (0x000D)
  ------------------
  290|       |
  291|  1.11k|  uint8_t transport_val[4] = {STUN_ATTRIBUTE_TRANSPORT_UDP_VALUE, 0x00, 0x00, 0x00};
  ------------------
  |  |  172|  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);
  ------------------
  |  |  120|  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};
  ------------------
  |  |  164|  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);
  ------------------
  |  |  104|  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);
  ------------------
  |  |  119|  1.11k|#define STUN_ATTRIBUTE_EVEN_PORT (0x0018)
  ------------------
  299|       |
  300|  1.11k|  stun_attr_add_str(buf, &len, STUN_ATTRIBUTE_DONT_FRAGMENT, NULL, 0);
  ------------------
  |  |  121|  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);
  ------------------
  |  |  105|  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);
  ------------------
  |  |  116|  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);
  ------------------
  |  |  118|  1.11k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  313|  1.11k|  stun_attr_add_addr_str(buf, &len, STUN_ATTRIBUTE_MAPPED_ADDRESS, &addr4);
  ------------------
  |  |   91|  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);
  ------------------
  |  |  105|  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);
  ------------------
  |  |  118|  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);
  ------------------
  |  |  165|  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: 998, False: 116]
  ------------------
  329|    998|    int data_len = (int)(Size - STUN_HEADER_LENGTH);
  ------------------
  |  |   46|    998|#define STUN_HEADER_LENGTH (20)
  ------------------
  330|    998|    if (data_len > 1024) {
  ------------------
  |  Branch (330:9): [True: 119, False: 879]
  ------------------
  331|    119|      data_len = 1024;
  332|    119|    }
  333|    998|    stun_attr_add_str(buf, &len, STUN_ATTRIBUTE_DATA, Data + STUN_HEADER_LENGTH, data_len);
  ------------------
  |  |  117|    998|#define STUN_ATTRIBUTE_DATA (0x0013)
  ------------------
                  stun_attr_add_str(buf, &len, STUN_ATTRIBUTE_DATA, Data + STUN_HEADER_LENGTH, data_len);
  ------------------
  |  |   46|    998|#define STUN_HEADER_LENGTH (20)
  ------------------
  334|    998|  }
  335|       |
  336|  1.11k|  stun_attr_add_fingerprint_str(buf, &len);
  337|  1.11k|}
FuzzStun.c:harness_old_stun:
  342|  1.72k|static void harness_old_stun(const uint8_t *Data, size_t Size) {
  343|  1.72k|  if (Size < STUN_HEADER_LENGTH || Size > 5120) {
  ------------------
  |  |   46|  3.45k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (343:7): [True: 80, False: 1.64k]
  |  Branch (343:36): [True: 87, False: 1.56k]
  ------------------
  344|    167|    return;
  345|    167|  }
  346|       |
  347|  1.56k|  uint8_t buf[5120];
  348|  1.56k|  memcpy(buf, Data, Size);
  349|       |
  350|  1.56k|  uint32_t cookie = 0;
  351|  1.56k|  bool is_old = old_stun_is_command_message_str(buf, Size, &cookie);
  352|  1.56k|  (void)stun_is_command_message_str(buf, Size);
  353|       |
  354|  1.56k|  if (is_old) {
  ------------------
  |  Branch (354:7): [True: 163, False: 1.39k]
  ------------------
  355|    163|    (void)stun_get_msg_type_str(buf, Size);
  356|    163|    (void)stun_get_method_str(buf, Size);
  357|       |
  358|    163|    stun_is_request_str(buf, Size);
  359|    163|    stun_is_indication_str(buf, Size);
  360|    163|    stun_is_success_response_str(buf, Size);
  361|       |
  362|    163|    int err_code = 0;
  363|    163|    uint8_t err_msg[256] = {0};
  364|    163|    stun_is_error_response_str(buf, Size, &err_code, err_msg, sizeof(err_msg));
  365|       |
  366|    163|    bool fp_present = false;
  367|    163|    stun_is_command_message_full_check_str(buf, Size, true, &fp_present);
  368|    163|    stun_is_command_message_full_check_str(buf, Size, false, &fp_present);
  369|       |
  370|    163|    stun_is_binding_request_str(buf, Size, 0);
  371|    163|    stun_is_binding_response_str(buf, Size);
  372|       |
  373|    163|    stun_attr_ref sar = stun_attr_get_first_str(buf, Size);
  374|    583|    while (sar) {
  ------------------
  |  Branch (374:12): [True: 420, False: 163]
  ------------------
  375|    420|      (void)stun_attr_get_type(sar);
  376|    420|      (void)stun_attr_get_len(sar);
  377|    420|      sar = stun_attr_get_next_str(buf, Size, sar);
  378|    420|    }
  379|    163|  }
  380|  1.56k|}
FuzzStun.c:harness_challenge_response_builder:
  404|  1.72k|static void harness_challenge_response_builder(const uint8_t *Data, size_t Size) {
  405|  1.72k|  if (!Size) {
  ------------------
  |  Branch (405:7): [True: 0, False: 1.72k]
  ------------------
  406|      0|    return;
  407|      0|  }
  408|       |
  409|  1.72k|  static const uint16_t kMethods[] = {
  410|  1.72k|      STUN_METHOD_ALLOCATE,
  ------------------
  |  |   78|  1.72k|#define STUN_METHOD_ALLOCATE (0x0003)
  ------------------
  411|  1.72k|      STUN_METHOD_BINDING,
  ------------------
  |  |   77|  1.72k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
  412|  1.72k|      STUN_METHOD_REFRESH,
  ------------------
  |  |   79|  1.72k|#define STUN_METHOD_REFRESH (0x0004)
  ------------------
  413|  1.72k|      STUN_METHOD_CHANNEL_BIND,
  ------------------
  |  |   83|  1.72k|#define STUN_METHOD_CHANNEL_BIND (0x0009)
  ------------------
  414|  1.72k|  };
  415|  1.72k|  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.72k|  const size_t realm_len = 1 + (Size > 1 ? (Data[1] % 16) : 0);
  ------------------
  |  Branch (421:33): [True: 1.69k, False: 35]
  ------------------
  422|  1.72k|  const size_t nonce_len = 1 + (Size > 2 ? (Data[2] % 16) : 0);
  ------------------
  |  Branch (422:33): [True: 1.68k, False: 47]
  ------------------
  423|  1.72k|  const size_t server_len = 1 + (Size > 3 ? (Data[3] % 16) : 0);
  ------------------
  |  Branch (423:34): [True: 1.67k, False: 55]
  ------------------
  424|       |
  425|  1.72k|  uint8_t realm_buf[STUN_MAX_REALM_SIZE + 1] = {0};
  426|  1.72k|  uint8_t nonce_buf[STUN_MAX_NONCE_SIZE + 1] = {0};
  427|  1.72k|  uint8_t server_buf[STUN_MAX_SERVER_NAME_SIZE + 1] = {0};
  428|  12.3k|  for (size_t i = 0; i < realm_len; ++i) {
  ------------------
  |  Branch (428:22): [True: 10.6k, False: 1.72k]
  ------------------
  429|  10.6k|    realm_buf[i] = (uint8_t)('a' + (i % 26));
  430|  10.6k|  }
  431|  6.61k|  for (size_t i = 0; i < nonce_len; ++i) {
  ------------------
  |  Branch (431:22): [True: 4.88k, False: 1.72k]
  ------------------
  432|  4.88k|    nonce_buf[i] = (uint8_t)('0' + (i % 10));
  433|  4.88k|  }
  434|  13.1k|  for (size_t i = 0; i < server_len; ++i) {
  ------------------
  |  Branch (434:22): [True: 11.4k, False: 1.72k]
  ------------------
  435|  11.4k|    server_buf[i] = (uint8_t)('A' + (i % 26));
  436|  11.4k|  }
  437|       |
  438|  1.72k|  stun_tid tid = {0};
  439|  22.4k|  for (size_t i = 0; i < STUN_TID_SIZE; ++i) {
  ------------------
  |  |   53|  22.4k|#define STUN_TID_SIZE (12)
  ------------------
  |  Branch (439:22): [True: 20.7k, False: 1.72k]
  ------------------
  440|  20.7k|    tid.tsx_id[i] = (uint8_t)(Size > i + 4 ? Data[i + 4] : (uint8_t)i);
  ------------------
  |  Branch (440:31): [True: 19.8k, False: 840]
  ------------------
  441|  20.7k|  }
  442|       |
  443|       |  /* Each variant builds a fresh error response and runs it through the
  444|       |   * predicate so the inner attribute lookups fire. */
  445|  1.72k|  static const struct {
  446|  1.72k|    uint16_t err_code;
  447|  1.72k|    bool include_realm;
  448|  1.72k|    bool include_nonce;
  449|  1.72k|    bool include_third_party_auth;
  450|  1.72k|  } kVariants[] = {
  451|  1.72k|      {401, true, true, false},   /* canonical 401 challenge: REALM + NONCE */
  452|  1.72k|      {401, true, true, true},    /* same + THIRD-PARTY-AUTHORIZATION (OAuth branch) */
  453|  1.72k|      {438, true, true, false},   /* covers the (*err_code) == 438 disjunct */
  454|  1.72k|      {401, true, false, false},  /* REALM present, NONCE missing — negative inner path */
  455|  1.72k|      {401, false, false, false}, /* err_code matches but no REALM — outer negative path */
  456|  1.72k|      {400, true, true, false},   /* err_code does not match 401/438 — early-out path */
  457|  1.72k|  };
  458|       |
  459|  12.0k|  for (size_t v = 0; v < sizeof(kVariants) / sizeof(kVariants[0]); ++v) {
  ------------------
  |  Branch (459:22): [True: 10.3k, False: 1.72k]
  ------------------
  460|  10.3k|    uint8_t buf[MAX_STUN_MESSAGE_SIZE] = {0};
  461|  10.3k|    size_t len = 0;
  462|  10.3k|    stun_init_error_response_str(method, buf, &len, kVariants[v].err_code, (const uint8_t *)"unauthorized", &tid, true);
  463|       |
  464|  10.3k|    if (kVariants[v].include_realm) {
  ------------------
  |  Branch (464:9): [True: 8.63k, False: 1.72k]
  ------------------
  465|  8.63k|      stun_attr_add_str(buf, &len, STUN_ATTRIBUTE_REALM, realm_buf, (int)realm_len);
  ------------------
  |  |  102|  8.63k|#define STUN_ATTRIBUTE_REALM (0x0014)
  ------------------
  466|  8.63k|    }
  467|  10.3k|    if (kVariants[v].include_third_party_auth) {
  ------------------
  |  Branch (467:9): [True: 1.72k, False: 8.63k]
  ------------------
  468|  1.72k|      stun_attr_add_str(buf, &len, STUN_ATTRIBUTE_THIRD_PARTY_AUTHORIZATION, server_buf, (int)server_len);
  ------------------
  |  |  223|  1.72k|#define STUN_ATTRIBUTE_THIRD_PARTY_AUTHORIZATION (0x802E)
  ------------------
  469|  1.72k|    }
  470|  10.3k|    if (kVariants[v].include_nonce) {
  ------------------
  |  Branch (470:9): [True: 6.90k, False: 3.45k]
  ------------------
  471|  6.90k|      stun_attr_add_str(buf, &len, STUN_ATTRIBUTE_NONCE, nonce_buf, (int)nonce_len);
  ------------------
  |  |  103|  6.90k|#define STUN_ATTRIBUTE_NONCE (0x0015)
  ------------------
  472|  6.90k|    }
  473|       |
  474|  10.3k|    int err_code = 0;
  475|  10.3k|    uint8_t err_msg[1024] = {0};
  476|  10.3k|    uint8_t out_realm[STUN_MAX_REALM_SIZE + 1] = {0};
  477|  10.3k|    uint8_t out_nonce[STUN_MAX_NONCE_SIZE + 1] = {0};
  478|  10.3k|    uint8_t out_server[STUN_MAX_SERVER_NAME_SIZE + 1] = {0};
  479|  10.3k|    bool oauth = false;
  480|  10.3k|    (void)stun_is_challenge_response_str(buf, len, &err_code, err_msg, sizeof(err_msg), out_realm, out_nonce,
  481|  10.3k|                                         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.3k|    (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.3k|  }
  488|  1.72k|}
FuzzStun.c:harness_full_addr_parser:
  493|  1.72k|static void harness_full_addr_parser(const uint8_t *Data, size_t Size) {
  494|  1.72k|  ioa_addr addr;
  495|  1.72k|  const uint16_t default_port = fuzz_u16(Data, Size, 0);
  496|  1.72k|  const uint16_t explicit_port = fuzz_u16(Data, Size, 2);
  497|       |
  498|  1.72k|  char ipv4_plain[MAX_IOA_ADDR_STRING];
  499|  1.72k|  char ipv4_with_port[MAX_IOA_ADDR_STRING];
  500|  1.72k|  char ipv6_bracketed[MAX_IOA_ADDR_STRING];
  501|  1.72k|  char ipv6_with_port[MAX_IOA_ADDR_STRING];
  502|  1.72k|  char ipv4_spaced[MAX_IOA_ADDR_STRING];
  503|       |
  504|  1.72k|  snprintf(ipv4_plain, sizeof(ipv4_plain), "%u.%u.%u.%u", fuzz_byte(Data, Size, 4), fuzz_byte(Data, Size, 5),
  505|  1.72k|           fuzz_byte(Data, Size, 6), fuzz_byte(Data, Size, 7));
  506|  1.72k|  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.72k|           fuzz_byte(Data, Size, 10), fuzz_byte(Data, Size, 11), explicit_port);
  508|  1.72k|  snprintf(ipv6_bracketed, sizeof(ipv6_bracketed), "[2001:db8:%x:%x::%x]", fuzz_u16(Data, Size, 12),
  509|  1.72k|           fuzz_u16(Data, Size, 14), fuzz_u16(Data, Size, 16));
  510|  1.72k|  snprintf(ipv6_with_port, sizeof(ipv6_with_port), "[2001:db8:%x:%x::%x]:%u", fuzz_u16(Data, Size, 18),
  511|  1.72k|           fuzz_u16(Data, Size, 20), fuzz_u16(Data, Size, 22), explicit_port);
  512|  1.72k|  snprintf(ipv4_spaced, sizeof(ipv4_spaced), "  %u.%u.%u.%u:%u", fuzz_byte(Data, Size, 24), fuzz_byte(Data, Size, 25),
  513|  1.72k|           fuzz_byte(Data, Size, 26), fuzz_byte(Data, Size, 27), explicit_port);
  514|       |
  515|  1.72k|  static const char *kFixedInputs[] = {
  516|  1.72k|      "", "0.0.0.0", "127.0.0.1:3478", "192.0.2.1:", "[::1]", "[::1]:5349", "[2001:db8::1]  ", "::1",
  517|  1.72k|  };
  518|       |
  519|  15.5k|  for (size_t i = 0; i < sizeof(kFixedInputs) / sizeof(kFixedInputs[0]); ++i) {
  ------------------
  |  Branch (519:22): [True: 13.8k, False: 1.72k]
  ------------------
  520|  13.8k|    memset(&addr, 0, sizeof(addr));
  521|  13.8k|    (void)make_ioa_addr_from_full_string((const uint8_t *)kFixedInputs[i], default_port, &addr);
  522|  13.8k|  }
  523|       |
  524|  1.72k|  const char *generated[] = {ipv4_plain, ipv4_with_port, ipv6_bracketed, ipv6_with_port, ipv4_spaced};
  525|  10.3k|  for (size_t i = 0; i < sizeof(generated) / sizeof(generated[0]); ++i) {
  ------------------
  |  Branch (525:22): [True: 8.63k, False: 1.72k]
  ------------------
  526|  8.63k|    memset(&addr, 0, sizeof(addr));
  527|  8.63k|    (void)make_ioa_addr_from_full_string((const uint8_t *)generated[i], default_port, &addr);
  528|  8.63k|  }
  529|       |
  530|       |  (void)make_ioa_addr_from_full_string((const uint8_t *)ipv4_plain, default_port, NULL);
  531|  1.72k|}
FuzzStun.c:fuzz_u16:
   29|  13.8k|static uint16_t fuzz_u16(const uint8_t *Data, size_t Size, size_t idx) {
   30|  13.8k|  return (uint16_t)(((uint16_t)fuzz_byte(Data, Size, idx) << 8) | (uint16_t)fuzz_byte(Data, Size, idx + 1));
   31|  13.8k|}
FuzzStun.c:fuzz_byte:
   27|   578k|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: 578k, False: 0]
  ------------------
FuzzStun.c:harness_integrity_attr_add:
  536|  1.72k|static void harness_integrity_attr_add(const uint8_t *Data, size_t Size) {
  537|  1.72k|  static const SHATYPE kShaTypes[] = {SHATYPE_SHA1, SHATYPE_SHA256, SHATYPE_SHA384, SHATYPE_SHA512};
  538|  1.72k|  const SHATYPE shatype = kShaTypes[fuzz_byte(Data, Size, 0) % (sizeof(kShaTypes) / sizeof(kShaTypes[0]))];
  539|       |
  540|  1.72k|  uint8_t uname[STUN_MAX_USERNAME_SIZE + 1] = {0};
  541|  1.72k|  uint8_t realm[STUN_MAX_REALM_SIZE + 1] = {0};
  542|  1.72k|  uint8_t nonce[STUN_MAX_NONCE_SIZE + 1] = {0};
  543|  1.72k|  uint8_t upwd[STUN_MAX_PWD_SIZE + 1] = {0};
  544|  1.72k|  password_t pwd = {0};
  545|  1.72k|  hmackey_t key = {0};
  546|       |
  547|  1.72k|  fuzz_printable_string(Data, Size, 1, uname, sizeof(uname));
  548|  1.72k|  fuzz_printable_string(Data, Size, 1 + sizeof(uname), realm, sizeof(realm));
  549|  1.72k|  fuzz_printable_string(Data, Size, 1 + sizeof(uname) + sizeof(realm), nonce, sizeof(nonce));
  550|  1.72k|  fuzz_printable_string(Data, Size, 1 + sizeof(uname) + sizeof(realm) + sizeof(nonce), upwd, sizeof(upwd));
  551|  1.72k|  fuzz_printable_string(Data, Size, 1 + sizeof(uname) + sizeof(realm) + sizeof(nonce) + sizeof(upwd), pwd, sizeof(pwd));
  552|       |
  553|  1.72k|  if (!uname[0]) {
  ------------------
  |  Branch (553:7): [True: 229, False: 1.49k]
  ------------------
  554|    229|    memcpy(uname, "fuzzuser", sizeof("fuzzuser"));
  555|    229|  }
  556|  1.72k|  if (!realm[0]) {
  ------------------
  |  Branch (556:7): [True: 850, False: 877]
  ------------------
  557|    850|    memcpy(realm, "fuzz.realm", sizeof("fuzz.realm"));
  558|    850|  }
  559|  1.72k|  if (!nonce[0]) {
  ------------------
  |  Branch (559:7): [True: 933, False: 794]
  ------------------
  560|    933|    memcpy(nonce, "fuzznonce", sizeof("fuzznonce"));
  561|    933|  }
  562|  1.72k|  if (!upwd[0]) {
  ------------------
  |  Branch (562:7): [True: 1.03k, False: 693]
  ------------------
  563|  1.03k|    memcpy(upwd, "fuzzpassword", sizeof("fuzzpassword"));
  564|  1.03k|  }
  565|  1.72k|  if (!pwd[0]) {
  ------------------
  |  Branch (565:7): [True: 679, False: 1.04k]
  ------------------
  566|    679|    memcpy(pwd, "shortterm", sizeof("shortterm"));
  567|    679|  }
  568|       |
  569|   112k|  for (size_t i = 0; i < sizeof(key); ++i) {
  ------------------
  |  Branch (569:22): [True: 110k, False: 1.72k]
  ------------------
  570|   110k|    key[i] = fuzz_byte(Data, Size, 32 + i);
  571|   110k|  }
  572|       |
  573|  1.72k|  uint8_t buf[MAX_STUN_MESSAGE_SIZE];
  574|  1.72k|  size_t len = 0;
  575|  1.72k|  stun_init_request_str(STUN_METHOD_BINDING, buf, &len);
  ------------------
  |  |   77|  1.72k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
  576|  1.72k|  (void)stun_attr_add_integrity_by_key_str(buf, &len, uname, realm, key, nonce, shatype);
  577|       |
  578|  1.72k|  len = 0;
  579|  1.72k|  stun_init_request_str(STUN_METHOD_ALLOCATE, buf, &len);
  ------------------
  |  |   78|  1.72k|#define STUN_METHOD_ALLOCATE (0x0003)
  ------------------
  580|  1.72k|  (void)stun_attr_add_integrity_by_user_str(buf, &len, uname, realm, upwd, nonce, shatype);
  581|       |
  582|  1.72k|  len = 0;
  583|  1.72k|  stun_init_request_str(STUN_METHOD_REFRESH, buf, &len);
  ------------------
  |  |   79|  1.72k|#define STUN_METHOD_REFRESH (0x0004)
  ------------------
  584|  1.72k|  (void)stun_attr_add_integrity_by_user_short_term_str(buf, &len, uname, pwd, shatype);
  585|       |
  586|  1.72k|  len = 0;
  587|  1.72k|  stun_init_request_str(STUN_METHOD_CHANNEL_BIND, buf, &len);
  ------------------
  |  |   83|  1.72k|#define STUN_METHOD_CHANNEL_BIND (0x0009)
  ------------------
  588|  1.72k|  (void)stun_attr_add_integrity_str(TURN_CREDENTIALS_SHORT_TERM, buf, &len, key, pwd, shatype);
  589|       |
  590|  1.72k|  len = 0;
  591|  1.72k|  stun_init_request_str(STUN_METHOD_BINDING, buf, &len);
  ------------------
  |  |   77|  1.72k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
  592|  1.72k|  (void)stun_attr_add_integrity_str(TURN_CREDENTIALS_LONG_TERM, buf, &len, key, pwd, shatype);
  593|  1.72k|}
FuzzStun.c:fuzz_printable_string:
   33|  8.63k|static void fuzz_printable_string(const uint8_t *Data, size_t Size, size_t idx, uint8_t *out, size_t out_size) {
   34|  8.63k|  if (!out_size) {
  ------------------
  |  Branch (34:7): [True: 0, False: 8.63k]
  ------------------
   35|      0|    return;
   36|      0|  }
   37|       |
   38|  8.63k|  const size_t max_len = out_size - 1;
   39|  8.63k|  const size_t len = max_len ? (size_t)(fuzz_byte(Data, Size, idx) % (max_len + 1)) : 0;
  ------------------
  |  Branch (39:22): [True: 8.63k, False: 0]
  ------------------
   40|   418k|  for (size_t i = 0; i < len; ++i) {
  ------------------
  |  Branch (40:22): [True: 409k, False: 8.63k]
  ------------------
   41|   409k|    out[i] = (uint8_t)(33 + (fuzz_byte(Data, Size, idx + 1 + i) % 94));
   42|   409k|  }
   43|  8.63k|  out[len] = 0;
   44|  8.63k|}

turn_malloc_impl:
  685|  9.54k|void *turn_malloc_impl(size_t sz, const char *file, int line) {
  686|  9.54k|  void *ptr = malloc(sz);
  687|  9.54k|  if (!ptr && sz) {
  ------------------
  |  Branch (687:7): [True: 0, False: 9.54k]
  |  Branch (687:15): [True: 0, False: 0]
  ------------------
  688|      0|    turn_out_of_memory(file, line, "malloc", sz);
  689|      0|  }
  690|  9.54k|  return ptr;
  691|  9.54k|}
turn_realloc_impl:
  701|      8|void *turn_realloc_impl(void *ptr, size_t sz, const char *file, int line) {
  702|      8|  void *newptr = realloc(ptr, sz);
  703|      8|  if (!newptr && sz) {
  ------------------
  |  Branch (703:7): [True: 0, False: 8]
  |  Branch (703:18): [True: 0, False: 0]
  ------------------
  704|      0|    turn_out_of_memory(file, line, "realloc", sz);
  705|      0|  }
  706|      8|  return newptr;
  707|      8|}
turn_strdup_impl:
  709|  22.4k|char *turn_strdup_impl(const char *s, const char *file, int line) {
  710|  22.4k|  if (!s) {
  ------------------
  |  Branch (710:7): [True: 0, False: 22.4k]
  ------------------
  711|      0|    return NULL;
  712|      0|  }
  713|  22.4k|  char *ptr = strdup(s);
  714|  22.4k|  if (!ptr) {
  ------------------
  |  Branch (714:7): [True: 0, False: 22.4k]
  ------------------
  715|      0|    turn_out_of_memory(file, line, "strdup", strlen(s) + 1);
  716|      0|  }
  717|  22.4k|  return ptr;
  718|  22.4k|}

addr_set_any:
   48|  19.2k|void addr_set_any(ioa_addr *addr) {
   49|  19.2k|  if (addr) {
  ------------------
  |  Branch (49:7): [True: 19.2k, False: 0]
  ------------------
   50|  19.2k|    memset(addr, 0, sizeof(ioa_addr));
   51|  19.2k|  }
   52|  19.2k|}
addr_eq_no_port:
  180|  15.2k|int addr_eq_no_port(const ioa_addr *a1, const ioa_addr *a2) {
  181|       |
  182|  15.2k|  if (!a1) {
  ------------------
  |  Branch (182:7): [True: 0, False: 15.2k]
  ------------------
  183|      0|    return (!a2);
  184|  15.2k|  } else if (!a2) {
  ------------------
  |  Branch (184:14): [True: 0, False: 15.2k]
  ------------------
  185|      0|    return (!a1);
  186|      0|  }
  187|       |
  188|  15.2k|  if (a1->ss.sa_family == a2->ss.sa_family) {
  ------------------
  |  Branch (188:7): [True: 7.65k, False: 7.63k]
  ------------------
  189|  7.65k|    if (a1->ss.sa_family == AF_INET) {
  ------------------
  |  Branch (189:9): [True: 5.18k, False: 2.47k]
  ------------------
  190|  5.18k|      if ((int)a1->s4.sin_addr.s_addr == (int)a2->s4.sin_addr.s_addr) {
  ------------------
  |  Branch (190:11): [True: 20, False: 5.16k]
  ------------------
  191|     20|        return 1;
  192|     20|      }
  193|  5.18k|    } else if (a1->ss.sa_family == AF_INET6) {
  ------------------
  |  Branch (193:16): [True: 2.47k, False: 0]
  ------------------
  194|  2.47k|      if (memcmp(&(a1->s6.sin6_addr), &(a2->s6.sin6_addr), sizeof(struct in6_addr)) == 0) {
  ------------------
  |  Branch (194:11): [True: 12, False: 2.46k]
  ------------------
  195|     12|        return 1;
  196|     12|      }
  197|  2.47k|    }
  198|  7.65k|  }
  199|  15.2k|  return 0;
  200|  15.2k|}
make_ioa_addr:
  202|  22.4k|int make_ioa_addr(const uint8_t *saddr0, uint16_t port, ioa_addr *addr) {
  203|       |
  204|  22.4k|  if (!saddr0 || !addr) {
  ------------------
  |  Branch (204:7): [True: 0, False: 22.4k]
  |  Branch (204:18): [True: 0, False: 22.4k]
  ------------------
  205|      0|    return -1;
  206|      0|  }
  207|       |
  208|  22.4k|  char ssaddr[257];
  209|  22.4k|  STRCPY(ssaddr, saddr0);
  ------------------
  |  |  240|  22.4k|  do {                                                                                                                 \
  |  |  241|  22.4k|    if ((const char *)(dst) != (const char *)(src)) {                                                                  \
  |  |  ------------------
  |  |  |  Branch (241:9): [True: 22.4k, False: 0]
  |  |  ------------------
  |  |  242|  22.4k|      if (sizeof(dst) == sizeof(char *))                                                                               \
  |  |  ------------------
  |  |  |  Branch (242:11): [Folded, False: 22.4k]
  |  |  ------------------
  |  |  243|  22.4k|        strcpy(((char *)(dst)), (const char *)(src));                                                                  \
  |  |  244|  22.4k|      else {                                                                                                           \
  |  |  245|  22.4k|        size_t szdst = sizeof((dst));                                                                                  \
  |  |  246|  22.4k|        strncpy((char *)(dst), (const char *)(src), szdst);                                                            \
  |  |  247|  22.4k|        ((char *)(dst))[szdst - 1] = 0;                                                                                \
  |  |  248|  22.4k|      }                                                                                                                \
  |  |  249|  22.4k|    }                                                                                                                  \
  |  |  250|  22.4k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (250:12): [Folded, False: 22.4k]
  |  |  ------------------
  ------------------
  210|       |
  211|  22.4k|  char *saddr = ssaddr;
  212|  22.4k|  while (*saddr == ' ') {
  ------------------
  |  Branch (212:10): [True: 0, False: 22.4k]
  ------------------
  213|      0|    ++saddr;
  214|      0|  }
  215|       |
  216|  22.4k|  size_t len = strlen(saddr);
  217|  22.4k|  while (len > 0) {
  ------------------
  |  Branch (217:10): [True: 19.0k, False: 3.45k]
  ------------------
  218|  19.0k|    if (saddr[len - 1] == ' ') {
  ------------------
  |  Branch (218:9): [True: 0, False: 19.0k]
  ------------------
  219|      0|      saddr[len - 1] = 0;
  220|      0|      --len;
  221|  19.0k|    } else {
  222|  19.0k|      break;
  223|  19.0k|    }
  224|  19.0k|  }
  225|       |
  226|  22.4k|  memset(addr, 0, sizeof(ioa_addr));
  227|  22.4k|  if ((len == 0) || (inet_pton(AF_INET, saddr, &addr->s4.sin_addr) == 1)) {
  ------------------
  |  Branch (227:7): [True: 3.45k, False: 19.0k]
  |  Branch (227:21): [True: 10.3k, False: 8.63k]
  ------------------
  228|  13.8k|    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|  13.8k|    addr->s4.sin_port = nswap16(port);
  ------------------
  |  |   86|  13.8k|#define nswap16(s) ntohs(s)
  ------------------
  233|  13.8k|  } else if (inet_pton(AF_INET6, saddr, &addr->s6.sin6_addr) == 1) {
  ------------------
  |  Branch (233:14): [True: 8.63k, False: 0]
  ------------------
  234|  8.63k|    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.63k|    addr->s6.sin6_port = nswap16(port);
  ------------------
  |  |   86|  8.63k|#define nswap16(s) ntohs(s)
  ------------------
  239|  8.63k|  } 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.4k|  return 0;
  300|  22.4k|}
make_ioa_addr_from_full_string:
  340|  24.1k|int make_ioa_addr_from_full_string(const uint8_t *saddr, uint16_t default_port, ioa_addr *addr) {
  341|  24.1k|  if (!addr) {
  ------------------
  |  Branch (341:7): [True: 1.72k, False: 22.4k]
  ------------------
  342|  1.72k|    return -1;
  343|  1.72k|  }
  344|       |
  345|  22.4k|  int ret = -1;
  346|  22.4k|  uint16_t port = 0;
  347|  22.4k|  char *s = turn_strdup((const char *)saddr);
  ------------------
  |  |  122|  22.4k|#define turn_strdup(s) turn_strdup_impl((s), __FILE__, __LINE__)
  ------------------
  348|  22.4k|  char *sa = get_addr_string_and_port(s, &port);
  349|  22.4k|  if (sa) {
  ------------------
  |  Branch (349:7): [True: 22.4k, False: 0]
  ------------------
  350|  22.4k|    if (port < 1) {
  ------------------
  |  Branch (350:9): [True: 14.1k, False: 8.30k]
  ------------------
  351|  14.1k|      port = default_port;
  352|  14.1k|    }
  353|  22.4k|    ret = make_ioa_addr((uint8_t *)sa, port, addr);
  354|  22.4k|  }
  355|  22.4k|  free(s);
  356|  22.4k|  return ret;
  357|  24.1k|}
addr_set_port:
  407|     32|void addr_set_port(ioa_addr *addr, uint16_t port) {
  408|     32|  if (addr) {
  ------------------
  |  Branch (408:7): [True: 32, False: 0]
  ------------------
  409|     32|    if (addr->s4.sin_family == AF_INET) {
  ------------------
  |  Branch (409:9): [True: 20, False: 12]
  ------------------
  410|     20|      addr->s4.sin_port = nswap16(port);
  ------------------
  |  |   86|     20|#define nswap16(s) ntohs(s)
  ------------------
  411|     20|    } else if (addr->s6.sin6_family == AF_INET6) {
  ------------------
  |  Branch (411:16): [True: 12, False: 0]
  ------------------
  412|       |      addr->s6.sin6_port = nswap16(port);
  ------------------
  |  |   86|     12|#define nswap16(s) ntohs(s)
  ------------------
  413|     12|    }
  414|     32|  }
  415|     32|}
addr_get_port:
  417|     32|uint16_t addr_get_port(const ioa_addr *addr) {
  418|     32|  if (!addr) {
  ------------------
  |  Branch (418:7): [True: 0, False: 32]
  ------------------
  419|      0|    return 0;
  420|      0|  }
  421|       |
  422|     32|  if (addr->s4.sin_family == AF_INET) {
  ------------------
  |  Branch (422:7): [True: 20, False: 12]
  ------------------
  423|     20|    return nswap16(addr->s4.sin_port);
  ------------------
  |  |   86|     20|#define nswap16(s) ntohs(s)
  ------------------
  424|     20|  } else if (addr->s6.sin6_family == AF_INET6) {
  ------------------
  |  Branch (424:14): [True: 12, False: 0]
  ------------------
  425|     12|    return nswap16(addr->s6.sin6_port);
  ------------------
  |  |   86|     12|#define nswap16(s) ntohs(s)
  ------------------
  426|     12|  }
  427|      0|  return 0;
  428|     32|}
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|    975|void map_addr_from_public_to_private(const ioa_addr *public_addr, ioa_addr *private_addr) {
  689|    975|  size_t i;
  690|  2.87k|  for (i = 0; i < mcount; ++i) {
  ------------------
  |  Branch (690:15): [True: 1.93k, False: 943]
  ------------------
  691|  1.93k|    if (addr_eq_no_port(public_addr, public_addrs[i])) {
  ------------------
  |  Branch (691:9): [True: 32, False: 1.89k]
  ------------------
  692|     32|      addr_cpy(private_addr, private_addrs[i]);
  693|     32|      addr_set_port(private_addr, addr_get_port(public_addr));
  694|     32|      return;
  695|     32|    }
  696|  1.93k|  }
  697|    943|  addr_cpy(private_addr, public_addr);
  698|    943|}
map_addr_from_private_to_public:
  700|  6.68k|void map_addr_from_private_to_public(const ioa_addr *private_addr, ioa_addr *public_addr) {
  701|  6.68k|  size_t i;
  702|  20.0k|  for (i = 0; i < mcount; ++i) {
  ------------------
  |  Branch (702:15): [True: 13.3k, False: 6.68k]
  ------------------
  703|  13.3k|    if (addr_eq_no_port(private_addr, private_addrs[i])) {
  ------------------
  |  Branch (703:9): [True: 0, False: 13.3k]
  ------------------
  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.3k|  }
  709|  6.68k|  addr_cpy(public_addr, private_addr);
  710|  6.68k|}
ns_turn_ioaddr.c:get_addr_string_and_port:
  302|  22.4k|static char *get_addr_string_and_port(char *s0, uint16_t *port) {
  303|  22.4k|  char *s = s0;
  304|  25.9k|  while (*s && (*s == ' ')) {
  ------------------
  |  Branch (304:10): [True: 24.1k, False: 1.72k]
  |  Branch (304:16): [True: 3.45k, False: 20.7k]
  ------------------
  305|  3.45k|    ++s;
  306|  3.45k|  }
  307|  22.4k|  if (*s == '[') {
  ------------------
  |  Branch (307:7): [True: 8.63k, False: 13.8k]
  ------------------
  308|  8.63k|    ++s;
  309|  8.63k|    char *tail = strstr(s, "]");
  310|  8.63k|    if (tail) {
  ------------------
  |  Branch (310:9): [True: 8.63k, False: 0]
  ------------------
  311|  8.63k|      *tail = 0;
  312|  8.63k|      ++tail;
  313|  12.0k|      while (*tail && (*tail == ' ')) {
  ------------------
  |  Branch (313:14): [True: 6.90k, False: 5.18k]
  |  Branch (313:23): [True: 3.45k, False: 3.45k]
  ------------------
  314|  3.45k|        ++tail;
  315|  3.45k|      }
  316|  8.63k|      if (*tail == ':') {
  ------------------
  |  Branch (316:11): [True: 3.45k, False: 5.18k]
  ------------------
  317|  3.45k|        ++tail;
  318|  3.45k|        *port = atoi(tail);
  319|  3.45k|        return s;
  320|  5.18k|      } else if (*tail == 0) {
  ------------------
  |  Branch (320:18): [True: 5.18k, False: 0]
  ------------------
  321|  5.18k|        *port = 0;
  322|  5.18k|        return s;
  323|  5.18k|      }
  324|  8.63k|    }
  325|  13.8k|  } else {
  326|  13.8k|    char *tail = strstr(s, ":");
  327|  13.8k|    if (tail) {
  ------------------
  |  Branch (327:9): [True: 8.63k, False: 5.18k]
  ------------------
  328|  8.63k|      *tail = 0;
  329|  8.63k|      ++tail;
  330|  8.63k|      *port = atoi(tail);
  331|  8.63k|      return s;
  332|  8.63k|    } else {
  333|  5.18k|      *port = 0;
  334|  5.18k|      return s;
  335|  5.18k|    }
  336|  13.8k|  }
  337|      0|  return NULL;
  338|  22.4k|}

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

turn_random_number:
  123|  56.9k|long turn_random_number(void) {
  124|  56.9k|  long ret = 0;
  125|  56.9k|#if defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
  126|  56.9k|  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|  56.9k|  return ret;
  136|  56.9k|}
stun_calculate_hmac:
  174|  7.19k|                         unsigned int *hmac_len, SHATYPE shatype) {
  175|  7.19k|  ERR_clear_error();
  176|  7.19k|  UNUSED_ARG(shatype);
  ------------------
  |  |  216|  7.19k|  do {                                                                                                                 \
  |  |  217|  7.19k|    A = A;                                                                                                             \
  |  |  218|  7.19k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (218:12): [Folded, False: 7.19k]
  |  |  ------------------
  ------------------
  177|       |
  178|  7.19k|  if (shatype == SHATYPE_SHA256) {
  ------------------
  |  Branch (178:7): [True: 2.57k, False: 4.61k]
  ------------------
  179|  2.57k|#if !defined(OPENSSL_NO_SHA256) && defined(SHA256_DIGEST_LENGTH)
  180|  2.57k|    if (!HMAC(EVP_sha256(), key, (int)keylen, buf, len, hmac, hmac_len)) {
  ------------------
  |  Branch (180:9): [True: 0, False: 2.57k]
  ------------------
  181|      0|      return false;
  182|      0|    }
  183|       |#else
  184|       |    fprintf(stderr, "SHA256 is not supported\n");
  185|       |    return false;
  186|       |#endif
  187|  4.61k|  } else if (shatype == SHATYPE_SHA384) {
  ------------------
  |  Branch (187:14): [True: 926, False: 3.68k]
  ------------------
  188|    926|#if !defined(OPENSSL_NO_SHA384) && defined(SHA384_DIGEST_LENGTH)
  189|    926|    if (!HMAC(EVP_sha384(), key, (int)keylen, buf, len, hmac, hmac_len)) {
  ------------------
  |  Branch (189:9): [True: 0, False: 926]
  ------------------
  190|      0|      return false;
  191|      0|    }
  192|       |#else
  193|       |    fprintf(stderr, "SHA384 is not supported\n");
  194|       |    return false;
  195|       |#endif
  196|  3.68k|  } else if (shatype == SHATYPE_SHA512) {
  ------------------
  |  Branch (196:14): [True: 1.31k, False: 2.37k]
  ------------------
  197|  1.31k|#if !defined(OPENSSL_NO_SHA512) && defined(SHA512_DIGEST_LENGTH)
  198|  1.31k|    if (!HMAC(EVP_sha512(), key, (int)keylen, buf, len, hmac, hmac_len)) {
  ------------------
  |  Branch (198:9): [True: 0, False: 1.31k]
  ------------------
  199|      0|      return false;
  200|      0|    }
  201|       |#else
  202|       |    fprintf(stderr, "SHA512 is not supported\n");
  203|       |    return false;
  204|       |#endif
  205|  2.37k|  } else if (!HMAC(EVP_sha1(), key, (int)keylen, buf, len, hmac, hmac_len)) {
  ------------------
  |  Branch (205:14): [True: 0, False: 2.37k]
  ------------------
  206|      0|    return false;
  207|      0|  }
  208|       |
  209|  7.19k|  return true;
  210|  7.19k|}
stun_produce_integrity_key_str:
  340|  9.53k|                                    SHATYPE shatype) {
  341|  9.53k|  bool ret;
  342|       |
  343|  9.53k|  ERR_clear_error();
  344|  9.53k|  UNUSED_ARG(shatype);
  ------------------
  |  |  216|  9.53k|  do {                                                                                                                 \
  |  |  217|  9.53k|    A = A;                                                                                                             \
  |  |  218|  9.53k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (218:12): [Folded, False: 9.53k]
  |  |  ------------------
  ------------------
  345|       |
  346|  9.53k|  const size_t ulen = strlen((const char *)uname);
  347|  9.53k|  const size_t rlen = strlen((const char *)realm);
  348|  9.53k|  const size_t plen = strlen((const char *)upwd);
  349|  9.53k|  const size_t sz = ulen + 1 + rlen + 1 + plen + 1 + 10;
  350|  9.53k|  const size_t strl = ulen + 1 + rlen + 1 + plen;
  351|  9.53k|  uint8_t *str = (uint8_t *)turn_malloc(sz + 1);
  ------------------
  |  |  119|  9.53k|#define turn_malloc(sz) turn_malloc_impl((sz), __FILE__, __LINE__)
  ------------------
  352|       |
  353|  9.53k|  strncpy((char *)str, (const char *)uname, sz);
  354|  9.53k|  str[ulen] = ':';
  355|  9.53k|  strncpy((char *)str + ulen + 1, (const char *)realm, sz - ulen - 1);
  356|  9.53k|  str[ulen + 1 + rlen] = ':';
  357|  9.53k|  strncpy((char *)str + ulen + 1 + rlen + 1, (const char *)upwd, sz - ulen - 1 - rlen - 1);
  358|  9.53k|  str[strl] = 0;
  359|       |
  360|  9.53k|  if (shatype == SHATYPE_SHA256) {
  ------------------
  |  Branch (360:7): [True: 3.76k, False: 5.77k]
  ------------------
  361|  3.76k|#if !defined(OPENSSL_NO_SHA256) && defined(SHA256_DIGEST_LENGTH)
  362|  3.76k|    unsigned int keylen = 0;
  363|  3.76k|    EVP_MD_CTX *ctx = EVP_MD_CTX_new();
  364|  3.76k|    EVP_DigestInit(ctx, EVP_sha256());
  365|  3.76k|    EVP_DigestUpdate(ctx, str, strl);
  366|  3.76k|    EVP_DigestFinal(ctx, key, &keylen);
  367|  3.76k|    EVP_MD_CTX_free(ctx);
  368|  3.76k|    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.78k, False: 3.98k]
  ------------------
  374|  1.78k|#if !defined(OPENSSL_NO_SHA384) && defined(SHA384_DIGEST_LENGTH)
  375|  1.78k|    unsigned int keylen = 0;
  376|  1.78k|    EVP_MD_CTX *ctx = EVP_MD_CTX_new();
  377|  1.78k|    EVP_DigestInit(ctx, EVP_sha384());
  378|  1.78k|    EVP_DigestUpdate(ctx, str, strl);
  379|  1.78k|    EVP_DigestFinal(ctx, key, &keylen);
  380|  1.78k|    EVP_MD_CTX_free(ctx);
  381|  1.78k|    ret = true;
  382|       |#else
  383|       |    fprintf(stderr, "SHA384 is not supported\n");
  384|       |    ret = false;
  385|       |#endif
  386|  3.98k|  } else if (shatype == SHATYPE_SHA512) {
  ------------------
  |  Branch (386:14): [True: 1.88k, False: 2.09k]
  ------------------
  387|  1.88k|#if !defined(OPENSSL_NO_SHA512) && defined(SHA512_DIGEST_LENGTH)
  388|  1.88k|    unsigned int keylen = 0;
  389|  1.88k|    EVP_MD_CTX *ctx = EVP_MD_CTX_new();
  390|  1.88k|    EVP_DigestInit(ctx, EVP_sha512());
  391|  1.88k|    EVP_DigestUpdate(ctx, str, strl);
  392|  1.88k|    EVP_DigestFinal(ctx, key, &keylen);
  393|  1.88k|    EVP_MD_CTX_free(ctx);
  394|  1.88k|    ret = true;
  395|       |#else
  396|       |    fprintf(stderr, "SHA512 is not supported\n");
  397|       |    ret = false;
  398|       |#endif
  399|  2.09k|  } else {
  400|  2.09k|#if OPENSSL_VERSION_NUMBER >= 0x30000000L
  401|  2.09k|    unsigned int keylen = 0;
  402|  2.09k|    EVP_MD_CTX *ctx = EVP_MD_CTX_new();
  403|  2.09k|    if (EVP_default_properties_is_fips_enabled(NULL)) {
  ------------------
  |  Branch (403:9): [True: 0, False: 2.09k]
  ------------------
  404|      0|      EVP_default_properties_enable_fips(NULL, 0);
  405|      0|    }
  406|  2.09k|    EVP_DigestInit_ex(ctx, EVP_md5(), NULL);
  407|  2.09k|    EVP_DigestUpdate(ctx, str, strl);
  408|  2.09k|    EVP_DigestFinal(ctx, key, &keylen);
  409|  2.09k|    EVP_MD_CTX_free(ctx);
  410|       |#else // OPENSSL_VERSION_NUMBER < 0x30000000L
  411|       |    unsigned int keylen = 0;
  412|       |    EVP_MD_CTX *ctx = EVP_MD_CTX_new();
  413|       |#if defined EVP_MD_CTX_FLAG_NON_FIPS_ALLOW && !defined(LIBRESSL_VERSION_NUMBER)
  414|       |    if (FIPS_mode()) {
  415|       |      EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
  416|       |    }
  417|       |#endif
  418|       |    EVP_DigestInit_ex(ctx, EVP_md5(), NULL);
  419|       |    EVP_DigestUpdate(ctx, str, strl);
  420|       |    EVP_DigestFinal(ctx, key, &keylen);
  421|       |    EVP_MD_CTX_free(ctx);
  422|       |#endif // OPENSSL_VERSION_NUMBER >= 0X30000000L
  423|  2.09k|    ret = true;
  424|  2.09k|  }
  425|       |
  426|  9.53k|  free(str);
  427|       |
  428|  9.53k|  return ret;
  429|  9.53k|}
stun_get_command_message_len_str:
  523|  1.96M|int stun_get_command_message_len_str(const uint8_t *buf, size_t len) {
  524|  1.96M|  if (len < STUN_HEADER_LENGTH) {
  ------------------
  |  |   46|  1.96M|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (524:7): [True: 22, False: 1.96M]
  ------------------
  525|     22|    return -1;
  526|     22|  }
  527|       |
  528|       |  /* Validate the size the buffer claims to be */
  529|  1.96M|  const size_t bufLen = (size_t)(turn_read_u16(buf + 2) + STUN_HEADER_LENGTH);
  ------------------
  |  |   46|  1.96M|#define STUN_HEADER_LENGTH (20)
  ------------------
  530|  1.96M|  if (bufLen > len) {
  ------------------
  |  Branch (530:7): [True: 1.06k, False: 1.96M]
  ------------------
  531|  1.06k|    return -1;
  532|  1.06k|  }
  533|       |
  534|  1.96M|  return bufLen;
  535|  1.96M|}
stun_make_type:
  547|  18.9k|uint16_t stun_make_type(uint16_t method) {
  548|  18.9k|  method = method & 0x0FFF;
  549|  18.9k|  return ((method & 0x000F) | ((method & 0x0070) << 1) | ((method & 0x0380) << 2) | ((method & 0x0C00) << 2));
  550|  18.9k|}
stun_get_method_str:
  552|  5.25k|uint16_t stun_get_method_str(const uint8_t *buf, size_t len) {
  553|  5.25k|  if (!buf || len < 2) {
  ------------------
  |  Branch (553:7): [True: 0, False: 5.25k]
  |  Branch (553:15): [True: 0, False: 5.25k]
  ------------------
  554|      0|    return (uint16_t)-1;
  555|      0|  }
  556|       |
  557|  5.25k|  const uint16_t tt = turn_read_u16(buf);
  558|       |
  559|  5.25k|  return (tt & 0x000F) | ((tt & 0x00E0) >> 1) | ((tt & 0x0E00) >> 2) | ((tt & 0x3000) >> 2);
  560|  5.25k|}
stun_get_msg_type_str:
  562|  23.8k|uint16_t stun_get_msg_type_str(const uint8_t *buf, size_t len) {
  563|  23.8k|  if (!buf || len < 2) {
  ------------------
  |  Branch (563:7): [True: 0, False: 23.8k]
  |  Branch (563:15): [True: 0, False: 23.8k]
  ------------------
  564|      0|    return (uint16_t)-1;
  565|      0|  }
  566|  23.8k|  return (turn_read_u16(buf) & 0x3FFF);
  567|  23.8k|}
is_channel_msg_str:
  569|  23.6k|bool is_channel_msg_str(const uint8_t *buf, size_t blen) {
  570|  23.6k|  return (buf && blen >= 4 && STUN_VALID_CHANNEL(turn_read_u16(buf)));
  ------------------
  |  |  159|  23.6k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (159:34): [True: 0, False: 23.6k]
  |  |  |  Branch (159:53): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (570:11): [True: 23.6k, False: 0]
  |  Branch (570:18): [True: 23.6k, False: 0]
  ------------------
  571|  23.6k|}
stun_is_command_message_str:
  575|  13.1k|bool stun_is_command_message_str(const uint8_t *buf, size_t blen) {
  576|  13.1k|  if (buf && blen >= STUN_HEADER_LENGTH) {
  ------------------
  |  |   46|  13.1k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (576:7): [True: 13.1k, False: 0]
  |  Branch (576:14): [True: 13.1k, False: 11]
  ------------------
  577|  13.1k|    if (!STUN_VALID_CHANNEL(turn_read_u16(buf))) {
  ------------------
  |  |  159|  13.1k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (159:34): [True: 383, False: 12.7k]
  |  |  |  Branch (159:53): [True: 104, False: 279]
  |  |  ------------------
  ------------------
  578|  13.0k|      if ((((uint8_t)buf[0]) & ((uint8_t)(0xC0))) == 0) {
  ------------------
  |  Branch (578:11): [True: 12.7k, False: 279]
  ------------------
  579|  12.7k|        if (turn_read_u32(buf + 4) == STUN_MAGIC_COOKIE) {
  ------------------
  |  |   56|  12.7k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (579:13): [True: 9.64k, False: 3.08k]
  ------------------
  580|  9.64k|          const uint16_t len = turn_read_u16(buf + 2);
  581|  9.64k|          if ((len & 0x0003) == 0) {
  ------------------
  |  Branch (581:15): [True: 9.51k, False: 127]
  ------------------
  582|  9.51k|            if ((size_t)(len + STUN_HEADER_LENGTH) == blen) {
  ------------------
  |  |   46|  9.51k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (582:17): [True: 9.01k, False: 506]
  ------------------
  583|  9.01k|              return true;
  584|  9.01k|            }
  585|  9.51k|          }
  586|  9.64k|        }
  587|  12.7k|      }
  588|  13.0k|    }
  589|  13.1k|  }
  590|  4.10k|  return false;
  591|  13.1k|}
old_stun_is_command_message_str:
  593|  1.56k|bool old_stun_is_command_message_str(const uint8_t *buf, size_t blen, uint32_t *cookie) {
  594|  1.56k|  if (buf && blen >= STUN_HEADER_LENGTH) {
  ------------------
  |  |   46|  1.56k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (594:7): [True: 1.56k, False: 0]
  |  Branch (594:14): [True: 1.56k, False: 0]
  ------------------
  595|  1.56k|    if (!STUN_VALID_CHANNEL(turn_read_u16(buf))) {
  ------------------
  |  |  159|  1.56k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (159:34): [True: 48, False: 1.51k]
  |  |  |  Branch (159:53): [True: 13, False: 35]
  |  |  ------------------
  ------------------
  596|  1.54k|      if ((((uint8_t)buf[0]) & ((uint8_t)(0xC0))) == 0) {
  ------------------
  |  Branch (596:11): [True: 1.51k, False: 35]
  ------------------
  597|  1.51k|        const uint32_t msg_cookie = turn_read_u32(buf + 4);
  598|  1.51k|        if (msg_cookie != STUN_MAGIC_COOKIE) {
  ------------------
  |  |   56|  1.51k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (598:13): [True: 304, False: 1.20k]
  ------------------
  599|    304|          const uint16_t len = turn_read_u16(buf + 2);
  600|    304|          if ((len & 0x0003) == 0) {
  ------------------
  |  Branch (600:15): [True: 236, False: 68]
  ------------------
  601|    236|            if ((size_t)(len + STUN_HEADER_LENGTH) == blen) {
  ------------------
  |  |   46|    236|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (601:17): [True: 163, False: 73]
  ------------------
  602|    163|              *cookie = msg_cookie;
  603|    163|              return true;
  604|    163|            }
  605|    236|          }
  606|    304|        }
  607|  1.51k|      }
  608|  1.54k|    }
  609|  1.56k|  }
  610|  1.39k|  return false;
  611|  1.56k|}
stun_is_command_message_full_check_str:
  614|  8.13k|                                            bool *fingerprint_present) {
  615|  8.13k|  if (!stun_is_command_message_str(buf, blen)) {
  ------------------
  |  Branch (615:7): [True: 2.49k, False: 5.64k]
  ------------------
  616|  2.49k|    return false;
  617|  2.49k|  }
  618|  5.64k|  stun_attr_ref sar = stun_attr_get_first_by_type_str(buf, blen, STUN_ATTRIBUTE_FINGERPRINT);
  ------------------
  |  |  111|  5.64k|#define STUN_ATTRIBUTE_FINGERPRINT (0x8028)
  ------------------
  619|  5.64k|  if (!sar) {
  ------------------
  |  Branch (619:7): [True: 5.09k, False: 545]
  ------------------
  620|  5.09k|    if (fingerprint_present) {
  ------------------
  |  Branch (620:9): [True: 0, False: 5.09k]
  ------------------
  621|      0|      *fingerprint_present = false;
  622|      0|    }
  623|  5.09k|    if (stun_get_method_str(buf, blen) == STUN_METHOD_BINDING) {
  ------------------
  |  |   77|  5.09k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
  |  Branch (623:9): [True: 160, False: 4.93k]
  ------------------
  624|    160|      return true;
  625|    160|    }
  626|  4.93k|    return !must_check_fingerprint;
  627|  5.09k|  }
  628|    545|  if (stun_attr_get_len(sar) != 4) {
  ------------------
  |  Branch (628:7): [True: 150, False: 395]
  ------------------
  629|    150|    return false;
  630|    150|  }
  631|    395|  const uint8_t *fingerprint = stun_attr_get_value(sar);
  632|    395|  if (!fingerprint) {
  ------------------
  |  Branch (632:7): [True: 0, False: 395]
  ------------------
  633|      0|    return !must_check_fingerprint;
  634|      0|  }
  635|    395|  const uint32_t crc32len = (uint32_t)((fingerprint - buf) - 4);
  636|    395|  const bool ret = (turn_read_u32(fingerprint) == (ns_crc32(buf, crc32len) ^ ((uint32_t)FINGERPRINT_XOR)));
  ------------------
  |  |   53|    395|#define FINGERPRINT_XOR 0x5354554e
  ------------------
  637|    395|  if (ret && fingerprint_present) {
  ------------------
  |  Branch (637:7): [True: 5, False: 390]
  |  Branch (637:14): [True: 0, False: 5]
  ------------------
  638|      0|    *fingerprint_present = ret;
  639|      0|  }
  640|    395|  return ret;
  641|    395|}
stun_is_request_str:
  643|    163|bool stun_is_request_str(const uint8_t *buf, size_t len) {
  644|    163|  if (is_channel_msg_str(buf, len)) {
  ------------------
  |  Branch (644:7): [True: 0, False: 163]
  ------------------
  645|      0|    return false;
  646|      0|  }
  647|    163|  return IS_STUN_REQUEST(stun_get_msg_type_str(buf, len));
  ------------------
  |  |   58|    163|#define IS_STUN_REQUEST(msg_type) (((msg_type)&0x0110) == 0x0000)
  ------------------
  648|    163|}
stun_is_success_response_str:
  650|    163|bool stun_is_success_response_str(const uint8_t *buf, size_t len) {
  651|    163|  if (is_channel_msg_str(buf, len)) {
  ------------------
  |  Branch (651:7): [True: 0, False: 163]
  ------------------
  652|      0|    return false;
  653|      0|  }
  654|    163|  return IS_STUN_SUCCESS_RESP(stun_get_msg_type_str(buf, len));
  ------------------
  |  |   60|    163|#define IS_STUN_SUCCESS_RESP(msg_type) (((msg_type)&0x0110) == 0x0100)
  ------------------
  655|    163|}
stun_is_error_response_str:
  657|  23.1k|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) {
  658|  23.1k|  if (is_channel_msg_str(buf, len)) {
  ------------------
  |  Branch (658:7): [True: 0, False: 23.1k]
  ------------------
  659|      0|    return false;
  660|      0|  }
  661|  23.1k|  if (IS_STUN_ERR_RESP(stun_get_msg_type_str(buf, len))) {
  ------------------
  |  |   61|  23.1k|#define IS_STUN_ERR_RESP(msg_type) (((msg_type)&0x0110) == 0x0110)
  |  |  ------------------
  |  |  |  Branch (61:36): [True: 21.4k, False: 1.69k]
  |  |  ------------------
  ------------------
  662|  21.4k|    if (err_code) {
  ------------------
  |  Branch (662:9): [True: 21.4k, False: 0]
  ------------------
  663|  21.4k|      stun_attr_ref sar = stun_attr_get_first_by_type_str(buf, len, STUN_ATTRIBUTE_ERROR_CODE);
  ------------------
  |  |   99|  21.4k|#define STUN_ATTRIBUTE_ERROR_CODE (0x0009)
  ------------------
  664|  21.4k|      if (sar) {
  ------------------
  |  Branch (664:11): [True: 20.9k, False: 479]
  ------------------
  665|  20.9k|        if (stun_attr_get_len(sar) >= 4) {
  ------------------
  |  Branch (665:13): [True: 20.9k, False: 29]
  ------------------
  666|  20.9k|          const uint8_t *val = (const uint8_t *)stun_attr_get_value(sar);
  667|  20.9k|          *err_code = (int)(val[2] * 100 + val[3]);
  668|  20.9k|          if (err_msg && err_msg_size > 0) {
  ------------------
  |  Branch (668:15): [True: 20.9k, False: 0]
  |  Branch (668:26): [True: 20.9k, False: 0]
  ------------------
  669|  20.9k|            err_msg[0] = 0;
  670|  20.9k|            if (stun_attr_get_len(sar) > 4) {
  ------------------
  |  Branch (670:17): [True: 20.8k, False: 123]
  ------------------
  671|  20.8k|              size_t msg_len = stun_attr_get_len(sar) - 4;
  672|  20.8k|              if (msg_len > (err_msg_size - 1)) {
  ------------------
  |  Branch (672:19): [True: 15, False: 20.8k]
  ------------------
  673|     15|                msg_len = err_msg_size - 1;
  674|     15|              }
  675|  20.8k|              memcpy(err_msg, val + 4, msg_len);
  676|  20.8k|              err_msg[msg_len] = 0;
  677|  20.8k|            }
  678|  20.9k|          }
  679|  20.9k|        }
  680|  20.9k|      }
  681|  21.4k|    }
  682|  21.4k|    return true;
  683|  21.4k|  }
  684|  1.69k|  return false;
  685|  23.1k|}
stun_is_challenge_response_str:
  689|  21.8k|                                    bool *oauth) {
  690|  21.8k|  const bool ret = stun_is_error_response_str(buf, len, err_code, err_msg, err_msg_size);
  691|       |
  692|  21.8k|  if (ret && (((*err_code) == 401) || ((*err_code) == 438))) {
  ------------------
  |  Branch (692:7): [True: 21.0k, False: 807]
  |  Branch (692:15): [True: 13.8k, False: 7.20k]
  |  Branch (692:39): [True: 3.47k, False: 3.72k]
  ------------------
  693|  17.3k|    stun_attr_ref sar = stun_attr_get_first_by_type_str(buf, len, STUN_ATTRIBUTE_REALM);
  ------------------
  |  |  102|  17.3k|#define STUN_ATTRIBUTE_REALM (0x0014)
  ------------------
  694|  17.3k|    if (sar) {
  ------------------
  |  Branch (694:9): [True: 13.8k, False: 3.46k]
  ------------------
  695|  13.8k|      bool found_oauth = false;
  696|       |
  697|  13.8k|      const uint8_t *value = stun_attr_get_value(sar);
  698|  13.8k|      if (value) {
  ------------------
  |  Branch (698:11): [True: 13.8k, False: 2]
  ------------------
  699|  13.8k|        size_t vlen = (size_t)stun_attr_get_len(sar);
  700|  13.8k|        vlen = min(vlen, (size_t)STUN_MAX_REALM_SIZE);
  ------------------
  |  |  138|  13.8k|#define min(a, b) ((a) <= (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (138:20): [True: 13.8k, False: 17]
  |  |  ------------------
  ------------------
  701|  13.8k|        memcpy(realm, value, vlen);
  702|  13.8k|        realm[vlen] = 0;
  703|  13.8k|        {
  704|  13.8k|          sar = stun_attr_get_first_by_type_str(buf, len, STUN_ATTRIBUTE_THIRD_PARTY_AUTHORIZATION);
  ------------------
  |  |  223|  13.8k|#define STUN_ATTRIBUTE_THIRD_PARTY_AUTHORIZATION (0x802E)
  ------------------
  705|  13.8k|          if (sar) {
  ------------------
  |  Branch (705:15): [True: 3.47k, False: 10.3k]
  ------------------
  706|  3.47k|            value = stun_attr_get_value(sar);
  707|  3.47k|            if (value) {
  ------------------
  |  Branch (707:17): [True: 3.47k, False: 1]
  ------------------
  708|  3.47k|              vlen = (size_t)stun_attr_get_len(sar);
  709|  3.47k|              vlen = min(vlen, (size_t)STUN_MAX_SERVER_NAME_SIZE);
  ------------------
  |  |  138|  3.47k|#define min(a, b) ((a) <= (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (138:20): [True: 3.47k, False: 1]
  |  |  ------------------
  ------------------
  710|  3.47k|              if (vlen > 0) {
  ------------------
  |  Branch (710:19): [True: 3.47k, False: 0]
  ------------------
  711|  3.47k|                if (server_name) {
  ------------------
  |  Branch (711:21): [True: 3.47k, False: 0]
  ------------------
  712|  3.47k|                  memcpy(server_name, value, vlen);
  713|  3.47k|                  server_name[vlen] = 0;
  714|  3.47k|                }
  715|  3.47k|                found_oauth = true;
  716|  3.47k|              }
  717|  3.47k|            }
  718|  3.47k|          }
  719|  13.8k|        }
  720|       |
  721|  13.8k|        sar = stun_attr_get_first_by_type_str(buf, len, STUN_ATTRIBUTE_NONCE);
  ------------------
  |  |  103|  13.8k|#define STUN_ATTRIBUTE_NONCE (0x0015)
  ------------------
  722|  13.8k|        if (sar) {
  ------------------
  |  Branch (722:13): [True: 10.3k, False: 3.48k]
  ------------------
  723|  10.3k|          value = stun_attr_get_value(sar);
  724|  10.3k|          if (value) {
  ------------------
  |  Branch (724:15): [True: 10.3k, False: 2]
  ------------------
  725|  10.3k|            vlen = (size_t)stun_attr_get_len(sar);
  726|  10.3k|            vlen = min(vlen, (size_t)STUN_MAX_NONCE_SIZE);
  ------------------
  |  |  138|  10.3k|#define min(a, b) ((a) <= (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (138:20): [True: 10.3k, False: 8]
  |  |  ------------------
  ------------------
  727|  10.3k|            memcpy(nonce, value, vlen);
  728|  10.3k|            nonce[vlen] = 0;
  729|  10.3k|            if (oauth) {
  ------------------
  |  Branch (729:17): [True: 5.19k, False: 5.18k]
  ------------------
  730|  5.19k|              *oauth = found_oauth;
  731|  5.19k|            }
  732|  10.3k|            return true;
  733|  10.3k|          }
  734|  10.3k|        }
  735|  13.8k|      }
  736|  13.8k|    }
  737|  17.3k|  }
  738|       |
  739|  11.4k|  return false;
  740|  21.8k|}
stun_is_indication_str:
  755|    163|bool stun_is_indication_str(const uint8_t *buf, size_t len) {
  756|    163|  if (is_channel_msg_str(buf, len)) {
  ------------------
  |  Branch (756:7): [True: 0, False: 163]
  ------------------
  757|      0|    return false;
  758|      0|  }
  759|    163|  return IS_STUN_INDICATION(stun_get_msg_type_str(buf, len));
  ------------------
  |  |   59|    163|#define IS_STUN_INDICATION(msg_type) (((msg_type)&0x0110) == 0x0010)
  ------------------
  760|    163|}
stun_make_request:
  762|  8.63k|uint16_t stun_make_request(uint16_t method) { return GET_STUN_REQUEST(stun_make_type(method)); }
  ------------------
  |  |   63|  8.63k|#define GET_STUN_REQUEST(msg_type) (msg_type & 0xFEEF)
  ------------------
stun_make_error_response:
  768|  10.3k|uint16_t stun_make_error_response(uint16_t method) { return GET_STUN_ERR_RESP(stun_make_type(method)); }
  ------------------
  |  |   66|  10.3k|#define GET_STUN_ERR_RESP(msg_type) (msg_type | 0x0110)
  ------------------
stun_init_buffer_str:
  772|  18.9k|void stun_init_buffer_str(uint8_t *buf, size_t *len) {
  773|  18.9k|  *len = STUN_HEADER_LENGTH;
  ------------------
  |  |   46|  18.9k|#define STUN_HEADER_LENGTH (20)
  ------------------
  774|  18.9k|  memset(buf, 0, *len);
  775|  18.9k|}
stun_init_command_str:
  777|  18.9k|void stun_init_command_str(uint16_t message_type, uint8_t *buf, size_t *len) {
  778|  18.9k|  stun_init_buffer_str(buf, len);
  779|  18.9k|  message_type &= (uint16_t)(0x3FFF);
  780|  18.9k|  turn_write_u16(buf, message_type);
  781|  18.9k|  turn_write_u16(buf + 2, 0);
  782|  18.9k|  turn_write_u32(buf + 4, STUN_MAGIC_COOKIE);
  ------------------
  |  |   56|  18.9k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  783|       |  stun_tid_generate_in_message_str(buf, NULL);
  784|  18.9k|}
stun_init_request_str:
  795|  8.63k|void stun_init_request_str(uint16_t method, uint8_t *buf, size_t *len) {
  796|  8.63k|  stun_init_command_str(stun_make_request(method), buf, len);
  797|  8.63k|}
get_default_reason:
  817|  1.11k|const uint8_t *get_default_reason(int error_code) {
  818|  1.11k|  const char *reason = "Unknown error";
  819|       |
  820|  1.11k|  switch (error_code) {
  821|      0|  case 300:
  ------------------
  |  Branch (821:3): [True: 0, False: 1.11k]
  ------------------
  822|      0|    reason = "Try Alternate";
  823|      0|    break;
  824|      0|  case 400:
  ------------------
  |  Branch (824:3): [True: 0, False: 1.11k]
  ------------------
  825|      0|    reason = "Bad Request";
  826|      0|    break;
  827|      0|  case 401:
  ------------------
  |  Branch (827:3): [True: 0, False: 1.11k]
  ------------------
  828|      0|    reason = "Unauthorized";
  829|      0|    break;
  830|      0|  case 403:
  ------------------
  |  Branch (830:3): [True: 0, False: 1.11k]
  ------------------
  831|      0|    reason = "Forbidden";
  832|      0|    break;
  833|      0|  case 404:
  ------------------
  |  Branch (833:3): [True: 0, False: 1.11k]
  ------------------
  834|      0|    reason = "Not Found";
  835|      0|    break;
  836|      0|  case 420:
  ------------------
  |  Branch (836:3): [True: 0, False: 1.11k]
  ------------------
  837|      0|    reason = "Unknown Attribute";
  838|      0|    break;
  839|      0|  case 437:
  ------------------
  |  Branch (839:3): [True: 0, False: 1.11k]
  ------------------
  840|      0|    reason = "Allocation Mismatch";
  841|      0|    break;
  842|      0|  case 438:
  ------------------
  |  Branch (842:3): [True: 0, False: 1.11k]
  ------------------
  843|      0|    reason = "Stale Nonce";
  844|      0|    break;
  845|  1.11k|  case 440:
  ------------------
  |  Branch (845:3): [True: 1.11k, False: 0]
  ------------------
  846|  1.11k|    reason = "Address Family not Supported";
  847|  1.11k|    break;
  848|      0|  case 441:
  ------------------
  |  Branch (848:3): [True: 0, False: 1.11k]
  ------------------
  849|      0|    reason = "Wrong Credentials";
  850|      0|    break;
  851|      0|  case 442:
  ------------------
  |  Branch (851:3): [True: 0, False: 1.11k]
  ------------------
  852|      0|    reason = "Unsupported Transport Protocol";
  853|      0|    break;
  854|      0|  case 443:
  ------------------
  |  Branch (854:3): [True: 0, False: 1.11k]
  ------------------
  855|      0|    reason = "Peer Address Family Mismatch";
  856|      0|    break;
  857|      0|  case 446:
  ------------------
  |  Branch (857:3): [True: 0, False: 1.11k]
  ------------------
  858|      0|    reason = "Connection Already Exists";
  859|      0|    break;
  860|      0|  case 447:
  ------------------
  |  Branch (860:3): [True: 0, False: 1.11k]
  ------------------
  861|      0|    reason = "Connection Timeout or Failure";
  862|      0|    break;
  863|      0|  case 486:
  ------------------
  |  Branch (863:3): [True: 0, False: 1.11k]
  ------------------
  864|      0|    reason = "Allocation Quota Reached";
  865|      0|    break;
  866|      0|  case 487:
  ------------------
  |  Branch (866:3): [True: 0, False: 1.11k]
  ------------------
  867|      0|    reason = "Role Conflict";
  868|      0|    break;
  869|      0|  case 500:
  ------------------
  |  Branch (869:3): [True: 0, False: 1.11k]
  ------------------
  870|      0|    reason = "Server Error";
  871|      0|    break;
  872|      0|  case 508:
  ------------------
  |  Branch (872:3): [True: 0, False: 1.11k]
  ------------------
  873|      0|    reason = "Insufficient Capacity";
  874|      0|    break;
  875|      0|  default:;
  ------------------
  |  Branch (875:3): [True: 0, False: 1.11k]
  ------------------
  876|  1.11k|  };
  877|       |
  878|  1.11k|  return (const uint8_t *)reason;
  879|  1.11k|}
stun_init_error_response_str:
  925|  10.3k|                                  const uint8_t *reason, stun_tid *id, bool include_reason_string) {
  926|       |
  927|  10.3k|  stun_init_command_str(stun_make_error_response(method), buf, len);
  928|       |
  929|       |  stun_init_error_response_common_str(buf, len, error_code, reason, id, include_reason_string, false);
  930|  10.3k|}
stun_is_binding_request_str:
 1372|    163|bool stun_is_binding_request_str(const uint8_t *buf, size_t len, size_t offset) {
 1373|    163|  if (offset < len) {
  ------------------
  |  Branch (1373:7): [True: 163, False: 0]
  ------------------
 1374|    163|    buf += offset;
 1375|    163|    len -= offset;
 1376|    163|    if (stun_is_command_message_str(buf, len)) {
  ------------------
  |  Branch (1376:9): [True: 0, False: 163]
  ------------------
 1377|      0|      if (stun_is_request_str(buf, len) && (stun_get_method_str(buf, len) == STUN_METHOD_BINDING)) {
  ------------------
  |  |   77|      0|#define STUN_METHOD_BINDING (0x0001)
  ------------------
  |  Branch (1377:11): [True: 0, False: 0]
  |  Branch (1377:44): [True: 0, False: 0]
  ------------------
 1378|      0|        return true;
 1379|      0|      }
 1380|      0|    }
 1381|    163|  }
 1382|    163|  return false;
 1383|    163|}
stun_is_binding_response_str:
 1385|    163|bool stun_is_binding_response_str(const uint8_t *buf, size_t len) {
 1386|    163|  if (stun_is_command_message_str(buf, len) && (stun_get_method_str(buf, len) == STUN_METHOD_BINDING)) {
  ------------------
  |  |   77|      0|#define STUN_METHOD_BINDING (0x0001)
  ------------------
  |  Branch (1386:7): [True: 0, False: 163]
  |  Branch (1386:48): [True: 0, False: 0]
  ------------------
 1387|      0|    if (stun_is_response_str(buf, len)) {
  ------------------
  |  Branch (1387:9): [True: 0, False: 0]
  ------------------
 1388|      0|      return true;
 1389|      0|    }
 1390|      0|  }
 1391|    163|  return false;
 1392|    163|}
stun_tid_from_message_str:
 1430|  16.2k|void stun_tid_from_message_str(const uint8_t *buf, size_t len, stun_tid *id) {
 1431|  16.2k|  UNUSED_ARG(len);
  ------------------
  |  |  216|  16.2k|  do {                                                                                                                 \
  |  |  217|  16.2k|    A = A;                                                                                                             \
  |  |  218|  16.2k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (218:12): [Folded, False: 16.2k]
  |  |  ------------------
  ------------------
 1432|  16.2k|  stun_tid_from_string(buf + 8, id);
 1433|  16.2k|}
stun_tid_message_cpy:
 1435|  29.3k|void stun_tid_message_cpy(uint8_t *buf, const stun_tid *id) {
 1436|  29.3k|  if (buf && id) {
  ------------------
  |  Branch (1436:7): [True: 29.3k, False: 0]
  |  Branch (1436:14): [True: 29.3k, False: 0]
  ------------------
 1437|  29.3k|    stun_tid_string_cpy(buf + 8, id);
 1438|  29.3k|  }
 1439|  29.3k|}
stun_tid_generate:
 1441|  18.9k|void stun_tid_generate(stun_tid *id) {
 1442|  18.9k|  if (id) {
  ------------------
  |  Branch (1442:7): [True: 18.9k, False: 0]
  ------------------
 1443|  18.9k|    turn_random_tid_size(id->tsx_id);
 1444|  18.9k|  }
 1445|  18.9k|}
stun_tid_generate_in_message_str:
 1447|  18.9k|void stun_tid_generate_in_message_str(uint8_t *buf, stun_tid *id) {
 1448|  18.9k|  stun_tid tmp;
 1449|  18.9k|  if (!id) {
  ------------------
  |  Branch (1449:7): [True: 18.9k, False: 0]
  ------------------
 1450|  18.9k|    id = &tmp;
 1451|  18.9k|  }
 1452|  18.9k|  stun_tid_generate(id);
 1453|  18.9k|  stun_tid_message_cpy(buf, id);
 1454|  18.9k|}
stun_attr_get_type:
 1478|  1.90M|int stun_attr_get_type(stun_attr_ref attr) {
 1479|  1.90M|  if (attr) {
  ------------------
  |  Branch (1479:7): [True: 1.90M, False: 0]
  ------------------
 1480|  1.90M|    return (int)turn_read_u16(attr);
 1481|  1.90M|  }
 1482|      0|  return -1;
 1483|  1.90M|}
stun_attr_get_len:
 1485|  3.65M|int stun_attr_get_len(stun_attr_ref attr) {
 1486|  3.65M|  if (attr) {
  ------------------
  |  Branch (1486:7): [True: 3.65M, False: 0]
  ------------------
 1487|  3.65M|    return (int)turn_read_u16((const uint8_t *)attr + 2);
 1488|  3.65M|  }
 1489|      0|  return -1;
 1490|  3.65M|}
stun_attr_get_value:
 1492|  86.2k|const uint8_t *stun_attr_get_value(stun_attr_ref attr) {
 1493|  86.2k|  if (attr) {
  ------------------
  |  Branch (1493:7): [True: 86.2k, False: 0]
  ------------------
 1494|  86.2k|    const int len = (int)turn_read_u16((const uint8_t *)attr + 2);
 1495|  86.2k|    if (len < 1) {
  ------------------
  |  Branch (1495:9): [True: 22.1k, False: 64.1k]
  ------------------
 1496|  22.1k|      return NULL;
 1497|  22.1k|    }
 1498|  64.1k|    return ((const uint8_t *)attr) + 4;
 1499|  86.2k|  }
 1500|      0|  return NULL;
 1501|  86.2k|}
stun_get_requested_address_family:
 1503|    108|int stun_get_requested_address_family(stun_attr_ref attr) {
 1504|    108|  if (attr) {
  ------------------
  |  Branch (1504:7): [True: 108, False: 0]
  ------------------
 1505|    108|    const int len = (int)turn_read_u16((const uint8_t *)attr + 2);
 1506|    108|    if (len != 4) {
  ------------------
  |  Branch (1506:9): [True: 62, False: 46]
  ------------------
 1507|     62|      return STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_INVALID;
  ------------------
  |  |  167|     62|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_INVALID (-1)
  ------------------
 1508|     62|    }
 1509|     46|    const int val = ((const uint8_t *)attr)[4];
 1510|     46|    switch (val) {
 1511|      4|    case STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV4:
  ------------------
  |  |  164|      4|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV4 (0x01)
  ------------------
  |  Branch (1511:5): [True: 4, False: 42]
  ------------------
 1512|      9|    case STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6:
  ------------------
  |  |  165|      9|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6 (0x02)
  ------------------
  |  Branch (1512:5): [True: 5, False: 41]
  ------------------
 1513|      9|      return val;
 1514|     37|    default:
  ------------------
  |  Branch (1514:5): [True: 37, False: 9]
  ------------------
 1515|     37|      return STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_INVALID;
  ------------------
  |  |  167|     37|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_INVALID (-1)
  ------------------
 1516|     46|    };
 1517|      0|  }
 1518|      0|  return STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_DEFAULT;
  ------------------
  |  |  166|      0|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_DEFAULT (0x00)
  ------------------
 1519|    108|}
stun_attr_get_channel_number:
 1521|  2.93k|uint16_t stun_attr_get_channel_number(stun_attr_ref attr) {
 1522|  2.93k|  if (attr) {
  ------------------
  |  Branch (1522:7): [True: 2.93k, False: 0]
  ------------------
 1523|  2.93k|    const uint8_t *value = stun_attr_get_value(attr);
 1524|  2.93k|    if (value && (stun_attr_get_len(attr) >= 2)) {
  ------------------
  |  Branch (1524:9): [True: 1.98k, False: 945]
  |  Branch (1524:18): [True: 1.35k, False: 633]
  ------------------
 1525|  1.35k|      const uint16_t cn = turn_read_u16(value);
 1526|  1.35k|      if (STUN_VALID_CHANNEL(cn)) {
  ------------------
  |  |  159|  1.35k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (159:34): [True: 636, False: 718]
  |  |  |  Branch (159:53): [True: 44, False: 592]
  |  |  ------------------
  ------------------
 1527|     44|        return cn;
 1528|     44|      }
 1529|  1.35k|    }
 1530|  2.93k|  }
 1531|  2.88k|  return 0;
 1532|  2.93k|}
stun_attr_get_bandwidth:
 1534|     68|band_limit_t stun_attr_get_bandwidth(stun_attr_ref attr) {
 1535|     68|  if (attr) {
  ------------------
  |  Branch (1535:7): [True: 68, False: 0]
  ------------------
 1536|     68|    const uint8_t *value = stun_attr_get_value(attr);
 1537|     68|    if (value && (stun_attr_get_len(attr) >= 4)) {
  ------------------
  |  Branch (1537:9): [True: 33, False: 35]
  |  Branch (1537:18): [True: 20, False: 13]
  ------------------
 1538|     20|      const uint32_t bps = turn_read_u32(value);
 1539|     20|      return (band_limit_t)(bps << 7);
 1540|     20|    }
 1541|     68|  }
 1542|     48|  return 0;
 1543|     68|}
stun_attr_get_reservation_token_value:
 1545|     33|uint64_t stun_attr_get_reservation_token_value(stun_attr_ref attr) {
 1546|     33|  if (attr) {
  ------------------
  |  Branch (1546:7): [True: 33, False: 0]
  ------------------
 1547|     33|    const uint8_t *value = stun_attr_get_value(attr);
 1548|     33|    if (value && (stun_attr_get_len(attr) == 8)) {
  ------------------
  |  Branch (1548:9): [True: 25, False: 8]
  |  Branch (1548:18): [True: 1, False: 24]
  ------------------
 1549|      1|      return turn_read_u64(value);
 1550|      1|    }
 1551|     33|  }
 1552|     32|  return 0;
 1553|     33|}
stun_attr_is_addr:
 1555|   185k|bool stun_attr_is_addr(stun_attr_ref attr) {
 1556|       |
 1557|   185k|  if (attr) {
  ------------------
  |  Branch (1557:7): [True: 185k, False: 0]
  ------------------
 1558|   185k|    switch (stun_attr_get_type(attr)) {
 1559|  13.8k|    case STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS:
  ------------------
  |  |  105|  13.8k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (1559:5): [True: 13.8k, False: 171k]
  ------------------
 1560|  26.6k|    case STUN_ATTRIBUTE_XOR_PEER_ADDRESS:
  ------------------
  |  |  116|  26.6k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  |  Branch (1560:5): [True: 12.8k, False: 172k]
  ------------------
 1561|  39.0k|    case STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS:
  ------------------
  |  |  118|  39.0k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  |  Branch (1561:5): [True: 12.3k, False: 173k]
  ------------------
 1562|  55.0k|    case STUN_ATTRIBUTE_MAPPED_ADDRESS:
  ------------------
  |  |   91|  55.0k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
  |  Branch (1562:5): [True: 15.9k, False: 169k]
  ------------------
 1563|  61.7k|    case STUN_ATTRIBUTE_ALTERNATE_SERVER:
  ------------------
  |  |  110|  61.7k|#define STUN_ATTRIBUTE_ALTERNATE_SERVER (0x8023)
  ------------------
  |  Branch (1563:5): [True: 6.70k, False: 178k]
  ------------------
 1564|  67.7k|    case OLD_STUN_ATTRIBUTE_RESPONSE_ADDRESS:
  ------------------
  |  |   92|  67.7k|#define OLD_STUN_ATTRIBUTE_RESPONSE_ADDRESS (0x0002)
  ------------------
  |  Branch (1564:5): [True: 6.01k, False: 179k]
  ------------------
 1565|  74.3k|    case OLD_STUN_ATTRIBUTE_SOURCE_ADDRESS:
  ------------------
  |  |   94|  74.3k|#define OLD_STUN_ATTRIBUTE_SOURCE_ADDRESS (0x0004)
  ------------------
  |  Branch (1565:5): [True: 6.60k, False: 178k]
  ------------------
 1566|  78.4k|    case OLD_STUN_ATTRIBUTE_CHANGED_ADDRESS:
  ------------------
  |  |   95|  78.4k|#define OLD_STUN_ATTRIBUTE_CHANGED_ADDRESS (0x0005)
  ------------------
  |  Branch (1566:5): [True: 4.15k, False: 181k]
  ------------------
 1567|  83.8k|    case OLD_STUN_ATTRIBUTE_REFLECTED_FROM:
  ------------------
  |  |  101|  83.8k|#define OLD_STUN_ATTRIBUTE_REFLECTED_FROM (0x000B)
  ------------------
  |  Branch (1567:5): [True: 5.36k, False: 180k]
  ------------------
 1568|  91.1k|    case STUN_ATTRIBUTE_RESPONSE_ORIGIN:
  ------------------
  |  |  132|  91.1k|#define STUN_ATTRIBUTE_RESPONSE_ORIGIN (0x802B)
  ------------------
  |  Branch (1568:5): [True: 7.32k, False: 178k]
  ------------------
 1569|  96.4k|    case STUN_ATTRIBUTE_OTHER_ADDRESS:
  ------------------
  |  |  133|  96.4k|#define STUN_ATTRIBUTE_OTHER_ADDRESS (0x802C)
  ------------------
  |  Branch (1569:5): [True: 5.27k, False: 180k]
  ------------------
 1570|  96.4k|      return true;
 1571|      0|      break;
 1572|  88.9k|    default:;
  ------------------
  |  Branch (1572:5): [True: 88.9k, False: 96.4k]
  ------------------
 1573|   185k|    };
 1574|  88.9k|  }
 1575|  88.9k|  return false;
 1576|   185k|}
stun_attr_get_even_port:
 1578|     26|uint8_t stun_attr_get_even_port(stun_attr_ref attr) {
 1579|     26|  if (attr) {
  ------------------
  |  Branch (1579:7): [True: 26, False: 0]
  ------------------
 1580|     26|    const uint8_t *value = stun_attr_get_value(attr);
 1581|     26|    if (value) {
  ------------------
  |  Branch (1581:9): [True: 13, False: 13]
  ------------------
 1582|     13|      if ((uint8_t)(value[0]) > 0x7F) {
  ------------------
  |  Branch (1582:11): [True: 6, False: 7]
  ------------------
 1583|      6|        return 1;
 1584|      6|      }
 1585|     13|    }
 1586|     26|  }
 1587|     20|  return 0;
 1588|     26|}
stun_attr_get_first_by_type_str:
 1598|   157k|stun_attr_ref stun_attr_get_first_by_type_str(const uint8_t *buf, size_t len, uint16_t attr_type) {
 1599|   157k|  stun_attr_ref attr = stun_attr_get_first_str(buf, len);
 1600|  1.67M|  while (attr) {
  ------------------
  |  Branch (1600:10): [True: 1.57M, False: 102k]
  ------------------
 1601|  1.57M|    if (stun_attr_get_type(attr) == attr_type) {
  ------------------
  |  Branch (1601:9): [True: 55.1k, False: 1.51M]
  ------------------
 1602|  55.1k|      return attr;
 1603|  55.1k|    }
 1604|  1.51M|    attr = stun_attr_get_next_str(buf, len, attr);
 1605|  1.51M|  }
 1606|       |
 1607|   102k|  return NULL;
 1608|   157k|}
stun_attr_get_first_str:
 1631|   169k|stun_attr_ref stun_attr_get_first_str(const uint8_t *buf, size_t len) {
 1632|   169k|  const int bufLen = stun_get_command_message_len_str(buf, len);
 1633|   169k|  if (bufLen > STUN_HEADER_LENGTH) {
  ------------------
  |  |   46|   169k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (1633:7): [True: 166k, False: 3.17k]
  ------------------
 1634|   166k|    stun_attr_ref attr = (stun_attr_ref)(buf + STUN_HEADER_LENGTH);
  ------------------
  |  |   46|   166k|#define STUN_HEADER_LENGTH (20)
  ------------------
 1635|   166k|    return stun_attr_check_valid(attr, bufLen - STUN_HEADER_LENGTH);
  ------------------
  |  |   46|   166k|#define STUN_HEADER_LENGTH (20)
  ------------------
 1636|   166k|  }
 1637|       |
 1638|  3.17k|  return NULL;
 1639|   169k|}
stun_attr_get_next_str:
 1641|  1.72M|stun_attr_ref stun_attr_get_next_str(const uint8_t *buf, size_t len, stun_attr_ref prev) {
 1642|  1.72M|  if (!prev) {
  ------------------
  |  Branch (1642:7): [True: 0, False: 1.72M]
  ------------------
 1643|      0|    return stun_attr_get_first_str(buf, len);
 1644|  1.72M|  } else {
 1645|  1.72M|    const uint8_t *end = buf + stun_get_command_message_len_str(buf, len);
 1646|  1.72M|    int attrlen = stun_attr_get_len(prev);
 1647|  1.72M|    const uint16_t rem4 = ((uint16_t)attrlen) & 0x0003;
 1648|  1.72M|    if (rem4) {
  ------------------
  |  Branch (1648:9): [True: 363k, False: 1.36M]
  ------------------
 1649|   363k|      attrlen = attrlen + 4 - (int)rem4;
 1650|   363k|    }
 1651|       |    /* Note the order here: operations on attrlen are untrusted as they may overflow */
 1652|  1.72M|    if (attrlen < end - (const uint8_t *)prev - 4) {
  ------------------
  |  Branch (1652:9): [True: 1.64M, False: 82.5k]
  ------------------
 1653|  1.64M|      const uint8_t *attr_end = (const uint8_t *)prev + 4 + attrlen;
 1654|  1.64M|      return stun_attr_check_valid(attr_end, end - attr_end);
 1655|  1.64M|    }
 1656|  82.5k|    return NULL;
 1657|  1.72M|  }
 1658|  1.72M|}
stun_attr_add_str:
 1660|  72.1k|bool stun_attr_add_str(uint8_t *buf, size_t *len, uint16_t attr, const uint8_t *avalue, int alen) {
 1661|  72.1k|  if (alen < 0) {
  ------------------
  |  Branch (1661:7): [True: 0, False: 72.1k]
  ------------------
 1662|      0|    alen = 0;
 1663|      0|  }
 1664|  72.1k|  uint8_t tmp[1];
 1665|  72.1k|  if (!avalue) {
  ------------------
  |  Branch (1665:7): [True: 1.11k, False: 71.0k]
  ------------------
 1666|  1.11k|    alen = 0;
 1667|  1.11k|    avalue = tmp;
 1668|  1.11k|  }
 1669|  72.1k|  const int clen = stun_get_command_message_len_str(buf, *len);
 1670|  72.1k|  int newlen = clen + 4 + alen;
 1671|  72.1k|  const int newlenrem4 = newlen & 0x00000003;
 1672|  72.1k|  int paddinglen = 0;
 1673|  72.1k|  if (newlenrem4) {
  ------------------
  |  Branch (1673:7): [True: 29.4k, False: 42.6k]
  ------------------
 1674|  29.4k|    paddinglen = 4 - newlenrem4;
 1675|  29.4k|    newlen = newlen + paddinglen;
 1676|  29.4k|  }
 1677|       |
 1678|  72.1k|  if (newlen >= MAX_STUN_MESSAGE_SIZE) {
  ------------------
  |  |  221|  72.1k|#define MAX_STUN_MESSAGE_SIZE (65507)
  ------------------
  |  Branch (1678:7): [True: 0, False: 72.1k]
  ------------------
 1679|      0|    return false;
 1680|      0|  }
 1681|       |
 1682|  72.1k|  uint8_t *attr_start = buf + clen;
 1683|       |
 1684|  72.1k|  stun_set_command_message_len_str(buf, newlen);
 1685|  72.1k|  *len = newlen;
 1686|       |
 1687|  72.1k|  turn_write_u16(attr_start, attr);
 1688|  72.1k|  turn_write_u16(attr_start + 2, (uint16_t)alen);
 1689|  72.1k|  if (alen > 0) {
  ------------------
  |  Branch (1689:7): [True: 71.0k, False: 1.11k]
  ------------------
 1690|  71.0k|    memcpy(attr_start + 4, avalue, alen);
 1691|  71.0k|  }
 1692|       |
 1693|       |  // Write 0 padding to not leak data
 1694|  72.1k|  memset(attr_start + 4 + alen, 0, paddinglen);
 1695|       |
 1696|       |  return true;
 1697|  72.1k|}
stun_attr_add_addr_str:
 1699|  6.68k|bool stun_attr_add_addr_str(uint8_t *buf, size_t *len, uint16_t attr_type, const ioa_addr *ca) {
 1700|       |
 1701|  6.68k|  stun_tid tid;
 1702|  6.68k|  stun_tid_from_message_str(buf, *len, &tid);
 1703|       |
 1704|  6.68k|  int xor_ed = 0;
 1705|  6.68k|  switch (attr_type) {
 1706|  2.22k|  case STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS:
  ------------------
  |  |  105|  2.22k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (1706:3): [True: 2.22k, False: 4.45k]
  ------------------
 1707|  3.34k|  case STUN_ATTRIBUTE_XOR_PEER_ADDRESS:
  ------------------
  |  |  116|  3.34k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  |  Branch (1707:3): [True: 1.11k, False: 5.57k]
  ------------------
 1708|  5.57k|  case STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS:
  ------------------
  |  |  118|  5.57k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  |  Branch (1708:3): [True: 2.22k, False: 4.45k]
  ------------------
 1709|  5.57k|    xor_ed = 1;
 1710|  5.57k|    break;
 1711|  1.11k|  default:;
  ------------------
  |  Branch (1711:3): [True: 1.11k, False: 5.57k]
  ------------------
 1712|  6.68k|  };
 1713|       |
 1714|  6.68k|  ioa_addr public_addr;
 1715|  6.68k|  map_addr_from_private_to_public(ca, &public_addr);
 1716|       |
 1717|  6.68k|  uint8_t cfield[64];
 1718|  6.68k|  int clen = 0;
 1719|  6.68k|  if (stun_addr_encode(&public_addr, cfield, &clen, xor_ed, STUN_MAGIC_COOKIE, tid.tsx_id) < 0) {
  ------------------
  |  |   56|  6.68k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (1719:7): [True: 0, False: 6.68k]
  ------------------
 1720|      0|    return false;
 1721|      0|  }
 1722|       |
 1723|  6.68k|  if (!stun_attr_add_str(buf, len, attr_type, (uint8_t *)(&cfield), clen)) {
  ------------------
  |  Branch (1723:7): [True: 0, False: 6.68k]
  ------------------
 1724|      0|    return false;
 1725|      0|  }
 1726|       |
 1727|  6.68k|  return true;
 1728|  6.68k|}
stun_attr_get_addr_str:
 1731|  9.61k|                            const ioa_addr *default_addr) {
 1732|  9.61k|  stun_tid tid;
 1733|  9.61k|  stun_tid_from_message_str(buf, len, &tid);
 1734|  9.61k|  ioa_addr public_addr;
 1735|       |
 1736|  9.61k|  addr_set_any(ca);
 1737|  9.61k|  addr_set_any(&public_addr);
 1738|       |
 1739|  9.61k|  const int attr_type = stun_attr_get_type(attr);
 1740|  9.61k|  if (attr_type < 0) {
  ------------------
  |  Branch (1740:7): [True: 0, False: 9.61k]
  ------------------
 1741|      0|    return false;
 1742|      0|  }
 1743|       |
 1744|  9.61k|  int xor_ed = 0;
 1745|  9.61k|  switch (attr_type) {
 1746|  1.83k|  case STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS:
  ------------------
  |  |  105|  1.83k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (1746:3): [True: 1.83k, False: 7.77k]
  ------------------
 1747|  3.48k|  case STUN_ATTRIBUTE_XOR_PEER_ADDRESS:
  ------------------
  |  |  116|  3.48k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  |  Branch (1747:3): [True: 1.64k, False: 7.96k]
  ------------------
 1748|  4.99k|  case STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS:
  ------------------
  |  |  118|  4.99k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  |  Branch (1748:3): [True: 1.51k, False: 8.09k]
  ------------------
 1749|  4.99k|    xor_ed = 1;
 1750|  4.99k|    break;
 1751|  4.61k|  default:;
  ------------------
  |  Branch (1751:3): [True: 4.61k, False: 4.99k]
  ------------------
 1752|  9.61k|  };
 1753|       |
 1754|  9.61k|  const uint8_t *cfield = stun_attr_get_value(attr);
 1755|  9.61k|  if (!cfield) {
  ------------------
  |  Branch (1755:7): [True: 6.06k, False: 3.55k]
  ------------------
 1756|  6.06k|    return false;
 1757|  6.06k|  }
 1758|       |
 1759|  3.55k|  if (stun_addr_decode(&public_addr, cfield, stun_attr_get_len(attr), xor_ed, STUN_MAGIC_COOKIE, tid.tsx_id) < 0) {
  ------------------
  |  |   56|  3.55k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (1759:7): [True: 2.57k, False: 975]
  ------------------
 1760|  2.57k|    return false;
 1761|  2.57k|  }
 1762|       |
 1763|    975|  map_addr_from_public_to_private(&public_addr, ca);
 1764|       |
 1765|    975|  if (default_addr && addr_any_no_port(ca) && !addr_any_no_port(default_addr)) {
  ------------------
  |  Branch (1765:7): [True: 0, False: 975]
  |  Branch (1765:23): [True: 0, False: 0]
  |  Branch (1765:47): [True: 0, False: 0]
  ------------------
 1766|      0|    const uint16_t port = addr_get_port(ca);
 1767|      0|    addr_cpy(ca, default_addr);
 1768|      0|    addr_set_port(ca, port);
 1769|      0|  }
 1770|       |
 1771|       |  return true;
 1772|  3.55k|}
stun_attr_get_first_addr_str:
 1775|  9.04k|                                  const ioa_addr *default_addr) {
 1776|  9.04k|  stun_attr_ref attr = stun_attr_get_first_str(buf, len);
 1777|       |
 1778|   172k|  while (attr) {
  ------------------
  |  Branch (1778:10): [True: 163k, False: 8.55k]
  ------------------
 1779|   163k|    if (stun_attr_is_addr(attr) && (attr_type == stun_attr_get_type(attr))) {
  ------------------
  |  Branch (1779:9): [True: 85.2k, False: 78.5k]
  |  Branch (1779:36): [True: 8.31k, False: 76.9k]
  ------------------
 1780|  8.31k|      if (stun_attr_get_addr_str(buf, len, attr, ca, default_addr)) {
  ------------------
  |  Branch (1780:11): [True: 491, False: 7.82k]
  ------------------
 1781|    491|        return true;
 1782|    491|      }
 1783|  8.31k|    }
 1784|   163k|    attr = stun_attr_get_next_str(buf, len, attr);
 1785|   163k|  }
 1786|       |
 1787|  8.55k|  return false;
 1788|  9.04k|}
stun_attr_add_channel_number_str:
 1790|  1.11k|bool stun_attr_add_channel_number_str(uint8_t *buf, size_t *len, uint16_t chnumber) {
 1791|       |
 1792|  1.11k|  uint16_t field[2];
 1793|  1.11k|  field[0] = nswap16(chnumber);
  ------------------
  |  |   86|  1.11k|#define nswap16(s) ntohs(s)
  ------------------
 1794|  1.11k|  field[1] = 0;
 1795|       |
 1796|  1.11k|  return stun_attr_add_str(buf, len, STUN_ATTRIBUTE_CHANNEL_NUMBER, (uint8_t *)(field), sizeof(field));
  ------------------
  |  |  113|  1.11k|#define STUN_ATTRIBUTE_CHANNEL_NUMBER (0x000C)
  ------------------
 1797|  1.11k|}
stun_attr_add_bandwidth_str:
 1799|  1.11k|bool stun_attr_add_bandwidth_str(uint8_t *buf, size_t *len, band_limit_t bps0) {
 1800|       |
 1801|  1.11k|  const uint32_t bps = (uint32_t)(band_limit_t)(bps0 >> 7);
 1802|       |
 1803|  1.11k|  uint32_t field = nswap32(bps);
  ------------------
  |  |   87|  1.11k|#define nswap32(ul) ntohl(ul)
  ------------------
 1804|       |
 1805|  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)
  |  |  ------------------
  |  |  |  |  115|  1.11k|#define STUN_ATTRIBUTE_BANDWIDTH (0x0010)
  |  |  ------------------
  ------------------
 1806|  1.11k|}
stun_attr_add_address_error_code:
 1808|  1.11k|bool stun_attr_add_address_error_code(uint8_t *buf, size_t *len, int requested_address_family, int error_code) {
 1809|  1.11k|  const uint8_t *reason = get_default_reason(error_code);
 1810|       |
 1811|  1.11k|  uint8_t avalue[513] = {0};
 1812|  1.11k|  avalue[0] = (uint8_t)requested_address_family;
 1813|  1.11k|  avalue[1] = 0;
 1814|  1.11k|  avalue[2] = (uint8_t)(error_code / 100);
 1815|  1.11k|  avalue[3] = (uint8_t)(error_code % 100);
 1816|  1.11k|  strncpy((char *)(avalue + 4), (const char *)reason, sizeof(avalue) - 4);
 1817|  1.11k|  avalue[sizeof(avalue) - 1] = 0;
 1818|       |
 1819|       |  /* RFC 8489 Section 14: the declared length excludes padding. */
 1820|  1.11k|  const int alen = 4 + (int)strlen((const char *)(avalue + 4));
 1821|       |
 1822|  1.11k|  return stun_attr_add_str(buf, len, STUN_ATTRIBUTE_ADDRESS_ERROR_CODE, (uint8_t *)avalue, alen);
  ------------------
  |  |  141|  1.11k|#define STUN_ATTRIBUTE_ADDRESS_ERROR_CODE (0x8001)
  ------------------
 1823|  1.11k|}
stun_attr_get_first_channel_number_str:
 1825|  1.13k|uint16_t stun_attr_get_first_channel_number_str(const uint8_t *buf, size_t len) {
 1826|       |
 1827|  1.13k|  stun_attr_ref attr = stun_attr_get_first_str(buf, len);
 1828|  22.5k|  while (attr) {
  ------------------
  |  Branch (1828:10): [True: 21.4k, False: 1.10k]
  ------------------
 1829|  21.4k|    if (stun_attr_get_type(attr) == STUN_ATTRIBUTE_CHANNEL_NUMBER) {
  ------------------
  |  |  113|  21.4k|#define STUN_ATTRIBUTE_CHANNEL_NUMBER (0x000C)
  ------------------
  |  Branch (1829:9): [True: 2.71k, False: 18.7k]
  ------------------
 1830|  2.71k|      const uint16_t ret = stun_attr_get_channel_number(attr);
 1831|  2.71k|      if (STUN_VALID_CHANNEL(ret)) {
  ------------------
  |  |  159|  2.71k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (159:34): [True: 25, False: 2.68k]
  |  |  |  Branch (159:53): [True: 25, False: 0]
  |  |  ------------------
  ------------------
 1832|     25|        return ret;
 1833|     25|      }
 1834|  2.71k|    }
 1835|  21.4k|    attr = stun_attr_get_next_str(buf, len, attr);
 1836|  21.4k|  }
 1837|       |
 1838|  1.10k|  return 0;
 1839|  1.13k|}
stun_attr_add_fingerprint_str:
 1843|  1.11k|bool stun_attr_add_fingerprint_str(uint8_t *buf, size_t *len) {
 1844|  1.11k|  uint32_t crc32 = 0;
 1845|  1.11k|  if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_FINGERPRINT, (uint8_t *)&crc32, 4)) {
  ------------------
  |  |  111|  1.11k|#define STUN_ATTRIBUTE_FINGERPRINT (0x8028)
  ------------------
  |  Branch (1845:7): [True: 0, False: 1.11k]
  ------------------
 1846|      0|    return false;
 1847|      0|  }
 1848|  1.11k|  crc32 = ns_crc32(buf, (int)*len - 8);
 1849|  1.11k|  turn_write_u32(buf + *len - 4, crc32 ^ ((uint32_t)FINGERPRINT_XOR));
  ------------------
  |  |   53|  1.11k|#define FINGERPRINT_XOR 0x5354554e
  ------------------
 1850|       |  return true;
 1851|  1.11k|}
get_hmackey_size:
 1944|  5.29k|size_t get_hmackey_size(SHATYPE shatype) {
 1945|  5.29k|  if (shatype == SHATYPE_SHA256) {
  ------------------
  |  Branch (1945:7): [True: 1.92k, False: 3.36k]
  ------------------
 1946|  1.92k|    return 32;
 1947|  1.92k|  }
 1948|  3.36k|  if (shatype == SHATYPE_SHA384) {
  ------------------
  |  Branch (1948:7): [True: 692, False: 2.67k]
  ------------------
 1949|    692|    return 48;
 1950|    692|  }
 1951|  2.67k|  if (shatype == SHATYPE_SHA512) {
  ------------------
  |  Branch (1951:7): [True: 985, False: 1.68k]
  ------------------
 1952|    985|    return 64;
 1953|    985|  }
 1954|  1.68k|  return 16;
 1955|  2.67k|}
stun_attr_add_integrity_str:
 1966|  6.90k|                                 SHATYPE shatype) {
 1967|  6.90k|  uint8_t hmac[MAXSHASIZE] = {0};
 1968|       |
 1969|  6.90k|  unsigned int shasize;
 1970|       |
 1971|  6.90k|  switch (shatype) {
 1972|  2.53k|  case SHATYPE_SHA256:
  ------------------
  |  Branch (1972:3): [True: 2.53k, False: 4.37k]
  ------------------
 1973|  2.53k|    shasize = SHA256SIZEBYTES;
  ------------------
  |  |  180|  2.53k|#define SHA256SIZEBYTES (32)
  ------------------
 1974|  2.53k|    break;
 1975|    916|  case SHATYPE_SHA384:
  ------------------
  |  Branch (1975:3): [True: 916, False: 5.99k]
  ------------------
 1976|    916|    shasize = SHA384SIZEBYTES;
  ------------------
  |  |  181|    916|#define SHA384SIZEBYTES (48)
  ------------------
 1977|    916|    break;
 1978|  1.30k|  case SHATYPE_SHA512:
  ------------------
  |  Branch (1978:3): [True: 1.30k, False: 5.60k]
  ------------------
 1979|  1.30k|    shasize = SHA512SIZEBYTES;
  ------------------
  |  |  182|  1.30k|#define SHA512SIZEBYTES (64)
  ------------------
 1980|  1.30k|    break;
 1981|  2.15k|  default:
  ------------------
  |  Branch (1981:3): [True: 2.15k, False: 4.75k]
  ------------------
 1982|  2.15k|    shasize = SHA1SIZEBYTES;
  ------------------
  |  |  179|  2.15k|#define SHA1SIZEBYTES (20)
  ------------------
 1983|  6.90k|  };
 1984|       |
 1985|  6.90k|  if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_MESSAGE_INTEGRITY, hmac, shasize)) {
  ------------------
  |  |   98|  6.90k|#define STUN_ATTRIBUTE_MESSAGE_INTEGRITY (0x0008)
  ------------------
  |  Branch (1985:7): [True: 0, False: 6.90k]
  ------------------
 1986|      0|    return false;
 1987|      0|  }
 1988|       |
 1989|  6.90k|  if (ct == TURN_CREDENTIALS_SHORT_TERM) {
  ------------------
  |  Branch (1989:7): [True: 1.72k, False: 5.18k]
  ------------------
 1990|  1.72k|    return stun_calculate_hmac(buf, *len - 4 - shasize, pwd, strlen((char *)pwd), buf + *len - shasize, &shasize,
 1991|  1.72k|                               shatype);
 1992|  5.18k|  } else {
 1993|  5.18k|    return stun_calculate_hmac(buf, *len - 4 - shasize, key, get_hmackey_size(shatype), buf + *len - shasize, &shasize,
 1994|  5.18k|                               shatype);
 1995|  5.18k|  }
 1996|  6.90k|}
stun_attr_add_integrity_by_key_str:
 1999|  3.45k|                                        hmackey_t key, const uint8_t *nonce, SHATYPE shatype) {
 2000|  3.45k|  if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_USERNAME, uname, (int)strlen((const char *)uname))) {
  ------------------
  |  |   96|  3.45k|#define STUN_ATTRIBUTE_USERNAME (0x0006)
  ------------------
  |  Branch (2000:7): [True: 0, False: 3.45k]
  ------------------
 2001|      0|    return false;
 2002|      0|  }
 2003|       |
 2004|  3.45k|  if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_NONCE, nonce, (int)strlen((const char *)nonce))) {
  ------------------
  |  |  103|  3.45k|#define STUN_ATTRIBUTE_NONCE (0x0015)
  ------------------
  |  Branch (2004:7): [True: 0, False: 3.45k]
  ------------------
 2005|      0|    return false;
 2006|      0|  }
 2007|       |
 2008|  3.45k|  if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_REALM, realm, (int)strlen((const char *)realm))) {
  ------------------
  |  |  102|  3.45k|#define STUN_ATTRIBUTE_REALM (0x0014)
  ------------------
  |  Branch (2008:7): [True: 0, False: 3.45k]
  ------------------
 2009|      0|    return false;
 2010|      0|  }
 2011|       |
 2012|  3.45k|  password_t p;
 2013|  3.45k|  return stun_attr_add_integrity_str(TURN_CREDENTIALS_LONG_TERM, buf, len, key, p, shatype);
 2014|  3.45k|}
stun_attr_add_integrity_by_user_str:
 2017|  1.72k|                                         const uint8_t *upwd, const uint8_t *nonce, SHATYPE shatype) {
 2018|  1.72k|  hmackey_t key;
 2019|       |
 2020|  1.72k|  if (!stun_produce_integrity_key_str(uname, realm, upwd, key, shatype)) {
  ------------------
  |  Branch (2020:7): [True: 0, False: 1.72k]
  ------------------
 2021|      0|    return false;
 2022|      0|  }
 2023|       |
 2024|  1.72k|  return stun_attr_add_integrity_by_key_str(buf, len, uname, realm, key, nonce, shatype);
 2025|  1.72k|}
stun_attr_add_integrity_by_user_short_term_str:
 2028|  1.72k|                                                    SHATYPE shatype) {
 2029|  1.72k|  if (stun_attr_add_str(buf, len, STUN_ATTRIBUTE_USERNAME, uname, (int)strlen((const char *)uname))) {
  ------------------
  |  |   96|  1.72k|#define STUN_ATTRIBUTE_USERNAME (0x0006)
  ------------------
  |  Branch (2029:7): [True: 1.72k, False: 0]
  ------------------
 2030|  1.72k|    return false;
 2031|  1.72k|  }
 2032|       |
 2033|      0|  hmackey_t key;
 2034|      0|  return stun_attr_add_integrity_str(TURN_CREDENTIALS_SHORT_TERM, buf, len, key, pwd, shatype);
 2035|  1.72k|}
stun_check_message_integrity_by_key_str:
 2041|  15.6k|                                            password_t pwd, SHATYPE shatype) {
 2042|  15.6k|  stun_attr_ref sar = stun_attr_get_first_by_type_str(buf, len, STUN_ATTRIBUTE_MESSAGE_INTEGRITY);
  ------------------
  |  |   98|  15.6k|#define STUN_ATTRIBUTE_MESSAGE_INTEGRITY (0x0008)
  ------------------
 2043|  15.6k|  if (!sar) {
  ------------------
  |  Branch (2043:7): [True: 14.1k, False: 1.44k]
  ------------------
 2044|  14.1k|    return -1;
 2045|  14.1k|  }
 2046|       |
 2047|  1.44k|  unsigned int shasize = 0;
 2048|  1.44k|  switch (stun_attr_get_len(sar)) {
 2049|    150|  case SHA256SIZEBYTES:
  ------------------
  |  |  180|    150|#define SHA256SIZEBYTES (32)
  ------------------
  |  Branch (2049:3): [True: 150, False: 1.29k]
  ------------------
 2050|    150|    shasize = SHA256SIZEBYTES;
  ------------------
  |  |  180|    150|#define SHA256SIZEBYTES (32)
  ------------------
 2051|    150|    if (shatype != SHATYPE_SHA256) {
  ------------------
  |  Branch (2051:9): [True: 105, False: 45]
  ------------------
 2052|    105|      return -1;
 2053|    105|    }
 2054|     45|    break;
 2055|     50|  case SHA384SIZEBYTES:
  ------------------
  |  |  181|     50|#define SHA384SIZEBYTES (48)
  ------------------
  |  Branch (2055:3): [True: 50, False: 1.39k]
  ------------------
 2056|     50|    shasize = SHA384SIZEBYTES;
  ------------------
  |  |  181|     50|#define SHA384SIZEBYTES (48)
  ------------------
 2057|     50|    if (shatype != SHATYPE_SHA384) {
  ------------------
  |  Branch (2057:9): [True: 40, False: 10]
  ------------------
 2058|     40|      return -1;
 2059|     40|    }
 2060|     10|    break;
 2061|     40|  case SHA512SIZEBYTES:
  ------------------
  |  |  182|     40|#define SHA512SIZEBYTES (64)
  ------------------
  |  Branch (2061:3): [True: 40, False: 1.40k]
  ------------------
 2062|     40|    shasize = SHA512SIZEBYTES;
  ------------------
  |  |  182|     40|#define SHA512SIZEBYTES (64)
  ------------------
 2063|     40|    if (shatype != SHATYPE_SHA512) {
  ------------------
  |  Branch (2063:9): [True: 32, False: 8]
  ------------------
 2064|     32|      return -1;
 2065|     32|    }
 2066|      8|    break;
 2067|    730|  case SHA1SIZEBYTES:
  ------------------
  |  |  179|    730|#define SHA1SIZEBYTES (20)
  ------------------
  |  Branch (2067:3): [True: 730, False: 710]
  ------------------
 2068|    730|    shasize = SHA1SIZEBYTES;
  ------------------
  |  |  179|    730|#define SHA1SIZEBYTES (20)
  ------------------
 2069|    730|    if (shatype != SHATYPE_SHA1) {
  ------------------
  |  Branch (2069:9): [True: 511, False: 219]
  ------------------
 2070|    511|      return -1;
 2071|    511|    }
 2072|    219|    break;
 2073|    470|  default:
  ------------------
  |  Branch (2073:3): [True: 470, False: 970]
  ------------------
 2074|    470|    return -1;
 2075|  1.44k|  };
 2076|       |
 2077|    282|  const int orig_len = stun_get_command_message_len_str(buf, len);
 2078|    282|  if (orig_len < 0) {
  ------------------
  |  Branch (2078:7): [True: 0, False: 282]
  ------------------
 2079|      0|    return -1;
 2080|      0|  }
 2081|       |
 2082|    282|  const int new_len = (int)((const uint8_t *)sar - buf) + 4 + shasize;
 2083|    282|  if (new_len > orig_len) {
  ------------------
  |  Branch (2083:7): [True: 0, False: 282]
  ------------------
 2084|      0|    return -1;
 2085|      0|  }
 2086|       |
 2087|    282|  if (!stun_set_command_message_len_str(buf, new_len)) {
  ------------------
  |  Branch (2087:7): [True: 0, False: 282]
  ------------------
 2088|      0|    return -1;
 2089|      0|  }
 2090|       |
 2091|    282|  int res = 0;
 2092|    282|  uint8_t new_hmac[MAXSHASIZE] = {0};
 2093|    282|  if (ct == TURN_CREDENTIALS_SHORT_TERM) {
  ------------------
  |  Branch (2093:7): [True: 170, False: 112]
  ------------------
 2094|    170|    if (!stun_calculate_hmac(buf, (size_t)new_len - 4 - shasize, pwd, strlen((char *)pwd), new_hmac, &shasize,
  ------------------
  |  Branch (2094:9): [True: 0, False: 170]
  ------------------
 2095|    170|                             shatype)) {
 2096|      0|      res = -1;
 2097|    170|    } else {
 2098|    170|      res = 0;
 2099|    170|    }
 2100|    170|  } else {
 2101|    112|    if (!stun_calculate_hmac(buf, (size_t)new_len - 4 - shasize, key, get_hmackey_size(shatype), new_hmac, &shasize,
  ------------------
  |  Branch (2101:9): [True: 0, False: 112]
  ------------------
 2102|    112|                             shatype)) {
 2103|      0|      res = -1;
 2104|    112|    } else {
 2105|    112|      res = 0;
 2106|    112|    }
 2107|    112|  }
 2108|       |
 2109|    282|  stun_set_command_message_len_str(buf, orig_len);
 2110|    282|  if (res < 0) {
  ------------------
  |  Branch (2110:7): [True: 0, False: 282]
  ------------------
 2111|      0|    return -1;
 2112|      0|  }
 2113|       |
 2114|    282|  const uint8_t *old_hmac = stun_attr_get_value(sar);
 2115|    282|  if (!old_hmac) {
  ------------------
  |  Branch (2115:7): [True: 0, False: 282]
  ------------------
 2116|      0|    return -1;
 2117|      0|  }
 2118|       |
 2119|       |  /* Use constant-time comparison: a short-circuiting memcmp leaks the matching prefix
 2120|       |     length via response timing, allowing byte-by-byte HMAC recovery. */
 2121|    282|  if (0 != CRYPTO_memcmp(old_hmac, new_hmac, shasize)) {
  ------------------
  |  Branch (2121:7): [True: 280, False: 2]
  ------------------
 2122|    280|    return 0;
 2123|    280|  }
 2124|       |
 2125|      2|  return +1;
 2126|    282|}
stun_check_message_integrity_str:
 2132|  15.6k|                                     const uint8_t *realm, const uint8_t *upwd, SHATYPE shatype) {
 2133|  15.6k|  hmackey_t key;
 2134|  15.6k|  password_t pwd;
 2135|       |
 2136|  15.6k|  if (ct == TURN_CREDENTIALS_SHORT_TERM) {
  ------------------
  |  Branch (2136:7): [True: 7.81k, False: 7.81k]
  ------------------
 2137|  7.81k|    strncpy((char *)pwd, (const char *)upwd, sizeof(password_t) - 1);
 2138|  7.81k|    pwd[sizeof(password_t) - 1] = 0;
 2139|  7.81k|  } else if (!stun_produce_integrity_key_str(uname, realm, upwd, key, shatype)) {
  ------------------
  |  Branch (2139:14): [True: 0, False: 7.81k]
  ------------------
 2140|      0|    return -1;
 2141|      0|  }
 2142|       |
 2143|  15.6k|  return stun_check_message_integrity_by_key_str(ct, buf, len, key, pwd, shatype);
 2144|  15.6k|}
stun_attr_get_change_request_str:
 2148|     39|bool stun_attr_get_change_request_str(stun_attr_ref attr, bool *change_ip, bool *change_port) {
 2149|     39|  if (stun_attr_get_len(attr) == 4) {
  ------------------
  |  Branch (2149:7): [True: 10, False: 29]
  ------------------
 2150|     10|    const uint8_t *value = stun_attr_get_value(attr);
 2151|     10|    if (value) {
  ------------------
  |  Branch (2151:9): [True: 10, False: 0]
  ------------------
 2152|     10|      *change_ip = (value[3] & 0x04);
 2153|     10|      *change_port = (value[3] & 0x02);
 2154|     10|      return true;
 2155|     10|    }
 2156|     10|  }
 2157|     29|  return false;
 2158|     39|}
stun_attr_add_change_request_str:
 2160|  1.11k|bool stun_attr_add_change_request_str(uint8_t *buf, size_t *len, bool change_ip, bool change_port) {
 2161|  1.11k|  uint8_t avalue[4] = {0, 0, 0, 0};
 2162|       |
 2163|  1.11k|  if (change_ip) {
  ------------------
  |  Branch (2163:7): [True: 1.11k, False: 0]
  ------------------
 2164|  1.11k|    if (change_port) {
  ------------------
  |  Branch (2164:9): [True: 1.11k, False: 0]
  ------------------
 2165|  1.11k|      avalue[3] = 0x06;
 2166|  1.11k|    } else {
 2167|      0|      avalue[3] = 0x04;
 2168|      0|    }
 2169|  1.11k|  } else if (change_port) {
  ------------------
  |  Branch (2169:14): [True: 0, False: 0]
  ------------------
 2170|      0|    avalue[3] = 0x02;
 2171|      0|  }
 2172|       |
 2173|  1.11k|  return stun_attr_add_str(buf, len, STUN_ATTRIBUTE_CHANGE_REQUEST, avalue, 4);
  ------------------
  |  |   93|  1.11k|#define STUN_ATTRIBUTE_CHANGE_REQUEST (0x0003)
  ------------------
 2174|  1.11k|}
stun_attr_get_response_port_str:
 2176|     35|int stun_attr_get_response_port_str(stun_attr_ref attr) {
 2177|     35|  if (stun_attr_get_len(attr) >= 2) {
  ------------------
  |  Branch (2177:7): [True: 30, False: 5]
  ------------------
 2178|     30|    const uint8_t *value = stun_attr_get_value(attr);
 2179|     30|    if (value) {
  ------------------
  |  Branch (2179:9): [True: 30, False: 0]
  ------------------
 2180|     30|      return turn_read_u16(value);
 2181|     30|    }
 2182|     30|  }
 2183|      5|  return -1;
 2184|     35|}
stun_attr_add_response_port_str:
 2186|  1.11k|bool stun_attr_add_response_port_str(uint8_t *buf, size_t *len, uint16_t port) {
 2187|  1.11k|  uint8_t avalue[4] = {0, 0, 0, 0};
 2188|  1.11k|  turn_write_u16(avalue, port);
 2189|       |
 2190|  1.11k|  return stun_attr_add_str(buf, len, STUN_ATTRIBUTE_RESPONSE_PORT, avalue, 4);
  ------------------
  |  |  131|  1.11k|#define STUN_ATTRIBUTE_RESPONSE_PORT (0x0027)
  ------------------
 2191|  1.11k|}
stun_attr_get_padding_len_str:
 2193|     35|int stun_attr_get_padding_len_str(stun_attr_ref attr) {
 2194|     35|  const int len = stun_attr_get_len(attr);
 2195|     35|  if (len < 0) {
  ------------------
  |  Branch (2195:7): [True: 0, False: 35]
  ------------------
 2196|      0|    return -1;
 2197|      0|  }
 2198|     35|  return (uint16_t)len;
 2199|     35|}
stun_attr_add_padding_str:
 2201|  1.11k|bool stun_attr_add_padding_str(uint8_t *buf, size_t *len, uint16_t padding_len) {
 2202|  1.11k|  uint8_t avalue[0xFFFF];
 2203|  1.11k|  memset(avalue, 0, padding_len);
 2204|       |
 2205|  1.11k|  return stun_attr_add_str(buf, len, STUN_ATTRIBUTE_PADDING, avalue, padding_len);
  ------------------
  |  |  130|  1.11k|#define STUN_ATTRIBUTE_PADDING (0x0026)
  ------------------
 2206|  1.11k|}
ns_turn_msg.c:fuzz_prng_next:
  112|  56.9k|static uint64_t fuzz_prng_next(void) {
  113|  56.9k|  static uint64_t state = UINT64_C(0x9e3779b97f4a7c15);
  114|       |
  115|  56.9k|  state += UINT64_C(0x9e3779b97f4a7c15);
  116|  56.9k|  uint64_t z = state;
  117|  56.9k|  z = (z ^ (z >> 30)) * UINT64_C(0xbf58476d1ce4e5b9);
  118|       |  z = (z ^ (z >> 27)) * UINT64_C(0x94d049bb133111eb);
  119|  56.9k|  return z ^ (z >> 31);
  120|  56.9k|}
ns_turn_msg.c:stun_init_error_response_common_str:
  882|  10.3k|                                                stun_tid *id, bool include_reason_string, bool pad_reason_phrase) {
  883|       |
  884|  10.3k|  if (include_reason_string && (!reason || !strcmp((const char *)reason, "Unknown error"))) {
  ------------------
  |  Branch (884:7): [True: 10.3k, False: 0]
  |  Branch (884:33): [True: 0, False: 10.3k]
  |  Branch (884:44): [True: 0, False: 10.3k]
  ------------------
  885|      0|    reason = get_default_reason(error_code);
  886|      0|  }
  887|       |
  888|  10.3k|  uint8_t avalue[513];
  889|  10.3k|  memset(avalue, 0, sizeof(avalue));
  890|  10.3k|  avalue[0] = 0;
  891|  10.3k|  avalue[1] = 0;
  892|  10.3k|  avalue[2] = (uint8_t)(error_code / 100);
  893|  10.3k|  avalue[3] = (uint8_t)(error_code % 100);
  894|  10.3k|  if (include_reason_string) {
  ------------------
  |  Branch (894:7): [True: 10.3k, False: 0]
  ------------------
  895|  10.3k|    strncpy((char *)(avalue + 4), (const char *)reason, sizeof(avalue) - 4);
  896|  10.3k|  }
  897|  10.3k|  avalue[sizeof(avalue) - 1] = 0;
  898|  10.3k|  int alen = 4 + (int)strlen((const char *)(avalue + 4));
  899|       |
  900|       |  /* RFC 3489 Section 11.2.9 requires a reason phrase length that is a multiple of 4;
  901|       |   * RFC 8489 Section 14 requires the declared length to exclude padding. */
  902|  10.3k|  if (pad_reason_phrase) {
  ------------------
  |  Branch (902:7): [True: 0, False: 10.3k]
  ------------------
  903|      0|    const int rem = alen % 4;
  904|      0|    if (rem) {
  ------------------
  |  Branch (904:9): [True: 0, False: 0]
  ------------------
  905|      0|      alen += (4 - rem);
  906|      0|    }
  907|      0|  }
  908|       |
  909|  10.3k|  stun_attr_add_str(buf, len, STUN_ATTRIBUTE_ERROR_CODE, (uint8_t *)avalue, alen);
  ------------------
  |  |   99|  10.3k|#define STUN_ATTRIBUTE_ERROR_CODE (0x0009)
  ------------------
  910|  10.3k|  if (id) {
  ------------------
  |  Branch (910:7): [True: 10.3k, False: 0]
  ------------------
  911|  10.3k|    stun_tid_message_cpy(buf, id);
  912|  10.3k|  }
  913|  10.3k|}
ns_turn_msg.c:stun_tid_from_string:
 1424|  16.2k|static void stun_tid_from_string(const uint8_t *s, stun_tid *id) {
 1425|  16.2k|  if (s && id) {
  ------------------
  |  Branch (1425:7): [True: 16.2k, False: 0]
  |  Branch (1425:12): [True: 16.2k, False: 0]
  ------------------
 1426|  16.2k|    memcpy(id->tsx_id, s, STUN_TID_SIZE);
  ------------------
  |  |   53|  16.2k|#define STUN_TID_SIZE (12)
  ------------------
 1427|  16.2k|  }
 1428|  16.2k|}
ns_turn_msg.c:stun_tid_string_cpy:
 1418|  29.3k|static void stun_tid_string_cpy(uint8_t *s, const stun_tid *id) {
 1419|  29.3k|  if (s && id) {
  ------------------
  |  Branch (1419:7): [True: 29.3k, False: 0]
  |  Branch (1419:12): [True: 29.3k, False: 0]
  ------------------
 1420|  29.3k|    memcpy(s, id->tsx_id, STUN_TID_SIZE);
  ------------------
  |  |   53|  29.3k|#define STUN_TID_SIZE (12)
  ------------------
 1421|  29.3k|  }
 1422|  29.3k|}
ns_turn_msg.c:turn_random_tid_size:
  154|  18.9k|static void turn_random_tid_size(void *id) {
  155|  18.9k|  uint8_t *ar = (uint8_t *)id;
  156|  18.9k|#if defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
  157|  18.9k|  if (ar) {
  ------------------
  |  Branch (157:7): [True: 18.9k, False: 0]
  ------------------
  158|  75.9k|    for (size_t i = 0; i < 3; ++i) {
  ------------------
  |  Branch (158:24): [True: 56.9k, False: 18.9k]
  ------------------
  159|  56.9k|      const uint32_t r = (uint32_t)turn_random_number();
  160|  56.9k|      memcpy(ar + i * sizeof(r), &r, sizeof(r));
  161|  56.9k|    }
  162|  18.9k|  }
  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|  18.9k|}
ns_turn_msg.c:stun_attr_check_valid:
 1610|  1.80M|static stun_attr_ref stun_attr_check_valid(stun_attr_ref attr, size_t remaining) {
 1611|  1.80M|  if (remaining >= 4) {
  ------------------
  |  Branch (1611:7): [True: 1.80M, False: 110]
  ------------------
 1612|       |    /* Read the size of the attribute */
 1613|  1.80M|    size_t attrlen = stun_attr_get_len(attr);
 1614|  1.80M|    remaining -= 4;
 1615|       |
 1616|       |    /* Round to boundary */
 1617|  1.80M|    const uint16_t rem4 = ((uint16_t)attrlen) & 0x0003;
 1618|  1.80M|    if (rem4) {
  ------------------
  |  Branch (1618:9): [True: 404k, False: 1.40M]
  ------------------
 1619|   404k|      attrlen = attrlen + 4 - (int)rem4;
 1620|   404k|    }
 1621|       |
 1622|       |    /* Check that there's enough space remaining */
 1623|  1.80M|    if (attrlen <= remaining) {
  ------------------
  |  Branch (1623:9): [True: 1.78M, False: 27.8k]
  ------------------
 1624|  1.78M|      return attr;
 1625|  1.78M|    }
 1626|  1.80M|  }
 1627|       |
 1628|  27.9k|  return NULL;
 1629|  1.80M|}
ns_turn_msg.c:stun_set_command_message_len_str:
  537|  72.6k|static bool stun_set_command_message_len_str(uint8_t *buf, int len) {
  538|  72.6k|  if (len < STUN_HEADER_LENGTH) {
  ------------------
  |  |   46|  72.6k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (538:7): [True: 0, False: 72.6k]
  ------------------
  539|      0|    return false;
  540|      0|  }
  541|  72.6k|  turn_write_u16(buf + 2, (uint16_t)(len - STUN_HEADER_LENGTH));
  ------------------
  |  |   46|  72.6k|#define STUN_HEADER_LENGTH (20)
  ------------------
  542|       |  return true;
  543|  72.6k|}
ns_turn_msg.c:ns_crc32:
 1890|  1.50k|static uint32_t ns_crc32(const uint8_t *buffer, uint32_t len) {
 1891|  1.50k|  uint32_t crc = CRC_MASK;
  ------------------
  |  | 1854|  1.50k|#define CRC_MASK 0xFFFFFFFFUL
  ------------------
 1892|  1.16M|  while (len--) {
  ------------------
  |  Branch (1892:10): [True: 1.15M, False: 1.50k]
  ------------------
 1893|  1.15M|    UPDATE_CRC(crc, *buffer++);
  ------------------
  |  | 1856|  1.15M|#define UPDATE_CRC(crc, c) crc = crctable[(uint8_t)crc ^ (uint8_t)(c)] ^ (crc >> 8)
  ------------------
 1894|  1.15M|  }
 1895|  1.50k|  return (~crc);
 1896|  1.50k|}

stun_addr_encode:
   42|  6.68k|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.68k|  if (!cfield || !clen || !ca || !tsx_id) {
  ------------------
  |  Branch (44:7): [True: 0, False: 6.68k]
  |  Branch (44:18): [True: 0, False: 6.68k]
  |  Branch (44:27): [True: 0, False: 6.68k]
  |  Branch (44:34): [True: 0, False: 6.68k]
  ------------------
   45|      0|    return -1;
   46|      0|  }
   47|       |
   48|  6.68k|  if (ca->ss.sa_family == AF_INET || ca->ss.sa_family == 0) {
  ------------------
  |  Branch (48:7): [True: 4.45k, False: 2.22k]
  |  Branch (48:38): [True: 0, False: 2.22k]
  ------------------
   49|       |
   50|       |    /* IPv4 address */
   51|       |
   52|  4.45k|    *clen = 8;
   53|       |
   54|  4.45k|    cfield[0] = 0;
   55|  4.45k|    cfield[1] = 1; // IPv4 family
   56|       |
   57|  4.45k|    if (xor_ed) {
  ------------------
  |  Branch (57:9): [True: 3.34k, False: 1.11k]
  ------------------
   58|       |
   59|       |      /* Port */
   60|  3.34k|      const uint16_t port = (ca->s4.sin_port) ^ nswap16(mc >> 16);
  ------------------
  |  |   86|  3.34k|#define nswap16(s) ntohs(s)
  ------------------
   61|  3.34k|      memcpy(cfield + 2, &port, sizeof(port));
   62|       |
   63|       |      /* Address */
   64|  3.34k|      const uint32_t addr = (ca->s4.sin_addr.s_addr) ^ nswap32(mc);
  ------------------
  |  |   87|  3.34k|#define nswap32(ul) ntohl(ul)
  ------------------
   65|  3.34k|      memcpy(cfield + 4, &addr, sizeof(addr));
   66|       |
   67|  3.34k|    } 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.45k|  } else if (ca->ss.sa_family == AF_INET6) {
  ------------------
  |  Branch (78:14): [True: 2.22k, False: 0]
  ------------------
   79|       |
   80|       |    /* IPv6 address */
   81|       |
   82|  2.22k|    *clen = 20;
   83|       |
   84|  2.22k|    cfield[0] = 0;
   85|  2.22k|    cfield[1] = 2; // IPv6 family
   86|       |
   87|  2.22k|    if (xor_ed) {
  ------------------
  |  Branch (87:9): [True: 2.22k, False: 0]
  ------------------
   88|       |
   89|  2.22k|      unsigned int i;
   90|  2.22k|      uint8_t *dst = ((uint8_t *)cfield) + 4;
   91|  2.22k|      const uint8_t *src = (const uint8_t *)&(ca->s6.sin6_addr);
   92|  2.22k|      uint32_t magic = nswap32(mc);
  ------------------
  |  |   87|  2.22k|#define nswap32(ul) ntohl(ul)
  ------------------
   93|       |
   94|       |      /* Port */
   95|  2.22k|      const uint16_t port = ca->s6.sin6_port ^ nswap16(mc >> 16);
  ------------------
  |  |   86|  2.22k|#define nswap16(s) ntohs(s)
  ------------------
   96|  2.22k|      memcpy(cfield + 2, &port, sizeof(port));
   97|       |
   98|       |      /* Address */
   99|       |
  100|  11.1k|      for (i = 0; i < 4; ++i) {
  ------------------
  |  Branch (100:19): [True: 8.91k, False: 2.22k]
  ------------------
  101|  8.91k|        dst[i] = (uint8_t)(src[i] ^ ((const uint8_t *)&magic)[i]);
  102|  8.91k|      }
  103|  28.9k|      for (i = 0; i < 12; ++i) {
  ------------------
  |  Branch (103:19): [True: 26.7k, False: 2.22k]
  ------------------
  104|  26.7k|        dst[i + 4] = (uint8_t)(src[i + 4] ^ tsx_id[i]);
  105|  26.7k|      }
  106|       |
  107|  2.22k|    } 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.22k|  } else {
  118|      0|    return -1;
  119|      0|  }
  120|       |
  121|  6.68k|  return 0;
  122|  6.68k|}
stun_addr_decode:
  124|  3.55k|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.55k|  if (!cfield || !len || !ca || !tsx_id || (len < 8)) {
  ------------------
  |  Branch (126:7): [True: 0, False: 3.55k]
  |  Branch (126:18): [True: 0, False: 3.55k]
  |  Branch (126:26): [True: 0, False: 3.55k]
  |  Branch (126:33): [True: 0, False: 3.55k]
  |  Branch (126:44): [True: 1.13k, False: 2.42k]
  ------------------
  127|  1.13k|    return -1;
  128|  1.13k|  }
  129|       |
  130|  2.42k|  if (cfield[0] != 0) {
  ------------------
  |  Branch (130:7): [True: 392, False: 2.02k]
  ------------------
  131|    392|    return -1;
  132|    392|  }
  133|       |
  134|  2.02k|  int sa_family;
  135|       |
  136|  2.02k|  if (cfield[1] == 1) {
  ------------------
  |  Branch (136:7): [True: 1.08k, False: 946]
  ------------------
  137|  1.08k|    sa_family = AF_INET;
  138|  1.08k|  } else if (cfield[1] == 2) {
  ------------------
  |  Branch (138:14): [True: 514, False: 432]
  ------------------
  139|    514|    sa_family = AF_INET6;
  140|    514|  } else {
  141|    432|    return -1;
  142|    432|  }
  143|       |
  144|  1.59k|  ca->ss.sa_family = sa_family;
  145|       |
  146|  1.59k|  if (sa_family == AF_INET) {
  ------------------
  |  Branch (146:7): [True: 1.08k, False: 514]
  ------------------
  147|       |
  148|  1.08k|    if (len != 8) {
  ------------------
  |  Branch (148:9): [True: 358, False: 724]
  ------------------
  149|    358|      return -1;
  150|    358|    }
  151|       |
  152|       |    /* IPv4 address */
  153|       |
  154|       |    /* Port */
  155|    724|    memcpy(&ca->s4.sin_port, cfield + 2, sizeof(ca->s4.sin_port));
  156|       |
  157|       |    /* Address */
  158|    724|    memcpy(&ca->s4.sin_addr.s_addr, cfield + 4, sizeof(ca->s4.sin_addr.s_addr));
  159|       |
  160|    724|    if (xor_ed) {
  ------------------
  |  Branch (160:9): [True: 239, False: 485]
  ------------------
  161|    239|      ca->s4.sin_port ^= nswap16(mc >> 16);
  ------------------
  |  |   86|    239|#define nswap16(s) ntohs(s)
  ------------------
  162|    239|      ca->s4.sin_addr.s_addr ^= nswap32(mc);
  ------------------
  |  |   87|    239|#define nswap32(ul) ntohl(ul)
  ------------------
  163|    239|    }
  164|       |
  165|    724|  } else if (sa_family == AF_INET6) {
  ------------------
  |  Branch (165:14): [True: 514, False: 0]
  ------------------
  166|       |
  167|       |    /* IPv6 address */
  168|       |
  169|    514|    if (len != 20) {
  ------------------
  |  Branch (169:9): [True: 263, False: 251]
  ------------------
  170|    263|      return -1;
  171|    263|    }
  172|       |
  173|       |    /* Port */
  174|    251|    memcpy(&ca->s6.sin6_port, cfield + 2, sizeof(ca->s6.sin6_port));
  175|       |
  176|       |    /* Address */
  177|    251|    memcpy(&ca->s6.sin6_addr, ((const uint8_t *)cfield) + 4, 16);
  178|       |
  179|    251|    if (xor_ed) {
  ------------------
  |  Branch (179:9): [True: 126, False: 125]
  ------------------
  180|       |
  181|    126|      unsigned int i;
  182|    126|      uint8_t *dst;
  183|    126|      const uint8_t *src;
  184|    126|      uint32_t magic = nswap32(mc);
  ------------------
  |  |   87|    126|#define nswap32(ul) ntohl(ul)
  ------------------
  185|       |
  186|       |      /* Port */
  187|    126|      ca->s6.sin6_port ^= nswap16(mc >> 16);
  ------------------
  |  |   86|    126|#define nswap16(s) ntohs(s)
  ------------------
  188|       |
  189|       |      /* Address */
  190|    126|      src = ((const uint8_t *)cfield) + 4;
  191|    126|      dst = (uint8_t *)&ca->s6.sin6_addr;
  192|    630|      for (i = 0; i < 4; ++i) {
  ------------------
  |  Branch (192:19): [True: 504, False: 126]
  ------------------
  193|    504|        dst[i] = (uint8_t)(src[i] ^ ((const uint8_t *)&magic)[i]);
  194|    504|      }
  195|  1.63k|      for (i = 0; i < 12; ++i) {
  ------------------
  |  Branch (195:19): [True: 1.51k, False: 126]
  ------------------
  196|  1.51k|        dst[i + 4] = (uint8_t)(src[i + 4] ^ tsx_id[i]);
  197|  1.51k|      }
  198|    126|    }
  199|       |
  200|    251|  } else {
  201|      0|    return -1;
  202|      0|  }
  203|       |
  204|    975|  return 0;
  205|  1.59k|}

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

