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

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

addr_set_any:
   48|  17.8k|void addr_set_any(ioa_addr *addr) {
   49|  17.8k|  if (addr) {
  ------------------
  |  Branch (49:7): [True: 17.8k, False: 0]
  ------------------
   50|  17.8k|    memset(addr, 0, sizeof(ioa_addr));
   51|  17.8k|  }
   52|  17.8k|}
addr_eq_no_port:
  180|  15.0k|int addr_eq_no_port(const ioa_addr *a1, const ioa_addr *a2) {
  181|       |
  182|  15.0k|  if (!a1) {
  ------------------
  |  Branch (182:7): [True: 0, False: 15.0k]
  ------------------
  183|      0|    return (!a2);
  184|  15.0k|  } else if (!a2) {
  ------------------
  |  Branch (184:14): [True: 0, False: 15.0k]
  ------------------
  185|      0|    return (!a1);
  186|      0|  }
  187|       |
  188|  15.0k|  if (a1->ss.sa_family == a2->ss.sa_family) {
  ------------------
  |  Branch (188:7): [True: 7.56k, False: 7.53k]
  ------------------
  189|  7.56k|    if (a1->ss.sa_family == AF_INET) {
  ------------------
  |  Branch (189:9): [True: 5.12k, False: 2.43k]
  ------------------
  190|  5.12k|      if ((int)a1->s4.sin_addr.s_addr == (int)a2->s4.sin_addr.s_addr) {
  ------------------
  |  Branch (190:11): [True: 31, False: 5.09k]
  ------------------
  191|     31|        return 1;
  192|     31|      }
  193|  5.12k|    } else if (a1->ss.sa_family == AF_INET6) {
  ------------------
  |  Branch (193:16): [True: 2.43k, False: 0]
  ------------------
  194|  2.43k|      if (memcmp(&(a1->s6.sin6_addr), &(a2->s6.sin6_addr), sizeof(struct in6_addr)) == 0) {
  ------------------
  |  Branch (194:11): [True: 14, False: 2.42k]
  ------------------
  195|     14|        return 1;
  196|     14|      }
  197|  2.43k|    }
  198|  7.56k|  }
  199|  15.0k|  return 0;
  200|  15.0k|}
make_ioa_addr:
  202|  22.8k|int make_ioa_addr(const uint8_t *saddr0, uint16_t port, ioa_addr *addr) {
  203|       |
  204|  22.8k|  if (!saddr0 || !addr) {
  ------------------
  |  Branch (204:7): [True: 0, False: 22.8k]
  |  Branch (204:18): [True: 0, False: 22.8k]
  ------------------
  205|      0|    return -1;
  206|      0|  }
  207|       |
  208|  22.8k|  char ssaddr[257];
  209|  22.8k|  STRCPY(ssaddr, saddr0);
  ------------------
  |  |  240|  22.8k|  do {                                                                                                                 \
  |  |  241|  22.8k|    if ((const char *)(dst) != (const char *)(src)) {                                                                  \
  |  |  ------------------
  |  |  |  Branch (241:9): [True: 22.8k, False: 0]
  |  |  ------------------
  |  |  242|  22.8k|      if (sizeof(dst) == sizeof(char *))                                                                               \
  |  |  ------------------
  |  |  |  Branch (242:11): [Folded, False: 22.8k]
  |  |  ------------------
  |  |  243|  22.8k|        strcpy(((char *)(dst)), (const char *)(src));                                                                  \
  |  |  244|  22.8k|      else {                                                                                                           \
  |  |  245|  22.8k|        size_t szdst = sizeof((dst));                                                                                  \
  |  |  246|  22.8k|        strncpy((char *)(dst), (const char *)(src), szdst);                                                            \
  |  |  247|  22.8k|        ((char *)(dst))[szdst - 1] = 0;                                                                                \
  |  |  248|  22.8k|      }                                                                                                                \
  |  |  249|  22.8k|    }                                                                                                                  \
  |  |  250|  22.8k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (250:12): [Folded, False: 22.8k]
  |  |  ------------------
  ------------------
  210|       |
  211|  22.8k|  char *saddr = ssaddr;
  212|  22.8k|  while (*saddr == ' ') {
  ------------------
  |  Branch (212:10): [True: 0, False: 22.8k]
  ------------------
  213|      0|    ++saddr;
  214|      0|  }
  215|       |
  216|  22.8k|  size_t len = strlen(saddr);
  217|  22.8k|  while (len > 0) {
  ------------------
  |  Branch (217:10): [True: 19.3k, False: 3.51k]
  ------------------
  218|  19.3k|    if (saddr[len - 1] == ' ') {
  ------------------
  |  Branch (218:9): [True: 0, False: 19.3k]
  ------------------
  219|      0|      saddr[len - 1] = 0;
  220|      0|      --len;
  221|  19.3k|    } else {
  222|  19.3k|      break;
  223|  19.3k|    }
  224|  19.3k|  }
  225|       |
  226|  22.8k|  memset(addr, 0, sizeof(ioa_addr));
  227|  22.8k|  if ((len == 0) || (inet_pton(AF_INET, saddr, &addr->s4.sin_addr) == 1)) {
  ------------------
  |  Branch (227:7): [True: 3.51k, False: 19.3k]
  |  Branch (227:21): [True: 10.5k, False: 8.77k]
  ------------------
  228|  14.0k|    addr->s4.sin_family = AF_INET;
  229|       |#if defined(TURN_HAS_SIN_LEN) /* tested when configured */
  230|       |    addr->s4.sin_len = sizeof(struct sockaddr_in);
  231|       |#endif
  232|  14.0k|    addr->s4.sin_port = nswap16(port);
  ------------------
  |  |   86|  14.0k|#define nswap16(s) ntohs(s)
  ------------------
  233|  14.0k|  } else if (inet_pton(AF_INET6, saddr, &addr->s6.sin6_addr) == 1) {
  ------------------
  |  Branch (233:14): [True: 8.77k, False: 0]
  ------------------
  234|  8.77k|    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.77k|    addr->s6.sin6_port = nswap16(port);
  ------------------
  |  |   86|  8.77k|#define nswap16(s) ntohs(s)
  ------------------
  239|  8.77k|  } 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.8k|  return 0;
  300|  22.8k|}
make_ioa_addr_from_full_string:
  340|  24.5k|int make_ioa_addr_from_full_string(const uint8_t *saddr, uint16_t default_port, ioa_addr *addr) {
  341|  24.5k|  if (!addr) {
  ------------------
  |  Branch (341:7): [True: 1.75k, False: 22.8k]
  ------------------
  342|  1.75k|    return -1;
  343|  1.75k|  }
  344|       |
  345|  22.8k|  int ret = -1;
  346|  22.8k|  uint16_t port = 0;
  347|  22.8k|  char *s = turn_strdup((const char *)saddr);
  ------------------
  |  |  122|  22.8k|#define turn_strdup(s) turn_strdup_impl((s), __FILE__, __LINE__)
  ------------------
  348|  22.8k|  char *sa = get_addr_string_and_port(s, &port);
  349|  22.8k|  if (sa) {
  ------------------
  |  Branch (349:7): [True: 22.8k, False: 0]
  ------------------
  350|  22.8k|    if (port < 1) {
  ------------------
  |  Branch (350:9): [True: 14.4k, False: 8.40k]
  ------------------
  351|  14.4k|      port = default_port;
  352|  14.4k|    }
  353|  22.8k|    ret = make_ioa_addr((uint8_t *)sa, port, addr);
  354|  22.8k|  }
  355|  22.8k|  free(s);
  356|  22.8k|  return ret;
  357|  24.5k|}
addr_set_port:
  407|     45|void addr_set_port(ioa_addr *addr, uint16_t port) {
  408|     45|  if (addr) {
  ------------------
  |  Branch (408:7): [True: 45, False: 0]
  ------------------
  409|     45|    if (addr->s4.sin_family == AF_INET) {
  ------------------
  |  Branch (409:9): [True: 31, False: 14]
  ------------------
  410|     31|      addr->s4.sin_port = nswap16(port);
  ------------------
  |  |   86|     31|#define nswap16(s) ntohs(s)
  ------------------
  411|     31|    } else if (addr->s6.sin6_family == AF_INET6) {
  ------------------
  |  Branch (411:16): [True: 14, False: 0]
  ------------------
  412|       |      addr->s6.sin6_port = nswap16(port);
  ------------------
  |  |   86|     14|#define nswap16(s) ntohs(s)
  ------------------
  413|     14|    }
  414|     45|  }
  415|     45|}
addr_get_port:
  417|     45|uint16_t addr_get_port(const ioa_addr *addr) {
  418|     45|  if (!addr) {
  ------------------
  |  Branch (418:7): [True: 0, False: 45]
  ------------------
  419|      0|    return 0;
  420|      0|  }
  421|       |
  422|     45|  if (addr->s4.sin_family == AF_INET) {
  ------------------
  |  Branch (422:7): [True: 31, False: 14]
  ------------------
  423|     31|    return nswap16(addr->s4.sin_port);
  ------------------
  |  |   86|     31|#define nswap16(s) ntohs(s)
  ------------------
  424|     31|  } else if (addr->s6.sin6_family == AF_INET6) {
  ------------------
  |  Branch (424:14): [True: 14, False: 0]
  ------------------
  425|     14|    return nswap16(addr->s6.sin6_port);
  ------------------
  |  |   86|     14|#define nswap16(s) ntohs(s)
  ------------------
  426|     14|  }
  427|      0|  return 0;
  428|     45|}
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|    969|void map_addr_from_public_to_private(const ioa_addr *public_addr, ioa_addr *private_addr) {
  689|    969|  size_t i;
  690|  2.83k|  for (i = 0; i < mcount; ++i) {
  ------------------
  |  Branch (690:15): [True: 1.90k, False: 924]
  ------------------
  691|  1.90k|    if (addr_eq_no_port(public_addr, public_addrs[i])) {
  ------------------
  |  Branch (691:9): [True: 45, False: 1.86k]
  ------------------
  692|     45|      addr_cpy(private_addr, private_addrs[i]);
  693|     45|      addr_set_port(private_addr, addr_get_port(public_addr));
  694|     45|      return;
  695|     45|    }
  696|  1.90k|  }
  697|    924|  addr_cpy(private_addr, public_addr);
  698|    924|}
map_addr_from_private_to_public:
  700|  6.59k|void map_addr_from_private_to_public(const ioa_addr *private_addr, ioa_addr *public_addr) {
  701|  6.59k|  size_t i;
  702|  19.7k|  for (i = 0; i < mcount; ++i) {
  ------------------
  |  Branch (702:15): [True: 13.1k, False: 6.59k]
  ------------------
  703|  13.1k|    if (addr_eq_no_port(private_addr, private_addrs[i])) {
  ------------------
  |  Branch (703:9): [True: 0, False: 13.1k]
  ------------------
  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.1k|  }
  709|  6.59k|  addr_cpy(public_addr, private_addr);
  710|  6.59k|}
ns_turn_ioaddr.c:get_addr_string_and_port:
  302|  22.8k|static char *get_addr_string_and_port(char *s0, uint16_t *port) {
  303|  22.8k|  char *s = s0;
  304|  26.3k|  while (*s && (*s == ' ')) {
  ------------------
  |  Branch (304:10): [True: 24.5k, False: 1.75k]
  |  Branch (304:16): [True: 3.51k, False: 21.0k]
  ------------------
  305|  3.51k|    ++s;
  306|  3.51k|  }
  307|  22.8k|  if (*s == '[') {
  ------------------
  |  Branch (307:7): [True: 8.77k, False: 14.0k]
  ------------------
  308|  8.77k|    ++s;
  309|  8.77k|    char *tail = strstr(s, "]");
  310|  8.77k|    if (tail) {
  ------------------
  |  Branch (310:9): [True: 8.77k, False: 0]
  ------------------
  311|  8.77k|      *tail = 0;
  312|  8.77k|      ++tail;
  313|  12.2k|      while (*tail && (*tail == ' ')) {
  ------------------
  |  Branch (313:14): [True: 7.02k, False: 5.26k]
  |  Branch (313:23): [True: 3.51k, False: 3.51k]
  ------------------
  314|  3.51k|        ++tail;
  315|  3.51k|      }
  316|  8.77k|      if (*tail == ':') {
  ------------------
  |  Branch (316:11): [True: 3.51k, False: 5.26k]
  ------------------
  317|  3.51k|        ++tail;
  318|  3.51k|        *port = atoi(tail);
  319|  3.51k|        return s;
  320|  5.26k|      } else if (*tail == 0) {
  ------------------
  |  Branch (320:18): [True: 5.26k, False: 0]
  ------------------
  321|  5.26k|        *port = 0;
  322|  5.26k|        return s;
  323|  5.26k|      }
  324|  8.77k|    }
  325|  14.0k|  } else {
  326|  14.0k|    char *tail = strstr(s, ":");
  327|  14.0k|    if (tail) {
  ------------------
  |  Branch (327:9): [True: 8.77k, False: 5.26k]
  ------------------
  328|  8.77k|      *tail = 0;
  329|  8.77k|      ++tail;
  330|  8.77k|      *port = atoi(tail);
  331|  8.77k|      return s;
  332|  8.77k|    } else {
  333|  5.26k|      *port = 0;
  334|  5.26k|      return s;
  335|  5.26k|    }
  336|  14.0k|  }
  337|      0|  return NULL;
  338|  22.8k|}

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

turn_random_number:
  123|  57.9k|long turn_random_number(void) {
  124|  57.9k|  long ret = 0;
  125|  57.9k|#if defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
  126|  57.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|  57.9k|  return ret;
  136|  57.9k|}
stun_calculate_hmac:
  174|  7.31k|                         unsigned int *hmac_len, SHATYPE shatype) {
  175|  7.31k|  ERR_clear_error();
  176|  7.31k|  UNUSED_ARG(shatype);
  ------------------
  |  |  216|  7.31k|  do {                                                                                                                 \
  |  |  217|  7.31k|    A = A;                                                                                                             \
  |  |  218|  7.31k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (218:12): [Folded, False: 7.31k]
  |  |  ------------------
  ------------------
  177|       |
  178|  7.31k|  if (shatype == SHATYPE_SHA256) {
  ------------------
  |  Branch (178:7): [True: 2.40k, False: 4.90k]
  ------------------
  179|  2.40k|#if !defined(OPENSSL_NO_SHA256) && defined(SHA256_DIGEST_LENGTH)
  180|  2.40k|    if (!HMAC(EVP_sha256(), key, (int)keylen, buf, len, hmac, hmac_len)) {
  ------------------
  |  Branch (180:9): [True: 0, False: 2.40k]
  ------------------
  181|      0|      return false;
  182|      0|    }
  183|       |#else
  184|       |    fprintf(stderr, "SHA256 is not supported\n");
  185|       |    return false;
  186|       |#endif
  187|  4.90k|  } else if (shatype == SHATYPE_SHA384) {
  ------------------
  |  Branch (187:14): [True: 976, False: 3.93k]
  ------------------
  188|    976|#if !defined(OPENSSL_NO_SHA384) && defined(SHA384_DIGEST_LENGTH)
  189|    976|    if (!HMAC(EVP_sha384(), key, (int)keylen, buf, len, hmac, hmac_len)) {
  ------------------
  |  Branch (189:9): [True: 0, False: 976]
  ------------------
  190|      0|      return false;
  191|      0|    }
  192|       |#else
  193|       |    fprintf(stderr, "SHA384 is not supported\n");
  194|       |    return false;
  195|       |#endif
  196|  3.93k|  } else if (shatype == SHATYPE_SHA512) {
  ------------------
  |  Branch (196:14): [True: 1.24k, False: 2.68k]
  ------------------
  197|  1.24k|#if !defined(OPENSSL_NO_SHA512) && defined(SHA512_DIGEST_LENGTH)
  198|  1.24k|    if (!HMAC(EVP_sha512(), key, (int)keylen, buf, len, hmac, hmac_len)) {
  ------------------
  |  Branch (198:9): [True: 0, False: 1.24k]
  ------------------
  199|      0|      return false;
  200|      0|    }
  201|       |#else
  202|       |    fprintf(stderr, "SHA512 is not supported\n");
  203|       |    return false;
  204|       |#endif
  205|  2.68k|  } else if (!HMAC(EVP_sha1(), key, (int)keylen, buf, len, hmac, hmac_len)) {
  ------------------
  |  Branch (205:14): [True: 0, False: 2.68k]
  ------------------
  206|      0|    return false;
  207|      0|  }
  208|       |
  209|  7.31k|  return true;
  210|  7.31k|}
stun_produce_integrity_key_str:
  340|  9.59k|                                    SHATYPE shatype) {
  341|  9.59k|  bool ret;
  342|       |
  343|  9.59k|  ERR_clear_error();
  344|  9.59k|  UNUSED_ARG(shatype);
  ------------------
  |  |  216|  9.59k|  do {                                                                                                                 \
  |  |  217|  9.59k|    A = A;                                                                                                             \
  |  |  218|  9.59k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (218:12): [Folded, False: 9.59k]
  |  |  ------------------
  ------------------
  345|       |
  346|  9.59k|  const size_t ulen = strlen((const char *)uname);
  347|  9.59k|  const size_t rlen = strlen((const char *)realm);
  348|  9.59k|  const size_t plen = strlen((const char *)upwd);
  349|  9.59k|  const size_t sz = ulen + 1 + rlen + 1 + plen + 1 + 10;
  350|  9.59k|  const size_t strl = ulen + 1 + rlen + 1 + plen;
  351|  9.59k|  uint8_t *str = (uint8_t *)turn_malloc(sz + 1);
  ------------------
  |  |  119|  9.59k|#define turn_malloc(sz) turn_malloc_impl((sz), __FILE__, __LINE__)
  ------------------
  352|       |
  353|  9.59k|  strncpy((char *)str, (const char *)uname, sz);
  354|  9.59k|  str[ulen] = ':';
  355|  9.59k|  strncpy((char *)str + ulen + 1, (const char *)realm, sz - ulen - 1);
  356|  9.59k|  str[ulen + 1 + rlen] = ':';
  357|  9.59k|  strncpy((char *)str + ulen + 1 + rlen + 1, (const char *)upwd, sz - ulen - 1 - rlen - 1);
  358|  9.59k|  str[strl] = 0;
  359|       |
  360|  9.59k|  if (shatype == SHATYPE_SHA256) {
  ------------------
  |  Branch (360:7): [True: 3.73k, False: 5.86k]
  ------------------
  361|  3.73k|#if !defined(OPENSSL_NO_SHA256) && defined(SHA256_DIGEST_LENGTH)
  362|  3.73k|    unsigned int keylen = 0;
  363|  3.73k|    EVP_MD_CTX *ctx = EVP_MD_CTX_new();
  364|  3.73k|    EVP_DigestInit(ctx, EVP_sha256());
  365|  3.73k|    EVP_DigestUpdate(ctx, str, strl);
  366|  3.73k|    EVP_DigestFinal(ctx, key, &keylen);
  367|  3.73k|    EVP_MD_CTX_free(ctx);
  368|  3.73k|    ret = true;
  369|       |#else
  370|       |    fprintf(stderr, "SHA256 is not supported\n");
  371|       |    ret = false;
  372|       |#endif
  373|  5.86k|  } else if (shatype == SHATYPE_SHA384) {
  ------------------
  |  Branch (373:14): [True: 1.80k, False: 4.05k]
  ------------------
  374|  1.80k|#if !defined(OPENSSL_NO_SHA384) && defined(SHA384_DIGEST_LENGTH)
  375|  1.80k|    unsigned int keylen = 0;
  376|  1.80k|    EVP_MD_CTX *ctx = EVP_MD_CTX_new();
  377|  1.80k|    EVP_DigestInit(ctx, EVP_sha384());
  378|  1.80k|    EVP_DigestUpdate(ctx, str, strl);
  379|  1.80k|    EVP_DigestFinal(ctx, key, &keylen);
  380|  1.80k|    EVP_MD_CTX_free(ctx);
  381|  1.80k|    ret = true;
  382|       |#else
  383|       |    fprintf(stderr, "SHA384 is not supported\n");
  384|       |    ret = false;
  385|       |#endif
  386|  4.05k|  } else if (shatype == SHATYPE_SHA512) {
  ------------------
  |  Branch (386:14): [True: 1.87k, False: 2.18k]
  ------------------
  387|  1.87k|#if !defined(OPENSSL_NO_SHA512) && defined(SHA512_DIGEST_LENGTH)
  388|  1.87k|    unsigned int keylen = 0;
  389|  1.87k|    EVP_MD_CTX *ctx = EVP_MD_CTX_new();
  390|  1.87k|    EVP_DigestInit(ctx, EVP_sha512());
  391|  1.87k|    EVP_DigestUpdate(ctx, str, strl);
  392|  1.87k|    EVP_DigestFinal(ctx, key, &keylen);
  393|  1.87k|    EVP_MD_CTX_free(ctx);
  394|  1.87k|    ret = true;
  395|       |#else
  396|       |    fprintf(stderr, "SHA512 is not supported\n");
  397|       |    ret = false;
  398|       |#endif
  399|  2.18k|  } else {
  400|  2.18k|#if OPENSSL_VERSION_NUMBER >= 0x30000000L
  401|  2.18k|    unsigned int keylen = 0;
  402|  2.18k|    EVP_MD_CTX *ctx = EVP_MD_CTX_new();
  403|  2.18k|    if (EVP_default_properties_is_fips_enabled(NULL)) {
  ------------------
  |  Branch (403:9): [True: 0, False: 2.18k]
  ------------------
  404|      0|      EVP_default_properties_enable_fips(NULL, 0);
  405|      0|    }
  406|  2.18k|    EVP_DigestInit_ex(ctx, EVP_md5(), NULL);
  407|  2.18k|    EVP_DigestUpdate(ctx, str, strl);
  408|  2.18k|    EVP_DigestFinal(ctx, key, &keylen);
  409|  2.18k|    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.18k|    ret = true;
  424|  2.18k|  }
  425|       |
  426|  9.59k|  free(str);
  427|       |
  428|  9.59k|  return ret;
  429|  9.59k|}
stun_get_command_message_len_str:
  523|  1.87M|int stun_get_command_message_len_str(const uint8_t *buf, size_t len) {
  524|  1.87M|  if (len < STUN_HEADER_LENGTH) {
  ------------------
  |  |   46|  1.87M|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (524:7): [True: 22, False: 1.87M]
  ------------------
  525|     22|    return -1;
  526|     22|  }
  527|       |
  528|       |  /* Validate the size the buffer claims to be */
  529|  1.87M|  const size_t bufLen = (size_t)(turn_read_u16(buf + 2) + STUN_HEADER_LENGTH);
  ------------------
  |  |   46|  1.87M|#define STUN_HEADER_LENGTH (20)
  ------------------
  530|  1.87M|  if (bufLen > len) {
  ------------------
  |  Branch (530:7): [True: 1.06k, False: 1.87M]
  ------------------
  531|  1.06k|    return -1;
  532|  1.06k|  }
  533|       |
  534|  1.87M|  return bufLen;
  535|  1.87M|}
stun_make_type:
  547|  19.3k|uint16_t stun_make_type(uint16_t method) {
  548|  19.3k|  method = method & 0x0FFF;
  549|  19.3k|  return ((method & 0x000F) | ((method & 0x0070) << 1) | ((method & 0x0380) << 2) | ((method & 0x0C00) << 2));
  550|  19.3k|}
stun_get_method_str:
  552|  5.19k|uint16_t stun_get_method_str(const uint8_t *buf, size_t len) {
  553|  5.19k|  if (!buf || len < 2) {
  ------------------
  |  Branch (553:7): [True: 0, False: 5.19k]
  |  Branch (553:15): [True: 0, False: 5.19k]
  ------------------
  554|      0|    return (uint16_t)-1;
  555|      0|  }
  556|       |
  557|  5.19k|  const uint16_t tt = turn_read_u16(buf);
  558|       |
  559|  5.19k|  return (tt & 0x000F) | ((tt & 0x00E0) >> 1) | ((tt & 0x0E00) >> 2) | ((tt & 0x3000) >> 2);
  560|  5.19k|}
stun_get_msg_type_str:
  562|  24.1k|uint16_t stun_get_msg_type_str(const uint8_t *buf, size_t len) {
  563|  24.1k|  if (!buf || len < 2) {
  ------------------
  |  Branch (563:7): [True: 0, False: 24.1k]
  |  Branch (563:15): [True: 0, False: 24.1k]
  ------------------
  564|      0|    return (uint16_t)-1;
  565|      0|  }
  566|  24.1k|  return (turn_read_u16(buf) & 0x3FFF);
  567|  24.1k|}
is_channel_msg_str:
  569|  24.0k|bool is_channel_msg_str(const uint8_t *buf, size_t blen) {
  570|  24.0k|  return (buf && blen >= 4 && STUN_VALID_CHANNEL(turn_read_u16(buf)));
  ------------------
  |  |  163|  24.0k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (163:34): [True: 0, False: 24.0k]
  |  |  |  Branch (163:53): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (570:11): [True: 24.0k, False: 0]
  |  Branch (570:18): [True: 24.0k, False: 0]
  ------------------
  571|  24.0k|}
stun_is_command_message_str:
  575|  13.2k|bool stun_is_command_message_str(const uint8_t *buf, size_t blen) {
  576|  13.2k|  if (buf && blen >= STUN_HEADER_LENGTH) {
  ------------------
  |  |   46|  13.2k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (576:7): [True: 13.2k, False: 0]
  |  Branch (576:14): [True: 13.2k, False: 11]
  ------------------
  577|  13.2k|    if (!STUN_VALID_CHANNEL(turn_read_u16(buf))) {
  ------------------
  |  |  163|  13.2k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (163:34): [True: 361, False: 12.8k]
  |  |  |  Branch (163:53): [True: 96, False: 265]
  |  |  ------------------
  ------------------
  578|  13.1k|      if ((((uint8_t)buf[0]) & ((uint8_t)(0xC0))) == 0) {
  ------------------
  |  Branch (578:11): [True: 12.8k, False: 265]
  ------------------
  579|  12.8k|        if (turn_read_u32(buf + 4) == STUN_MAGIC_COOKIE) {
  ------------------
  |  |   60|  12.8k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (579:13): [True: 9.62k, False: 3.23k]
  ------------------
  580|  9.62k|          const uint16_t len = turn_read_u16(buf + 2);
  581|  9.62k|          if ((len & 0x0003) == 0) {
  ------------------
  |  Branch (581:15): [True: 9.43k, False: 192]
  ------------------
  582|  9.43k|            if ((size_t)(len + STUN_HEADER_LENGTH) == blen) {
  ------------------
  |  |   46|  9.43k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (582:17): [True: 8.89k, False: 542]
  ------------------
  583|  8.89k|              return true;
  584|  8.89k|            }
  585|  9.43k|          }
  586|  9.62k|        }
  587|  12.8k|      }
  588|  13.1k|    }
  589|  13.2k|  }
  590|  4.33k|  return false;
  591|  13.2k|}
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))) {
  ------------------
  |  |  163|  1.56k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (163:34): [True: 45, False: 1.52k]
  |  |  |  Branch (163:53): [True: 12, False: 33]
  |  |  ------------------
  ------------------
  596|  1.55k|      if ((((uint8_t)buf[0]) & ((uint8_t)(0xC0))) == 0) {
  ------------------
  |  Branch (596:11): [True: 1.52k, False: 33]
  ------------------
  597|  1.52k|        const uint32_t msg_cookie = turn_read_u32(buf + 4);
  598|  1.52k|        if (msg_cookie != STUN_MAGIC_COOKIE) {
  ------------------
  |  |   60|  1.52k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (598:13): [True: 317, False: 1.20k]
  ------------------
  599|    317|          const uint16_t len = turn_read_u16(buf + 2);
  600|    317|          if ((len & 0x0003) == 0) {
  ------------------
  |  Branch (600:15): [True: 250, False: 67]
  ------------------
  601|    250|            if ((size_t)(len + STUN_HEADER_LENGTH) == blen) {
  ------------------
  |  |   46|    250|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (601:17): [True: 174, False: 76]
  ------------------
  602|    174|              *cookie = msg_cookie;
  603|    174|              return true;
  604|    174|            }
  605|    250|          }
  606|    317|        }
  607|  1.52k|      }
  608|  1.55k|    }
  609|  1.56k|  }
  610|  1.39k|  return false;
  611|  1.56k|}
stun_is_command_message_full_check_str:
  614|  8.18k|                                            bool *fingerprint_present) {
  615|  8.18k|  if (!stun_is_command_message_str(buf, blen)) {
  ------------------
  |  Branch (615:7): [True: 2.62k, False: 5.56k]
  ------------------
  616|  2.62k|    return false;
  617|  2.62k|  }
  618|  5.56k|  stun_attr_ref sar = stun_attr_get_first_by_type_str(buf, blen, STUN_ATTRIBUTE_FINGERPRINT);
  ------------------
  |  |  115|  5.56k|#define STUN_ATTRIBUTE_FINGERPRINT (0x8028)
  ------------------
  619|  5.56k|  if (!sar) {
  ------------------
  |  Branch (619:7): [True: 5.02k, False: 535]
  ------------------
  620|  5.02k|    if (fingerprint_present) {
  ------------------
  |  Branch (620:9): [True: 0, False: 5.02k]
  ------------------
  621|      0|      *fingerprint_present = false;
  622|      0|    }
  623|  5.02k|    if (stun_get_method_str(buf, blen) == STUN_METHOD_BINDING) {
  ------------------
  |  |   81|  5.02k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
  |  Branch (623:9): [True: 200, False: 4.82k]
  ------------------
  624|    200|      return true;
  625|    200|    }
  626|  4.82k|    return !must_check_fingerprint;
  627|  5.02k|  }
  628|    535|  if (stun_attr_get_len(sar) != 4) {
  ------------------
  |  Branch (628:7): [True: 130, False: 405]
  ------------------
  629|    130|    return false;
  630|    130|  }
  631|    405|  const uint8_t *fingerprint = stun_attr_get_value(sar);
  632|    405|  if (!fingerprint) {
  ------------------
  |  Branch (632:7): [True: 0, False: 405]
  ------------------
  633|      0|    return !must_check_fingerprint;
  634|      0|  }
  635|    405|  const uint32_t crc32len = (uint32_t)((fingerprint - buf) - 4);
  636|    405|  const bool ret = (turn_read_u32(fingerprint) == (ns_crc32(buf, crc32len) ^ ((uint32_t)FINGERPRINT_XOR)));
  ------------------
  |  |   53|    405|#define FINGERPRINT_XOR 0x5354554e
  ------------------
  637|    405|  if (ret && fingerprint_present) {
  ------------------
  |  Branch (637:7): [True: 5, False: 400]
  |  Branch (637:14): [True: 0, False: 5]
  ------------------
  638|      0|    *fingerprint_present = ret;
  639|      0|  }
  640|    405|  return ret;
  641|    405|}
stun_is_request_str:
  643|    174|bool stun_is_request_str(const uint8_t *buf, size_t len) {
  644|    174|  if (is_channel_msg_str(buf, len)) {
  ------------------
  |  Branch (644:7): [True: 0, False: 174]
  ------------------
  645|      0|    return false;
  646|      0|  }
  647|    174|  return IS_STUN_REQUEST(stun_get_msg_type_str(buf, len));
  ------------------
  |  |   62|    174|#define IS_STUN_REQUEST(msg_type) (((msg_type)&0x0110) == 0x0000)
  ------------------
  648|    174|}
stun_is_success_response_str:
  650|    174|bool stun_is_success_response_str(const uint8_t *buf, size_t len) {
  651|    174|  if (is_channel_msg_str(buf, len)) {
  ------------------
  |  Branch (651:7): [True: 0, False: 174]
  ------------------
  652|      0|    return false;
  653|      0|  }
  654|    174|  return IS_STUN_SUCCESS_RESP(stun_get_msg_type_str(buf, len));
  ------------------
  |  |   64|    174|#define IS_STUN_SUCCESS_RESP(msg_type) (((msg_type)&0x0110) == 0x0100)
  ------------------
  655|    174|}
stun_is_error_response_str:
  657|  23.4k|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.4k|  if (is_channel_msg_str(buf, len)) {
  ------------------
  |  Branch (658:7): [True: 0, False: 23.4k]
  ------------------
  659|      0|    return false;
  660|      0|  }
  661|  23.4k|  if (IS_STUN_ERR_RESP(stun_get_msg_type_str(buf, len))) {
  ------------------
  |  |   65|  23.4k|#define IS_STUN_ERR_RESP(msg_type) (((msg_type)&0x0110) == 0x0110)
  |  |  ------------------
  |  |  |  Branch (65:36): [True: 21.7k, False: 1.72k]
  |  |  ------------------
  ------------------
  662|  21.7k|    if (err_code) {
  ------------------
  |  Branch (662:9): [True: 21.7k, False: 0]
  ------------------
  663|  21.7k|      stun_attr_ref sar = stun_attr_get_first_by_type_str(buf, len, STUN_ATTRIBUTE_ERROR_CODE);
  ------------------
  |  |  103|  21.7k|#define STUN_ATTRIBUTE_ERROR_CODE (0x0009)
  ------------------
  664|  21.7k|      if (sar) {
  ------------------
  |  Branch (664:11): [True: 21.3k, False: 445]
  ------------------
  665|  21.3k|        if (stun_attr_get_len(sar) >= 4) {
  ------------------
  |  Branch (665:13): [True: 21.2k, False: 36]
  ------------------
  666|  21.2k|          const uint8_t *val = (const uint8_t *)stun_attr_get_value(sar);
  667|  21.2k|          *err_code = (int)(val[2] * 100 + val[3]);
  668|  21.2k|          if (err_msg && err_msg_size > 0) {
  ------------------
  |  Branch (668:15): [True: 21.2k, False: 0]
  |  Branch (668:26): [True: 21.2k, False: 0]
  ------------------
  669|  21.2k|            err_msg[0] = 0;
  670|  21.2k|            if (stun_attr_get_len(sar) > 4) {
  ------------------
  |  Branch (670:17): [True: 21.1k, False: 133]
  ------------------
  671|  21.1k|              size_t msg_len = stun_attr_get_len(sar) - 4;
  672|  21.1k|              if (msg_len > (err_msg_size - 1)) {
  ------------------
  |  Branch (672:19): [True: 19, False: 21.1k]
  ------------------
  673|     19|                msg_len = err_msg_size - 1;
  674|     19|              }
  675|  21.1k|              memcpy(err_msg, val + 4, msg_len);
  676|  21.1k|              err_msg[msg_len] = 0;
  677|  21.1k|            }
  678|  21.2k|          }
  679|  21.2k|        }
  680|  21.3k|      }
  681|  21.7k|    }
  682|  21.7k|    return true;
  683|  21.7k|  }
  684|  1.72k|  return false;
  685|  23.4k|}
stun_is_challenge_response_str:
  689|  22.1k|                                    bool *oauth) {
  690|  22.1k|  const bool ret = stun_is_error_response_str(buf, len, err_code, err_msg, err_msg_size);
  691|       |
  692|  22.1k|  if (ret && (((*err_code) == 401) || ((*err_code) == 438))) {
  ------------------
  |  Branch (692:7): [True: 21.3k, False: 811]
  |  Branch (692:15): [True: 14.0k, False: 7.28k]
  |  Branch (692:39): [True: 3.52k, False: 3.76k]
  ------------------
  693|  17.6k|    stun_attr_ref sar = stun_attr_get_first_by_type_str(buf, len, STUN_ATTRIBUTE_REALM);
  ------------------
  |  |  106|  17.6k|#define STUN_ATTRIBUTE_REALM (0x0014)
  ------------------
  694|  17.6k|    if (sar) {
  ------------------
  |  Branch (694:9): [True: 14.0k, False: 3.51k]
  ------------------
  695|  14.0k|      bool found_oauth = false;
  696|       |
  697|  14.0k|      const uint8_t *value = stun_attr_get_value(sar);
  698|  14.0k|      if (value) {
  ------------------
  |  Branch (698:11): [True: 14.0k, False: 1]
  ------------------
  699|  14.0k|        size_t vlen = (size_t)stun_attr_get_len(sar);
  700|       |        /* Truncating would corrupt the realm mid-codepoint and fail the integrity
  701|       |         * check later with an unrelated error; reject the challenge instead. */
  702|  14.0k|        if (vlen > (size_t)STUN_MAX_REALM_SIZE) {
  ------------------
  |  |   54|  14.0k|#define STUN_MAX_REALM_SIZE (763)
  ------------------
  |  Branch (702:13): [True: 3, False: 14.0k]
  ------------------
  703|      3|          return false;
  704|      3|        }
  705|  14.0k|        memcpy(realm, value, vlen);
  706|  14.0k|        realm[vlen] = 0;
  707|  14.0k|        {
  708|  14.0k|          sar = stun_attr_get_first_by_type_str(buf, len, STUN_ATTRIBUTE_THIRD_PARTY_AUTHORIZATION);
  ------------------
  |  |  227|  14.0k|#define STUN_ATTRIBUTE_THIRD_PARTY_AUTHORIZATION (0x802E)
  ------------------
  709|  14.0k|          if (sar) {
  ------------------
  |  Branch (709:15): [True: 3.53k, False: 10.5k]
  ------------------
  710|  3.53k|            value = stun_attr_get_value(sar);
  711|  3.53k|            if (value) {
  ------------------
  |  Branch (711:17): [True: 3.53k, False: 2]
  ------------------
  712|  3.53k|              vlen = (size_t)stun_attr_get_len(sar);
  713|  3.53k|              vlen = min(vlen, (size_t)STUN_MAX_SERVER_NAME_SIZE);
  ------------------
  |  |  138|  3.53k|#define min(a, b) ((a) <= (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (138:20): [True: 3.53k, False: 3]
  |  |  ------------------
  ------------------
  714|  3.53k|              if (vlen > 0) {
  ------------------
  |  Branch (714:19): [True: 3.53k, False: 0]
  ------------------
  715|  3.53k|                if (server_name) {
  ------------------
  |  Branch (715:21): [True: 3.53k, False: 0]
  ------------------
  716|  3.53k|                  memcpy(server_name, value, vlen);
  717|  3.53k|                  server_name[vlen] = 0;
  718|  3.53k|                }
  719|  3.53k|                found_oauth = true;
  720|  3.53k|              }
  721|  3.53k|            }
  722|  3.53k|          }
  723|  14.0k|        }
  724|       |
  725|  14.0k|        sar = stun_attr_get_first_by_type_str(buf, len, STUN_ATTRIBUTE_NONCE);
  ------------------
  |  |  107|  14.0k|#define STUN_ATTRIBUTE_NONCE (0x0015)
  ------------------
  726|  14.0k|        if (sar) {
  ------------------
  |  Branch (726:13): [True: 10.5k, False: 3.54k]
  ------------------
  727|  10.5k|          value = stun_attr_get_value(sar);
  728|  10.5k|          if (value) {
  ------------------
  |  Branch (728:15): [True: 10.5k, False: 2]
  ------------------
  729|  10.5k|            vlen = (size_t)stun_attr_get_len(sar);
  730|  10.5k|            if (vlen > (size_t)STUN_MAX_NONCE_SIZE) {
  ------------------
  |  |   55|  10.5k|#define STUN_MAX_NONCE_SIZE (763)
  ------------------
  |  Branch (730:17): [True: 1, False: 10.5k]
  ------------------
  731|      1|              return false;
  732|      1|            }
  733|  10.5k|            memcpy(nonce, value, vlen);
  734|  10.5k|            nonce[vlen] = 0;
  735|  10.5k|            if (oauth) {
  ------------------
  |  Branch (735:17): [True: 5.27k, False: 5.26k]
  ------------------
  736|  5.27k|              *oauth = found_oauth;
  737|  5.27k|            }
  738|  10.5k|            return true;
  739|  10.5k|          }
  740|  10.5k|        }
  741|  14.0k|      }
  742|  14.0k|    }
  743|  17.6k|  }
  744|       |
  745|  11.6k|  return false;
  746|  22.1k|}
stun_is_indication_str:
  761|    174|bool stun_is_indication_str(const uint8_t *buf, size_t len) {
  762|    174|  if (is_channel_msg_str(buf, len)) {
  ------------------
  |  Branch (762:7): [True: 0, False: 174]
  ------------------
  763|      0|    return false;
  764|      0|  }
  765|    174|  return IS_STUN_INDICATION(stun_get_msg_type_str(buf, len));
  ------------------
  |  |   63|    174|#define IS_STUN_INDICATION(msg_type) (((msg_type)&0x0110) == 0x0010)
  ------------------
  766|    174|}
stun_make_request:
  768|  8.77k|uint16_t stun_make_request(uint16_t method) { return GET_STUN_REQUEST(stun_make_type(method)); }
  ------------------
  |  |   67|  8.77k|#define GET_STUN_REQUEST(msg_type) (msg_type & 0xFEEF)
  ------------------
stun_make_error_response:
  774|  10.5k|uint16_t stun_make_error_response(uint16_t method) { return GET_STUN_ERR_RESP(stun_make_type(method)); }
  ------------------
  |  |   70|  10.5k|#define GET_STUN_ERR_RESP(msg_type) (msg_type | 0x0110)
  ------------------
stun_init_buffer_str:
  778|  19.3k|void stun_init_buffer_str(uint8_t *buf, size_t *len) {
  779|  19.3k|  *len = STUN_HEADER_LENGTH;
  ------------------
  |  |   46|  19.3k|#define STUN_HEADER_LENGTH (20)
  ------------------
  780|  19.3k|  memset(buf, 0, *len);
  781|  19.3k|}
stun_init_command_str:
  783|  19.3k|void stun_init_command_str(uint16_t message_type, uint8_t *buf, size_t *len) {
  784|  19.3k|  stun_init_buffer_str(buf, len);
  785|  19.3k|  message_type &= (uint16_t)(0x3FFF);
  786|  19.3k|  turn_write_u16(buf, message_type);
  787|  19.3k|  turn_write_u16(buf + 2, 0);
  788|  19.3k|  turn_write_u32(buf + 4, STUN_MAGIC_COOKIE);
  ------------------
  |  |   60|  19.3k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  789|       |  stun_tid_generate_in_message_str(buf, NULL);
  790|  19.3k|}
stun_init_request_str:
  801|  8.77k|void stun_init_request_str(uint16_t method, uint8_t *buf, size_t *len) {
  802|  8.77k|  stun_init_command_str(stun_make_request(method), buf, len);
  803|  8.77k|}
get_default_reason:
  823|  1.09k|const uint8_t *get_default_reason(int error_code) {
  824|  1.09k|  const char *reason = "Unknown error";
  825|       |
  826|  1.09k|  switch (error_code) {
  827|      0|  case 300:
  ------------------
  |  Branch (827:3): [True: 0, False: 1.09k]
  ------------------
  828|      0|    reason = "Try Alternate";
  829|      0|    break;
  830|      0|  case 400:
  ------------------
  |  Branch (830:3): [True: 0, False: 1.09k]
  ------------------
  831|      0|    reason = "Bad Request";
  832|      0|    break;
  833|      0|  case 401:
  ------------------
  |  Branch (833:3): [True: 0, False: 1.09k]
  ------------------
  834|      0|    reason = "Unauthorized";
  835|      0|    break;
  836|      0|  case 403:
  ------------------
  |  Branch (836:3): [True: 0, False: 1.09k]
  ------------------
  837|      0|    reason = "Forbidden";
  838|      0|    break;
  839|      0|  case 404:
  ------------------
  |  Branch (839:3): [True: 0, False: 1.09k]
  ------------------
  840|      0|    reason = "Not Found";
  841|      0|    break;
  842|      0|  case 420:
  ------------------
  |  Branch (842:3): [True: 0, False: 1.09k]
  ------------------
  843|      0|    reason = "Unknown Attribute";
  844|      0|    break;
  845|      0|  case 437:
  ------------------
  |  Branch (845:3): [True: 0, False: 1.09k]
  ------------------
  846|      0|    reason = "Allocation Mismatch";
  847|      0|    break;
  848|      0|  case 438:
  ------------------
  |  Branch (848:3): [True: 0, False: 1.09k]
  ------------------
  849|      0|    reason = "Stale Nonce";
  850|      0|    break;
  851|  1.09k|  case 440:
  ------------------
  |  Branch (851:3): [True: 1.09k, False: 0]
  ------------------
  852|  1.09k|    reason = "Address Family not Supported";
  853|  1.09k|    break;
  854|      0|  case 441:
  ------------------
  |  Branch (854:3): [True: 0, False: 1.09k]
  ------------------
  855|      0|    reason = "Wrong Credentials";
  856|      0|    break;
  857|      0|  case 442:
  ------------------
  |  Branch (857:3): [True: 0, False: 1.09k]
  ------------------
  858|      0|    reason = "Unsupported Transport Protocol";
  859|      0|    break;
  860|      0|  case 443:
  ------------------
  |  Branch (860:3): [True: 0, False: 1.09k]
  ------------------
  861|      0|    reason = "Peer Address Family Mismatch";
  862|      0|    break;
  863|      0|  case 446:
  ------------------
  |  Branch (863:3): [True: 0, False: 1.09k]
  ------------------
  864|      0|    reason = "Connection Already Exists";
  865|      0|    break;
  866|      0|  case 447:
  ------------------
  |  Branch (866:3): [True: 0, False: 1.09k]
  ------------------
  867|      0|    reason = "Connection Timeout or Failure";
  868|      0|    break;
  869|      0|  case 486:
  ------------------
  |  Branch (869:3): [True: 0, False: 1.09k]
  ------------------
  870|      0|    reason = "Allocation Quota Reached";
  871|      0|    break;
  872|      0|  case 487:
  ------------------
  |  Branch (872:3): [True: 0, False: 1.09k]
  ------------------
  873|      0|    reason = "Role Conflict";
  874|      0|    break;
  875|      0|  case 500:
  ------------------
  |  Branch (875:3): [True: 0, False: 1.09k]
  ------------------
  876|      0|    reason = "Server Error";
  877|      0|    break;
  878|      0|  case 508:
  ------------------
  |  Branch (878:3): [True: 0, False: 1.09k]
  ------------------
  879|      0|    reason = "Insufficient Capacity";
  880|      0|    break;
  881|      0|  default:;
  ------------------
  |  Branch (881:3): [True: 0, False: 1.09k]
  ------------------
  882|  1.09k|  };
  883|       |
  884|  1.09k|  return (const uint8_t *)reason;
  885|  1.09k|}
stun_init_error_response_str:
  931|  10.5k|                                  const uint8_t *reason, stun_tid *id, bool include_reason_string) {
  932|       |
  933|  10.5k|  stun_init_command_str(stun_make_error_response(method), buf, len);
  934|       |
  935|       |  stun_init_error_response_common_str(buf, len, error_code, reason, id, include_reason_string, false);
  936|  10.5k|}
stun_is_binding_request_str:
 1378|    174|bool stun_is_binding_request_str(const uint8_t *buf, size_t len, size_t offset) {
 1379|    174|  if (offset < len) {
  ------------------
  |  Branch (1379:7): [True: 174, False: 0]
  ------------------
 1380|    174|    buf += offset;
 1381|    174|    len -= offset;
 1382|    174|    if (stun_is_command_message_str(buf, len)) {
  ------------------
  |  Branch (1382:9): [True: 0, False: 174]
  ------------------
 1383|      0|      if (stun_is_request_str(buf, len) && (stun_get_method_str(buf, len) == STUN_METHOD_BINDING)) {
  ------------------
  |  |   81|      0|#define STUN_METHOD_BINDING (0x0001)
  ------------------
  |  Branch (1383:11): [True: 0, False: 0]
  |  Branch (1383:44): [True: 0, False: 0]
  ------------------
 1384|      0|        return true;
 1385|      0|      }
 1386|      0|    }
 1387|    174|  }
 1388|    174|  return false;
 1389|    174|}
stun_is_binding_response_str:
 1391|    174|bool stun_is_binding_response_str(const uint8_t *buf, size_t len) {
 1392|    174|  if (stun_is_command_message_str(buf, len) && (stun_get_method_str(buf, len) == STUN_METHOD_BINDING)) {
  ------------------
  |  |   81|      0|#define STUN_METHOD_BINDING (0x0001)
  ------------------
  |  Branch (1392:7): [True: 0, False: 174]
  |  Branch (1392:48): [True: 0, False: 0]
  ------------------
 1393|      0|    if (stun_is_response_str(buf, len)) {
  ------------------
  |  Branch (1393:9): [True: 0, False: 0]
  ------------------
 1394|      0|      return true;
 1395|      0|    }
 1396|      0|  }
 1397|    174|  return false;
 1398|    174|}
stun_tid_from_message_str:
 1436|  15.5k|void stun_tid_from_message_str(const uint8_t *buf, size_t len, stun_tid *id) {
 1437|  15.5k|  UNUSED_ARG(len);
  ------------------
  |  |  216|  15.5k|  do {                                                                                                                 \
  |  |  217|  15.5k|    A = A;                                                                                                             \
  |  |  218|  15.5k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (218:12): [Folded, False: 15.5k]
  |  |  ------------------
  ------------------
 1438|  15.5k|  stun_tid_from_string(buf + 8, id);
 1439|  15.5k|}
stun_tid_message_cpy:
 1441|  29.8k|void stun_tid_message_cpy(uint8_t *buf, const stun_tid *id) {
 1442|  29.8k|  if (buf && id) {
  ------------------
  |  Branch (1442:7): [True: 29.8k, False: 0]
  |  Branch (1442:14): [True: 29.8k, False: 0]
  ------------------
 1443|  29.8k|    stun_tid_string_cpy(buf + 8, id);
 1444|  29.8k|  }
 1445|  29.8k|}
stun_tid_generate:
 1447|  19.3k|void stun_tid_generate(stun_tid *id) {
 1448|  19.3k|  if (id) {
  ------------------
  |  Branch (1448:7): [True: 19.3k, False: 0]
  ------------------
 1449|  19.3k|    turn_random_tid_size(id->tsx_id);
 1450|  19.3k|  }
 1451|  19.3k|}
stun_tid_generate_in_message_str:
 1453|  19.3k|void stun_tid_generate_in_message_str(uint8_t *buf, stun_tid *id) {
 1454|  19.3k|  stun_tid tmp;
 1455|  19.3k|  if (!id) {
  ------------------
  |  Branch (1455:7): [True: 19.3k, False: 0]
  ------------------
 1456|  19.3k|    id = &tmp;
 1457|  19.3k|  }
 1458|  19.3k|  stun_tid_generate(id);
 1459|  19.3k|  stun_tid_message_cpy(buf, id);
 1460|  19.3k|}
stun_attr_get_type:
 1484|  1.80M|int stun_attr_get_type(stun_attr_ref attr) {
 1485|  1.80M|  if (attr) {
  ------------------
  |  Branch (1485:7): [True: 1.80M, False: 0]
  ------------------
 1486|  1.80M|    return (int)turn_read_u16(attr);
 1487|  1.80M|  }
 1488|      0|  return -1;
 1489|  1.80M|}
stun_attr_get_len:
 1491|  3.48M|int stun_attr_get_len(stun_attr_ref attr) {
 1492|  3.48M|  if (attr) {
  ------------------
  |  Branch (1492:7): [True: 3.48M, False: 0]
  ------------------
 1493|  3.48M|    return (int)turn_read_u16((const uint8_t *)attr + 2);
 1494|  3.48M|  }
 1495|      0|  return -1;
 1496|  3.48M|}
stun_attr_get_value:
 1498|  86.7k|const uint8_t *stun_attr_get_value(stun_attr_ref attr) {
 1499|  86.7k|  if (attr) {
  ------------------
  |  Branch (1499:7): [True: 86.7k, False: 0]
  ------------------
 1500|  86.7k|    const int len = (int)turn_read_u16((const uint8_t *)attr + 2);
 1501|  86.7k|    if (len < 1) {
  ------------------
  |  Branch (1501:9): [True: 21.7k, False: 65.0k]
  ------------------
 1502|  21.7k|      return NULL;
 1503|  21.7k|    }
 1504|  65.0k|    return ((const uint8_t *)attr) + 4;
 1505|  86.7k|  }
 1506|      0|  return NULL;
 1507|  86.7k|}
stun_get_requested_address_family:
 1509|    113|int stun_get_requested_address_family(stun_attr_ref attr) {
 1510|    113|  if (attr) {
  ------------------
  |  Branch (1510:7): [True: 113, False: 0]
  ------------------
 1511|    113|    const int len = (int)turn_read_u16((const uint8_t *)attr + 2);
 1512|    113|    if (len != 4) {
  ------------------
  |  Branch (1512:9): [True: 78, False: 35]
  ------------------
 1513|     78|      return STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_INVALID;
  ------------------
  |  |  171|     78|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_INVALID (-1)
  ------------------
 1514|     78|    }
 1515|     35|    const int val = ((const uint8_t *)attr)[4];
 1516|     35|    switch (val) {
 1517|      5|    case STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV4:
  ------------------
  |  |  168|      5|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV4 (0x01)
  ------------------
  |  Branch (1517:5): [True: 5, False: 30]
  ------------------
 1518|      9|    case STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6:
  ------------------
  |  |  169|      9|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6 (0x02)
  ------------------
  |  Branch (1518:5): [True: 4, False: 31]
  ------------------
 1519|      9|      return val;
 1520|     26|    default:
  ------------------
  |  Branch (1520:5): [True: 26, False: 9]
  ------------------
 1521|     26|      return STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_INVALID;
  ------------------
  |  |  171|     26|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_INVALID (-1)
  ------------------
 1522|     35|    };
 1523|      0|  }
 1524|      0|  return STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_DEFAULT;
  ------------------
  |  |  170|      0|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_DEFAULT (0x00)
  ------------------
 1525|    113|}
stun_attr_get_channel_number:
 1527|  3.16k|uint16_t stun_attr_get_channel_number(stun_attr_ref attr) {
 1528|  3.16k|  if (attr) {
  ------------------
  |  Branch (1528:7): [True: 3.16k, False: 0]
  ------------------
 1529|  3.16k|    const uint8_t *value = stun_attr_get_value(attr);
 1530|  3.16k|    if (value && (stun_attr_get_len(attr) >= 2)) {
  ------------------
  |  Branch (1530:9): [True: 2.20k, False: 959]
  |  Branch (1530:18): [True: 1.48k, False: 719]
  ------------------
 1531|  1.48k|      const uint16_t cn = turn_read_u16(value);
 1532|  1.48k|      if (STUN_VALID_CHANNEL(cn)) {
  ------------------
  |  |  163|  1.48k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (163:34): [True: 600, False: 882]
  |  |  |  Branch (163:53): [True: 40, False: 560]
  |  |  ------------------
  ------------------
 1533|     40|        return cn;
 1534|     40|      }
 1535|  1.48k|    }
 1536|  3.16k|  }
 1537|  3.12k|  return 0;
 1538|  3.16k|}
stun_attr_get_bandwidth:
 1540|     64|band_limit_t stun_attr_get_bandwidth(stun_attr_ref attr) {
 1541|     64|  if (attr) {
  ------------------
  |  Branch (1541:7): [True: 64, False: 0]
  ------------------
 1542|     64|    const uint8_t *value = stun_attr_get_value(attr);
 1543|     64|    if (value && (stun_attr_get_len(attr) >= 4)) {
  ------------------
  |  Branch (1543:9): [True: 31, False: 33]
  |  Branch (1543:18): [True: 17, False: 14]
  ------------------
 1544|     17|      const uint32_t bps = turn_read_u32(value);
 1545|     17|      return (band_limit_t)(bps << 7);
 1546|     17|    }
 1547|     64|  }
 1548|     47|  return 0;
 1549|     64|}
stun_attr_get_reservation_token_value:
 1551|     46|uint64_t stun_attr_get_reservation_token_value(stun_attr_ref attr) {
 1552|     46|  if (attr) {
  ------------------
  |  Branch (1552:7): [True: 46, False: 0]
  ------------------
 1553|     46|    const uint8_t *value = stun_attr_get_value(attr);
 1554|     46|    if (value && (stun_attr_get_len(attr) == 8)) {
  ------------------
  |  Branch (1554:9): [True: 28, False: 18]
  |  Branch (1554:18): [True: 2, False: 26]
  ------------------
 1555|      2|      return turn_read_u64(value);
 1556|      2|    }
 1557|     46|  }
 1558|     44|  return 0;
 1559|     46|}
stun_attr_is_addr:
 1561|   187k|bool stun_attr_is_addr(stun_attr_ref attr) {
 1562|       |
 1563|   187k|  if (attr) {
  ------------------
  |  Branch (1563:7): [True: 187k, False: 0]
  ------------------
 1564|   187k|    switch (stun_attr_get_type(attr)) {
 1565|  15.2k|    case STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS:
  ------------------
  |  |  109|  15.2k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (1565:5): [True: 15.2k, False: 172k]
  ------------------
 1566|  27.1k|    case STUN_ATTRIBUTE_XOR_PEER_ADDRESS:
  ------------------
  |  |  120|  27.1k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  |  Branch (1566:5): [True: 11.9k, False: 175k]
  ------------------
 1567|  35.7k|    case STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS:
  ------------------
  |  |  122|  35.7k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  |  Branch (1567:5): [True: 8.56k, False: 178k]
  ------------------
 1568|  51.2k|    case STUN_ATTRIBUTE_MAPPED_ADDRESS:
  ------------------
  |  |   95|  51.2k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
  |  Branch (1568:5): [True: 15.4k, False: 171k]
  ------------------
 1569|  56.8k|    case STUN_ATTRIBUTE_ALTERNATE_SERVER:
  ------------------
  |  |  114|  56.8k|#define STUN_ATTRIBUTE_ALTERNATE_SERVER (0x8023)
  ------------------
  |  Branch (1569:5): [True: 5.67k, False: 181k]
  ------------------
 1570|  60.3k|    case OLD_STUN_ATTRIBUTE_RESPONSE_ADDRESS:
  ------------------
  |  |   96|  60.3k|#define OLD_STUN_ATTRIBUTE_RESPONSE_ADDRESS (0x0002)
  ------------------
  |  Branch (1570:5): [True: 3.46k, False: 183k]
  ------------------
 1571|  64.9k|    case OLD_STUN_ATTRIBUTE_SOURCE_ADDRESS:
  ------------------
  |  |   98|  64.9k|#define OLD_STUN_ATTRIBUTE_SOURCE_ADDRESS (0x0004)
  ------------------
  |  Branch (1571:5): [True: 4.55k, False: 182k]
  ------------------
 1572|  69.9k|    case OLD_STUN_ATTRIBUTE_CHANGED_ADDRESS:
  ------------------
  |  |   99|  69.9k|#define OLD_STUN_ATTRIBUTE_CHANGED_ADDRESS (0x0005)
  ------------------
  |  Branch (1572:5): [True: 5.02k, False: 182k]
  ------------------
 1573|  76.9k|    case OLD_STUN_ATTRIBUTE_REFLECTED_FROM:
  ------------------
  |  |  105|  76.9k|#define OLD_STUN_ATTRIBUTE_REFLECTED_FROM (0x000B)
  ------------------
  |  Branch (1573:5): [True: 7.04k, False: 180k]
  ------------------
 1574|  83.7k|    case STUN_ATTRIBUTE_RESPONSE_ORIGIN:
  ------------------
  |  |  136|  83.7k|#define STUN_ATTRIBUTE_RESPONSE_ORIGIN (0x802B)
  ------------------
  |  Branch (1574:5): [True: 6.80k, False: 180k]
  ------------------
 1575|  88.9k|    case STUN_ATTRIBUTE_OTHER_ADDRESS:
  ------------------
  |  |  137|  88.9k|#define STUN_ATTRIBUTE_OTHER_ADDRESS (0x802C)
  ------------------
  |  Branch (1575:5): [True: 5.19k, False: 182k]
  ------------------
 1576|  88.9k|      return true;
 1577|      0|      break;
 1578|  98.2k|    default:;
  ------------------
  |  Branch (1578:5): [True: 98.2k, False: 88.9k]
  ------------------
 1579|   187k|    };
 1580|  98.2k|  }
 1581|  98.2k|  return false;
 1582|   187k|}
stun_attr_get_even_port:
 1584|     31|uint8_t stun_attr_get_even_port(stun_attr_ref attr) {
 1585|     31|  if (attr) {
  ------------------
  |  Branch (1585:7): [True: 31, False: 0]
  ------------------
 1586|     31|    const uint8_t *value = stun_attr_get_value(attr);
 1587|     31|    if (value) {
  ------------------
  |  Branch (1587:9): [True: 18, False: 13]
  ------------------
 1588|     18|      if ((uint8_t)(value[0]) > 0x7F) {
  ------------------
  |  Branch (1588:11): [True: 5, False: 13]
  ------------------
 1589|      5|        return 1;
 1590|      5|      }
 1591|     18|    }
 1592|     31|  }
 1593|     26|  return 0;
 1594|     31|}
stun_attr_get_first_by_type_str:
 1604|   158k|stun_attr_ref stun_attr_get_first_by_type_str(const uint8_t *buf, size_t len, uint16_t attr_type) {
 1605|   158k|  stun_attr_ref attr = stun_attr_get_first_str(buf, len);
 1606|  1.58M|  while (attr) {
  ------------------
  |  Branch (1606:10): [True: 1.48M, False: 102k]
  ------------------
 1607|  1.48M|    if (stun_attr_get_type(attr) == attr_type) {
  ------------------
  |  Branch (1607:9): [True: 55.8k, False: 1.42M]
  ------------------
 1608|  55.8k|      return attr;
 1609|  55.8k|    }
 1610|  1.42M|    attr = stun_attr_get_next_str(buf, len, attr);
 1611|  1.42M|  }
 1612|       |
 1613|   102k|  return NULL;
 1614|   158k|}
stun_attr_get_first_str:
 1637|   169k|stun_attr_ref stun_attr_get_first_str(const uint8_t *buf, size_t len) {
 1638|   169k|  const int bufLen = stun_get_command_message_len_str(buf, len);
 1639|   169k|  if (bufLen > STUN_HEADER_LENGTH) {
  ------------------
  |  |   46|   169k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (1639:7): [True: 166k, False: 3.34k]
  ------------------
 1640|   166k|    stun_attr_ref attr = (stun_attr_ref)(buf + STUN_HEADER_LENGTH);
  ------------------
  |  |   46|   166k|#define STUN_HEADER_LENGTH (20)
  ------------------
 1641|   166k|    return stun_attr_check_valid(attr, bufLen - STUN_HEADER_LENGTH);
  ------------------
  |  |   46|   166k|#define STUN_HEADER_LENGTH (20)
  ------------------
 1642|   166k|  }
 1643|       |
 1644|  3.34k|  return NULL;
 1645|   169k|}
stun_attr_get_next_str:
 1647|  1.63M|stun_attr_ref stun_attr_get_next_str(const uint8_t *buf, size_t len, stun_attr_ref prev) {
 1648|  1.63M|  if (!prev) {
  ------------------
  |  Branch (1648:7): [True: 0, False: 1.63M]
  ------------------
 1649|      0|    return stun_attr_get_first_str(buf, len);
 1650|  1.63M|  } else {
 1651|  1.63M|    const uint8_t *end = buf + stun_get_command_message_len_str(buf, len);
 1652|  1.63M|    int attrlen = stun_attr_get_len(prev);
 1653|  1.63M|    const uint16_t rem4 = ((uint16_t)attrlen) & 0x0003;
 1654|  1.63M|    if (rem4) {
  ------------------
  |  Branch (1654:9): [True: 361k, False: 1.27M]
  ------------------
 1655|   361k|      attrlen = attrlen + 4 - (int)rem4;
 1656|   361k|    }
 1657|       |    /* Note the order here: operations on attrlen are untrusted as they may overflow */
 1658|  1.63M|    if (attrlen < end - (const uint8_t *)prev - 4) {
  ------------------
  |  Branch (1658:9): [True: 1.55M, False: 81.4k]
  ------------------
 1659|  1.55M|      const uint8_t *attr_end = (const uint8_t *)prev + 4 + attrlen;
 1660|  1.55M|      return stun_attr_check_valid(attr_end, end - attr_end);
 1661|  1.55M|    }
 1662|  81.4k|    return NULL;
 1663|  1.63M|  }
 1664|  1.63M|}
stun_attr_add_str:
 1666|  72.5k|bool stun_attr_add_str(uint8_t *buf, size_t *len, uint16_t attr, const uint8_t *avalue, int alen) {
 1667|  72.5k|  if (alen < 0) {
  ------------------
  |  Branch (1667:7): [True: 0, False: 72.5k]
  ------------------
 1668|      0|    alen = 0;
 1669|      0|  }
 1670|  72.5k|  uint8_t tmp[1];
 1671|  72.5k|  if (!avalue) {
  ------------------
  |  Branch (1671:7): [True: 1.09k, False: 71.4k]
  ------------------
 1672|  1.09k|    alen = 0;
 1673|  1.09k|    avalue = tmp;
 1674|  1.09k|  }
 1675|  72.5k|  const int clen = stun_get_command_message_len_str(buf, *len);
 1676|  72.5k|  int newlen = clen + 4 + alen;
 1677|  72.5k|  const int newlenrem4 = newlen & 0x00000003;
 1678|  72.5k|  int paddinglen = 0;
 1679|  72.5k|  if (newlenrem4) {
  ------------------
  |  Branch (1679:7): [True: 28.8k, False: 43.6k]
  ------------------
 1680|  28.8k|    paddinglen = 4 - newlenrem4;
 1681|  28.8k|    newlen = newlen + paddinglen;
 1682|  28.8k|  }
 1683|       |
 1684|  72.5k|  if (newlen >= MAX_STUN_MESSAGE_SIZE) {
  ------------------
  |  |  221|  72.5k|#define MAX_STUN_MESSAGE_SIZE (65507)
  ------------------
  |  Branch (1684:7): [True: 0, False: 72.5k]
  ------------------
 1685|      0|    return false;
 1686|      0|  }
 1687|       |
 1688|  72.5k|  uint8_t *attr_start = buf + clen;
 1689|       |
 1690|  72.5k|  stun_set_command_message_len_str(buf, newlen);
 1691|  72.5k|  *len = newlen;
 1692|       |
 1693|  72.5k|  turn_write_u16(attr_start, attr);
 1694|  72.5k|  turn_write_u16(attr_start + 2, (uint16_t)alen);
 1695|  72.5k|  if (alen > 0) {
  ------------------
  |  Branch (1695:7): [True: 71.4k, False: 1.09k]
  ------------------
 1696|  71.4k|    memcpy(attr_start + 4, avalue, alen);
 1697|  71.4k|  }
 1698|       |
 1699|       |  // Write 0 padding to not leak data
 1700|  72.5k|  memset(attr_start + 4 + alen, 0, paddinglen);
 1701|       |
 1702|       |  return true;
 1703|  72.5k|}
stun_attr_add_addr_str:
 1705|  6.59k|bool stun_attr_add_addr_str(uint8_t *buf, size_t *len, uint16_t attr_type, const ioa_addr *ca) {
 1706|       |
 1707|  6.59k|  stun_tid tid;
 1708|  6.59k|  stun_tid_from_message_str(buf, *len, &tid);
 1709|       |
 1710|  6.59k|  int xor_ed = 0;
 1711|  6.59k|  switch (attr_type) {
 1712|  2.19k|  case STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS:
  ------------------
  |  |  109|  2.19k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (1712:3): [True: 2.19k, False: 4.39k]
  ------------------
 1713|  3.29k|  case STUN_ATTRIBUTE_XOR_PEER_ADDRESS:
  ------------------
  |  |  120|  3.29k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  |  Branch (1713:3): [True: 1.09k, False: 5.49k]
  ------------------
 1714|  5.49k|  case STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS:
  ------------------
  |  |  122|  5.49k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  |  Branch (1714:3): [True: 2.19k, False: 4.39k]
  ------------------
 1715|  5.49k|    xor_ed = 1;
 1716|  5.49k|    break;
 1717|  1.09k|  default:;
  ------------------
  |  Branch (1717:3): [True: 1.09k, False: 5.49k]
  ------------------
 1718|  6.59k|  };
 1719|       |
 1720|  6.59k|  ioa_addr public_addr;
 1721|  6.59k|  map_addr_from_private_to_public(ca, &public_addr);
 1722|       |
 1723|  6.59k|  uint8_t cfield[64];
 1724|  6.59k|  int clen = 0;
 1725|  6.59k|  if (stun_addr_encode(&public_addr, cfield, &clen, xor_ed, STUN_MAGIC_COOKIE, tid.tsx_id) < 0) {
  ------------------
  |  |   60|  6.59k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (1725:7): [True: 0, False: 6.59k]
  ------------------
 1726|      0|    return false;
 1727|      0|  }
 1728|       |
 1729|  6.59k|  if (!stun_attr_add_str(buf, len, attr_type, (uint8_t *)(&cfield), clen)) {
  ------------------
  |  Branch (1729:7): [True: 0, False: 6.59k]
  ------------------
 1730|      0|    return false;
 1731|      0|  }
 1732|       |
 1733|  6.59k|  return true;
 1734|  6.59k|}
stun_attr_get_addr_str:
 1737|  8.91k|                            const ioa_addr *default_addr) {
 1738|  8.91k|  stun_tid tid;
 1739|  8.91k|  stun_tid_from_message_str(buf, len, &tid);
 1740|  8.91k|  ioa_addr public_addr;
 1741|       |
 1742|  8.91k|  addr_set_any(ca);
 1743|  8.91k|  addr_set_any(&public_addr);
 1744|       |
 1745|  8.91k|  const int attr_type = stun_attr_get_type(attr);
 1746|  8.91k|  if (attr_type < 0) {
  ------------------
  |  Branch (1746:7): [True: 0, False: 8.91k]
  ------------------
 1747|      0|    return false;
 1748|      0|  }
 1749|       |
 1750|  8.91k|  int xor_ed = 0;
 1751|  8.91k|  switch (attr_type) {
 1752|  1.94k|  case STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS:
  ------------------
  |  |  109|  1.94k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (1752:3): [True: 1.94k, False: 6.97k]
  ------------------
 1753|  3.47k|  case STUN_ATTRIBUTE_XOR_PEER_ADDRESS:
  ------------------
  |  |  120|  3.47k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  |  Branch (1753:3): [True: 1.53k, False: 7.38k]
  ------------------
 1754|  4.59k|  case STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS:
  ------------------
  |  |  122|  4.59k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  |  Branch (1754:3): [True: 1.12k, False: 7.79k]
  ------------------
 1755|  4.59k|    xor_ed = 1;
 1756|  4.59k|    break;
 1757|  4.31k|  default:;
  ------------------
  |  Branch (1757:3): [True: 4.31k, False: 4.59k]
  ------------------
 1758|  8.91k|  };
 1759|       |
 1760|  8.91k|  const uint8_t *cfield = stun_attr_get_value(attr);
 1761|  8.91k|  if (!cfield) {
  ------------------
  |  Branch (1761:7): [True: 5.47k, False: 3.43k]
  ------------------
 1762|  5.47k|    return false;
 1763|  5.47k|  }
 1764|       |
 1765|  3.43k|  if (stun_addr_decode(&public_addr, cfield, stun_attr_get_len(attr), xor_ed, STUN_MAGIC_COOKIE, tid.tsx_id) < 0) {
  ------------------
  |  |   60|  3.43k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (1765:7): [True: 2.46k, False: 969]
  ------------------
 1766|  2.46k|    return false;
 1767|  2.46k|  }
 1768|       |
 1769|    969|  map_addr_from_public_to_private(&public_addr, ca);
 1770|       |
 1771|    969|  if (default_addr && addr_any_no_port(ca) && !addr_any_no_port(default_addr)) {
  ------------------
  |  Branch (1771:7): [True: 0, False: 969]
  |  Branch (1771:23): [True: 0, False: 0]
  |  Branch (1771:47): [True: 0, False: 0]
  ------------------
 1772|      0|    const uint16_t port = addr_get_port(ca);
 1773|      0|    addr_cpy(ca, default_addr);
 1774|      0|    addr_set_port(ca, port);
 1775|      0|  }
 1776|       |
 1777|       |  return true;
 1778|  3.43k|}
stun_attr_get_first_addr_str:
 1781|  8.98k|                                  const ioa_addr *default_addr) {
 1782|  8.98k|  stun_attr_ref attr = stun_attr_get_first_str(buf, len);
 1783|       |
 1784|   173k|  while (attr) {
  ------------------
  |  Branch (1784:10): [True: 165k, False: 8.50k]
  ------------------
 1785|   165k|    if (stun_attr_is_addr(attr) && (attr_type == stun_attr_get_type(attr))) {
  ------------------
  |  Branch (1785:9): [True: 78.5k, False: 86.8k]
  |  Branch (1785:36): [True: 7.67k, False: 70.9k]
  ------------------
 1786|  7.67k|      if (stun_attr_get_addr_str(buf, len, attr, ca, default_addr)) {
  ------------------
  |  Branch (1786:11): [True: 481, False: 7.19k]
  ------------------
 1787|    481|        return true;
 1788|    481|      }
 1789|  7.67k|    }
 1790|   164k|    attr = stun_attr_get_next_str(buf, len, attr);
 1791|   164k|  }
 1792|       |
 1793|  8.50k|  return false;
 1794|  8.98k|}
stun_attr_add_channel_number_str:
 1796|  1.09k|bool stun_attr_add_channel_number_str(uint8_t *buf, size_t *len, uint16_t chnumber) {
 1797|       |
 1798|  1.09k|  uint16_t field[2];
 1799|  1.09k|  field[0] = nswap16(chnumber);
  ------------------
  |  |   86|  1.09k|#define nswap16(s) ntohs(s)
  ------------------
 1800|  1.09k|  field[1] = 0;
 1801|       |
 1802|  1.09k|  return stun_attr_add_str(buf, len, STUN_ATTRIBUTE_CHANNEL_NUMBER, (uint8_t *)(field), sizeof(field));
  ------------------
  |  |  117|  1.09k|#define STUN_ATTRIBUTE_CHANNEL_NUMBER (0x000C)
  ------------------
 1803|  1.09k|}
stun_attr_add_bandwidth_str:
 1805|  1.09k|bool stun_attr_add_bandwidth_str(uint8_t *buf, size_t *len, band_limit_t bps0) {
 1806|       |
 1807|  1.09k|  const uint32_t bps = (uint32_t)(band_limit_t)(bps0 >> 7);
 1808|       |
 1809|  1.09k|  uint32_t field = nswap32(bps);
  ------------------
  |  |   87|  1.09k|#define nswap32(ul) ntohl(ul)
  ------------------
 1810|       |
 1811|  1.09k|  return stun_attr_add_str(buf, len, STUN_ATTRIBUTE_NEW_BANDWIDTH, (uint8_t *)(&field), sizeof(field));
  ------------------
  |  |   52|  1.09k|#define STUN_ATTRIBUTE_NEW_BANDWIDTH (0x8000 + STUN_ATTRIBUTE_BANDWIDTH)
  |  |  ------------------
  |  |  |  |  119|  1.09k|#define STUN_ATTRIBUTE_BANDWIDTH (0x0010)
  |  |  ------------------
  ------------------
 1812|  1.09k|}
stun_attr_add_address_error_code:
 1814|  1.09k|bool stun_attr_add_address_error_code(uint8_t *buf, size_t *len, int requested_address_family, int error_code) {
 1815|  1.09k|  const uint8_t *reason = get_default_reason(error_code);
 1816|       |
 1817|  1.09k|  uint8_t avalue[513] = {0};
 1818|  1.09k|  avalue[0] = (uint8_t)requested_address_family;
 1819|  1.09k|  avalue[1] = 0;
 1820|  1.09k|  avalue[2] = (uint8_t)(error_code / 100);
 1821|  1.09k|  avalue[3] = (uint8_t)(error_code % 100);
 1822|  1.09k|  strncpy((char *)(avalue + 4), (const char *)reason, sizeof(avalue) - 4);
 1823|  1.09k|  avalue[sizeof(avalue) - 1] = 0;
 1824|       |
 1825|       |  /* RFC 8489 Section 14: the declared length excludes padding. */
 1826|  1.09k|  const int alen = 4 + (int)strlen((const char *)(avalue + 4));
 1827|       |
 1828|  1.09k|  return stun_attr_add_str(buf, len, STUN_ATTRIBUTE_ADDRESS_ERROR_CODE, (uint8_t *)avalue, alen);
  ------------------
  |  |  145|  1.09k|#define STUN_ATTRIBUTE_ADDRESS_ERROR_CODE (0x8001)
  ------------------
 1829|  1.09k|}
stun_attr_get_first_channel_number_str:
 1831|  1.12k|uint16_t stun_attr_get_first_channel_number_str(const uint8_t *buf, size_t len) {
 1832|       |
 1833|  1.12k|  stun_attr_ref attr = stun_attr_get_first_str(buf, len);
 1834|  22.8k|  while (attr) {
  ------------------
  |  Branch (1834:10): [True: 21.7k, False: 1.10k]
  ------------------
 1835|  21.7k|    if (stun_attr_get_type(attr) == STUN_ATTRIBUTE_CHANNEL_NUMBER) {
  ------------------
  |  |  117|  21.7k|#define STUN_ATTRIBUTE_CHANNEL_NUMBER (0x000C)
  ------------------
  |  Branch (1835:9): [True: 2.95k, False: 18.7k]
  ------------------
 1836|  2.95k|      const uint16_t ret = stun_attr_get_channel_number(attr);
 1837|  2.95k|      if (STUN_VALID_CHANNEL(ret)) {
  ------------------
  |  |  163|  2.95k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (163:34): [True: 21, False: 2.93k]
  |  |  |  Branch (163:53): [True: 21, False: 0]
  |  |  ------------------
  ------------------
 1838|     21|        return ret;
 1839|     21|      }
 1840|  2.95k|    }
 1841|  21.7k|    attr = stun_attr_get_next_str(buf, len, attr);
 1842|  21.7k|  }
 1843|       |
 1844|  1.10k|  return 0;
 1845|  1.12k|}
stun_attr_add_fingerprint_str:
 1849|  1.09k|bool stun_attr_add_fingerprint_str(uint8_t *buf, size_t *len) {
 1850|  1.09k|  uint32_t crc32 = 0;
 1851|  1.09k|  if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_FINGERPRINT, (uint8_t *)&crc32, 4)) {
  ------------------
  |  |  115|  1.09k|#define STUN_ATTRIBUTE_FINGERPRINT (0x8028)
  ------------------
  |  Branch (1851:7): [True: 0, False: 1.09k]
  ------------------
 1852|      0|    return false;
 1853|      0|  }
 1854|  1.09k|  crc32 = ns_crc32(buf, (int)*len - 8);
 1855|  1.09k|  turn_write_u32(buf + *len - 4, crc32 ^ ((uint32_t)FINGERPRINT_XOR));
  ------------------
  |  |   53|  1.09k|#define FINGERPRINT_XOR 0x5354554e
  ------------------
 1856|       |  return true;
 1857|  1.09k|}
get_hmackey_size:
 1950|  5.38k|size_t get_hmackey_size(SHATYPE shatype) {
 1951|  5.38k|  if (shatype == SHATYPE_SHA256) {
  ------------------
  |  Branch (1951:7): [True: 1.79k, False: 3.58k]
  ------------------
 1952|  1.79k|    return 32;
 1953|  1.79k|  }
 1954|  3.58k|  if (shatype == SHATYPE_SHA384) {
  ------------------
  |  Branch (1954:7): [True: 729, False: 2.85k]
  ------------------
 1955|    729|    return 48;
 1956|    729|  }
 1957|  2.85k|  if (shatype == SHATYPE_SHA512) {
  ------------------
  |  Branch (1957:7): [True: 934, False: 1.91k]
  ------------------
 1958|    934|    return 64;
 1959|    934|  }
 1960|  1.91k|  return 16;
 1961|  2.85k|}
stun_attr_add_integrity_str:
 1972|  7.02k|                                 SHATYPE shatype) {
 1973|  7.02k|  uint8_t hmac[MAXSHASIZE] = {0};
 1974|       |
 1975|  7.02k|  unsigned int shasize;
 1976|       |
 1977|  7.02k|  switch (shatype) {
 1978|  2.35k|  case SHATYPE_SHA256:
  ------------------
  |  Branch (1978:3): [True: 2.35k, False: 4.66k]
  ------------------
 1979|  2.35k|    shasize = SHA256SIZEBYTES;
  ------------------
  |  |  184|  2.35k|#define SHA256SIZEBYTES (32)
  ------------------
 1980|  2.35k|    break;
 1981|    964|  case SHATYPE_SHA384:
  ------------------
  |  Branch (1981:3): [True: 964, False: 6.05k]
  ------------------
 1982|    964|    shasize = SHA384SIZEBYTES;
  ------------------
  |  |  185|    964|#define SHA384SIZEBYTES (48)
  ------------------
 1983|    964|    break;
 1984|  1.24k|  case SHATYPE_SHA512:
  ------------------
  |  Branch (1984:3): [True: 1.24k, False: 5.78k]
  ------------------
 1985|  1.24k|    shasize = SHA512SIZEBYTES;
  ------------------
  |  |  186|  1.24k|#define SHA512SIZEBYTES (64)
  ------------------
 1986|  1.24k|    break;
 1987|  2.46k|  default:
  ------------------
  |  Branch (1987:3): [True: 2.46k, False: 4.56k]
  ------------------
 1988|  2.46k|    shasize = SHA1SIZEBYTES;
  ------------------
  |  |  183|  2.46k|#define SHA1SIZEBYTES (20)
  ------------------
 1989|  7.02k|  };
 1990|       |
 1991|  7.02k|  if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_MESSAGE_INTEGRITY, hmac, shasize)) {
  ------------------
  |  |  102|  7.02k|#define STUN_ATTRIBUTE_MESSAGE_INTEGRITY (0x0008)
  ------------------
  |  Branch (1991:7): [True: 0, False: 7.02k]
  ------------------
 1992|      0|    return false;
 1993|      0|  }
 1994|       |
 1995|  7.02k|  if (ct == TURN_CREDENTIALS_SHORT_TERM) {
  ------------------
  |  Branch (1995:7): [True: 1.75k, False: 5.26k]
  ------------------
 1996|  1.75k|    return stun_calculate_hmac(buf, *len - 4 - shasize, pwd, strlen((char *)pwd), buf + *len - shasize, &shasize,
 1997|  1.75k|                               shatype);
 1998|  5.26k|  } else {
 1999|  5.26k|    return stun_calculate_hmac(buf, *len - 4 - shasize, key, get_hmackey_size(shatype), buf + *len - shasize, &shasize,
 2000|  5.26k|                               shatype);
 2001|  5.26k|  }
 2002|  7.02k|}
stun_attr_add_integrity_by_key_str:
 2005|  3.51k|                                        hmackey_t key, const uint8_t *nonce, SHATYPE shatype) {
 2006|  3.51k|  if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_USERNAME, uname, (int)strlen((const char *)uname))) {
  ------------------
  |  |  100|  3.51k|#define STUN_ATTRIBUTE_USERNAME (0x0006)
  ------------------
  |  Branch (2006:7): [True: 0, False: 3.51k]
  ------------------
 2007|      0|    return false;
 2008|      0|  }
 2009|       |
 2010|  3.51k|  if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_NONCE, nonce, (int)strlen((const char *)nonce))) {
  ------------------
  |  |  107|  3.51k|#define STUN_ATTRIBUTE_NONCE (0x0015)
  ------------------
  |  Branch (2010:7): [True: 0, False: 3.51k]
  ------------------
 2011|      0|    return false;
 2012|      0|  }
 2013|       |
 2014|  3.51k|  if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_REALM, realm, (int)strlen((const char *)realm))) {
  ------------------
  |  |  106|  3.51k|#define STUN_ATTRIBUTE_REALM (0x0014)
  ------------------
  |  Branch (2014:7): [True: 0, False: 3.51k]
  ------------------
 2015|      0|    return false;
 2016|      0|  }
 2017|       |
 2018|  3.51k|  password_t p;
 2019|  3.51k|  return stun_attr_add_integrity_str(TURN_CREDENTIALS_LONG_TERM, buf, len, key, p, shatype);
 2020|  3.51k|}
stun_attr_add_integrity_by_user_str:
 2023|  1.75k|                                         const uint8_t *upwd, const uint8_t *nonce, SHATYPE shatype) {
 2024|  1.75k|  hmackey_t key;
 2025|       |
 2026|  1.75k|  if (!stun_produce_integrity_key_str(uname, realm, upwd, key, shatype)) {
  ------------------
  |  Branch (2026:7): [True: 0, False: 1.75k]
  ------------------
 2027|      0|    return false;
 2028|      0|  }
 2029|       |
 2030|  1.75k|  return stun_attr_add_integrity_by_key_str(buf, len, uname, realm, key, nonce, shatype);
 2031|  1.75k|}
stun_attr_add_integrity_by_user_short_term_str:
 2034|  1.75k|                                                    SHATYPE shatype) {
 2035|  1.75k|  if (stun_attr_add_str(buf, len, STUN_ATTRIBUTE_USERNAME, uname, (int)strlen((const char *)uname))) {
  ------------------
  |  |  100|  1.75k|#define STUN_ATTRIBUTE_USERNAME (0x0006)
  ------------------
  |  Branch (2035:7): [True: 1.75k, False: 0]
  ------------------
 2036|  1.75k|    return false;
 2037|  1.75k|  }
 2038|       |
 2039|      0|  hmackey_t key;
 2040|      0|  return stun_attr_add_integrity_str(TURN_CREDENTIALS_SHORT_TERM, buf, len, key, pwd, shatype);
 2041|  1.75k|}
stun_check_message_integrity_by_key_str:
 2047|  15.6k|                                            password_t pwd, SHATYPE shatype) {
 2048|  15.6k|  stun_attr_ref sar = stun_attr_get_first_by_type_str(buf, len, STUN_ATTRIBUTE_MESSAGE_INTEGRITY);
  ------------------
  |  |  102|  15.6k|#define STUN_ATTRIBUTE_MESSAGE_INTEGRITY (0x0008)
  ------------------
 2049|  15.6k|  if (!sar) {
  ------------------
  |  Branch (2049:7): [True: 14.3k, False: 1.37k]
  ------------------
 2050|  14.3k|    return -1;
 2051|  14.3k|  }
 2052|       |
 2053|  1.37k|  unsigned int shasize = 0;
 2054|  1.37k|  switch (stun_attr_get_len(sar)) {
 2055|    160|  case SHA256SIZEBYTES:
  ------------------
  |  |  184|    160|#define SHA256SIZEBYTES (32)
  ------------------
  |  Branch (2055:3): [True: 160, False: 1.21k]
  ------------------
 2056|    160|    shasize = SHA256SIZEBYTES;
  ------------------
  |  |  184|    160|#define SHA256SIZEBYTES (32)
  ------------------
 2057|    160|    if (shatype != SHATYPE_SHA256) {
  ------------------
  |  Branch (2057:9): [True: 112, False: 48]
  ------------------
 2058|    112|      return -1;
 2059|    112|    }
 2060|     48|    break;
 2061|     60|  case SHA384SIZEBYTES:
  ------------------
  |  |  185|     60|#define SHA384SIZEBYTES (48)
  ------------------
  |  Branch (2061:3): [True: 60, False: 1.31k]
  ------------------
 2062|     60|    shasize = SHA384SIZEBYTES;
  ------------------
  |  |  185|     60|#define SHA384SIZEBYTES (48)
  ------------------
 2063|     60|    if (shatype != SHATYPE_SHA384) {
  ------------------
  |  Branch (2063:9): [True: 48, False: 12]
  ------------------
 2064|     48|      return -1;
 2065|     48|    }
 2066|     12|    break;
 2067|     40|  case SHA512SIZEBYTES:
  ------------------
  |  |  186|     40|#define SHA512SIZEBYTES (64)
  ------------------
  |  Branch (2067:3): [True: 40, False: 1.33k]
  ------------------
 2068|     40|    shasize = SHA512SIZEBYTES;
  ------------------
  |  |  186|     40|#define SHA512SIZEBYTES (64)
  ------------------
 2069|     40|    if (shatype != SHATYPE_SHA512) {
  ------------------
  |  Branch (2069:9): [True: 32, False: 8]
  ------------------
 2070|     32|      return -1;
 2071|     32|    }
 2072|      8|    break;
 2073|    740|  case SHA1SIZEBYTES:
  ------------------
  |  |  183|    740|#define SHA1SIZEBYTES (20)
  ------------------
  |  Branch (2073:3): [True: 740, False: 630]
  ------------------
 2074|    740|    shasize = SHA1SIZEBYTES;
  ------------------
  |  |  183|    740|#define SHA1SIZEBYTES (20)
  ------------------
 2075|    740|    if (shatype != SHATYPE_SHA1) {
  ------------------
  |  Branch (2075:9): [True: 518, False: 222]
  ------------------
 2076|    518|      return -1;
 2077|    518|    }
 2078|    222|    break;
 2079|    370|  default:
  ------------------
  |  Branch (2079:3): [True: 370, False: 1.00k]
  ------------------
 2080|    370|    return -1;
 2081|  1.37k|  };
 2082|       |
 2083|    290|  const int orig_len = stun_get_command_message_len_str(buf, len);
 2084|    290|  if (orig_len < 0) {
  ------------------
  |  Branch (2084:7): [True: 0, False: 290]
  ------------------
 2085|      0|    return -1;
 2086|      0|  }
 2087|       |
 2088|    290|  const int new_len = (int)((const uint8_t *)sar - buf) + 4 + shasize;
 2089|    290|  if (new_len > orig_len) {
  ------------------
  |  Branch (2089:7): [True: 0, False: 290]
  ------------------
 2090|      0|    return -1;
 2091|      0|  }
 2092|       |
 2093|    290|  if (!stun_set_command_message_len_str(buf, new_len)) {
  ------------------
  |  Branch (2093:7): [True: 0, False: 290]
  ------------------
 2094|      0|    return -1;
 2095|      0|  }
 2096|       |
 2097|    290|  int res = 0;
 2098|    290|  uint8_t new_hmac[MAXSHASIZE] = {0};
 2099|    290|  if (ct == TURN_CREDENTIALS_SHORT_TERM) {
  ------------------
  |  Branch (2099:7): [True: 174, False: 116]
  ------------------
 2100|    174|    if (!stun_calculate_hmac(buf, (size_t)new_len - 4 - shasize, pwd, strlen((char *)pwd), new_hmac, &shasize,
  ------------------
  |  Branch (2100:9): [True: 0, False: 174]
  ------------------
 2101|    174|                             shatype)) {
 2102|      0|      res = -1;
 2103|    174|    } else {
 2104|    174|      res = 0;
 2105|    174|    }
 2106|    174|  } else {
 2107|    116|    if (!stun_calculate_hmac(buf, (size_t)new_len - 4 - shasize, key, get_hmackey_size(shatype), new_hmac, &shasize,
  ------------------
  |  Branch (2107:9): [True: 0, False: 116]
  ------------------
 2108|    116|                             shatype)) {
 2109|      0|      res = -1;
 2110|    116|    } else {
 2111|    116|      res = 0;
 2112|    116|    }
 2113|    116|  }
 2114|       |
 2115|    290|  stun_set_command_message_len_str(buf, orig_len);
 2116|    290|  if (res < 0) {
  ------------------
  |  Branch (2116:7): [True: 0, False: 290]
  ------------------
 2117|      0|    return -1;
 2118|      0|  }
 2119|       |
 2120|    290|  const uint8_t *old_hmac = stun_attr_get_value(sar);
 2121|    290|  if (!old_hmac) {
  ------------------
  |  Branch (2121:7): [True: 0, False: 290]
  ------------------
 2122|      0|    return -1;
 2123|      0|  }
 2124|       |
 2125|       |  /* Use constant-time comparison: a short-circuiting memcmp leaks the matching prefix
 2126|       |     length via response timing, allowing byte-by-byte HMAC recovery. */
 2127|    290|  if (0 != CRYPTO_memcmp(old_hmac, new_hmac, shasize)) {
  ------------------
  |  Branch (2127:7): [True: 288, False: 2]
  ------------------
 2128|    288|    return 0;
 2129|    288|  }
 2130|       |
 2131|      2|  return +1;
 2132|    290|}
stun_check_message_integrity_str:
 2138|  15.6k|                                     const uint8_t *realm, const uint8_t *upwd, SHATYPE shatype) {
 2139|  15.6k|  hmackey_t key;
 2140|  15.6k|  password_t pwd;
 2141|       |
 2142|  15.6k|  if (ct == TURN_CREDENTIALS_SHORT_TERM) {
  ------------------
  |  Branch (2142:7): [True: 7.84k, False: 7.84k]
  ------------------
 2143|  7.84k|    strncpy((char *)pwd, (const char *)upwd, sizeof(password_t) - 1);
 2144|  7.84k|    pwd[sizeof(password_t) - 1] = 0;
 2145|  7.84k|  } else if (!stun_produce_integrity_key_str(uname, realm, upwd, key, shatype)) {
  ------------------
  |  Branch (2145:14): [True: 0, False: 7.84k]
  ------------------
 2146|      0|    return -1;
 2147|      0|  }
 2148|       |
 2149|  15.6k|  return stun_check_message_integrity_by_key_str(ct, buf, len, key, pwd, shatype);
 2150|  15.6k|}
stun_attr_get_change_request_str:
 2154|     52|bool stun_attr_get_change_request_str(stun_attr_ref attr, bool *change_ip, bool *change_port) {
 2155|     52|  if (stun_attr_get_len(attr) == 4) {
  ------------------
  |  Branch (2155:7): [True: 10, False: 42]
  ------------------
 2156|     10|    const uint8_t *value = stun_attr_get_value(attr);
 2157|     10|    if (value) {
  ------------------
  |  Branch (2157:9): [True: 10, False: 0]
  ------------------
 2158|     10|      *change_ip = (value[3] & 0x04);
 2159|     10|      *change_port = (value[3] & 0x02);
 2160|     10|      return true;
 2161|     10|    }
 2162|     10|  }
 2163|     42|  return false;
 2164|     52|}
stun_attr_add_change_request_str:
 2166|  1.09k|bool stun_attr_add_change_request_str(uint8_t *buf, size_t *len, bool change_ip, bool change_port) {
 2167|  1.09k|  uint8_t avalue[4] = {0, 0, 0, 0};
 2168|       |
 2169|  1.09k|  if (change_ip) {
  ------------------
  |  Branch (2169:7): [True: 1.09k, False: 0]
  ------------------
 2170|  1.09k|    if (change_port) {
  ------------------
  |  Branch (2170:9): [True: 1.09k, False: 0]
  ------------------
 2171|  1.09k|      avalue[3] = 0x06;
 2172|  1.09k|    } else {
 2173|      0|      avalue[3] = 0x04;
 2174|      0|    }
 2175|  1.09k|  } else if (change_port) {
  ------------------
  |  Branch (2175:14): [True: 0, False: 0]
  ------------------
 2176|      0|    avalue[3] = 0x02;
 2177|      0|  }
 2178|       |
 2179|  1.09k|  return stun_attr_add_str(buf, len, STUN_ATTRIBUTE_CHANGE_REQUEST, avalue, 4);
  ------------------
  |  |   97|  1.09k|#define STUN_ATTRIBUTE_CHANGE_REQUEST (0x0003)
  ------------------
 2180|  1.09k|}
stun_attr_get_response_port_str:
 2182|     44|int stun_attr_get_response_port_str(stun_attr_ref attr) {
 2183|     44|  if (stun_attr_get_len(attr) >= 2) {
  ------------------
  |  Branch (2183:7): [True: 32, False: 12]
  ------------------
 2184|     32|    const uint8_t *value = stun_attr_get_value(attr);
 2185|     32|    if (value) {
  ------------------
  |  Branch (2185:9): [True: 32, False: 0]
  ------------------
 2186|     32|      return turn_read_u16(value);
 2187|     32|    }
 2188|     32|  }
 2189|     12|  return -1;
 2190|     44|}
stun_attr_add_response_port_str:
 2192|  1.09k|bool stun_attr_add_response_port_str(uint8_t *buf, size_t *len, uint16_t port) {
 2193|  1.09k|  uint8_t avalue[4] = {0, 0, 0, 0};
 2194|  1.09k|  turn_write_u16(avalue, port);
 2195|       |
 2196|  1.09k|  return stun_attr_add_str(buf, len, STUN_ATTRIBUTE_RESPONSE_PORT, avalue, 4);
  ------------------
  |  |  135|  1.09k|#define STUN_ATTRIBUTE_RESPONSE_PORT (0x0027)
  ------------------
 2197|  1.09k|}
stun_attr_get_padding_len_str:
 2199|     33|int stun_attr_get_padding_len_str(stun_attr_ref attr) {
 2200|     33|  const int len = stun_attr_get_len(attr);
 2201|     33|  if (len < 0) {
  ------------------
  |  Branch (2201:7): [True: 0, False: 33]
  ------------------
 2202|      0|    return -1;
 2203|      0|  }
 2204|     33|  return (uint16_t)len;
 2205|     33|}
stun_attr_add_padding_str:
 2207|  1.09k|bool stun_attr_add_padding_str(uint8_t *buf, size_t *len, uint16_t padding_len) {
 2208|  1.09k|  uint8_t avalue[0xFFFF];
 2209|  1.09k|  memset(avalue, 0, padding_len);
 2210|       |
 2211|  1.09k|  return stun_attr_add_str(buf, len, STUN_ATTRIBUTE_PADDING, avalue, padding_len);
  ------------------
  |  |  134|  1.09k|#define STUN_ATTRIBUTE_PADDING (0x0026)
  ------------------
 2212|  1.09k|}
ns_turn_msg.c:fuzz_prng_next:
  112|  57.9k|static uint64_t fuzz_prng_next(void) {
  113|  57.9k|  static uint64_t state = UINT64_C(0x9e3779b97f4a7c15);
  114|       |
  115|  57.9k|  state += UINT64_C(0x9e3779b97f4a7c15);
  116|  57.9k|  uint64_t z = state;
  117|  57.9k|  z = (z ^ (z >> 30)) * UINT64_C(0xbf58476d1ce4e5b9);
  118|       |  z = (z ^ (z >> 27)) * UINT64_C(0x94d049bb133111eb);
  119|  57.9k|  return z ^ (z >> 31);
  120|  57.9k|}
ns_turn_msg.c:stun_init_error_response_common_str:
  888|  10.5k|                                                stun_tid *id, bool include_reason_string, bool pad_reason_phrase) {
  889|       |
  890|  10.5k|  if (include_reason_string && (!reason || !strcmp((const char *)reason, "Unknown error"))) {
  ------------------
  |  Branch (890:7): [True: 10.5k, False: 0]
  |  Branch (890:33): [True: 0, False: 10.5k]
  |  Branch (890:44): [True: 0, False: 10.5k]
  ------------------
  891|      0|    reason = get_default_reason(error_code);
  892|      0|  }
  893|       |
  894|  10.5k|  uint8_t avalue[513];
  895|  10.5k|  memset(avalue, 0, sizeof(avalue));
  896|  10.5k|  avalue[0] = 0;
  897|  10.5k|  avalue[1] = 0;
  898|  10.5k|  avalue[2] = (uint8_t)(error_code / 100);
  899|  10.5k|  avalue[3] = (uint8_t)(error_code % 100);
  900|  10.5k|  if (include_reason_string) {
  ------------------
  |  Branch (900:7): [True: 10.5k, False: 0]
  ------------------
  901|  10.5k|    strncpy((char *)(avalue + 4), (const char *)reason, sizeof(avalue) - 4);
  902|  10.5k|  }
  903|  10.5k|  avalue[sizeof(avalue) - 1] = 0;
  904|  10.5k|  int alen = 4 + (int)strlen((const char *)(avalue + 4));
  905|       |
  906|       |  /* RFC 3489 Section 11.2.9 requires a reason phrase length that is a multiple of 4;
  907|       |   * RFC 8489 Section 14 requires the declared length to exclude padding. */
  908|  10.5k|  if (pad_reason_phrase) {
  ------------------
  |  Branch (908:7): [True: 0, False: 10.5k]
  ------------------
  909|      0|    const int rem = alen % 4;
  910|      0|    if (rem) {
  ------------------
  |  Branch (910:9): [True: 0, False: 0]
  ------------------
  911|      0|      alen += (4 - rem);
  912|      0|    }
  913|      0|  }
  914|       |
  915|  10.5k|  stun_attr_add_str(buf, len, STUN_ATTRIBUTE_ERROR_CODE, (uint8_t *)avalue, alen);
  ------------------
  |  |  103|  10.5k|#define STUN_ATTRIBUTE_ERROR_CODE (0x0009)
  ------------------
  916|  10.5k|  if (id) {
  ------------------
  |  Branch (916:7): [True: 10.5k, False: 0]
  ------------------
  917|  10.5k|    stun_tid_message_cpy(buf, id);
  918|  10.5k|  }
  919|  10.5k|}
ns_turn_msg.c:stun_tid_from_string:
 1430|  15.5k|static void stun_tid_from_string(const uint8_t *s, stun_tid *id) {
 1431|  15.5k|  if (s && id) {
  ------------------
  |  Branch (1431:7): [True: 15.5k, False: 0]
  |  Branch (1431:12): [True: 15.5k, False: 0]
  ------------------
 1432|  15.5k|    memcpy(id->tsx_id, s, STUN_TID_SIZE);
  ------------------
  |  |   53|  15.5k|#define STUN_TID_SIZE (12)
  ------------------
 1433|  15.5k|  }
 1434|  15.5k|}
ns_turn_msg.c:stun_tid_string_cpy:
 1424|  29.8k|static void stun_tid_string_cpy(uint8_t *s, const stun_tid *id) {
 1425|  29.8k|  if (s && id) {
  ------------------
  |  Branch (1425:7): [True: 29.8k, False: 0]
  |  Branch (1425:12): [True: 29.8k, False: 0]
  ------------------
 1426|  29.8k|    memcpy(s, id->tsx_id, STUN_TID_SIZE);
  ------------------
  |  |   53|  29.8k|#define STUN_TID_SIZE (12)
  ------------------
 1427|  29.8k|  }
 1428|  29.8k|}
ns_turn_msg.c:turn_random_tid_size:
  154|  19.3k|static void turn_random_tid_size(void *id) {
  155|  19.3k|  uint8_t *ar = (uint8_t *)id;
  156|  19.3k|#if defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
  157|  19.3k|  if (ar) {
  ------------------
  |  Branch (157:7): [True: 19.3k, False: 0]
  ------------------
  158|  77.2k|    for (size_t i = 0; i < 3; ++i) {
  ------------------
  |  Branch (158:24): [True: 57.9k, False: 19.3k]
  ------------------
  159|  57.9k|      const uint32_t r = (uint32_t)turn_random_number();
  160|  57.9k|      memcpy(ar + i * sizeof(r), &r, sizeof(r));
  161|  57.9k|    }
  162|  19.3k|  }
  163|       |#else
  164|       |  if (!RAND_bytes((unsigned char *)ar, 12)) {
  165|       |    for (size_t i = 0; i < 3; ++i) {
  166|       |      const uint32_t r = (uint32_t)turn_random_number();
  167|       |      memcpy(ar + i * sizeof(r), &r, sizeof(r));
  168|       |    }
  169|       |  }
  170|       |#endif
  171|  19.3k|}
ns_turn_msg.c:stun_attr_check_valid:
 1616|  1.72M|static stun_attr_ref stun_attr_check_valid(stun_attr_ref attr, size_t remaining) {
 1617|  1.72M|  if (remaining >= 4) {
  ------------------
  |  Branch (1617:7): [True: 1.72M, False: 110]
  ------------------
 1618|       |    /* Read the size of the attribute */
 1619|  1.72M|    size_t attrlen = stun_attr_get_len(attr);
 1620|  1.72M|    remaining -= 4;
 1621|       |
 1622|       |    /* Round to boundary */
 1623|  1.72M|    const uint16_t rem4 = ((uint16_t)attrlen) & 0x0003;
 1624|  1.72M|    if (rem4) {
  ------------------
  |  Branch (1624:9): [True: 401k, False: 1.32M]
  ------------------
 1625|   401k|      attrlen = attrlen + 4 - (int)rem4;
 1626|   401k|    }
 1627|       |
 1628|       |    /* Check that there's enough space remaining */
 1629|  1.72M|    if (attrlen <= remaining) {
  ------------------
  |  Branch (1629:9): [True: 1.69M, False: 28.4k]
  ------------------
 1630|  1.69M|      return attr;
 1631|  1.69M|    }
 1632|  1.72M|  }
 1633|       |
 1634|  28.6k|  return NULL;
 1635|  1.72M|}
ns_turn_msg.c:stun_set_command_message_len_str:
  537|  73.1k|static bool stun_set_command_message_len_str(uint8_t *buf, int len) {
  538|  73.1k|  if (len < STUN_HEADER_LENGTH) {
  ------------------
  |  |   46|  73.1k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (538:7): [True: 0, False: 73.1k]
  ------------------
  539|      0|    return false;
  540|      0|  }
  541|  73.1k|  turn_write_u16(buf + 2, (uint16_t)(len - STUN_HEADER_LENGTH));
  ------------------
  |  |   46|  73.1k|#define STUN_HEADER_LENGTH (20)
  ------------------
  542|       |  return true;
  543|  73.1k|}
ns_turn_msg.c:ns_crc32:
 1896|  1.50k|static uint32_t ns_crc32(const uint8_t *buffer, uint32_t len) {
 1897|  1.50k|  uint32_t crc = CRC_MASK;
  ------------------
  |  | 1860|  1.50k|#define CRC_MASK 0xFFFFFFFFUL
  ------------------
 1898|  1.06M|  while (len--) {
  ------------------
  |  Branch (1898:10): [True: 1.06M, False: 1.50k]
  ------------------
 1899|  1.06M|    UPDATE_CRC(crc, *buffer++);
  ------------------
  |  | 1862|  1.06M|#define UPDATE_CRC(crc, c) crc = crctable[(uint8_t)crc ^ (uint8_t)(c)] ^ (crc >> 8)
  ------------------
 1900|  1.06M|  }
 1901|  1.50k|  return (~crc);
 1902|  1.50k|}

stun_addr_encode:
   42|  6.59k|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.59k|  if (!cfield || !clen || !ca || !tsx_id) {
  ------------------
  |  Branch (44:7): [True: 0, False: 6.59k]
  |  Branch (44:18): [True: 0, False: 6.59k]
  |  Branch (44:27): [True: 0, False: 6.59k]
  |  Branch (44:34): [True: 0, False: 6.59k]
  ------------------
   45|      0|    return -1;
   46|      0|  }
   47|       |
   48|  6.59k|  if (ca->ss.sa_family == AF_INET || ca->ss.sa_family == 0) {
  ------------------
  |  Branch (48:7): [True: 4.39k, False: 2.19k]
  |  Branch (48:38): [True: 0, False: 2.19k]
  ------------------
   49|       |
   50|       |    /* IPv4 address */
   51|       |
   52|  4.39k|    *clen = 8;
   53|       |
   54|  4.39k|    cfield[0] = 0;
   55|  4.39k|    cfield[1] = 1; // IPv4 family
   56|       |
   57|  4.39k|    if (xor_ed) {
  ------------------
  |  Branch (57:9): [True: 3.29k, False: 1.09k]
  ------------------
   58|       |
   59|       |      /* Port */
   60|  3.29k|      const uint16_t port = (ca->s4.sin_port) ^ nswap16(mc >> 16);
  ------------------
  |  |   86|  3.29k|#define nswap16(s) ntohs(s)
  ------------------
   61|  3.29k|      memcpy(cfield + 2, &port, sizeof(port));
   62|       |
   63|       |      /* Address */
   64|  3.29k|      const uint32_t addr = (ca->s4.sin_addr.s_addr) ^ nswap32(mc);
  ------------------
  |  |   87|  3.29k|#define nswap32(ul) ntohl(ul)
  ------------------
   65|  3.29k|      memcpy(cfield + 4, &addr, sizeof(addr));
   66|       |
   67|  3.29k|    } else {
   68|       |
   69|       |      /* Port */
   70|  1.09k|      const uint16_t port = ca->s4.sin_port;
   71|  1.09k|      memcpy(cfield + 2, &port, sizeof(port));
   72|       |
   73|       |      /* Address */
   74|  1.09k|      const uint32_t addr = ca->s4.sin_addr.s_addr;
   75|  1.09k|      memcpy(cfield + 4, &addr, sizeof(addr));
   76|  1.09k|    }
   77|       |
   78|  4.39k|  } else if (ca->ss.sa_family == AF_INET6) {
  ------------------
  |  Branch (78:14): [True: 2.19k, False: 0]
  ------------------
   79|       |
   80|       |    /* IPv6 address */
   81|       |
   82|  2.19k|    *clen = 20;
   83|       |
   84|  2.19k|    cfield[0] = 0;
   85|  2.19k|    cfield[1] = 2; // IPv6 family
   86|       |
   87|  2.19k|    if (xor_ed) {
  ------------------
  |  Branch (87:9): [True: 2.19k, False: 0]
  ------------------
   88|       |
   89|  2.19k|      unsigned int i;
   90|  2.19k|      uint8_t *dst = ((uint8_t *)cfield) + 4;
   91|  2.19k|      const uint8_t *src = (const uint8_t *)&(ca->s6.sin6_addr);
   92|  2.19k|      uint32_t magic = nswap32(mc);
  ------------------
  |  |   87|  2.19k|#define nswap32(ul) ntohl(ul)
  ------------------
   93|       |
   94|       |      /* Port */
   95|  2.19k|      const uint16_t port = ca->s6.sin6_port ^ nswap16(mc >> 16);
  ------------------
  |  |   86|  2.19k|#define nswap16(s) ntohs(s)
  ------------------
   96|  2.19k|      memcpy(cfield + 2, &port, sizeof(port));
   97|       |
   98|       |      /* Address */
   99|       |
  100|  10.9k|      for (i = 0; i < 4; ++i) {
  ------------------
  |  Branch (100:19): [True: 8.79k, False: 2.19k]
  ------------------
  101|  8.79k|        dst[i] = (uint8_t)(src[i] ^ ((const uint8_t *)&magic)[i]);
  102|  8.79k|      }
  103|  28.5k|      for (i = 0; i < 12; ++i) {
  ------------------
  |  Branch (103:19): [True: 26.3k, False: 2.19k]
  ------------------
  104|  26.3k|        dst[i + 4] = (uint8_t)(src[i + 4] ^ tsx_id[i]);
  105|  26.3k|      }
  106|       |
  107|  2.19k|    } 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.19k|  } else {
  118|      0|    return -1;
  119|      0|  }
  120|       |
  121|  6.59k|  return 0;
  122|  6.59k|}
stun_addr_decode:
  124|  3.43k|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.43k|  if (!cfield || !len || !ca || !tsx_id || (len < 8)) {
  ------------------
  |  Branch (126:7): [True: 0, False: 3.43k]
  |  Branch (126:18): [True: 0, False: 3.43k]
  |  Branch (126:26): [True: 0, False: 3.43k]
  |  Branch (126:33): [True: 0, False: 3.43k]
  |  Branch (126:44): [True: 1.08k, False: 2.35k]
  ------------------
  127|  1.08k|    return -1;
  128|  1.08k|  }
  129|       |
  130|  2.35k|  if (cfield[0] != 0) {
  ------------------
  |  Branch (130:7): [True: 387, False: 1.96k]
  ------------------
  131|    387|    return -1;
  132|    387|  }
  133|       |
  134|  1.96k|  int sa_family;
  135|       |
  136|  1.96k|  if (cfield[1] == 1) {
  ------------------
  |  Branch (136:7): [True: 1.05k, False: 905]
  ------------------
  137|  1.05k|    sa_family = AF_INET;
  138|  1.05k|  } else if (cfield[1] == 2) {
  ------------------
  |  Branch (138:14): [True: 477, False: 428]
  ------------------
  139|    477|    sa_family = AF_INET6;
  140|    477|  } else {
  141|    428|    return -1;
  142|    428|  }
  143|       |
  144|  1.53k|  ca->ss.sa_family = sa_family;
  145|       |
  146|  1.53k|  if (sa_family == AF_INET) {
  ------------------
  |  Branch (146:7): [True: 1.05k, False: 477]
  ------------------
  147|       |
  148|  1.05k|    if (len != 8) {
  ------------------
  |  Branch (148:9): [True: 325, False: 733]
  ------------------
  149|    325|      return -1;
  150|    325|    }
  151|       |
  152|       |    /* IPv4 address */
  153|       |
  154|       |    /* Port */
  155|    733|    memcpy(&ca->s4.sin_port, cfield + 2, sizeof(ca->s4.sin_port));
  156|       |
  157|       |    /* Address */
  158|    733|    memcpy(&ca->s4.sin_addr.s_addr, cfield + 4, sizeof(ca->s4.sin_addr.s_addr));
  159|       |
  160|    733|    if (xor_ed) {
  ------------------
  |  Branch (160:9): [True: 263, False: 470]
  ------------------
  161|    263|      ca->s4.sin_port ^= nswap16(mc >> 16);
  ------------------
  |  |   86|    263|#define nswap16(s) ntohs(s)
  ------------------
  162|    263|      ca->s4.sin_addr.s_addr ^= nswap32(mc);
  ------------------
  |  |   87|    263|#define nswap32(ul) ntohl(ul)
  ------------------
  163|    263|    }
  164|       |
  165|    733|  } else if (sa_family == AF_INET6) {
  ------------------
  |  Branch (165:14): [True: 477, False: 0]
  ------------------
  166|       |
  167|       |    /* IPv6 address */
  168|       |
  169|    477|    if (len != 20) {
  ------------------
  |  Branch (169:9): [True: 241, False: 236]
  ------------------
  170|    241|      return -1;
  171|    241|    }
  172|       |
  173|       |    /* Port */
  174|    236|    memcpy(&ca->s6.sin6_port, cfield + 2, sizeof(ca->s6.sin6_port));
  175|       |
  176|       |    /* Address */
  177|    236|    memcpy(&ca->s6.sin6_addr, ((const uint8_t *)cfield) + 4, 16);
  178|       |
  179|    236|    if (xor_ed) {
  ------------------
  |  Branch (179:9): [True: 116, False: 120]
  ------------------
  180|       |
  181|    116|      unsigned int i;
  182|    116|      uint8_t *dst;
  183|    116|      const uint8_t *src;
  184|    116|      uint32_t magic = nswap32(mc);
  ------------------
  |  |   87|    116|#define nswap32(ul) ntohl(ul)
  ------------------
  185|       |
  186|       |      /* Port */
  187|    116|      ca->s6.sin6_port ^= nswap16(mc >> 16);
  ------------------
  |  |   86|    116|#define nswap16(s) ntohs(s)
  ------------------
  188|       |
  189|       |      /* Address */
  190|    116|      src = ((const uint8_t *)cfield) + 4;
  191|    116|      dst = (uint8_t *)&ca->s6.sin6_addr;
  192|    580|      for (i = 0; i < 4; ++i) {
  ------------------
  |  Branch (192:19): [True: 464, False: 116]
  ------------------
  193|    464|        dst[i] = (uint8_t)(src[i] ^ ((const uint8_t *)&magic)[i]);
  194|    464|      }
  195|  1.50k|      for (i = 0; i < 12; ++i) {
  ------------------
  |  Branch (195:19): [True: 1.39k, False: 116]
  ------------------
  196|  1.39k|        dst[i + 4] = (uint8_t)(src[i + 4] ^ tsx_id[i]);
  197|  1.39k|      }
  198|    116|    }
  199|       |
  200|    236|  } else {
  201|      0|    return -1;
  202|      0|  }
  203|       |
  204|    969|  return 0;
  205|  1.53k|}

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

