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:
  816|  1.76k|extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
  817|  1.76k|  harness_stun_client(Data, Size);
  818|  1.76k|  harness_channel_data(Data, Size);
  819|  1.76k|  harness_addr_codec(Data, Size);
  820|  1.76k|  harness_message_builders(Data, Size);
  821|  1.76k|  harness_attr_get_first_addr(Data, Size);
  822|  1.76k|  harness_response_matrix(Data, Size);
  823|  1.76k|  harness_stun_buffer_api(Data, Size);
  824|  1.76k|  return 0;
  825|  1.76k|}
FuzzStunClient.c:harness_stun_client:
  212|  1.76k|static void harness_stun_client(const uint8_t *Data, size_t Size) {
  213|  1.76k|  if (Size < 10 || Size > 5120) {
  ------------------
  |  Branch (213:7): [True: 511, False: 1.25k]
  |  Branch (213:20): [True: 95, False: 1.16k]
  ------------------
  214|    606|    return;
  215|    606|  }
  216|       |
  217|  1.16k|  stun_buffer buf;
  218|  1.16k|  buf.len = Size;
  219|  1.16k|  memcpy(buf.buf, Data, buf.len);
  220|       |
  221|  1.16k|  if (!stun_is_command_message(&buf)) {
  ------------------
  |  Branch (221:7): [True: 1.00k, False: 159]
  ------------------
  222|  1.00k|    return;
  223|  1.00k|  }
  224|       |
  225|    159|  (void)stun_get_method_str(buf.buf, buf.len);
  226|    159|  (void)stun_get_msg_type_str(buf.buf, buf.len);
  227|       |
  228|    159|  if (stun_is_response(&buf) && stun_is_success_response(&buf) && stun_is_binding_response(&buf)) {
  ------------------
  |  Branch (228:7): [True: 146, False: 13]
  |  Branch (228:33): [True: 42, False: 104]
  |  Branch (228:67): [True: 9, False: 33]
  ------------------
  229|      9|    return;
  230|      9|  }
  231|       |
  232|    150|  stun_is_indication_str(buf.buf, buf.len);
  233|       |
  234|    150|  int err_code = 0;
  235|    150|  uint8_t err_msg[256] = {0};
  236|    150|  stun_is_error_response_str(buf.buf, buf.len, &err_code, err_msg, sizeof(err_msg));
  237|    150|}
FuzzStunClient.c:harness_channel_data:
  242|  1.76k|static void harness_channel_data(const uint8_t *Data, size_t Size) {
  243|  1.76k|  if (Size < 4 || Size > 8192) {
  ------------------
  |  Branch (243:7): [True: 291, False: 1.47k]
  |  Branch (243:19): [True: 70, False: 1.40k]
  ------------------
  244|    361|    return;
  245|    361|  }
  246|       |
  247|  1.40k|  uint8_t buf[8192] = {0};
  248|  1.40k|  memcpy(buf, Data, Size);
  249|       |
  250|  1.40k|  size_t app_len_tcp = 0;
  251|  1.40k|  size_t app_len_udp = 0;
  252|       |
  253|  1.40k|  int mlen_tcp = stun_get_message_len_str(buf, Size, 1, &app_len_tcp);
  254|  1.40k|  int mlen_udp = stun_get_message_len_str(buf, Size, 0, &app_len_udp);
  255|       |
  256|  1.40k|  if (mlen_tcp > 0) {
  ------------------
  |  Branch (256:7): [True: 550, False: 858]
  ------------------
  257|    550|    if (app_len_tcp > Size) {
  ------------------
  |  Branch (257:9): [True: 0, False: 550]
  ------------------
  258|      0|      __builtin_trap();
  259|      0|    }
  260|    550|    if ((size_t)mlen_tcp > Size) {
  ------------------
  |  Branch (260:9): [True: 0, False: 550]
  ------------------
  261|      0|      __builtin_trap();
  262|      0|    }
  263|    550|    if ((size_t)mlen_tcp < app_len_tcp) {
  ------------------
  |  Branch (263:9): [True: 0, False: 550]
  ------------------
  264|      0|      __builtin_trap();
  265|      0|    }
  266|    550|  }
  267|       |
  268|  1.40k|  if (mlen_udp > 0) {
  ------------------
  |  Branch (268:7): [True: 565, False: 843]
  ------------------
  269|    565|    if (app_len_udp > Size) {
  ------------------
  |  Branch (269:9): [True: 0, False: 565]
  ------------------
  270|      0|      __builtin_trap();
  271|      0|    }
  272|    565|    if ((size_t)mlen_udp > Size) {
  ------------------
  |  Branch (272:9): [True: 0, False: 565]
  ------------------
  273|      0|      __builtin_trap();
  274|      0|    }
  275|    565|  }
  276|       |
  277|  1.40k|  size_t blen_tcp = Size;
  278|  1.40k|  uint16_t chn_tcp = 0;
  279|  1.40k|  bool is_chan_tcp = stun_is_channel_message_str(buf, &blen_tcp, &chn_tcp, true);
  280|       |
  281|  1.40k|  size_t blen_udp = Size;
  282|  1.40k|  uint16_t chn_udp = 0;
  283|  1.40k|  bool is_chan_udp = stun_is_channel_message_str(buf, &blen_udp, &chn_udp, false);
  284|       |
  285|  1.40k|  if (is_chan_tcp && (blen_tcp < 4 || blen_tcp > Size)) {
  ------------------
  |  Branch (285:7): [True: 95, False: 1.31k]
  |  Branch (285:23): [True: 0, False: 95]
  |  Branch (285:39): [True: 0, False: 95]
  ------------------
  286|      0|    __builtin_trap();
  287|      0|  }
  288|  1.40k|  if (is_chan_udp && (blen_udp < 4 || blen_udp > Size)) {
  ------------------
  |  Branch (288:7): [True: 98, False: 1.31k]
  |  Branch (288:23): [True: 0, False: 98]
  |  Branch (288:39): [True: 0, False: 98]
  ------------------
  289|      0|    __builtin_trap();
  290|      0|  }
  291|  1.40k|}
FuzzStunClient.c:harness_addr_codec:
  296|  1.76k|static void harness_addr_codec(const uint8_t *Data, size_t Size) {
  297|  1.76k|  if (Size < 2 || Size > 64) {
  ------------------
  |  Branch (297:7): [True: 73, False: 1.69k]
  |  Branch (297:19): [True: 499, False: 1.19k]
  ------------------
  298|    572|    return;
  299|    572|  }
  300|       |
  301|  1.19k|  uint8_t tid[STUN_TID_SIZE] = {0};
  302|  1.19k|  size_t tid_bytes = Size > (STUN_TID_SIZE + 2) ? STUN_TID_SIZE : (Size > 2 ? Size - 2 : 0);
  ------------------
  |  |   53|  1.19k|#define STUN_TID_SIZE (12)
  ------------------
                size_t tid_bytes = Size > (STUN_TID_SIZE + 2) ? STUN_TID_SIZE : (Size > 2 ? Size - 2 : 0);
  ------------------
  |  |   53|    678|#define STUN_TID_SIZE (12)
  ------------------
  |  Branch (302:22): [True: 678, False: 519]
  |  Branch (302:68): [True: 435, False: 84]
  ------------------
  303|  1.19k|  memcpy(tid, Data, tid_bytes);
  304|  1.19k|  const uint8_t *payload = Data + tid_bytes;
  305|  1.19k|  int payload_len = (int)(Size - tid_bytes);
  306|       |
  307|  1.19k|  ioa_addr addr = {0};
  308|       |
  309|       |  /* XOR decode + round-trip */
  310|  1.19k|  if (stun_addr_decode(&addr, payload, payload_len, 1, STUN_MAGIC_COOKIE, tid) == 0) {
  ------------------
  |  |   56|  1.19k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (310:7): [True: 11, False: 1.18k]
  ------------------
  311|     11|    uint8_t enc_buf[32] = {0};
  312|     11|    int enc_len = 0;
  313|     11|    if (stun_addr_encode(&addr, enc_buf, &enc_len, 1, STUN_MAGIC_COOKIE, tid) == 0) {
  ------------------
  |  |   56|     11|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (313:9): [True: 11, False: 0]
  ------------------
  314|     11|      ioa_addr addr2 = {0};
  315|     11|      stun_addr_decode(&addr2, enc_buf, enc_len, 1, STUN_MAGIC_COOKIE, tid);
  ------------------
  |  |   56|     11|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  316|     11|    }
  317|     11|  }
  318|       |
  319|       |  /* Plain decode + round-trip */
  320|  1.19k|  memset(&addr, 0, sizeof(addr));
  321|  1.19k|  if (stun_addr_decode(&addr, payload, payload_len, 0, 0, tid) == 0) {
  ------------------
  |  Branch (321:7): [True: 11, False: 1.18k]
  ------------------
  322|     11|    uint8_t enc_buf[32] = {0};
  323|     11|    int enc_len = 0;
  324|     11|    if (stun_addr_encode(&addr, enc_buf, &enc_len, 0, 0, tid) == 0) {
  ------------------
  |  Branch (324:9): [True: 11, False: 0]
  ------------------
  325|     11|      ioa_addr addr2 = {0};
  326|     11|      stun_addr_decode(&addr2, enc_buf, enc_len, 0, 0, tid);
  327|     11|    }
  328|     11|  }
  329|       |
  330|       |  /* Alternate magic cookie (old STUN) */
  331|  1.19k|  memset(&addr, 0, sizeof(addr));
  332|  1.19k|  uint32_t alt_cookie = 0;
  333|  1.19k|  if (Size >= 4) {
  ------------------
  |  Branch (333:7): [True: 979, False: 218]
  ------------------
  334|    979|    memcpy(&alt_cookie, Data, 4);
  335|    979|  }
  336|  1.19k|  (void)stun_addr_decode(&addr, payload, payload_len, 1, alt_cookie, tid);
  337|  1.19k|}
FuzzStunClient.c:harness_message_builders:
  342|  1.76k|static void harness_message_builders(const uint8_t *Data, size_t Size) {
  343|  1.76k|  if (!Size || Size > 4096) {
  ------------------
  |  Branch (343:7): [True: 0, False: 1.76k]
  |  Branch (343:16): [True: 140, False: 1.62k]
  ------------------
  344|    140|    return;
  345|    140|  }
  346|       |
  347|  1.62k|  static const uint16_t kMethods[] = {
  348|  1.62k|      STUN_METHOD_ALLOCATE, STUN_METHOD_BINDING, STUN_METHOD_CHANNEL_BIND, STUN_METHOD_REFRESH, STUN_METHOD_CONNECT,
  ------------------
  |  |   78|  1.62k|#define STUN_METHOD_ALLOCATE (0x0003)
  ------------------
                    STUN_METHOD_ALLOCATE, STUN_METHOD_BINDING, STUN_METHOD_CHANNEL_BIND, STUN_METHOD_REFRESH, STUN_METHOD_CONNECT,
  ------------------
  |  |   77|  1.62k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
                    STUN_METHOD_ALLOCATE, STUN_METHOD_BINDING, STUN_METHOD_CHANNEL_BIND, STUN_METHOD_REFRESH, STUN_METHOD_CONNECT,
  ------------------
  |  |   83|  1.62k|#define STUN_METHOD_CHANNEL_BIND (0x0009)
  ------------------
                    STUN_METHOD_ALLOCATE, STUN_METHOD_BINDING, STUN_METHOD_CHANNEL_BIND, STUN_METHOD_REFRESH, STUN_METHOD_CONNECT,
  ------------------
  |  |   79|  1.62k|#define STUN_METHOD_REFRESH (0x0004)
  ------------------
                    STUN_METHOD_ALLOCATE, STUN_METHOD_BINDING, STUN_METHOD_CHANNEL_BIND, STUN_METHOD_REFRESH, STUN_METHOD_CONNECT,
  ------------------
  |  |   86|  1.62k|#define STUN_METHOD_CONNECT (0x000a)
  ------------------
  349|  1.62k|  };
  350|  1.62k|  static const uint16_t kErrorCodes[] = {
  351|  1.62k|      300, 400, 401, 403, 420, 437, 438, 440, 441, 442, 443, 446, 447, 486, 487, 500, 508, 699,
  352|  1.62k|  };
  353|       |
  354|  1.62k|  stun_tid tid = {0};
  355|  1.62k|  ioa_addr relay1 = {0};
  356|  1.62k|  ioa_addr relay2 = {0};
  357|  1.62k|  ioa_addr reflexive = {0};
  358|  1.62k|  ioa_addr peer = {0};
  359|  1.62k|  ioa_addr default_addr = {0};
  360|  1.62k|  char reason[96] = {0};
  361|  1.62k|  char mobile_id[96] = {0};
  362|  1.62k|  uint8_t raw[MAX_STUN_MESSAGE_SIZE] = {0};
  363|       |
  364|  1.62k|  fuzz_tid(Data, Size, 0, &tid);
  365|  1.62k|  fuzz_addr(Data, Size, 16, &relay1);
  366|  1.62k|  fuzz_addr(Data, Size, 40, &relay2);
  367|  1.62k|  fuzz_addr(Data, Size, 64, &reflexive);
  368|  1.62k|  fuzz_addr(Data, Size, 88, &peer);
  369|  1.62k|  fuzz_addr(Data, Size, 112, &default_addr);
  370|  1.62k|  fuzz_string(Data, Size, 136, reason, sizeof(reason));
  371|  1.62k|  fuzz_string(Data, Size, 232, mobile_id, sizeof(mobile_id));
  372|       |
  373|  1.62k|  const uint16_t method = kMethods[fuzz_byte(Data, Size, 328) % (sizeof(kMethods) / sizeof(kMethods[0]))];
  374|  1.62k|  const uint16_t error_code = kErrorCodes[fuzz_byte(Data, Size, 329) % (sizeof(kErrorCodes) / sizeof(kErrorCodes[0]))];
  375|  1.62k|  const uint32_t lifetime = fuzz_u32(Data, Size, 330);
  376|  1.62k|  const uint32_t max_lifetime = fuzz_u32(Data, Size, 334);
  377|  1.62k|  const uint64_t reservation_token = fuzz_u64(Data, Size, 338);
  378|  1.62k|  const uint16_t channel_number = fuzz_u16(Data, Size, 346);
  379|  1.62k|  const bool include_reason = fuzz_flag(Data, Size, 348);
  380|  1.62k|  const bool old_stun = fuzz_flag(Data, Size, 349);
  381|  1.62k|  const bool stun_backward_compatibility = fuzz_flag(Data, Size, 350);
  382|  1.62k|  const uint32_t old_cookie = fuzz_u32(Data, Size, 351);
  383|       |
  384|       |  /* Direct wrapper coverage for stun_init_error_response(). */
  385|  1.62k|  {
  386|  1.62k|    stun_buffer msg;
  387|  1.62k|    stun_init_buffer(&msg);
  388|  1.62k|    stun_init_error_response(method, &msg, error_code, reason[0] ? (const uint8_t *)reason : NULL, &tid,
  ------------------
  |  Branch (388:56): [True: 1.12k, False: 506]
  ------------------
  389|  1.62k|                             include_reason);
  390|  1.62k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_MAPPED_ADDRESS, &default_addr);
  ------------------
  |  |   91|  1.62k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
  391|  1.62k|  }
  392|       |
  393|       |  /* Success allocate response covers addr extraction; error allocate response
  394|       |   * forces the shared error builder path. */
  395|  1.62k|  {
  396|  1.62k|    stun_buffer msg;
  397|  1.62k|    stun_init_buffer(&msg);
  398|  1.62k|    (void)stun_set_allocate_response(&msg, &tid, &relay1, fuzz_flag(Data, Size, 355) ? &relay2 : NULL, &reflexive,
  ------------------
  |  Branch (398:59): [True: 602, False: 1.02k]
  ------------------
  399|  1.62k|                                     lifetime, max_lifetime, 0, (const uint8_t *)reason, reservation_token, mobile_id,
  400|  1.62k|                                     include_reason);
  401|  1.62k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, &default_addr);
  ------------------
  |  |  118|  1.62k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  402|       |
  403|  1.62k|    size_t raw_len = sizeof(raw);
  404|  1.62k|    (void)stun_set_allocate_response_str(raw, &raw_len, &tid, &relay1, &relay2, &reflexive, lifetime, max_lifetime, 0,
  405|  1.62k|                                         (const uint8_t *)reason, reservation_token, mobile_id, include_reason);
  406|  1.62k|    inspect_raw_message(raw, raw_len, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, &default_addr);
  ------------------
  |  |  118|  1.62k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  407|       |
  408|  1.62k|    stun_init_buffer(&msg);
  409|  1.62k|    (void)stun_set_allocate_response(&msg, &tid, NULL, NULL, NULL, lifetime, max_lifetime, error_code,
  410|  1.62k|                                     reason[0] ? (const uint8_t *)reason : NULL, reservation_token, mobile_id,
  ------------------
  |  Branch (410:38): [True: 1.12k, False: 506]
  ------------------
  411|  1.62k|                                     include_reason);
  412|  1.62k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, &default_addr);
  ------------------
  |  |  118|  1.62k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  413|       |
  414|  1.62k|    raw_len = sizeof(raw);
  415|  1.62k|    (void)stun_set_allocate_response_str(raw, &raw_len, &tid, NULL, NULL, NULL, lifetime, max_lifetime, error_code,
  416|  1.62k|                                         reason[0] ? (const uint8_t *)reason : NULL, reservation_token, mobile_id,
  ------------------
  |  Branch (416:42): [True: 1.12k, False: 506]
  ------------------
  417|  1.62k|                                         include_reason);
  418|  1.62k|    inspect_raw_message(raw, raw_len, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, &default_addr);
  ------------------
  |  |  118|  1.62k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  419|  1.62k|  }
  420|       |
  421|  1.62k|  {
  422|  1.62k|    stun_buffer msg;
  423|  1.62k|    stun_init_buffer(&msg);
  424|  1.62k|    (void)stun_set_binding_response(&msg, &tid, &reflexive, 0, (const uint8_t *)reason, include_reason);
  425|  1.62k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS, &default_addr);
  ------------------
  |  |  105|  1.62k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  426|       |
  427|  1.62k|    size_t raw_len = sizeof(raw);
  428|  1.62k|    (void)stun_set_binding_response_str(raw, &raw_len, &tid, &reflexive, 0, (const uint8_t *)reason, old_cookie,
  429|  1.62k|                                        old_stun, stun_backward_compatibility, include_reason);
  430|  1.62k|    inspect_raw_message(raw, raw_len, old_stun ? STUN_ATTRIBUTE_MAPPED_ADDRESS : STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS,
  ------------------
  |  |   91|    661|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
                  inspect_raw_message(raw, raw_len, old_stun ? STUN_ATTRIBUTE_MAPPED_ADDRESS : STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS,
  ------------------
  |  |  105|  2.59k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (430:39): [True: 661, False: 968]
  ------------------
  431|  1.62k|                        &default_addr);
  432|       |
  433|  1.62k|    stun_init_buffer(&msg);
  434|  1.62k|    (void)stun_set_binding_response(&msg, &tid, NULL, error_code, reason[0] ? (const uint8_t *)reason : NULL,
  ------------------
  |  Branch (434:67): [True: 1.12k, False: 506]
  ------------------
  435|  1.62k|                                    include_reason);
  436|  1.62k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_MAPPED_ADDRESS, &default_addr);
  ------------------
  |  |   91|  1.62k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
  437|       |
  438|  1.62k|    raw_len = sizeof(raw);
  439|  1.62k|    (void)stun_set_binding_response_str(raw, &raw_len, &tid, NULL, error_code,
  440|  1.62k|                                        reason[0] ? (const uint8_t *)reason : NULL, old_cookie, old_stun,
  ------------------
  |  Branch (440:41): [True: 1.12k, False: 506]
  ------------------
  441|  1.62k|                                        stun_backward_compatibility, include_reason);
  442|  1.62k|    inspect_raw_message(raw, raw_len, STUN_ATTRIBUTE_MAPPED_ADDRESS, &default_addr);
  ------------------
  |  |   91|  1.62k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
  443|  1.62k|  }
  444|       |
  445|  1.62k|  {
  446|  1.62k|    stun_buffer msg;
  447|  1.62k|    stun_init_buffer(&msg);
  448|  1.62k|    (void)stun_set_channel_bind_request(&msg, fuzz_flag(Data, Size, 356) ? &peer : NULL, channel_number);
  ------------------
  |  Branch (448:47): [True: 665, False: 964]
  ------------------
  449|  1.62k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &default_addr);
  ------------------
  |  |  116|  1.62k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  450|       |
  451|  1.62k|    size_t raw_len = sizeof(raw);
  452|  1.62k|    (void)stun_set_channel_bind_request_str(raw, &raw_len, fuzz_flag(Data, Size, 357) ? &peer : NULL, channel_number);
  ------------------
  |  Branch (452:60): [True: 641, False: 988]
  ------------------
  453|  1.62k|    inspect_raw_message(raw, raw_len, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &default_addr);
  ------------------
  |  |  116|  1.62k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  454|       |
  455|  1.62k|    stun_init_buffer(&msg);
  456|  1.62k|    stun_set_channel_bind_response(&msg, &tid, 0, (const uint8_t *)reason, include_reason);
  457|  1.62k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &default_addr);
  ------------------
  |  |  116|  1.62k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  458|       |
  459|  1.62k|    raw_len = sizeof(raw);
  460|  1.62k|    stun_set_channel_bind_response_str(raw, &raw_len, &tid, error_code, reason[0] ? (const uint8_t *)reason : NULL,
  ------------------
  |  Branch (460:73): [True: 1.12k, False: 506]
  ------------------
  461|  1.62k|                                       include_reason);
  462|  1.62k|    inspect_raw_message(raw, raw_len, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &default_addr);
  ------------------
  |  |  116|  1.62k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  463|  1.62k|  }
  464|  1.62k|}
FuzzStunClient.c:fuzz_tid:
   57|  4.88k|static void fuzz_tid(const uint8_t *Data, size_t Size, size_t idx, stun_tid *tid) {
   58|  4.88k|  if (!tid) {
  ------------------
  |  Branch (58:7): [True: 0, False: 4.88k]
  ------------------
   59|      0|    return;
   60|      0|  }
   61|       |
   62|  4.88k|  memset(tid, 0, sizeof(*tid));
   63|  63.5k|  for (size_t i = 0; i < STUN_TID_SIZE; ++i) {
  ------------------
  |  |   53|  63.5k|#define STUN_TID_SIZE (12)
  ------------------
  |  Branch (63:22): [True: 58.6k, False: 4.88k]
  ------------------
   64|  58.6k|    tid->tsx_id[i] = fuzz_byte(Data, Size, idx + i);
   65|  58.6k|  }
   66|  4.88k|}
FuzzStunClient.c:fuzz_addr:
   68|  20.5k|static void fuzz_addr(const uint8_t *Data, size_t Size, size_t idx, ioa_addr *addr) {
   69|  20.5k|  if (!addr) {
  ------------------
  |  Branch (69:7): [True: 0, False: 20.5k]
  ------------------
   70|      0|    return;
   71|      0|  }
   72|       |
   73|  20.5k|  memset(addr, 0, sizeof(*addr));
   74|       |
   75|  20.5k|  if (fuzz_flag(Data, Size, idx)) {
  ------------------
  |  Branch (75:7): [True: 8.38k, False: 12.1k]
  ------------------
   76|  8.38k|    addr->s6.sin6_family = AF_INET6;
   77|  8.38k|    addr->s6.sin6_port = htons(fuzz_u16(Data, Size, idx + 1));
   78|   142k|    for (size_t i = 0; i < 16; ++i) {
  ------------------
  |  Branch (78:24): [True: 134k, False: 8.38k]
  ------------------
   79|   134k|      addr->s6.sin6_addr.s6_addr[i] = fuzz_byte(Data, Size, idx + 3 + i);
   80|   134k|    }
   81|  8.38k|    if (!memcmp(addr->s6.sin6_addr.s6_addr, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16)) {
  ------------------
  |  Branch (81:9): [True: 49, False: 8.34k]
  ------------------
   82|     49|      addr->s6.sin6_addr.s6_addr[15] = 1;
   83|     49|    }
   84|  12.1k|  } else {
   85|  12.1k|    addr->s4.sin_family = AF_INET;
   86|  12.1k|    addr->s4.sin_port = htons(fuzz_u16(Data, Size, idx + 1));
   87|       |    addr->s4.sin_addr.s_addr = htonl(fuzz_u32(Data, Size, idx + 3) | 1u);
   88|  12.1k|  }
   89|  20.5k|}
FuzzStunClient.c:fuzz_string:
   42|  9.77k|static void fuzz_string(const uint8_t *Data, size_t Size, size_t idx, char *out, size_t out_size) {
   43|  9.77k|  if (!out || !out_size) {
  ------------------
  |  Branch (43:7): [True: 0, False: 9.77k]
  |  Branch (43:15): [True: 0, False: 9.77k]
  ------------------
   44|      0|    return;
   45|      0|  }
   46|       |
   47|  9.77k|  const size_t max_len = out_size - 1;
   48|  9.77k|  const size_t len = max_len ? (size_t)(fuzz_byte(Data, Size, idx) % (max_len + 1)) : 0;
  ------------------
  |  Branch (48:22): [True: 9.77k, False: 0]
  ------------------
   49|       |
   50|   257k|  for (size_t i = 0; i < len; ++i) {
  ------------------
  |  Branch (50:22): [True: 247k, False: 9.77k]
  ------------------
   51|   247k|    out[i] = (char)('A' + (fuzz_byte(Data, Size, idx + 1 + i) % 26));
   52|   247k|  }
   53|       |
   54|  9.77k|  out[len] = '\0';
   55|  9.77k|}
FuzzStunClient.c:fuzz_byte:
   26|   664k|static uint8_t fuzz_byte(const uint8_t *Data, size_t Size, size_t idx) { return Size ? Data[idx % Size] : 0; }
  ------------------
  |  Branch (26:81): [True: 664k, False: 0]
  ------------------
FuzzStunClient.c:fuzz_u32:
   32|  28.4k|static uint32_t fuzz_u32(const uint8_t *Data, size_t Size, size_t idx) {
   33|  28.4k|  return ((uint32_t)fuzz_u16(Data, Size, idx) << 16) | (uint32_t)fuzz_u16(Data, Size, idx + 2);
   34|  28.4k|}
FuzzStunClient.c:fuzz_u64:
   36|  3.25k|static uint64_t fuzz_u64(const uint8_t *Data, size_t Size, size_t idx) {
   37|  3.25k|  return ((uint64_t)fuzz_u32(Data, Size, idx) << 32) | (uint64_t)fuzz_u32(Data, Size, idx + 4);
   38|  3.25k|}
FuzzStunClient.c:fuzz_u16:
   28|  84.0k|static uint16_t fuzz_u16(const uint8_t *Data, size_t Size, size_t idx) {
   29|  84.0k|  return (uint16_t)(((uint16_t)fuzz_byte(Data, Size, idx) << 8) | (uint16_t)fuzz_byte(Data, Size, idx + 1));
   30|  84.0k|}
FuzzStunClient.c:fuzz_flag:
   40|  36.8k|static bool fuzz_flag(const uint8_t *Data, size_t Size, size_t idx) { return (fuzz_byte(Data, Size, idx) & 1u) != 0; }
FuzzStunClient.c:inspect_buffer_message:
   91|  40.7k|static void inspect_buffer_message(stun_buffer *msg, uint16_t addr_attr_type, const ioa_addr *default_addr) {
   92|  40.7k|  if (!msg) {
  ------------------
  |  Branch (92:7): [True: 0, False: 40.7k]
  ------------------
   93|      0|    return;
   94|      0|  }
   95|       |
   96|  40.7k|  (void)stun_get_command_message_len(msg);
   97|  40.7k|  (void)stun_is_command_message(msg);
   98|  40.7k|  (void)stun_is_request(msg);
   99|  40.7k|  (void)stun_is_response(msg);
  100|  40.7k|  (void)stun_is_success_response(msg);
  101|  40.7k|  (void)stun_is_binding_response(msg);
  102|  40.7k|  (void)stun_get_method(msg);
  103|  40.7k|  (void)stun_get_msg_type(msg);
  104|       |
  105|  40.7k|  {
  106|  40.7k|    int err_code = 0;
  107|  40.7k|    uint8_t err_msg[256] = {0};
  108|  40.7k|    (void)stun_is_error_response(msg, &err_code, err_msg, sizeof(err_msg));
  109|  40.7k|  }
  110|       |
  111|  40.7k|  {
  112|  40.7k|    ioa_addr parsed = {0};
  113|  40.7k|    (void)stun_attr_get_first_addr(msg, addr_attr_type, &parsed, default_addr);
  114|  40.7k|  }
  115|       |
  116|  40.7k|  {
  117|  40.7k|    stun_attr_ref attr = stun_attr_get_first(msg);
  118|   111k|    while (attr) {
  ------------------
  |  Branch (118:12): [True: 71.2k, False: 40.7k]
  ------------------
  119|  71.2k|      (void)stun_attr_get_type(attr);
  120|  71.2k|      (void)stun_attr_get_len(attr);
  121|  71.2k|      if (stun_attr_is_addr(attr)) {
  ------------------
  |  Branch (121:11): [True: 23.4k, False: 47.8k]
  ------------------
  122|  23.4k|        ioa_addr parsed = {0};
  123|  23.4k|        (void)stun_attr_get_addr(msg, attr, &parsed, default_addr);
  124|  23.4k|      }
  125|  71.2k|      attr = stun_attr_get_next(msg, attr);
  126|  71.2k|    }
  127|  40.7k|  }
  128|       |
  129|  40.7k|  (void)stun_attr_get_first_channel_number(msg);
  130|  40.7k|}
FuzzStunClient.c:inspect_raw_message:
  132|  34.2k|static void inspect_raw_message(const uint8_t *buf, size_t len, uint16_t addr_attr_type, const ioa_addr *default_addr) {
  133|  34.2k|  if (!buf || !len) {
  ------------------
  |  Branch (133:7): [True: 0, False: 34.2k]
  |  Branch (133:15): [True: 0, False: 34.2k]
  ------------------
  134|      0|    return;
  135|      0|  }
  136|       |
  137|  34.2k|  (void)stun_is_command_message_str((uint8_t *)buf, len);
  138|  34.2k|  (void)stun_is_request_str(buf, len);
  139|  34.2k|  (void)stun_is_response_str(buf, len);
  140|  34.2k|  (void)stun_is_success_response_str(buf, len);
  141|  34.2k|  (void)stun_is_binding_response_str(buf, len);
  142|  34.2k|  (void)stun_get_method_str(buf, len);
  143|  34.2k|  (void)stun_get_msg_type_str(buf, len);
  144|       |
  145|  34.2k|  {
  146|  34.2k|    int err_code = 0;
  147|  34.2k|    uint8_t err_msg[256] = {0};
  148|  34.2k|    (void)stun_is_error_response_str(buf, len, &err_code, err_msg, sizeof(err_msg));
  149|  34.2k|  }
  150|       |
  151|  34.2k|  {
  152|  34.2k|    ioa_addr parsed = {0};
  153|  34.2k|    (void)stun_attr_get_first_addr_str(buf, len, addr_attr_type, &parsed, default_addr);
  154|  34.2k|  }
  155|       |
  156|  34.2k|  {
  157|  34.2k|    stun_attr_ref attr = stun_attr_get_first_str(buf, len);
  158|  88.5k|    while (attr) {
  ------------------
  |  Branch (158:12): [True: 54.2k, False: 34.2k]
  ------------------
  159|  54.2k|      (void)stun_attr_get_type(attr);
  160|  54.2k|      (void)stun_attr_get_len(attr);
  161|  54.2k|      if (stun_attr_is_addr(attr)) {
  ------------------
  |  Branch (161:11): [True: 24.4k, False: 29.8k]
  ------------------
  162|  24.4k|        ioa_addr parsed = {0};
  163|  24.4k|        (void)stun_attr_get_addr_str(buf, len, attr, &parsed, default_addr);
  164|  24.4k|      }
  165|  54.2k|      attr = stun_attr_get_next_str(buf, len, attr);
  166|  54.2k|    }
  167|  34.2k|  }
  168|       |
  169|  34.2k|  (void)stun_attr_get_first_channel_number_str(buf, len);
  170|  34.2k|}
FuzzStunClient.c:harness_attr_get_first_addr:
  187|  1.76k|static void harness_attr_get_first_addr(const uint8_t *Data, size_t Size) {
  188|  1.76k|  if (Size < STUN_HEADER_LENGTH || Size > 5120) {
  ------------------
  |  |   46|  3.53k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (188:7): [True: 634, False: 1.13k]
  |  Branch (188:36): [True: 95, False: 1.04k]
  ------------------
  189|    729|    return;
  190|    729|  }
  191|       |
  192|  1.04k|  stun_buffer msg;
  193|  1.04k|  msg.len = Size;
  194|  1.04k|  memcpy(msg.buf, Data, Size);
  195|       |
  196|  1.04k|  ioa_addr default_addr = {0};
  197|  1.04k|  fuzz_addr(Data, Size, 0, &default_addr);
  198|       |
  199|  1.04k|  const size_t num_attrs = sizeof(kFirstAddrAttrs) / sizeof(kFirstAddrAttrs[0]);
  200|  9.36k|  for (size_t i = 0; i < num_attrs; ++i) {
  ------------------
  |  Branch (200:22): [True: 8.32k, False: 1.04k]
  ------------------
  201|  8.32k|    ioa_addr parsed = {0};
  202|  8.32k|    (void)stun_attr_get_first_addr(&msg, kFirstAddrAttrs[i], &parsed, NULL);
  203|       |
  204|  8.32k|    memset(&parsed, 0, sizeof(parsed));
  205|  8.32k|    (void)stun_attr_get_first_addr(&msg, kFirstAddrAttrs[i], &parsed, &default_addr);
  206|  8.32k|  }
  207|  1.04k|}
FuzzStunClient.c:harness_response_matrix:
  477|  1.76k|static void harness_response_matrix(const uint8_t *Data, size_t Size) {
  478|  1.76k|  if (!Size || Size > 4096) {
  ------------------
  |  Branch (478:7): [True: 0, False: 1.76k]
  |  Branch (478:16): [True: 140, False: 1.62k]
  ------------------
  479|    140|    return;
  480|    140|  }
  481|       |
  482|  1.62k|  stun_tid tid = {0};
  483|  1.62k|  ioa_addr relay1 = {0};
  484|  1.62k|  ioa_addr relay2 = {0};
  485|  1.62k|  ioa_addr reflexive = {0};
  486|  1.62k|  ioa_addr peer = {0};
  487|  1.62k|  ioa_addr default_addr = {0};
  488|  1.62k|  char reason[96] = {0};
  489|  1.62k|  char mobile_id[96] = {0};
  490|  1.62k|  uint8_t raw[MAX_STUN_MESSAGE_SIZE] = {0};
  491|       |
  492|  1.62k|  fuzz_tid(Data, Size, 0, &tid);
  493|  1.62k|  fuzz_addr(Data, Size, 16, &relay1);
  494|  1.62k|  fuzz_addr(Data, Size, 40, &relay2);
  495|  1.62k|  fuzz_addr(Data, Size, 64, &reflexive);
  496|  1.62k|  fuzz_addr(Data, Size, 88, &peer);
  497|  1.62k|  fuzz_addr(Data, Size, 112, &default_addr);
  498|  1.62k|  fuzz_string(Data, Size, 136, reason, sizeof(reason));
  499|  1.62k|  fuzz_string(Data, Size, 232, mobile_id, sizeof(mobile_id));
  500|       |
  501|  1.62k|  const uint32_t max_lifetime = fuzz_u32(Data, Size, 328) | 1u;
  502|  1.62k|  const uint64_t reservation_token = fuzz_u64(Data, Size, 332) | 1ull;
  503|  1.62k|  const uint16_t channel_number_valid = (uint16_t)(0x4000u + (fuzz_u16(Data, Size, 340) % (0x7FFFu - 0x4000u + 1u)));
  504|  1.62k|  const uint32_t old_cookie = fuzz_u32(Data, Size, 344);
  505|       |
  506|       |  /* stun_init_error_response — cover (reason NULL vs set) × (include reason). */
  507|  1.62k|  {
  508|  1.62k|    stun_buffer msg;
  509|  1.62k|    stun_init_buffer(&msg);
  510|  1.62k|    stun_init_error_response(STUN_METHOD_ALLOCATE, &msg, 437, NULL, &tid, false);
  ------------------
  |  |   78|  1.62k|#define STUN_METHOD_ALLOCATE (0x0003)
  ------------------
  511|  1.62k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_MAPPED_ADDRESS, &default_addr);
  ------------------
  |  |   91|  1.62k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
  512|       |
  513|  1.62k|    stun_init_buffer(&msg);
  514|  1.62k|    stun_init_error_response(STUN_METHOD_BINDING, &msg, 400, (const uint8_t *)reason, &tid, true);
  ------------------
  |  |   77|  1.62k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
  515|  1.62k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_MAPPED_ADDRESS, &default_addr);
  ------------------
  |  |   91|  1.62k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
  516|  1.62k|  }
  517|       |
  518|       |  /* stun_set_allocate_response / _str — cover every optional-field branch and
  519|       |   * the error path independently of the fuzzer selectors. */
  520|  1.62k|  {
  521|  1.62k|    stun_buffer msg;
  522|       |
  523|       |    /* Minimal success: relay1 only, no reflexive, no reservation, no mobile id,
  524|       |     * lifetime 0 (triggers the <1 default branch). */
  525|  1.62k|    stun_init_buffer(&msg);
  526|  1.62k|    (void)stun_set_allocate_response(&msg, &tid, &relay1, NULL, NULL, 0, max_lifetime, 0, NULL, 0, NULL, false);
  527|  1.62k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, &default_addr);
  ------------------
  |  |  118|  1.62k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  528|       |
  529|  1.62k|    size_t raw_len = sizeof(raw);
  530|  1.62k|    (void)stun_set_allocate_response_str(raw, &raw_len, &tid, &relay1, NULL, NULL, 0, max_lifetime, 0, NULL, 0, NULL,
  531|  1.62k|                                         false);
  532|  1.62k|    inspect_raw_message(raw, raw_len, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, &default_addr);
  ------------------
  |  |  118|  1.62k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  533|       |
  534|       |    /* Full success: both relays + reflexive + reservation + mobile id,
  535|       |     * lifetime > max (triggers clamp branch). */
  536|  1.62k|    stun_init_buffer(&msg);
  537|  1.62k|    (void)stun_set_allocate_response(&msg, &tid, &relay1, &relay2, &reflexive, max_lifetime + 1, max_lifetime, 0,
  538|  1.62k|                                     (const uint8_t *)reason, reservation_token, mobile_id, true);
  539|  1.62k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, &default_addr);
  ------------------
  |  |  118|  1.62k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  540|       |
  541|  1.62k|    raw_len = sizeof(raw);
  542|  1.62k|    (void)stun_set_allocate_response_str(raw, &raw_len, &tid, &relay1, &relay2, &reflexive, max_lifetime + 1,
  543|  1.62k|                                         max_lifetime, 0, (const uint8_t *)reason, reservation_token, mobile_id, true);
  544|  1.62k|    inspect_raw_message(raw, raw_len, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, &default_addr);
  ------------------
  |  |  118|  1.62k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  545|       |
  546|       |    /* Error path with and without a reason string. */
  547|  1.62k|    stun_init_buffer(&msg);
  548|  1.62k|    (void)stun_set_allocate_response(&msg, &tid, NULL, NULL, NULL, 0, max_lifetime, 441, NULL, 0, NULL, false);
  549|  1.62k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, &default_addr);
  ------------------
  |  |  118|  1.62k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  550|       |
  551|  1.62k|    raw_len = sizeof(raw);
  552|  1.62k|    (void)stun_set_allocate_response_str(raw, &raw_len, &tid, NULL, NULL, NULL, 0, max_lifetime, 508,
  553|  1.62k|                                         (const uint8_t *)reason, 0, NULL, true);
  554|  1.62k|    inspect_raw_message(raw, raw_len, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, &default_addr);
  ------------------
  |  |  118|  1.62k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  555|  1.62k|  }
  556|       |
  557|       |  /* stun_set_binding_response / _str — cover success × error × old_stun. */
  558|  1.62k|  {
  559|  1.62k|    stun_buffer msg;
  560|       |
  561|  1.62k|    stun_init_buffer(&msg);
  562|  1.62k|    (void)stun_set_binding_response(&msg, &tid, &reflexive, 0, NULL, false);
  563|  1.62k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS, &default_addr);
  ------------------
  |  |  105|  1.62k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  564|       |
  565|  1.62k|    stun_init_buffer(&msg);
  566|  1.62k|    (void)stun_set_binding_response(&msg, &tid, NULL, 420, (const uint8_t *)reason, true);
  567|  1.62k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_MAPPED_ADDRESS, &default_addr);
  ------------------
  |  |   91|  1.62k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
  568|       |
  569|  1.62k|    const bool matrix_old_stun[] = {false, true};
  570|  1.62k|    const bool matrix_backcompat[] = {false, true};
  571|  4.88k|    for (size_t o = 0; o < sizeof(matrix_old_stun) / sizeof(matrix_old_stun[0]); ++o) {
  ------------------
  |  Branch (571:24): [True: 3.25k, False: 1.62k]
  ------------------
  572|  9.77k|      for (size_t b = 0; b < sizeof(matrix_backcompat) / sizeof(matrix_backcompat[0]); ++b) {
  ------------------
  |  Branch (572:26): [True: 6.51k, False: 3.25k]
  ------------------
  573|  6.51k|        size_t raw_len = sizeof(raw);
  574|  6.51k|        (void)stun_set_binding_response_str(raw, &raw_len, &tid, &reflexive, 0, NULL, old_cookie, matrix_old_stun[o],
  575|  6.51k|                                            matrix_backcompat[b], false);
  576|  6.51k|        inspect_raw_message(raw, raw_len,
  577|  6.51k|                            matrix_old_stun[o] ? STUN_ATTRIBUTE_MAPPED_ADDRESS : STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS,
  ------------------
  |  |   91|  3.25k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
                                          matrix_old_stun[o] ? STUN_ATTRIBUTE_MAPPED_ADDRESS : STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS,
  ------------------
  |  |  105|  9.77k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (577:29): [True: 3.25k, False: 3.25k]
  ------------------
  578|  6.51k|                            &default_addr);
  579|       |
  580|  6.51k|        raw_len = sizeof(raw);
  581|  6.51k|        (void)stun_set_binding_response_str(raw, &raw_len, &tid, NULL, 500, (const uint8_t *)reason, old_cookie,
  582|  6.51k|                                            matrix_old_stun[o], matrix_backcompat[b], true);
  583|  6.51k|        inspect_raw_message(raw, raw_len, STUN_ATTRIBUTE_MAPPED_ADDRESS, &default_addr);
  ------------------
  |  |   91|  6.51k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
  584|  6.51k|      }
  585|  3.25k|    }
  586|  1.62k|  }
  587|       |
  588|       |  /* stun_set_channel_bind_request / _str — cover peer NULL vs set. */
  589|  1.62k|  {
  590|  1.62k|    stun_buffer msg;
  591|       |
  592|  1.62k|    stun_init_buffer(&msg);
  593|  1.62k|    (void)stun_set_channel_bind_request(&msg, NULL, channel_number_valid);
  594|  1.62k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &default_addr);
  ------------------
  |  |  116|  1.62k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  595|       |
  596|  1.62k|    stun_init_buffer(&msg);
  597|  1.62k|    (void)stun_set_channel_bind_request(&msg, &peer, channel_number_valid);
  598|  1.62k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &default_addr);
  ------------------
  |  |  116|  1.62k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  599|       |
  600|  1.62k|    size_t raw_len = sizeof(raw);
  601|  1.62k|    (void)stun_set_channel_bind_request_str(raw, &raw_len, NULL, channel_number_valid);
  602|  1.62k|    inspect_raw_message(raw, raw_len, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &default_addr);
  ------------------
  |  |  116|  1.62k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  603|       |
  604|  1.62k|    raw_len = sizeof(raw);
  605|  1.62k|    (void)stun_set_channel_bind_request_str(raw, &raw_len, &peer, channel_number_valid);
  606|  1.62k|    inspect_raw_message(raw, raw_len, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &default_addr);
  ------------------
  |  |  116|  1.62k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  607|  1.62k|  }
  608|       |
  609|       |  /* stun_set_channel_bind_response / _str — cover success vs error. */
  610|  1.62k|  {
  611|  1.62k|    stun_buffer msg;
  612|       |
  613|  1.62k|    stun_init_buffer(&msg);
  614|  1.62k|    stun_set_channel_bind_response(&msg, &tid, 0, NULL, false);
  615|  1.62k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &default_addr);
  ------------------
  |  |  116|  1.62k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  616|       |
  617|  1.62k|    stun_init_buffer(&msg);
  618|  1.62k|    stun_set_channel_bind_response(&msg, &tid, 438, (const uint8_t *)reason, true);
  619|  1.62k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &default_addr);
  ------------------
  |  |  116|  1.62k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  620|       |
  621|  1.62k|    size_t raw_len = sizeof(raw);
  622|  1.62k|    stun_set_channel_bind_response_str(raw, &raw_len, &tid, 0, NULL, false);
  623|  1.62k|    inspect_raw_message(raw, raw_len, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &default_addr);
  ------------------
  |  |  116|  1.62k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  624|       |
  625|  1.62k|    raw_len = sizeof(raw);
  626|  1.62k|    stun_set_channel_bind_response_str(raw, &raw_len, &tid, 486, (const uint8_t *)reason, true);
  627|  1.62k|    inspect_raw_message(raw, raw_len, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &default_addr);
  ------------------
  |  |  116|  1.62k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  628|  1.62k|  }
  629|  1.62k|}
FuzzStunClient.c:harness_stun_buffer_api:
  653|  1.76k|static void harness_stun_buffer_api(const uint8_t *Data, size_t Size) {
  654|  1.76k|  if (!Size || Size > 4096) {
  ------------------
  |  Branch (654:7): [True: 0, False: 1.76k]
  |  Branch (654:16): [True: 140, False: 1.62k]
  ------------------
  655|    140|    return;
  656|    140|  }
  657|       |
  658|  1.62k|  static const uint16_t kMethods[] = {
  659|  1.62k|      STUN_METHOD_ALLOCATE, STUN_METHOD_BINDING, STUN_METHOD_CHANNEL_BIND, STUN_METHOD_REFRESH, STUN_METHOD_CONNECT,
  ------------------
  |  |   78|  1.62k|#define STUN_METHOD_ALLOCATE (0x0003)
  ------------------
                    STUN_METHOD_ALLOCATE, STUN_METHOD_BINDING, STUN_METHOD_CHANNEL_BIND, STUN_METHOD_REFRESH, STUN_METHOD_CONNECT,
  ------------------
  |  |   77|  1.62k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
                    STUN_METHOD_ALLOCATE, STUN_METHOD_BINDING, STUN_METHOD_CHANNEL_BIND, STUN_METHOD_REFRESH, STUN_METHOD_CONNECT,
  ------------------
  |  |   83|  1.62k|#define STUN_METHOD_CHANNEL_BIND (0x0009)
  ------------------
                    STUN_METHOD_ALLOCATE, STUN_METHOD_BINDING, STUN_METHOD_CHANNEL_BIND, STUN_METHOD_REFRESH, STUN_METHOD_CONNECT,
  ------------------
  |  |   79|  1.62k|#define STUN_METHOD_REFRESH (0x0004)
  ------------------
                    STUN_METHOD_ALLOCATE, STUN_METHOD_BINDING, STUN_METHOD_CHANNEL_BIND, STUN_METHOD_REFRESH, STUN_METHOD_CONNECT,
  ------------------
  |  |   86|  1.62k|#define STUN_METHOD_CONNECT (0x000a)
  ------------------
  660|  1.62k|  };
  661|       |
  662|  1.62k|  stun_tid tid = {0};
  663|  1.62k|  ioa_addr peer = {0};
  664|  1.62k|  ioa_addr default_addr = {0};
  665|  1.62k|  char attr_value[64] = {0};
  666|  1.62k|  char rt[8] = {0};
  667|       |
  668|  1.62k|  fuzz_tid(Data, Size, 0, &tid);
  669|  1.62k|  fuzz_addr(Data, Size, 16, &peer);
  670|  1.62k|  fuzz_addr(Data, Size, 40, &default_addr);
  671|  1.62k|  fuzz_string(Data, Size, 64, attr_value, sizeof(attr_value));
  672|  1.62k|  fuzz_string(Data, Size, 128, rt, sizeof(rt));
  673|       |
  674|  1.62k|  const uint16_t method = kMethods[fuzz_byte(Data, Size, 200) % (sizeof(kMethods) / sizeof(kMethods[0]))];
  675|  1.62k|  const uint32_t lifetime = fuzz_u32(Data, Size, 201);
  676|  1.62k|  const uint16_t channel_number = (uint16_t)(0x4000u + (fuzz_u16(Data, Size, 205) & 0x3FFFu));
  677|  1.62k|  const uint8_t transport = fuzz_byte(Data, Size, 207);
  678|  1.62k|  const uint8_t even_port_value = fuzz_byte(Data, Size, 208);
  679|  1.62k|  const bool af4 = fuzz_flag(Data, Size, 209);
  680|  1.62k|  const bool af6 = fuzz_flag(Data, Size, 210);
  681|  1.62k|  const bool mobile = fuzz_flag(Data, Size, 211);
  682|  1.62k|  const bool padding = fuzz_flag(Data, Size, 212);
  683|  1.62k|  const int chan_payload_len = (int)(fuzz_u16(Data, Size, 213) % 256);
  684|  1.62k|  const int ep = (int)(int8_t)fuzz_byte(Data, Size, 215);
  685|       |
  686|       |  /* NULL-guard branches. */
  687|  1.62k|  (void)stun_get_size(NULL);
  688|  1.62k|  (void)stun_init_buffer(NULL);
  689|  1.62k|  (void)stun_get_msg_type(NULL);
  690|  1.62k|  {
  691|  1.62k|    stun_tid scratch = {0};
  692|  1.62k|    stun_tid_generate_in_message(NULL, &scratch);
  693|  1.62k|  }
  694|       |
  695|       |  /* stun_init_request — also covers stun_get_size (non-NULL), the static
  696|       |   * stun_init_command helper, and stun_attr_add* / stun_attr_get_first_by_type
  697|       |   * over the freshly built message. */
  698|  1.62k|  {
  699|  1.62k|    stun_buffer msg;
  700|  1.62k|    stun_init_buffer(&msg);
  701|  1.62k|    stun_init_request(method, &msg);
  702|       |
  703|  1.62k|    stun_tid extracted = {0};
  704|  1.62k|    stun_tid_from_message(&msg, &extracted);
  705|  1.62k|    stun_tid_generate_in_message(&msg, &extracted);
  706|       |
  707|  1.62k|    const int alen = (int)strlen(attr_value);
  708|  1.62k|    (void)stun_attr_add(&msg, STUN_ATTRIBUTE_USERNAME, attr_value, alen);
  ------------------
  |  |   96|  1.62k|#define STUN_ATTRIBUTE_USERNAME (0x0006)
  ------------------
  709|  1.62k|    (void)stun_attr_add_channel_number(&msg, channel_number);
  710|  1.62k|    (void)stun_attr_add_addr(&msg, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &peer);
  ------------------
  |  |  116|  1.62k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  711|  1.62k|    (void)stun_attr_add_even_port(&msg, even_port_value);
  712|  1.62k|    (void)stun_attr_add_even_port(&msg, 0);
  713|       |
  714|  1.62k|    (void)stun_attr_get_first_by_type(&msg, STUN_ATTRIBUTE_USERNAME);
  ------------------
  |  |   96|  1.62k|#define STUN_ATTRIBUTE_USERNAME (0x0006)
  ------------------
  715|  1.62k|    (void)stun_attr_get_first_by_type(&msg, STUN_ATTRIBUTE_CHANNEL_NUMBER);
  ------------------
  |  |  113|  1.62k|#define STUN_ATTRIBUTE_CHANNEL_NUMBER (0x000C)
  ------------------
  716|  1.62k|    (void)stun_attr_get_first_by_type(&msg, STUN_ATTRIBUTE_XOR_PEER_ADDRESS);
  ------------------
  |  |  116|  1.62k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  717|  1.62k|    (void)stun_attr_get_first_by_type(&msg, STUN_ATTRIBUTE_EVEN_PORT);
  ------------------
  |  |  119|  1.62k|#define STUN_ATTRIBUTE_EVEN_PORT (0x0018)
  ------------------
  718|       |
  719|  1.62k|    (void)stun_is_indication(&msg);
  720|  1.62k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &default_addr);
  ------------------
  |  |  116|  1.62k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  721|  1.62k|  }
  722|       |
  723|       |  /* stun_init_indication — drives the IS_STUN_INDICATION branch of
  724|       |   * stun_is_indication. */
  725|  1.62k|  {
  726|  1.62k|    stun_buffer msg;
  727|  1.62k|    stun_init_buffer(&msg);
  728|  1.62k|    stun_init_indication(method, &msg);
  729|  1.62k|    (void)stun_is_indication(&msg);
  730|  1.62k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &default_addr);
  ------------------
  |  |  116|  1.62k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  731|  1.62k|  }
  732|       |
  733|       |  /* stun_init_success_response. */
  734|  1.62k|  {
  735|  1.62k|    stun_buffer msg;
  736|  1.62k|    stun_init_buffer(&msg);
  737|  1.62k|    stun_init_success_response(method, &msg, &tid);
  738|  1.62k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_MAPPED_ADDRESS, &default_addr);
  ------------------
  |  |   91|  1.62k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
  739|  1.62k|  }
  740|       |
  741|       |  /* stun_set_allocate_request — both rt NULL and rt non-NULL paths. */
  742|  1.62k|  {
  743|  1.62k|    stun_buffer msg;
  744|  1.62k|    stun_init_buffer(&msg);
  745|  1.62k|    (void)stun_set_allocate_request(&msg, lifetime, af4, af6, transport, mobile, rt[0] ? rt : NULL, ep);
  ------------------
  |  Branch (745:82): [True: 996, False: 633]
  ------------------
  746|  1.62k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, &default_addr);
  ------------------
  |  |  118|  1.62k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  747|       |
  748|  1.62k|    stun_init_buffer(&msg);
  749|  1.62k|    (void)stun_set_allocate_request(&msg, lifetime, !af4, !af6, transport, !mobile, NULL, ep);
  750|  1.62k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, &default_addr);
  ------------------
  |  |  118|  1.62k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  751|  1.62k|  }
  752|       |
  753|       |  /* stun_set_binding_request + stun_prepare_binding_request (both currently
  754|       |   * delegate to stun_set_binding_request_str but exercise the wrappers). */
  755|  1.62k|  {
  756|  1.62k|    stun_buffer msg;
  757|  1.62k|    stun_init_buffer(&msg);
  758|  1.62k|    stun_set_binding_request(&msg);
  759|  1.62k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_MAPPED_ADDRESS, &default_addr);
  ------------------
  |  |   91|  1.62k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
  760|       |
  761|  1.62k|    stun_init_buffer(&msg);
  762|  1.62k|    stun_prepare_binding_request(&msg);
  763|  1.62k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_MAPPED_ADDRESS, &default_addr);
  ------------------
  |  |   91|  1.62k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
  764|  1.62k|  }
  765|       |
  766|       |  /* stun_init_channel_message + stun_is_channel_message wrappers. */
  767|  1.62k|  {
  768|  1.62k|    stun_buffer msg;
  769|  1.62k|    stun_init_buffer(&msg);
  770|  1.62k|    if (stun_init_channel_message(channel_number, &msg, chan_payload_len, padding)) {
  ------------------
  |  Branch (770:9): [True: 1.62k, False: 0]
  ------------------
  771|  1.62k|      uint16_t parsed_chn = 0;
  772|  1.62k|      (void)stun_is_channel_message(&msg, &parsed_chn, true);
  773|  1.62k|      (void)stun_is_channel_message(&msg, &parsed_chn, false);
  774|  1.62k|    }
  775|  1.62k|    {
  776|  1.62k|      uint16_t chn = 0;
  777|  1.62k|      (void)stun_is_channel_message(NULL, &chn, false);
  778|  1.62k|    }
  779|  1.62k|  }
  780|       |
  781|       |  /* Raw fuzzer bytes through the wrapper-form predicates so they see
  782|       |   * malformed inputs the serializer paths above never produce. */
  783|  1.62k|  {
  784|  1.62k|    stun_buffer msg;
  785|  1.62k|    msg.len = Size > sizeof(msg.buf) ? sizeof(msg.buf) : Size;
  ------------------
  |  Branch (785:15): [True: 0, False: 1.62k]
  ------------------
  786|  1.62k|    memcpy(msg.buf, Data, msg.len);
  787|       |
  788|  1.62k|    (void)stun_is_indication(&msg);
  789|       |
  790|  1.62k|    stun_tid extracted = {0};
  791|  1.62k|    stun_tid_from_message(&msg, &extracted);
  792|       |
  793|  1.62k|    {
  794|  1.62k|      uint16_t chn = 0;
  795|  1.62k|      const size_t saved_len = msg.len;
  796|  1.62k|      (void)stun_is_channel_message(&msg, &chn, true);
  797|  1.62k|      msg.len = saved_len;
  798|  1.62k|      (void)stun_is_channel_message(&msg, &chn, false);
  799|  1.62k|    }
  800|       |
  801|  1.62k|    (void)stun_attr_get_first_by_type(&msg, STUN_ATTRIBUTE_USERNAME);
  ------------------
  |  |   96|  1.62k|#define STUN_ATTRIBUTE_USERNAME (0x0006)
  ------------------
  802|  1.62k|    (void)stun_attr_get_first_by_type(&msg, STUN_ATTRIBUTE_XOR_PEER_ADDRESS);
  ------------------
  |  |  116|  1.62k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  803|  1.62k|    (void)stun_attr_get_first_by_type(&msg, STUN_ATTRIBUTE_CHANNEL_NUMBER);
  ------------------
  |  |  113|  1.62k|#define STUN_ATTRIBUTE_CHANNEL_NUMBER (0x000C)
  ------------------
  804|  1.62k|  }
  805|  1.62k|}

turn_malloc_impl:
  685|      8|void *turn_malloc_impl(size_t sz, const char *file, int line) {
  686|      8|  void *ptr = malloc(sz);
  687|      8|  if (!ptr && sz) {
  ------------------
  |  Branch (687:7): [True: 0, False: 8]
  |  Branch (687:15): [True: 0, False: 0]
  ------------------
  688|      0|    turn_out_of_memory(file, line, "malloc", sz);
  689|      0|  }
  690|      8|  return ptr;
  691|      8|}
turn_realloc_impl:
  701|      8|void *turn_realloc_impl(void *ptr, size_t sz, const char *file, int line) {
  702|      8|  void *newptr = realloc(ptr, sz);
  703|      8|  if (!newptr && sz) {
  ------------------
  |  Branch (703:7): [True: 0, False: 8]
  |  Branch (703:18): [True: 0, False: 0]
  ------------------
  704|      0|    turn_out_of_memory(file, line, "realloc", sz);
  705|      0|  }
  706|      8|  return newptr;
  707|      8|}

stun_init_buffer:
   41|  43.9k|int stun_init_buffer(stun_buffer *buf) {
   42|  43.9k|  if (!buf) {
  ------------------
  |  Branch (42:7): [True: 1.62k, False: 42.3k]
  ------------------
   43|  1.62k|    return -1;
   44|  1.62k|  }
   45|  42.3k|  memset(buf->buf, 0, sizeof(buf->buf));
   46|  42.3k|  buf->len = 0;
   47|  42.3k|  buf->offset = 0;
   48|  42.3k|  buf->coffset = 0;
   49|  42.3k|  return 0;
   50|  43.9k|}
stun_get_size:
   52|  11.4k|int stun_get_size(const stun_buffer *buf) {
   53|  11.4k|  if (!buf) {
  ------------------
  |  Branch (53:7): [True: 1.62k, False: 9.77k]
  ------------------
   54|  1.62k|    return 0;
   55|  1.62k|  }
   56|  9.77k|  return sizeof(buf->buf);
   57|  11.4k|}
stun_tid_from_message:
   61|  3.25k|void stun_tid_from_message(const stun_buffer *buf, stun_tid *id) {
   62|  3.25k|  stun_tid_from_message_str(buf->buf, (size_t)(buf->len), id);
   63|  3.25k|}
stun_tid_generate_in_message:
   65|  3.25k|void stun_tid_generate_in_message(stun_buffer *buf, stun_tid *id) {
   66|  3.25k|  if (buf) {
  ------------------
  |  Branch (66:7): [True: 1.62k, False: 1.62k]
  ------------------
   67|  1.62k|    stun_tid_generate_in_message_str(buf->buf, id);
   68|  1.62k|  }
   69|  3.25k|}
stun_is_command_message:
   80|  41.8k|bool stun_is_command_message(const stun_buffer *buf) {
   81|  41.8k|  if (!buf || buf->len <= 0) {
  ------------------
  |  Branch (81:7): [True: 0, False: 41.8k]
  |  Branch (81:15): [True: 0, False: 41.8k]
  ------------------
   82|      0|    return false;
   83|  41.8k|  } else {
   84|  41.8k|    return stun_is_command_message_str(buf->buf, (size_t)(buf->len));
   85|  41.8k|  }
   86|  41.8k|}
stun_is_request:
   88|  40.7k|bool stun_is_request(const stun_buffer *buf) { return stun_is_request_str(buf->buf, (size_t)buf->len); }
stun_is_success_response:
   90|  40.8k|bool stun_is_success_response(const stun_buffer *buf) {
   91|  40.8k|  return stun_is_success_response_str(buf->buf, (size_t)(buf->len));
   92|  40.8k|}
stun_is_error_response:
   94|  40.7k|bool stun_is_error_response(const stun_buffer *buf, int *err_code, uint8_t *err_msg, size_t err_msg_size) {
   95|  40.7k|  return stun_is_error_response_str(buf->buf, (size_t)(buf->len), err_code, err_msg, err_msg_size);
   96|  40.7k|}
stun_is_response:
   98|  40.8k|bool stun_is_response(const stun_buffer *buf) { return stun_is_response_str(buf->buf, (size_t)(buf->len)); }
stun_is_indication:
  100|  4.88k|bool stun_is_indication(const stun_buffer *buf) {
  101|  4.88k|  if (is_channel_msg(buf)) {
  ------------------
  |  Branch (101:7): [True: 521, False: 4.36k]
  ------------------
  102|    521|    return false;
  103|    521|  }
  104|  4.36k|  return IS_STUN_INDICATION(stun_get_msg_type(buf));
  ------------------
  |  |   59|  4.36k|#define IS_STUN_INDICATION(msg_type) (((msg_type)&0x0110) == 0x0010)
  ------------------
  105|  4.88k|}
stun_get_method:
  107|  40.7k|uint16_t stun_get_method(const stun_buffer *buf) { return stun_get_method_str(buf->buf, (size_t)(buf->len)); }
stun_get_msg_type:
  109|  46.7k|uint16_t stun_get_msg_type(const stun_buffer *buf) {
  110|  46.7k|  if (!buf) {
  ------------------
  |  Branch (110:7): [True: 1.62k, False: 45.0k]
  ------------------
  111|  1.62k|    return (uint16_t)-1;
  112|  1.62k|  }
  113|  45.0k|  return stun_get_msg_type_str(buf->buf, (size_t)buf->len);
  114|  46.7k|}
stun_init_request:
  123|  1.62k|void stun_init_request(uint16_t method, stun_buffer *buf) { stun_init_command(stun_make_request(method), buf); }
stun_init_indication:
  125|  1.62k|void stun_init_indication(uint16_t method, stun_buffer *buf) { stun_init_command(stun_make_indication(method), buf); }
stun_init_success_response:
  127|  1.62k|void stun_init_success_response(uint16_t method, stun_buffer *buf, stun_tid *id) {
  128|  1.62k|  buf->len = stun_get_size(buf);
  129|  1.62k|  stun_init_success_response_str(method, buf->buf, &(buf->len), id);
  130|  1.62k|}
stun_init_error_response:
  133|  4.88k|                              stun_tid *id, bool include_reason_string) {
  134|  4.88k|  buf->len = stun_get_size(buf);
  135|  4.88k|  stun_init_error_response_str(method, buf->buf, &(buf->len), error_code, reason, id, include_reason_string);
  136|  4.88k|}
stun_get_command_message_len:
  140|  40.7k|int stun_get_command_message_len(const stun_buffer *buf) {
  141|  40.7k|  return stun_get_command_message_len_str(buf->buf, buf->len);
  142|  40.7k|}
stun_init_channel_message:
  146|  1.62k|bool stun_init_channel_message(uint16_t chnumber, stun_buffer *buf, int length, bool do_padding) {
  147|  1.62k|  return stun_init_channel_message_str(chnumber, buf->buf, &(buf->len), length, do_padding);
  148|  1.62k|}
stun_is_channel_message:
  150|  8.14k|bool stun_is_channel_message(stun_buffer *buf, uint16_t *chnumber, bool is_padding_mandatory) {
  151|  8.14k|  if (!buf) {
  ------------------
  |  Branch (151:7): [True: 1.62k, False: 6.51k]
  ------------------
  152|  1.62k|    return false;
  153|  1.62k|  }
  154|  6.51k|  size_t blen = buf->len;
  155|  6.51k|  const bool ret = stun_is_channel_message_str(buf->buf, &blen, chnumber, is_padding_mandatory);
  156|  6.51k|  if (ret) {
  ------------------
  |  Branch (156:7): [True: 3.43k, False: 3.08k]
  ------------------
  157|  3.43k|    buf->len = blen;
  158|  3.43k|  }
  159|  6.51k|  return ret;
  160|  8.14k|}
stun_set_allocate_request:
  165|  3.25k|                               const char *rt, int ep) {
  166|  3.25k|  return stun_set_allocate_request_str(buf->buf, &(buf->len), lifetime, af4, af6, transport, mobile, rt, ep);
  167|  3.25k|}
stun_set_allocate_response:
  172|  8.14k|                                uint64_t reservation_token, char *mobile_id, bool include_reason_string) {
  173|       |
  174|  8.14k|  return stun_set_allocate_response_str(buf->buf, &(buf->len), tid, relayed_addr1, relayed_addr2, reflexive_addr,
  175|  8.14k|                                        lifetime, max_lifetime, error_code, reason, reservation_token, mobile_id,
  176|  8.14k|                                        include_reason_string);
  177|  8.14k|}
stun_set_channel_bind_request:
  181|  4.88k|uint16_t stun_set_channel_bind_request(stun_buffer *buf, const ioa_addr *peer_addr, uint16_t channel_number) {
  182|       |
  183|  4.88k|  return stun_set_channel_bind_request_str(buf->buf, &(buf->len), peer_addr, channel_number);
  184|  4.88k|}
stun_set_channel_bind_response:
  187|  4.88k|                                    bool include_reason_string) {
  188|  4.88k|  stun_set_channel_bind_response_str(buf->buf, &(buf->len), tid, error_code, reason, include_reason_string);
  189|  4.88k|}
stun_attr_get_first:
  193|  40.7k|stun_attr_ref stun_attr_get_first(const stun_buffer *buf) { return stun_attr_get_first_str(buf->buf, buf->len); }
stun_attr_get_next:
  195|  71.2k|stun_attr_ref stun_attr_get_next(const stun_buffer *buf, stun_attr_ref prev) {
  196|  71.2k|  return stun_attr_get_next_str(buf->buf, buf->len, prev);
  197|  71.2k|}
stun_attr_add:
  199|  4.88k|bool stun_attr_add(stun_buffer *buf, uint16_t attr, const char *avalue, int alen) {
  200|  4.88k|  return stun_attr_add_str(buf->buf, &(buf->len), attr, (const uint8_t *)avalue, alen);
  201|  4.88k|}
stun_attr_add_channel_number:
  203|  1.62k|bool stun_attr_add_channel_number(stun_buffer *buf, uint16_t chnumber) {
  204|  1.62k|  return stun_attr_add_channel_number_str(buf->buf, &(buf->len), chnumber);
  205|  1.62k|}
stun_attr_add_addr:
  207|  1.62k|bool stun_attr_add_addr(stun_buffer *buf, uint16_t attr_type, const ioa_addr *ca) {
  208|  1.62k|  return stun_attr_add_addr_str(buf->buf, &(buf->len), attr_type, ca);
  209|  1.62k|}
stun_attr_get_addr:
  211|  23.4k|bool stun_attr_get_addr(const stun_buffer *buf, stun_attr_ref attr, ioa_addr *ca, const ioa_addr *default_addr) {
  212|  23.4k|  return stun_attr_get_addr_str(buf->buf, buf->len, attr, ca, default_addr);
  213|  23.4k|}
stun_attr_get_first_addr:
  215|  57.3k|bool stun_attr_get_first_addr(const stun_buffer *buf, uint16_t attr_type, ioa_addr *ca, const ioa_addr *default_addr) {
  216|  57.3k|  return stun_attr_get_first_addr_str(buf->buf, buf->len, attr_type, ca, default_addr);
  217|  57.3k|}
stun_attr_add_even_port:
  219|  3.25k|bool stun_attr_add_even_port(stun_buffer *buf, uint8_t value) {
  220|  3.25k|  if (value) {
  ------------------
  |  Branch (220:7): [True: 1.19k, False: 2.06k]
  ------------------
  221|  1.19k|    value = 0x80;
  222|  1.19k|  }
  223|  3.25k|  return stun_attr_add(buf, STUN_ATTRIBUTE_EVEN_PORT, (const char *)&value, 1);
  ------------------
  |  |  119|  3.25k|#define STUN_ATTRIBUTE_EVEN_PORT (0x0018)
  ------------------
  224|  3.25k|}
stun_attr_get_first_channel_number:
  226|  40.7k|uint16_t stun_attr_get_first_channel_number(const stun_buffer *buf) {
  227|  40.7k|  return stun_attr_get_first_channel_number_str(buf->buf, buf->len);
  228|  40.7k|}
stun_attr_get_first_by_type:
  230|  11.4k|stun_attr_ref stun_attr_get_first_by_type(const stun_buffer *buf, uint16_t attr_type) {
  231|  11.4k|  return stun_attr_get_first_by_type_str(buf->buf, buf->len, attr_type);
  232|  11.4k|}
stun_set_binding_request:
  236|  1.62k|void stun_set_binding_request(stun_buffer *buf) { stun_set_binding_request_str(buf->buf, (size_t *)(&(buf->len))); }
stun_set_binding_response:
  239|  6.51k|                               const uint8_t *reason, bool include_reason_string) {
  240|  6.51k|  return stun_set_binding_response_str(buf->buf, &(buf->len), tid, reflexive_addr, error_code, reason, 0, false, true,
  241|  6.51k|                                       include_reason_string);
  242|  6.51k|}
stun_prepare_binding_request:
  244|  1.62k|void stun_prepare_binding_request(stun_buffer *buf) { stun_set_binding_request_str(buf->buf, (size_t *)(&(buf->len))); }
stun_is_binding_response:
  246|  40.7k|bool stun_is_binding_response(const stun_buffer *buf) { return stun_is_binding_response_str(buf->buf, buf->len); }
stun_buffer.c:is_channel_msg:
   73|  4.88k|static inline bool is_channel_msg(const stun_buffer *buf) {
   74|  4.88k|  if (buf && buf->len > 0) {
  ------------------
  |  Branch (74:7): [True: 4.88k, False: 0]
  |  Branch (74:14): [True: 4.88k, False: 0]
  ------------------
   75|  4.88k|    return is_channel_msg_str(buf->buf, (size_t)(buf->len));
   76|  4.88k|  }
   77|      0|  return false;
   78|  4.88k|}
stun_buffer.c:stun_init_command:
  118|  3.25k|static void stun_init_command(uint16_t message_type, stun_buffer *buf) {
  119|  3.25k|  buf->len = stun_get_size(buf);
  120|  3.25k|  stun_init_command_str(message_type, buf->buf, &(buf->len));
  121|  3.25k|}

addr_set_any:
   48|   178k|void addr_set_any(ioa_addr *addr) {
   49|   178k|  if (addr) {
  ------------------
  |  Branch (49:7): [True: 178k, False: 0]
  ------------------
   50|   178k|    memset(addr, 0, sizeof(ioa_addr));
   51|   178k|  }
   52|   178k|}
addr_any_no_port:
   78|  89.2k|int addr_any_no_port(const ioa_addr *addr) {
   79|  89.2k|  if (!addr) {
  ------------------
  |  Branch (79:7): [True: 0, False: 89.2k]
  ------------------
   80|      0|    return 1;
   81|      0|  }
   82|       |
   83|  89.2k|  if (addr->ss.sa_family == AF_INET) {
  ------------------
  |  Branch (83:7): [True: 58.1k, False: 31.0k]
  ------------------
   84|  58.1k|    return (addr->s4.sin_addr.s_addr == 0);
   85|  58.1k|  } else if (addr->ss.sa_family == AF_INET6) {
  ------------------
  |  Branch (85:14): [True: 31.0k, False: 0]
  ------------------
   86|  31.0k|    size_t i;
   87|  51.0k|    for (i = 0; i < sizeof(addr->s6.sin6_addr); i++) {
  ------------------
  |  Branch (87:17): [True: 51.0k, False: 6]
  ------------------
   88|  51.0k|      if (((const char *)(&(addr->s6.sin6_addr)))[i]) {
  ------------------
  |  Branch (88:11): [True: 31.0k, False: 19.9k]
  ------------------
   89|  31.0k|        return 0;
   90|  31.0k|      }
   91|  51.0k|    }
   92|  31.0k|  }
   93|       |
   94|      6|  return 1;
   95|  89.2k|}
addr_eq_no_port:
  180|   253k|int addr_eq_no_port(const ioa_addr *a1, const ioa_addr *a2) {
  181|       |
  182|   253k|  if (!a1) {
  ------------------
  |  Branch (182:7): [True: 0, False: 253k]
  ------------------
  183|      0|    return (!a2);
  184|   253k|  } else if (!a2) {
  ------------------
  |  Branch (184:14): [True: 0, False: 253k]
  ------------------
  185|      0|    return (!a1);
  186|      0|  }
  187|       |
  188|   253k|  if (a1->ss.sa_family == a2->ss.sa_family) {
  ------------------
  |  Branch (188:7): [True: 121k, False: 131k]
  ------------------
  189|   121k|    if (a1->ss.sa_family == AF_INET) {
  ------------------
  |  Branch (189:9): [True: 77.3k, False: 44.2k]
  ------------------
  190|  77.3k|      if ((int)a1->s4.sin_addr.s_addr == (int)a2->s4.sin_addr.s_addr) {
  ------------------
  |  Branch (190:11): [True: 423, False: 76.8k]
  ------------------
  191|    423|        return 1;
  192|    423|      }
  193|  77.3k|    } else if (a1->ss.sa_family == AF_INET6) {
  ------------------
  |  Branch (193:16): [True: 44.2k, False: 0]
  ------------------
  194|  44.2k|      if (memcmp(&(a1->s6.sin6_addr), &(a2->s6.sin6_addr), sizeof(struct in6_addr)) == 0) {
  ------------------
  |  Branch (194:11): [True: 265, False: 44.0k]
  ------------------
  195|    265|        return 1;
  196|    265|      }
  197|  44.2k|    }
  198|   121k|  }
  199|   252k|  return 0;
  200|   253k|}
make_ioa_addr:
  202|      8|int make_ioa_addr(const uint8_t *saddr0, uint16_t port, ioa_addr *addr) {
  203|       |
  204|      8|  if (!saddr0 || !addr) {
  ------------------
  |  Branch (204:7): [True: 0, False: 8]
  |  Branch (204:18): [True: 0, False: 8]
  ------------------
  205|      0|    return -1;
  206|      0|  }
  207|       |
  208|      8|  char ssaddr[257];
  209|      8|  STRCPY(ssaddr, saddr0);
  ------------------
  |  |  198|      8|  do {                                                                                                                 \
  |  |  199|      8|    if ((const char *)(dst) != (const char *)(src)) {                                                                  \
  |  |  ------------------
  |  |  |  Branch (199:9): [True: 8, False: 0]
  |  |  ------------------
  |  |  200|      8|      if (sizeof(dst) == sizeof(char *))                                                                               \
  |  |  ------------------
  |  |  |  Branch (200:11): [Folded, False: 8]
  |  |  ------------------
  |  |  201|      8|        strcpy(((char *)(dst)), (const char *)(src));                                                                  \
  |  |  202|      8|      else {                                                                                                           \
  |  |  203|      8|        size_t szdst = sizeof((dst));                                                                                  \
  |  |  204|      8|        strncpy((char *)(dst), (const char *)(src), szdst);                                                            \
  |  |  205|      8|        ((char *)(dst))[szdst - 1] = 0;                                                                                \
  |  |  206|      8|      }                                                                                                                \
  |  |  207|      8|    }                                                                                                                  \
  |  |  208|      8|  } while (0)
  |  |  ------------------
  |  |  |  Branch (208:12): [Folded, False: 8]
  |  |  ------------------
  ------------------
  210|       |
  211|      8|  char *saddr = ssaddr;
  212|      8|  while (*saddr == ' ') {
  ------------------
  |  Branch (212:10): [True: 0, False: 8]
  ------------------
  213|      0|    ++saddr;
  214|      0|  }
  215|       |
  216|      8|  size_t len = strlen(saddr);
  217|      8|  while (len > 0) {
  ------------------
  |  Branch (217:10): [True: 8, False: 0]
  ------------------
  218|      8|    if (saddr[len - 1] == ' ') {
  ------------------
  |  Branch (218:9): [True: 0, False: 8]
  ------------------
  219|      0|      saddr[len - 1] = 0;
  220|      0|      --len;
  221|      8|    } else {
  222|      8|      break;
  223|      8|    }
  224|      8|  }
  225|       |
  226|      8|  memset(addr, 0, sizeof(ioa_addr));
  227|      8|  if ((len == 0) || (inet_pton(AF_INET, saddr, &addr->s4.sin_addr) == 1)) {
  ------------------
  |  Branch (227:7): [True: 0, False: 8]
  |  Branch (227:21): [True: 4, False: 4]
  ------------------
  228|      4|    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|      4|    addr->s4.sin_port = nswap16(port);
  ------------------
  |  |   86|      4|#define nswap16(s) ntohs(s)
  ------------------
  233|      4|  } else if (inet_pton(AF_INET6, saddr, &addr->s6.sin6_addr) == 1) {
  ------------------
  |  Branch (233:14): [True: 4, False: 0]
  ------------------
  234|      4|    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|      4|    addr->s6.sin6_port = nswap16(port);
  ------------------
  |  |   86|      4|#define nswap16(s) ntohs(s)
  ------------------
  239|      4|  } 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|      8|  return 0;
  300|      8|}
addr_set_port:
  407|  11.1k|void addr_set_port(ioa_addr *addr, uint16_t port) {
  408|  11.1k|  if (addr) {
  ------------------
  |  Branch (408:7): [True: 11.1k, False: 0]
  ------------------
  409|  11.1k|    if (addr->s4.sin_family == AF_INET) {
  ------------------
  |  Branch (409:9): [True: 6.91k, False: 4.25k]
  ------------------
  410|  6.91k|      addr->s4.sin_port = nswap16(port);
  ------------------
  |  |   86|  6.91k|#define nswap16(s) ntohs(s)
  ------------------
  411|  6.91k|    } else if (addr->s6.sin6_family == AF_INET6) {
  ------------------
  |  Branch (411:16): [True: 4.25k, False: 0]
  ------------------
  412|       |      addr->s6.sin6_port = nswap16(port);
  ------------------
  |  |   86|  4.25k|#define nswap16(s) ntohs(s)
  ------------------
  413|  4.25k|    }
  414|  11.1k|  }
  415|  11.1k|}
addr_get_port:
  417|  11.1k|uint16_t addr_get_port(const ioa_addr *addr) {
  418|  11.1k|  if (!addr) {
  ------------------
  |  Branch (418:7): [True: 0, False: 11.1k]
  ------------------
  419|      0|    return 0;
  420|      0|  }
  421|       |
  422|  11.1k|  if (addr->s4.sin_family == AF_INET) {
  ------------------
  |  Branch (422:7): [True: 10.9k, False: 271]
  ------------------
  423|  10.9k|    return nswap16(addr->s4.sin_port);
  ------------------
  |  |   86|  10.9k|#define nswap16(s) ntohs(s)
  ------------------
  424|  10.9k|  } else if (addr->s6.sin6_family == AF_INET6) {
  ------------------
  |  Branch (424:14): [True: 271, False: 0]
  ------------------
  425|    271|    return nswap16(addr->s6.sin6_port);
  ------------------
  |  |   86|    271|#define nswap16(s) ntohs(s)
  ------------------
  426|    271|  }
  427|      0|  return 0;
  428|  11.1k|}
ioa_addr_add_mapping:
  679|      4|void ioa_addr_add_mapping(ioa_addr *apub, ioa_addr *apriv) {
  680|      4|  const size_t new_size = msz + sizeof(ioa_addr *);
  681|      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__)
  ------------------
  682|      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__)
  ------------------
  683|      4|  public_addrs[mcount] = (ioa_addr *)turn_malloc(sizeof(ioa_addr));
  ------------------
  |  |  119|      4|#define turn_malloc(sz) turn_malloc_impl((sz), __FILE__, __LINE__)
  ------------------
  684|      4|  private_addrs[mcount] = (ioa_addr *)turn_malloc(sizeof(ioa_addr));
  ------------------
  |  |  119|      4|#define turn_malloc(sz) turn_malloc_impl((sz), __FILE__, __LINE__)
  ------------------
  685|      4|  addr_cpy(public_addrs[mcount], apub);
  686|      4|  addr_cpy(private_addrs[mcount], apriv);
  687|      4|  ++mcount;
  688|      4|  msz += sizeof(ioa_addr *);
  689|      4|}
map_addr_from_public_to_private:
  691|  78.9k|void map_addr_from_public_to_private(const ioa_addr *public_addr, ioa_addr *private_addr) {
  692|  78.9k|  size_t i;
  693|   236k|  for (i = 0; i < mcount; ++i) {
  ------------------
  |  Branch (693:15): [True: 157k, False: 78.5k]
  ------------------
  694|   157k|    if (addr_eq_no_port(public_addr, public_addrs[i])) {
  ------------------
  |  Branch (694:9): [True: 433, False: 157k]
  ------------------
  695|    433|      addr_cpy(private_addr, private_addrs[i]);
  696|    433|      addr_set_port(private_addr, addr_get_port(public_addr));
  697|    433|      return;
  698|    433|    }
  699|   157k|  }
  700|  78.5k|  addr_cpy(private_addr, public_addr);
  701|  78.5k|}
map_addr_from_private_to_public:
  703|  47.8k|void map_addr_from_private_to_public(const ioa_addr *private_addr, ioa_addr *public_addr) {
  704|  47.8k|  size_t i;
  705|   143k|  for (i = 0; i < mcount; ++i) {
  ------------------
  |  Branch (705:15): [True: 95.4k, False: 47.5k]
  ------------------
  706|  95.4k|    if (addr_eq_no_port(private_addr, private_addrs[i])) {
  ------------------
  |  Branch (706:9): [True: 255, False: 95.2k]
  ------------------
  707|    255|      addr_cpy(public_addr, public_addrs[i]);
  708|    255|      addr_set_port(public_addr, addr_get_port(private_addr));
  709|    255|      return;
  710|    255|    }
  711|  95.4k|  }
  712|  47.5k|  addr_cpy(public_addr, private_addr);
  713|  47.5k|}

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

turn_random_number:
  123|   232k|long turn_random_number(void) {
  124|   232k|  long ret = 0;
  125|   232k|#if defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
  126|   232k|  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|   232k|  return ret;
  136|   232k|}
stun_get_command_message_len_str:
  394|   918k|int stun_get_command_message_len_str(const uint8_t *buf, size_t len) {
  395|   918k|  if (len < STUN_HEADER_LENGTH) {
  ------------------
  |  |   46|   918k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (395:7): [True: 1.94k, False: 917k]
  ------------------
  396|  1.94k|    return -1;
  397|  1.94k|  }
  398|       |
  399|       |  /* Validate the size the buffer claims to be */
  400|   917k|  const size_t bufLen = (size_t)(nswap16(((const uint16_t *)(buf))[1]) + STUN_HEADER_LENGTH);
  ------------------
  |  |   86|   917k|#define nswap16(s) ntohs(s)
  ------------------
                const size_t bufLen = (size_t)(nswap16(((const uint16_t *)(buf))[1]) + STUN_HEADER_LENGTH);
  ------------------
  |  |   46|   917k|#define STUN_HEADER_LENGTH (20)
  ------------------
  401|   917k|  if (bufLen > len) {
  ------------------
  |  Branch (401:7): [True: 8.74k, False: 908k]
  ------------------
  402|  8.74k|    return -1;
  403|  8.74k|  }
  404|       |
  405|   908k|  return bufLen;
  406|   917k|}
stun_make_type:
  418|  74.9k|uint16_t stun_make_type(uint16_t method) {
  419|  74.9k|  method = method & 0x0FFF;
  420|  74.9k|  return ((method & 0x000F) | ((method & 0x0070) << 1) | ((method & 0x0380) << 2) | ((method & 0x0C00) << 2));
  421|  74.9k|}
stun_get_method_str:
  423|   142k|uint16_t stun_get_method_str(const uint8_t *buf, size_t len) {
  424|   142k|  if (!buf || len < 2) {
  ------------------
  |  Branch (424:7): [True: 0, False: 142k]
  |  Branch (424:15): [True: 0, False: 142k]
  ------------------
  425|      0|    return (uint16_t)-1;
  426|      0|  }
  427|       |
  428|   142k|  const uint16_t tt = nswap16(((const uint16_t *)buf)[0]);
  ------------------
  |  |   86|   142k|#define nswap16(s) ntohs(s)
  ------------------
  429|       |
  430|   142k|  return (tt & 0x000F) | ((tt & 0x00E0) >> 1) | ((tt & 0x0E00) >> 2) | ((tt & 0x3000) >> 2);
  431|   142k|}
stun_get_msg_type_str:
  433|   461k|uint16_t stun_get_msg_type_str(const uint8_t *buf, size_t len) {
  434|   461k|  if (!buf || len < 2) {
  ------------------
  |  Branch (434:7): [True: 0, False: 461k]
  |  Branch (434:15): [True: 73, False: 461k]
  ------------------
  435|     73|    return (uint16_t)-1;
  436|     73|  }
  437|   461k|  return ((nswap16(((const uint16_t *)buf)[0])) & 0x3FFF);
  ------------------
  |  |   86|   461k|#define nswap16(s) ntohs(s)
  ------------------
  438|   461k|}
is_channel_msg_str:
  440|   326k|bool is_channel_msg_str(const uint8_t *buf, size_t blen) {
  441|   326k|  return (buf && blen >= 4 && STUN_VALID_CHANNEL(nswap16(((const uint16_t *)buf)[0])));
  ------------------
  |  |  144|   325k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (144:34): [True: 708, False: 325k]
  |  |  |  Branch (144:53): [True: 521, False: 187]
  |  |  ------------------
  ------------------
  |  Branch (441:11): [True: 326k, False: 0]
  |  Branch (441:18): [True: 325k, False: 291]
  ------------------
  442|   326k|}
stun_is_command_message_str:
  446|   151k|bool stun_is_command_message_str(const uint8_t *buf, size_t blen) {
  447|   151k|  if (buf && blen >= STUN_HEADER_LENGTH) {
  ------------------
  |  |   46|   151k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (447:7): [True: 151k, False: 0]
  |  Branch (447:14): [True: 150k, False: 123]
  ------------------
  448|   150k|    if (!STUN_VALID_CHANNEL(nswap16(((const uint16_t *)buf)[0]))) {
  ------------------
  |  |  144|   150k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (144:34): [True: 517, False: 150k]
  |  |  |  Branch (144:53): [True: 438, False: 79]
  |  |  ------------------
  ------------------
  449|   150k|      if ((((uint8_t)buf[0]) & ((uint8_t)(0xC0))) == 0) {
  ------------------
  |  Branch (449:11): [True: 150k, False: 79]
  ------------------
  450|   150k|        if (nswap32(((const uint32_t *)(buf))[1]) == STUN_MAGIC_COOKIE) {
  ------------------
  |  |   87|   150k|#define nswap32(ul) ntohl(ul)
  ------------------
                      if (nswap32(((const uint32_t *)(buf))[1]) == STUN_MAGIC_COOKIE) {
  ------------------
  |  |   56|   150k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (450:13): [True: 134k, False: 15.6k]
  ------------------
  451|   134k|          const uint16_t len = nswap16(((const uint16_t *)(buf))[1]);
  ------------------
  |  |   86|   134k|#define nswap16(s) ntohs(s)
  ------------------
  452|   134k|          if ((len & 0x0003) == 0) {
  ------------------
  |  Branch (452:15): [True: 134k, False: 4]
  ------------------
  453|   134k|            if ((size_t)(len + STUN_HEADER_LENGTH) == blen) {
  ------------------
  |  |   46|   134k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (453:17): [True: 134k, False: 52]
  ------------------
  454|   134k|              return true;
  455|   134k|            }
  456|   134k|          }
  457|   134k|        }
  458|   150k|      }
  459|   150k|    }
  460|   150k|  }
  461|  16.3k|  return false;
  462|   151k|}
stun_is_request_str:
  513|  74.9k|bool stun_is_request_str(const uint8_t *buf, size_t len) {
  514|  74.9k|  if (is_channel_msg_str(buf, len)) {
  ------------------
  |  Branch (514:7): [True: 0, False: 74.9k]
  ------------------
  515|      0|    return false;
  516|      0|  }
  517|  74.9k|  return IS_STUN_REQUEST(stun_get_msg_type_str(buf, len));
  ------------------
  |  |   58|  74.9k|#define IS_STUN_REQUEST(msg_type) (((msg_type)&0x0110) == 0x0000)
  ------------------
  518|  74.9k|}
stun_is_success_response_str:
  520|  75.0k|bool stun_is_success_response_str(const uint8_t *buf, size_t len) {
  521|  75.0k|  if (is_channel_msg_str(buf, len)) {
  ------------------
  |  Branch (521:7): [True: 0, False: 75.0k]
  ------------------
  522|      0|    return false;
  523|      0|  }
  524|  75.0k|  return IS_STUN_SUCCESS_RESP(stun_get_msg_type_str(buf, len));
  ------------------
  |  |   60|  75.0k|#define IS_STUN_SUCCESS_RESP(msg_type) (((msg_type)&0x0110) == 0x0100)
  ------------------
  525|  75.0k|}
stun_is_error_response_str:
  527|  75.0k|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) {
  528|  75.0k|  if (is_channel_msg_str(buf, len)) {
  ------------------
  |  Branch (528:7): [True: 0, False: 75.0k]
  ------------------
  529|      0|    return false;
  530|      0|  }
  531|  75.0k|  if (IS_STUN_ERR_RESP(stun_get_msg_type_str(buf, len))) {
  ------------------
  |  |   61|  75.0k|#define IS_STUN_ERR_RESP(msg_type) (((msg_type)&0x0110) == 0x0110)
  |  |  ------------------
  |  |  |  Branch (61:36): [True: 27.7k, False: 47.2k]
  |  |  ------------------
  ------------------
  532|  27.7k|    if (err_code) {
  ------------------
  |  Branch (532:9): [True: 27.7k, False: 0]
  ------------------
  533|  27.7k|      stun_attr_ref sar = stun_attr_get_first_by_type_str(buf, len, STUN_ATTRIBUTE_ERROR_CODE);
  ------------------
  |  |   99|  27.7k|#define STUN_ATTRIBUTE_ERROR_CODE (0x0009)
  ------------------
  534|  27.7k|      if (sar) {
  ------------------
  |  Branch (534:11): [True: 27.7k, False: 56]
  ------------------
  535|  27.7k|        if (stun_attr_get_len(sar) >= 4) {
  ------------------
  |  Branch (535:13): [True: 27.7k, False: 12]
  ------------------
  536|  27.7k|          const uint8_t *val = (const uint8_t *)stun_attr_get_value(sar);
  537|  27.7k|          *err_code = (int)(val[2] * 100 + val[3]);
  538|  27.7k|          if (err_msg && err_msg_size > 0) {
  ------------------
  |  Branch (538:15): [True: 27.7k, False: 0]
  |  Branch (538:26): [True: 27.7k, False: 0]
  ------------------
  539|  27.7k|            err_msg[0] = 0;
  540|  27.7k|            if (stun_attr_get_len(sar) > 4) {
  ------------------
  |  Branch (540:17): [True: 14.2k, False: 13.4k]
  ------------------
  541|  14.2k|              size_t msg_len = stun_attr_get_len(sar) - 4;
  542|  14.2k|              if (msg_len > (err_msg_size - 1)) {
  ------------------
  |  Branch (542:19): [True: 15, False: 14.2k]
  ------------------
  543|     15|                msg_len = err_msg_size - 1;
  544|     15|              }
  545|  14.2k|              memcpy(err_msg, val + 4, msg_len);
  546|  14.2k|              err_msg[msg_len] = 0;
  547|  14.2k|            }
  548|  27.7k|          }
  549|  27.7k|        }
  550|  27.7k|      }
  551|  27.7k|    }
  552|  27.7k|    return true;
  553|  27.7k|  }
  554|  47.2k|  return false;
  555|  75.0k|}
stun_is_response_str:
  612|  96.0k|bool stun_is_response_str(const uint8_t *buf, size_t len) {
  613|  96.0k|  if (is_channel_msg_str(buf, len)) {
  ------------------
  |  Branch (613:7): [True: 0, False: 96.0k]
  ------------------
  614|      0|    return false;
  615|      0|  }
  616|  96.0k|  if (IS_STUN_SUCCESS_RESP(stun_get_msg_type_str(buf, len))) {
  ------------------
  |  |   60|  96.0k|#define IS_STUN_SUCCESS_RESP(msg_type) (((msg_type)&0x0110) == 0x0100)
  |  |  ------------------
  |  |  |  Branch (60:40): [True: 35.5k, False: 60.5k]
  |  |  ------------------
  ------------------
  617|  35.5k|    return true;
  618|  35.5k|  }
  619|  60.5k|  if (IS_STUN_ERR_RESP(stun_get_msg_type_str(buf, len))) {
  ------------------
  |  |   61|  60.5k|#define IS_STUN_ERR_RESP(msg_type) (((msg_type)&0x0110) == 0x0110)
  |  |  ------------------
  |  |  |  Branch (61:36): [True: 37.2k, False: 23.2k]
  |  |  ------------------
  ------------------
  620|  37.2k|    return true;
  621|  37.2k|  }
  622|  23.2k|  return false;
  623|  60.5k|}
stun_is_indication_str:
  625|    150|bool stun_is_indication_str(const uint8_t *buf, size_t len) {
  626|    150|  if (is_channel_msg_str(buf, len)) {
  ------------------
  |  Branch (626:7): [True: 0, False: 150]
  ------------------
  627|      0|    return false;
  628|      0|  }
  629|    150|  return IS_STUN_INDICATION(stun_get_msg_type_str(buf, len));
  ------------------
  |  |   59|    150|#define IS_STUN_INDICATION(msg_type) (((msg_type)&0x0110) == 0x0010)
  ------------------
  630|    150|}
stun_make_request:
  632|  17.9k|uint16_t stun_make_request(uint16_t method) { return GET_STUN_REQUEST(stun_make_type(method)); }
  ------------------
  |  |   63|  17.9k|#define GET_STUN_REQUEST(msg_type) (msg_type & 0xFEEF)
  ------------------
stun_make_indication:
  634|  1.62k|uint16_t stun_make_indication(uint16_t method) { return GET_STUN_INDICATION(stun_make_type(method)); }
  ------------------
  |  |   64|  1.62k|#define GET_STUN_INDICATION(msg_type) ((msg_type & 0xFEEF) | 0x0010)
  ------------------
stun_make_success_response:
  636|  27.6k|uint16_t stun_make_success_response(uint16_t method) { return GET_STUN_SUCCESS_RESP(stun_make_type(method)); }
  ------------------
  |  |   65|  27.6k|#define GET_STUN_SUCCESS_RESP(msg_type) ((msg_type & 0xFEEF) | 0x0100)
  ------------------
stun_make_error_response:
  638|  27.6k|uint16_t stun_make_error_response(uint16_t method) { return GET_STUN_ERR_RESP(stun_make_type(method)); }
  ------------------
  |  |   66|  27.6k|#define GET_STUN_ERR_RESP(msg_type) (msg_type | 0x0110)
  ------------------
stun_init_buffer_str:
  642|  74.9k|void stun_init_buffer_str(uint8_t *buf, size_t *len) {
  643|  74.9k|  *len = STUN_HEADER_LENGTH;
  ------------------
  |  |   46|  74.9k|#define STUN_HEADER_LENGTH (20)
  ------------------
  644|  74.9k|  memset(buf, 0, *len);
  645|  74.9k|}
stun_init_command_str:
  647|  67.0k|void stun_init_command_str(uint16_t message_type, uint8_t *buf, size_t *len) {
  648|  67.0k|  stun_init_buffer_str(buf, len);
  649|  67.0k|  message_type &= (uint16_t)(0x3FFF);
  650|  67.0k|  ((uint16_t *)buf)[0] = nswap16(message_type);
  ------------------
  |  |   86|  67.0k|#define nswap16(s) ntohs(s)
  ------------------
  651|  67.0k|  ((uint16_t *)buf)[1] = 0;
  652|  67.0k|  ((uint32_t *)buf)[1] = nswap32(STUN_MAGIC_COOKIE);
  ------------------
  |  |   87|  67.0k|#define nswap32(ul) ntohl(ul)
  ------------------
  653|       |  stun_tid_generate_in_message_str(buf, NULL);
  654|  67.0k|}
old_stun_init_command_str:
  656|  7.83k|void old_stun_init_command_str(uint16_t message_type, uint8_t *buf, size_t *len, uint32_t cookie) {
  657|  7.83k|  stun_init_buffer_str(buf, len);
  658|  7.83k|  message_type &= (uint16_t)(0x3FFF);
  659|  7.83k|  ((uint16_t *)buf)[0] = nswap16(message_type);
  ------------------
  |  |   86|  7.83k|#define nswap16(s) ntohs(s)
  ------------------
  660|  7.83k|  ((uint16_t *)buf)[1] = 0;
  661|  7.83k|  ((uint32_t *)buf)[1] = nswap32(cookie);
  ------------------
  |  |   87|  7.83k|#define nswap32(ul) ntohl(ul)
  ------------------
  662|       |  stun_tid_generate_in_message_str(buf, NULL);
  663|  7.83k|}
stun_init_request_str:
  665|  16.2k|void stun_init_request_str(uint16_t method, uint8_t *buf, size_t *len) {
  666|  16.2k|  stun_init_command_str(stun_make_request(method), buf, len);
  667|  16.2k|}
stun_init_success_response_str:
  673|  23.7k|void stun_init_success_response_str(uint16_t method, uint8_t *buf, size_t *len, stun_tid *id) {
  674|  23.7k|  stun_init_command_str(stun_make_success_response(method), buf, len);
  675|  23.7k|  if (id) {
  ------------------
  |  Branch (675:7): [True: 23.7k, False: 0]
  ------------------
  676|  23.7k|    stun_tid_message_cpy(buf, id);
  677|  23.7k|  }
  678|  23.7k|}
old_stun_init_success_response_str:
  680|  3.91k|void old_stun_init_success_response_str(uint16_t method, uint8_t *buf, size_t *len, stun_tid *id, uint32_t cookie) {
  681|  3.91k|  old_stun_init_command_str(stun_make_success_response(method), buf, len, cookie);
  682|  3.91k|  if (id) {
  ------------------
  |  Branch (682:7): [True: 3.91k, False: 0]
  ------------------
  683|  3.91k|    stun_tid_message_cpy(buf, id);
  684|  3.91k|  }
  685|  3.91k|}
get_default_reason:
  687|  1.00k|const uint8_t *get_default_reason(int error_code) {
  688|  1.00k|  const char *reason = "Unknown error";
  689|       |
  690|  1.00k|  switch (error_code) {
  691|    402|  case 300:
  ------------------
  |  Branch (691:3): [True: 402, False: 606]
  ------------------
  692|    402|    reason = "Try Alternate";
  693|    402|    break;
  694|     60|  case 400:
  ------------------
  |  Branch (694:3): [True: 60, False: 948]
  ------------------
  695|     60|    reason = "Bad Request";
  696|     60|    break;
  697|     24|  case 401:
  ------------------
  |  Branch (697:3): [True: 24, False: 984]
  ------------------
  698|     24|    reason = "Unauthorized";
  699|     24|    break;
  700|    108|  case 403:
  ------------------
  |  Branch (700:3): [True: 108, False: 900]
  ------------------
  701|    108|    reason = "Forbidden";
  702|    108|    break;
  703|      0|  case 404:
  ------------------
  |  Branch (703:3): [True: 0, False: 1.00k]
  ------------------
  704|      0|    reason = "Not Found";
  705|      0|    break;
  706|     24|  case 420:
  ------------------
  |  Branch (706:3): [True: 24, False: 984]
  ------------------
  707|     24|    reason = "Unknown Attribute";
  708|     24|    break;
  709|     30|  case 437:
  ------------------
  |  Branch (709:3): [True: 30, False: 978]
  ------------------
  710|     30|    reason = "Allocation Mismatch";
  711|     30|    break;
  712|     30|  case 438:
  ------------------
  |  Branch (712:3): [True: 30, False: 978]
  ------------------
  713|     30|    reason = "Stale Nonce";
  714|     30|    break;
  715|     30|  case 440:
  ------------------
  |  Branch (715:3): [True: 30, False: 978]
  ------------------
  716|     30|    reason = "Address Family not Supported";
  717|     30|    break;
  718|     24|  case 441:
  ------------------
  |  Branch (718:3): [True: 24, False: 984]
  ------------------
  719|     24|    reason = "Wrong Credentials";
  720|     24|    break;
  721|     30|  case 442:
  ------------------
  |  Branch (721:3): [True: 30, False: 978]
  ------------------
  722|     30|    reason = "Unsupported Transport Protocol";
  723|     30|    break;
  724|     12|  case 443:
  ------------------
  |  Branch (724:3): [True: 12, False: 996]
  ------------------
  725|     12|    reason = "Peer Address Family Mismatch";
  726|     12|    break;
  727|     48|  case 446:
  ------------------
  |  Branch (727:3): [True: 48, False: 960]
  ------------------
  728|     48|    reason = "Connection Already Exists";
  729|     48|    break;
  730|     24|  case 447:
  ------------------
  |  Branch (730:3): [True: 24, False: 984]
  ------------------
  731|     24|    reason = "Connection Timeout or Failure";
  732|     24|    break;
  733|     42|  case 486:
  ------------------
  |  Branch (733:3): [True: 42, False: 966]
  ------------------
  734|     42|    reason = "Allocation Quota Reached";
  735|     42|    break;
  736|     42|  case 487:
  ------------------
  |  Branch (736:3): [True: 42, False: 966]
  ------------------
  737|     42|    reason = "Role Conflict";
  738|     42|    break;
  739|     30|  case 500:
  ------------------
  |  Branch (739:3): [True: 30, False: 978]
  ------------------
  740|     30|    reason = "Server Error";
  741|     30|    break;
  742|     24|  case 508:
  ------------------
  |  Branch (742:3): [True: 24, False: 984]
  ------------------
  743|     24|    reason = "Insufficient Capacity";
  744|     24|    break;
  745|     24|  default:;
  ------------------
  |  Branch (745:3): [True: 24, False: 984]
  ------------------
  746|  1.00k|  };
  747|       |
  748|  1.00k|  return (const uint8_t *)reason;
  749|  1.00k|}
old_stun_init_error_response_str:
  786|  3.91k|                                      bool include_reason_string) {
  787|       |
  788|  3.91k|  old_stun_init_command_str(stun_make_error_response(method), buf, len, cookie);
  789|       |
  790|  3.91k|  stun_init_error_response_common_str(buf, len, error_code, reason, id, include_reason_string);
  791|  3.91k|}
stun_init_error_response_str:
  794|  23.7k|                                  const uint8_t *reason, stun_tid *id, bool include_reason_string) {
  795|       |
  796|  23.7k|  stun_init_command_str(stun_make_error_response(method), buf, len);
  797|       |
  798|  23.7k|  stun_init_error_response_common_str(buf, len, error_code, reason, id, include_reason_string);
  799|  23.7k|}
stun_init_channel_message_str:
  803|  1.62k|bool stun_init_channel_message_str(uint16_t chnumber, uint8_t *buf, size_t *len, int length, bool do_padding) {
  804|  1.62k|  uint16_t rlen = (uint16_t)length;
  805|       |
  806|  1.62k|  if (length < 0 || (MAX_STUN_MESSAGE_SIZE < (4 + length))) {
  ------------------
  |  |  179|  1.62k|#define MAX_STUN_MESSAGE_SIZE (65507)
  ------------------
  |  Branch (806:7): [True: 0, False: 1.62k]
  |  Branch (806:21): [True: 0, False: 1.62k]
  ------------------
  807|      0|    return false;
  808|      0|  }
  809|  1.62k|  ((uint16_t *)(buf))[0] = nswap16(chnumber);
  ------------------
  |  |   86|  1.62k|#define nswap16(s) ntohs(s)
  ------------------
  810|  1.62k|  ((uint16_t *)(buf))[1] = nswap16((uint16_t)length);
  ------------------
  |  |   86|  1.62k|#define nswap16(s) ntohs(s)
  ------------------
  811|       |
  812|  1.62k|  if (do_padding && (rlen & 0x0003)) {
  ------------------
  |  Branch (812:7): [True: 644, False: 985]
  |  Branch (812:21): [True: 448, False: 196]
  ------------------
  813|    448|    const uint16_t padded = ((rlen >> 2) + 1) << 2;
  814|       |    // Zero the pad bytes so stale buffer contents are not leaked on the wire
  815|       |    // (matches the padding handling in stun_attr_add_str).
  816|    448|    memset(buf + 4 + rlen, 0, (size_t)(padded - rlen));
  817|    448|    rlen = padded;
  818|    448|  }
  819|       |
  820|  1.62k|  *len = 4 + rlen;
  821|       |
  822|       |  return true;
  823|  1.62k|}
stun_is_channel_message_str:
  825|  9.33k|bool stun_is_channel_message_str(const uint8_t *buf, size_t *blen, uint16_t *chnumber, bool mandatory_padding) {
  826|  9.33k|  uint16_t datalen_header;
  827|  9.33k|  uint16_t datalen_actual;
  828|       |
  829|  9.33k|  if (!blen || (*blen < 4)) {
  ------------------
  |  Branch (829:7): [True: 0, False: 9.33k]
  |  Branch (829:16): [True: 582, False: 8.75k]
  ------------------
  830|    582|    return false;
  831|    582|  }
  832|       |
  833|  8.75k|  const uint16_t chn = nswap16(((const uint16_t *)(buf))[0]);
  ------------------
  |  |   86|  8.75k|#define nswap16(s) ntohs(s)
  ------------------
  834|  8.75k|  if (!STUN_VALID_CHANNEL(chn)) {
  ------------------
  |  |  144|  8.75k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (144:34): [True: 6.18k, False: 2.56k]
  |  |  |  Branch (144:53): [True: 5.43k, False: 756]
  |  |  ------------------
  ------------------
  835|  3.32k|    return false;
  836|  3.32k|  }
  837|       |
  838|       |  /* Clamp to uint16_t range for comparison without mutating the caller's
  839|       |   * *blen — the modification to *blen at the end of this function is
  840|       |   * intentional (it reports actual message length consumed), but clamping
  841|       |   * during validation must not alter the caller's view of the buffer size
  842|       |   * if the function later returns false (issue #1837). */
  843|  5.43k|  const uint16_t blen16 = (*blen > (uint16_t)-1) ? (uint16_t)-1 : (uint16_t)*blen;
  ------------------
  |  Branch (843:27): [True: 0, False: 5.43k]
  ------------------
  844|  5.43k|  datalen_actual = blen16 - 4;
  845|  5.43k|  datalen_header = ((const uint16_t *)buf)[1];
  846|  5.43k|  datalen_header = nswap16(datalen_header);
  ------------------
  |  |   86|  5.43k|#define nswap16(s) ntohs(s)
  ------------------
  847|       |
  848|  5.43k|  if (datalen_header > datalen_actual) {
  ------------------
  |  Branch (848:7): [True: 1.57k, False: 3.85k]
  ------------------
  849|  1.57k|    return false;
  850|  1.57k|  }
  851|       |
  852|  3.85k|  if (datalen_header != datalen_actual) {
  ------------------
  |  Branch (852:7): [True: 984, False: 2.86k]
  ------------------
  853|       |
  854|       |    /* maybe there are padding bytes for 32-bit alignment. Mandatory for TCP. Optional for UDP */
  855|       |
  856|    984|    if (datalen_actual & 0x0003) {
  ------------------
  |  Branch (856:9): [True: 228, False: 756]
  ------------------
  857|       |
  858|    228|      if (mandatory_padding) {
  ------------------
  |  Branch (858:11): [True: 114, False: 114]
  ------------------
  859|    114|        return false;
  860|    114|      } else if (datalen_header == 0) {
  ------------------
  |  Branch (860:18): [True: 30, False: 84]
  ------------------
  861|     30|        return false;
  862|     84|      } else {
  863|     84|        const uint16_t diff = datalen_actual - datalen_header;
  864|     84|        if (diff > 3) {
  ------------------
  |  Branch (864:13): [True: 79, False: 5]
  ------------------
  865|     79|          return false;
  866|     79|        }
  867|     84|      }
  868|    228|    }
  869|    984|  }
  870|       |
  871|  3.62k|  *blen = datalen_header + 4;
  872|       |
  873|  3.62k|  if (chnumber) {
  ------------------
  |  Branch (873:7): [True: 3.62k, False: 0]
  ------------------
  874|  3.62k|    *chnumber = chn;
  875|  3.62k|  }
  876|       |
  877|       |  return true;
  878|  3.85k|}
is_http:
  926|  2.43k|int is_http(const char *s, size_t blen) {
  927|  2.43k|  if (s && blen >= 12) {
  ------------------
  |  Branch (927:7): [True: 2.43k, False: 0]
  |  Branch (927:12): [True: 1.96k, False: 470]
  ------------------
  928|  1.96k|    if (has_prefix(s, blen, "GET ", false) || has_prefix(s, blen, "POST ", false) ||
  ------------------
  |  Branch (928:9): [True: 134, False: 1.82k]
  |  Branch (928:47): [True: 318, False: 1.51k]
  ------------------
  929|  1.51k|        has_prefix(s, blen, "DELETE ", false) || has_prefix(s, blen, "PUT ", false)) {
  ------------------
  |  Branch (929:9): [True: 8, False: 1.50k]
  |  Branch (929:50): [True: 270, False: 1.23k]
  ------------------
  930|    730|      const char *sp = findstr(s + 4, blen - 4, " HTTP/", false);
  931|    730|      if (sp) {
  ------------------
  |  Branch (931:11): [True: 686, False: 44]
  ------------------
  932|    686|        sp += 6;
  933|    686|        const size_t diff_blen = sp - s;
  934|    686|        if (diff_blen + 4 <= blen) {
  ------------------
  |  Branch (934:13): [True: 658, False: 28]
  ------------------
  935|    658|          sp = findstr(sp, blen - diff_blen, "\r\n\r\n", false);
  936|    658|          if (sp) {
  ------------------
  |  Branch (936:15): [True: 594, False: 64]
  ------------------
  937|    594|            int ret_len = (int)(sp - s + 4);
  938|    594|            const char *clheader = "content-length: ";
  939|    594|            const char *cl = findstr(s, sp - s, clheader, true);
  940|    594|            if (cl) {
  ------------------
  |  Branch (940:17): [True: 402, False: 192]
  ------------------
  941|    402|              const unsigned long clen = strtoul(cl + strlen(clheader), NULL, 10);
  942|    402|              if (clen > 0 && clen < (0x0FFFFFFF)) {
  ------------------
  |  Branch (942:19): [True: 394, False: 8]
  |  Branch (942:31): [True: 166, False: 228]
  ------------------
  943|    166|                ret_len += (int)clen;
  944|    166|              }
  945|    402|            }
  946|    594|            return ret_len;
  947|    594|          }
  948|    658|        }
  949|    686|      }
  950|    730|    }
  951|  1.96k|  }
  952|  1.83k|  return 0;
  953|  2.43k|}
stun_get_message_len_str:
  955|  2.81k|int stun_get_message_len_str(uint8_t *buf, size_t blen, int padding, size_t *app_len) {
  956|  2.81k|  if (buf && blen) {
  ------------------
  |  Branch (956:7): [True: 2.81k, False: 0]
  |  Branch (956:14): [True: 2.81k, False: 0]
  ------------------
  957|       |    /* STUN request/response ? */
  958|  2.81k|    if (buf && blen >= STUN_HEADER_LENGTH) {
  ------------------
  |  |   46|  2.81k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (958:9): [True: 2.81k, False: 0]
  |  Branch (958:16): [True: 2.13k, False: 686]
  ------------------
  959|  2.13k|      if (!STUN_VALID_CHANNEL(nswap16(((const uint16_t *)buf)[0]))) {
  ------------------
  |  |  144|  2.13k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (144:34): [True: 1.08k, False: 1.04k]
  |  |  |  Branch (144:53): [True: 920, False: 162]
  |  |  ------------------
  ------------------
  960|  1.21k|        if ((((uint8_t)buf[0]) & ((uint8_t)(0xC0))) == 0) {
  ------------------
  |  Branch (960:13): [True: 1.04k, False: 162]
  ------------------
  961|  1.04k|          if (nswap32(((const uint32_t *)(buf))[1]) == STUN_MAGIC_COOKIE) {
  ------------------
  |  |   87|  1.04k|#define nswap32(ul) ntohl(ul)
  ------------------
                        if (nswap32(((const uint32_t *)(buf))[1]) == STUN_MAGIC_COOKIE) {
  ------------------
  |  |   56|  1.04k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (961:15): [True: 430, False: 618]
  ------------------
  962|       |            /* Use uint32_t to avoid uint16_t truncation overflow when the body
  963|       |             * length is near 0xFFFF: e.g. 65532 + STUN_HEADER_LENGTH (20) =
  964|       |             * 65552, which wraps to 16 in uint16_t and lets the truncated value
  965|       |             * pass the bounds check, desynchronizing TCP/TLS framing. Mirrors
  966|       |             * the channel-data path below. */
  967|    430|            uint32_t len = (uint32_t)nswap16(((const uint16_t *)(buf))[1]);
  ------------------
  |  |   86|    430|#define nswap16(s) ntohs(s)
  ------------------
  968|    430|            if ((len & 0x0003u) == 0) {
  ------------------
  |  Branch (968:17): [True: 422, False: 8]
  ------------------
  969|    422|              len += STUN_HEADER_LENGTH;
  ------------------
  |  |   46|    422|#define STUN_HEADER_LENGTH (20)
  ------------------
  970|    422|              if (len <= blen) {
  ------------------
  |  Branch (970:19): [True: 384, False: 38]
  ------------------
  971|    384|                *app_len = len;
  972|    384|                return (int)len;
  973|    384|              }
  974|    422|            }
  975|    430|          }
  976|  1.04k|        }
  977|  1.21k|      }
  978|  2.13k|    }
  979|       |
  980|       |    // HTTP request ?
  981|  2.43k|    {
  982|  2.43k|      const int http_len = is_http(((char *)buf), blen);
  983|  2.43k|      if ((http_len > 0) && ((size_t)http_len <= blen)) {
  ------------------
  |  Branch (983:11): [True: 594, False: 1.83k]
  |  Branch (983:29): [True: 430, False: 164]
  ------------------
  984|    430|        *app_len = (size_t)http_len;
  985|    430|        return http_len;
  986|    430|      }
  987|  2.43k|    }
  988|       |
  989|       |    /* STUN channel ? */
  990|  2.00k|    if (blen >= 4) {
  ------------------
  |  Branch (990:9): [True: 2.00k, False: 0]
  ------------------
  991|  2.00k|      const uint16_t chn = nswap16(((const uint16_t *)(buf))[0]);
  ------------------
  |  |   86|  2.00k|#define nswap16(s) ntohs(s)
  ------------------
  992|  2.00k|      if (STUN_VALID_CHANNEL(chn)) {
  ------------------
  |  |  144|  2.00k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (144:34): [True: 1.08k, False: 920]
  |  |  |  Branch (144:53): [True: 700, False: 382]
  |  |  ------------------
  ------------------
  993|       |
  994|       |        /* Use uint32_t to avoid uint16_t truncation overflow when data_len is
  995|       |         * near 0xFFFF: 4 + 0xFFFF = 65539, which wraps to 3 in uint16_t and
  996|       |         * causes TCP framing bypass (CVE candidate, issue #1837). */
  997|    700|        uint32_t bret = 4u + (uint32_t)nswap16(((const uint16_t *)(buf))[1]);
  ------------------
  |  |   86|    700|#define nswap16(s) ntohs(s)
  ------------------
  998|       |
  999|    700|        *app_len = bret;
 1000|       |
 1001|    700|        if (padding && (bret & 0x0003u)) {
  ------------------
  |  Branch (1001:13): [True: 350, False: 350]
  |  Branch (1001:24): [True: 114, False: 236]
  ------------------
 1002|    114|          bret = ((bret >> 2) + 1u) << 2;
 1003|    114|        }
 1004|       |
 1005|    700|        if (bret <= blen) {
  ------------------
  |  Branch (1005:13): [True: 301, False: 399]
  ------------------
 1006|    301|          return (int)bret;
 1007|    301|        }
 1008|    700|      }
 1009|  2.00k|    }
 1010|  2.00k|  }
 1011|       |
 1012|  1.70k|  return -1;
 1013|  2.81k|}
stun_set_allocate_request_str:
 1018|  3.25k|                                   bool mobile, const char *rt, int ep) {
 1019|       |
 1020|  3.25k|  stun_init_request_str(STUN_METHOD_ALLOCATE, buf, len);
  ------------------
  |  |   78|  3.25k|#define STUN_METHOD_ALLOCATE (0x0003)
  ------------------
 1021|       |
 1022|       |  // REQUESTED-TRANSPORT
 1023|  3.25k|  {
 1024|  3.25k|    uint8_t field[4];
 1025|  3.25k|    field[0] = transport;
 1026|  3.25k|    field[1] = 0;
 1027|  3.25k|    field[2] = 0;
 1028|  3.25k|    field[3] = 0;
 1029|  3.25k|    if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_REQUESTED_TRANSPORT, field, sizeof(field))) {
  ------------------
  |  |  120|  3.25k|#define STUN_ATTRIBUTE_REQUESTED_TRANSPORT (0x0019)
  ------------------
  |  Branch (1029:9): [True: 0, False: 3.25k]
  ------------------
 1030|      0|      return false;
 1031|      0|    }
 1032|  3.25k|  }
 1033|       |
 1034|       |  // LIFETIME
 1035|  3.25k|  {
 1036|  3.25k|    if (lifetime < 1) {
  ------------------
  |  Branch (1036:9): [True: 346, False: 2.91k]
  ------------------
 1037|    346|      lifetime = STUN_DEFAULT_ALLOCATE_LIFETIME;
  ------------------
  |  |   69|    346|#define STUN_DEFAULT_ALLOCATE_LIFETIME (600)
  ------------------
 1038|    346|    }
 1039|  3.25k|    uint32_t field = nswap32(lifetime);
  ------------------
  |  |   87|  3.25k|#define nswap32(ul) ntohl(ul)
  ------------------
 1040|  3.25k|    if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_LIFETIME, (uint8_t *)(&field), sizeof(field))) {
  ------------------
  |  |  114|  3.25k|#define STUN_ATTRIBUTE_LIFETIME (0x000D)
  ------------------
  |  Branch (1040:9): [True: 0, False: 3.25k]
  ------------------
 1041|      0|      return false;
 1042|      0|    }
 1043|  3.25k|  }
 1044|       |
 1045|       |  // MICE
 1046|  3.25k|  if (mobile) {
  ------------------
  |  Branch (1046:7): [True: 1.62k, False: 1.62k]
  ------------------
 1047|  1.62k|    if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_MOBILITY_TICKET, (const uint8_t *)"", 0)) {
  ------------------
  |  |   47|  1.62k|#define STUN_ATTRIBUTE_MOBILITY_TICKET (0x8030)
  ------------------
  |  Branch (1047:9): [True: 0, False: 1.62k]
  ------------------
 1048|      0|      return false;
 1049|      0|    }
 1050|  1.62k|  }
 1051|       |
 1052|  3.25k|  if (ep > -1) {
  ------------------
  |  Branch (1052:7): [True: 2.41k, False: 840]
  ------------------
 1053|  2.41k|    uint8_t value = ep ? 0x80 : 0x00;
  ------------------
  |  Branch (1053:21): [True: 1.43k, False: 982]
  ------------------
 1054|  2.41k|    if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_EVEN_PORT, (const uint8_t *)&value, 1)) {
  ------------------
  |  |  119|  2.41k|#define STUN_ATTRIBUTE_EVEN_PORT (0x0018)
  ------------------
  |  Branch (1054:9): [True: 0, False: 2.41k]
  ------------------
 1055|      0|      return false;
 1056|      0|    }
 1057|  2.41k|  }
 1058|       |
 1059|       |  // RESERVATION-TOKEN, EVEN-PORT and DUAL-ALLOCATION are mutually exclusive:
 1060|  3.25k|  if (rt) {
  ------------------
  |  Branch (1060:7): [True: 996, False: 2.26k]
  ------------------
 1061|       |
 1062|    996|    stun_attr_add_str(buf, len, STUN_ATTRIBUTE_RESERVATION_TOKEN, (const uint8_t *)rt, 8);
  ------------------
  |  |  123|    996|#define STUN_ATTRIBUTE_RESERVATION_TOKEN (0x0022)
  ------------------
 1063|       |
 1064|  2.26k|  } else {
 1065|       |
 1066|       |    // ADRESS-FAMILY
 1067|  2.26k|    if (af4 && !af6) {
  ------------------
  |  Branch (1067:9): [True: 1.10k, False: 1.15k]
  |  Branch (1067:16): [True: 329, False: 775]
  ------------------
 1068|    329|      uint8_t field[4];
 1069|    329|      field[0] = (uint8_t)STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV4;
  ------------------
  |  |  149|    329|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV4 (0x01)
  ------------------
 1070|    329|      field[1] = 0;
 1071|    329|      field[2] = 0;
 1072|    329|      field[3] = 0;
 1073|    329|      if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY, field, sizeof(field))) {
  ------------------
  |  |  104|    329|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY (0x0017)
  ------------------
  |  Branch (1073:11): [True: 0, False: 329]
  ------------------
 1074|      0|        return false;
 1075|      0|      }
 1076|    329|    }
 1077|       |
 1078|  2.26k|    if (af6 && !af4) {
  ------------------
  |  Branch (1078:9): [True: 1.17k, False: 1.08k]
  |  Branch (1078:16): [True: 401, False: 775]
  ------------------
 1079|    401|      uint8_t field[4];
 1080|    401|      field[0] = (uint8_t)STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6;
  ------------------
  |  |  150|    401|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6 (0x02)
  ------------------
 1081|    401|      field[1] = 0;
 1082|    401|      field[2] = 0;
 1083|    401|      field[3] = 0;
 1084|    401|      if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY, field, sizeof(field))) {
  ------------------
  |  |  104|    401|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY (0x0017)
  ------------------
  |  Branch (1084:11): [True: 0, False: 401]
  ------------------
 1085|      0|        return false;
 1086|      0|      }
 1087|    401|    }
 1088|       |
 1089|  2.26k|    if (af4 && af6) {
  ------------------
  |  Branch (1089:9): [True: 1.10k, False: 1.15k]
  |  Branch (1089:16): [True: 775, False: 329]
  ------------------
 1090|    775|      uint8_t field[4];
 1091|    775|      field[0] = (uint8_t)STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6;
  ------------------
  |  |  150|    775|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6 (0x02)
  ------------------
 1092|    775|      field[1] = 0;
 1093|    775|      field[2] = 0;
 1094|    775|      field[3] = 0;
 1095|    775|      if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_ADDITIONAL_ADDRESS_FAMILY, field, sizeof(field))) {
  ------------------
  |  |  140|    775|#define STUN_ATTRIBUTE_ADDITIONAL_ADDRESS_FAMILY (0x8000)
  ------------------
  |  Branch (1095:11): [True: 0, False: 775]
  ------------------
 1096|      0|        return false;
 1097|      0|      }
 1098|    775|    }
 1099|  2.26k|  }
 1100|       |
 1101|  3.25k|  return true;
 1102|  3.25k|}
stun_set_allocate_response_str:
 1107|  16.2k|                                    uint64_t reservation_token, char *mobile_id, bool include_reason_string) {
 1108|       |
 1109|  16.2k|  if (!error_code) {
  ------------------
  |  Branch (1109:7): [True: 9.77k, False: 6.51k]
  ------------------
 1110|       |
 1111|  9.77k|    stun_init_success_response_str(STUN_METHOD_ALLOCATE, buf, len, tid);
  ------------------
  |  |   78|  9.77k|#define STUN_METHOD_ALLOCATE (0x0003)
  ------------------
 1112|       |
 1113|  9.77k|    if (relayed_addr1) {
  ------------------
  |  Branch (1113:9): [True: 9.77k, False: 0]
  ------------------
 1114|  9.77k|      if (!stun_attr_add_addr_str(buf, len, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, relayed_addr1)) {
  ------------------
  |  |  118|  9.77k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  |  Branch (1114:11): [True: 0, False: 9.77k]
  ------------------
 1115|      0|        return false;
 1116|      0|      }
 1117|  9.77k|    }
 1118|       |
 1119|  9.77k|    if (relayed_addr2) {
  ------------------
  |  Branch (1119:9): [True: 5.48k, False: 4.28k]
  ------------------
 1120|  5.48k|      if (!stun_attr_add_addr_str(buf, len, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, relayed_addr2)) {
  ------------------
  |  |  118|  5.48k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  |  Branch (1120:11): [True: 0, False: 5.48k]
  ------------------
 1121|      0|        return false;
 1122|      0|      }
 1123|  5.48k|    }
 1124|       |
 1125|  9.77k|    if (reflexive_addr) {
  ------------------
  |  Branch (1125:9): [True: 6.51k, False: 3.25k]
  ------------------
 1126|  6.51k|      if (!stun_attr_add_addr_str(buf, len, STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS, reflexive_addr)) {
  ------------------
  |  |  105|  6.51k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (1126:11): [True: 0, False: 6.51k]
  ------------------
 1127|      0|        return false;
 1128|      0|      }
 1129|  6.51k|    }
 1130|       |
 1131|  9.77k|    if (reservation_token) {
  ------------------
  |  Branch (1131:9): [True: 6.39k, False: 3.38k]
  ------------------
 1132|  6.39k|      reservation_token = nswap64(reservation_token);
  ------------------
  |  |   88|  6.39k|#define nswap64(ull) ioa_ntoh64(ull)
  |  |  ------------------
  |  |  |  |  115|  6.39k|#define ioa_ntoh64 _ioa_ntoh64
  |  |  ------------------
  ------------------
 1133|  6.39k|      stun_attr_add_str(buf, len, STUN_ATTRIBUTE_RESERVATION_TOKEN, (uint8_t *)(&reservation_token), 8);
  ------------------
  |  |  123|  6.39k|#define STUN_ATTRIBUTE_RESERVATION_TOKEN (0x0022)
  ------------------
 1134|  6.39k|    }
 1135|       |
 1136|  9.77k|    {
 1137|  9.77k|      if (lifetime < 1) {
  ------------------
  |  Branch (1137:11): [True: 3.61k, False: 6.15k]
  ------------------
 1138|  3.61k|        lifetime = STUN_DEFAULT_ALLOCATE_LIFETIME;
  ------------------
  |  |   69|  3.61k|#define STUN_DEFAULT_ALLOCATE_LIFETIME (600)
  ------------------
 1139|  6.15k|      } else if (lifetime > max_lifetime) {
  ------------------
  |  Branch (1139:18): [True: 4.44k, False: 1.71k]
  ------------------
 1140|  4.44k|        lifetime = max_lifetime;
 1141|  4.44k|      }
 1142|       |
 1143|  9.77k|      uint32_t field = nswap32(lifetime);
  ------------------
  |  |   87|  9.77k|#define nswap32(ul) ntohl(ul)
  ------------------
 1144|  9.77k|      if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_LIFETIME, (uint8_t *)(&field), sizeof(field))) {
  ------------------
  |  |  114|  9.77k|#define STUN_ATTRIBUTE_LIFETIME (0x000D)
  ------------------
  |  Branch (1144:11): [True: 0, False: 9.77k]
  ------------------
 1145|      0|        return false;
 1146|      0|      }
 1147|  9.77k|    }
 1148|       |
 1149|  9.77k|    if (mobile_id && *mobile_id) {
  ------------------
  |  Branch (1149:9): [True: 6.51k, False: 3.25k]
  |  Branch (1149:22): [True: 4.50k, False: 2.00k]
  ------------------
 1150|  4.50k|      if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_MOBILITY_TICKET, (uint8_t *)mobile_id, (int)strlen(mobile_id))) {
  ------------------
  |  |   47|  4.50k|#define STUN_ATTRIBUTE_MOBILITY_TICKET (0x8030)
  ------------------
  |  Branch (1150:11): [True: 0, False: 4.50k]
  ------------------
 1151|      0|        return false;
 1152|      0|      }
 1153|  4.50k|    }
 1154|       |
 1155|  9.77k|  } else {
 1156|  6.51k|    stun_init_error_response_str(STUN_METHOD_ALLOCATE, buf, len, error_code, reason, tid, include_reason_string);
  ------------------
  |  |   78|  6.51k|#define STUN_METHOD_ALLOCATE (0x0003)
  ------------------
 1157|  6.51k|  }
 1158|       |
 1159|  16.2k|  return true;
 1160|  16.2k|}
stun_set_channel_bind_request_str:
 1165|  9.77k|                                           uint16_t channel_number) {
 1166|       |
 1167|  9.77k|  if (!STUN_VALID_CHANNEL(channel_number)) {
  ------------------
  |  |  144|  9.77k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (144:34): [True: 7.97k, False: 1.79k]
  |  |  |  Branch (144:53): [True: 6.97k, False: 1.00k]
  |  |  ------------------
  ------------------
 1168|  2.80k|    channel_number = 0x4000 + ((uint16_t)(((uint32_t)turn_random_number()) % (0x7FFF - 0x4000 + 1)));
 1169|  2.80k|  }
 1170|       |
 1171|  9.77k|  stun_init_request_str(STUN_METHOD_CHANNEL_BIND, buf, len);
  ------------------
  |  |   83|  9.77k|#define STUN_METHOD_CHANNEL_BIND (0x0009)
  ------------------
 1172|       |
 1173|  9.77k|  if (!stun_attr_add_channel_number_str(buf, len, channel_number)) {
  ------------------
  |  Branch (1173:7): [True: 0, False: 9.77k]
  ------------------
 1174|      0|    return 0;
 1175|      0|  }
 1176|       |
 1177|  9.77k|  if (!peer_addr) {
  ------------------
  |  Branch (1177:7): [True: 5.21k, False: 4.56k]
  ------------------
 1178|  5.21k|    ioa_addr ca;
 1179|  5.21k|    memset(&ca, 0, sizeof(ioa_addr));
 1180|       |
 1181|  5.21k|    if (!stun_attr_add_addr_str(buf, len, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &ca)) {
  ------------------
  |  |  116|  5.21k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  |  Branch (1181:9): [True: 0, False: 5.21k]
  ------------------
 1182|      0|      return 0;
 1183|      0|    }
 1184|  5.21k|  } else {
 1185|  4.56k|    if (!stun_attr_add_addr_str(buf, len, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, peer_addr)) {
  ------------------
  |  |  116|  4.56k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  |  Branch (1185:9): [True: 0, False: 4.56k]
  ------------------
 1186|      0|      return 0;
 1187|      0|    }
 1188|  4.56k|  }
 1189|       |
 1190|  9.77k|  return channel_number;
 1191|  9.77k|}
stun_set_channel_bind_response_str:
 1194|  9.77k|                                        bool include_reason_string) {
 1195|  9.77k|  if (!error_code) {
  ------------------
  |  Branch (1195:7): [True: 4.88k, False: 4.88k]
  ------------------
 1196|  4.88k|    stun_init_success_response_str(STUN_METHOD_CHANNEL_BIND, buf, len, tid);
  ------------------
  |  |   83|  4.88k|#define STUN_METHOD_CHANNEL_BIND (0x0009)
  ------------------
 1197|  4.88k|  } else {
 1198|  4.88k|    stun_init_error_response_str(STUN_METHOD_CHANNEL_BIND, buf, len, error_code, reason, tid, include_reason_string);
  ------------------
  |  |   83|  4.88k|#define STUN_METHOD_CHANNEL_BIND (0x0009)
  ------------------
 1199|  4.88k|  }
 1200|  9.77k|}
stun_set_binding_request_str:
 1204|  3.25k|void stun_set_binding_request_str(uint8_t *buf, size_t *len) { stun_init_request_str(STUN_METHOD_BINDING, buf, len); }
  ------------------
  |  |   77|  3.25k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
stun_set_binding_response_str:
 1210|  22.8k|{
 1211|  22.8k|  if (!error_code) {
  ------------------
  |  Branch (1211:7): [True: 11.4k, False: 11.4k]
  ------------------
 1212|  11.4k|    if (!old_stun) {
  ------------------
  |  Branch (1212:9): [True: 7.48k, False: 3.91k]
  ------------------
 1213|  7.48k|      stun_init_success_response_str(STUN_METHOD_BINDING, buf, len, tid);
  ------------------
  |  |   77|  7.48k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
 1214|  7.48k|    } else {
 1215|  3.91k|      old_stun_init_success_response_str(STUN_METHOD_BINDING, buf, len, tid, cookie);
  ------------------
  |  |   77|  3.91k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
 1216|  3.91k|    }
 1217|  11.4k|    if (!old_stun && reflexive_addr) {
  ------------------
  |  Branch (1217:9): [True: 7.48k, False: 3.91k]
  |  Branch (1217:22): [True: 7.48k, False: 0]
  ------------------
 1218|  7.48k|      if (!stun_attr_add_addr_str(buf, len, STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS, reflexive_addr)) {
  ------------------
  |  |  105|  7.48k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (1218:11): [True: 0, False: 7.48k]
  ------------------
 1219|      0|        return false;
 1220|      0|      }
 1221|  7.48k|    }
 1222|  11.4k|    if (reflexive_addr) {
  ------------------
  |  Branch (1222:9): [True: 11.4k, False: 0]
  ------------------
 1223|  11.4k|      if (stun_backward_compatibility &&
  ------------------
  |  Branch (1223:11): [True: 7.15k, False: 4.24k]
  ------------------
 1224|  7.15k|          !stun_attr_add_addr_str(buf, len, STUN_ATTRIBUTE_MAPPED_ADDRESS, reflexive_addr)) {
  ------------------
  |  |   91|  7.15k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
  |  Branch (1224:11): [True: 0, False: 7.15k]
  ------------------
 1225|      0|        return false;
 1226|      0|      }
 1227|  11.4k|    }
 1228|  11.4k|  } else if (!old_stun) {
  ------------------
  |  Branch (1228:14): [True: 7.48k, False: 3.91k]
  ------------------
 1229|  7.48k|    stun_init_error_response_str(STUN_METHOD_BINDING, buf, len, error_code, reason, tid, include_reason_string);
  ------------------
  |  |   77|  7.48k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
 1230|  7.48k|  } else {
 1231|  3.91k|    old_stun_init_error_response_str(STUN_METHOD_BINDING, buf, len, error_code, reason, tid, cookie,
  ------------------
  |  |   77|  3.91k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
 1232|  3.91k|                                     include_reason_string);
 1233|  3.91k|  }
 1234|       |
 1235|  22.8k|  return true;
 1236|  22.8k|}
stun_is_binding_response_str:
 1251|  74.9k|bool stun_is_binding_response_str(const uint8_t *buf, size_t len) {
 1252|  74.9k|  if (stun_is_command_message_str(buf, len) && (stun_get_method_str(buf, len) == STUN_METHOD_BINDING)) {
  ------------------
  |  |   77|  67.3k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
  |  Branch (1252:7): [True: 67.3k, False: 7.65k]
  |  Branch (1252:48): [True: 20.9k, False: 46.3k]
  ------------------
 1253|  20.9k|    if (stun_is_response_str(buf, len)) {
  ------------------
  |  Branch (1253:9): [True: 17.2k, False: 3.68k]
  ------------------
 1254|  17.2k|      return true;
 1255|  17.2k|    }
 1256|  20.9k|  }
 1257|  57.7k|  return false;
 1258|  74.9k|}
stun_tid_from_message_str:
 1296|   140k|void stun_tid_from_message_str(const uint8_t *buf, size_t len, stun_tid *id) {
 1297|   140k|  UNUSED_ARG(len);
  ------------------
  |  |  174|   140k|  do {                                                                                                                 \
  |  |  175|   140k|    A = A;                                                                                                             \
  |  |  176|   140k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (176:12): [Folded, False: 140k]
  |  |  ------------------
  ------------------
 1298|   140k|  stun_tid_from_string(buf + 8, id);
 1299|   140k|}
stun_tid_message_cpy:
 1301|   131k|void stun_tid_message_cpy(uint8_t *buf, const stun_tid *id) {
 1302|   131k|  if (buf && id) {
  ------------------
  |  Branch (1302:7): [True: 131k, False: 0]
  |  Branch (1302:14): [True: 131k, False: 0]
  ------------------
 1303|   131k|    stun_tid_string_cpy(buf + 8, id);
 1304|   131k|  }
 1305|   131k|}
stun_tid_generate:
 1307|  76.5k|void stun_tid_generate(stun_tid *id) {
 1308|  76.5k|  if (id) {
  ------------------
  |  Branch (1308:7): [True: 76.5k, False: 0]
  ------------------
 1309|  76.5k|    turn_random_tid_size(id->tsx_id);
 1310|  76.5k|  }
 1311|  76.5k|}
stun_tid_generate_in_message_str:
 1313|  76.5k|void stun_tid_generate_in_message_str(uint8_t *buf, stun_tid *id) {
 1314|  76.5k|  stun_tid tmp;
 1315|  76.5k|  if (!id) {
  ------------------
  |  Branch (1315:7): [True: 74.9k, False: 1.62k]
  ------------------
 1316|  74.9k|    id = &tmp;
 1317|  74.9k|  }
 1318|  76.5k|  stun_tid_generate(id);
 1319|  76.5k|  stun_tid_message_cpy(buf, id);
 1320|  76.5k|}
stun_attr_get_type:
 1344|   886k|int stun_attr_get_type(stun_attr_ref attr) {
 1345|   886k|  if (attr) {
  ------------------
  |  Branch (1345:7): [True: 886k, False: 0]
  ------------------
 1346|   886k|    uint16_t val;
 1347|   886k|    memcpy(&val, attr, sizeof(val));
 1348|   886k|    return (int)(nswap16(val));
  ------------------
  |  |   86|   886k|#define nswap16(s) ntohs(s)
  ------------------
 1349|   886k|  }
 1350|      0|  return -1;
 1351|   886k|}
stun_attr_get_len:
 1353|  1.31M|int stun_attr_get_len(stun_attr_ref attr) {
 1354|  1.31M|  if (attr) {
  ------------------
  |  Branch (1354:7): [True: 1.31M, False: 0]
  ------------------
 1355|  1.31M|    uint16_t val;
 1356|  1.31M|    memcpy(&val, (const uint8_t *)attr + 2, sizeof(val));
 1357|  1.31M|    return (int)(nswap16(val));
  ------------------
  |  |   86|  1.31M|#define nswap16(s) ntohs(s)
  ------------------
 1358|  1.31M|  }
 1359|      0|  return -1;
 1360|  1.31M|}
stun_attr_get_value:
 1362|   128k|const uint8_t *stun_attr_get_value(stun_attr_ref attr) {
 1363|   128k|  if (attr) {
  ------------------
  |  Branch (1363:7): [True: 128k, False: 0]
  ------------------
 1364|   128k|    uint16_t val;
 1365|   128k|    memcpy(&val, (const uint8_t *)attr + 2, sizeof(val));
 1366|   128k|    const int len = (int)(nswap16(val));
  ------------------
  |  |   86|   128k|#define nswap16(s) ntohs(s)
  ------------------
 1367|   128k|    if (len < 1) {
  ------------------
  |  Branch (1367:9): [True: 5.38k, False: 123k]
  ------------------
 1368|  5.38k|      return NULL;
 1369|  5.38k|    }
 1370|   123k|    return ((const uint8_t *)attr) + 4;
 1371|   128k|  }
 1372|      0|  return NULL;
 1373|   128k|}
stun_attr_get_channel_number:
 1395|  11.4k|uint16_t stun_attr_get_channel_number(stun_attr_ref attr) {
 1396|  11.4k|  if (attr) {
  ------------------
  |  Branch (1396:7): [True: 11.4k, False: 0]
  ------------------
 1397|  11.4k|    const uint8_t *value = stun_attr_get_value(attr);
 1398|  11.4k|    if (value && (stun_attr_get_len(attr) >= 2)) {
  ------------------
  |  Branch (1398:9): [True: 11.4k, False: 0]
  |  Branch (1398:18): [True: 11.4k, False: 0]
  ------------------
 1399|  11.4k|      const uint16_t cn = nswap16(((const uint16_t *)value)[0]);
  ------------------
  |  |   86|  11.4k|#define nswap16(s) ntohs(s)
  ------------------
 1400|  11.4k|      if (STUN_VALID_CHANNEL(cn)) {
  ------------------
  |  |  144|  11.4k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (144:34): [True: 11.4k, False: 0]
  |  |  |  Branch (144:53): [True: 11.4k, False: 0]
  |  |  ------------------
  ------------------
 1401|  11.4k|        return cn;
 1402|  11.4k|      }
 1403|  11.4k|    }
 1404|  11.4k|  }
 1405|      0|  return 0;
 1406|  11.4k|}
stun_attr_is_addr:
 1431|   374k|bool stun_attr_is_addr(stun_attr_ref attr) {
 1432|       |
 1433|   374k|  if (attr) {
  ------------------
  |  Branch (1433:7): [True: 374k, False: 0]
  ------------------
 1434|   374k|    switch (stun_attr_get_type(attr)) {
 1435|  33.0k|    case STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS:
  ------------------
  |  |  105|  33.0k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (1435:5): [True: 33.0k, False: 341k]
  ------------------
 1436|  82.1k|    case STUN_ATTRIBUTE_XOR_PEER_ADDRESS:
  ------------------
  |  |  116|  82.1k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  |  Branch (1436:5): [True: 49.0k, False: 325k]
  ------------------
 1437|   130k|    case STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS:
  ------------------
  |  |  118|   130k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  |  Branch (1437:5): [True: 47.9k, False: 326k]
  ------------------
 1438|   157k|    case STUN_ATTRIBUTE_MAPPED_ADDRESS:
  ------------------
  |  |   91|   157k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
  |  Branch (1438:5): [True: 27.5k, False: 346k]
  ------------------
 1439|   163k|    case STUN_ATTRIBUTE_ALTERNATE_SERVER:
  ------------------
  |  |  110|   163k|#define STUN_ATTRIBUTE_ALTERNATE_SERVER (0x8023)
  ------------------
  |  Branch (1439:5): [True: 6.00k, False: 368k]
  ------------------
 1440|   164k|    case OLD_STUN_ATTRIBUTE_RESPONSE_ADDRESS:
  ------------------
  |  |   92|   164k|#define OLD_STUN_ATTRIBUTE_RESPONSE_ADDRESS (0x0002)
  ------------------
  |  Branch (1440:5): [True: 776, False: 373k]
  ------------------
 1441|   165k|    case OLD_STUN_ATTRIBUTE_SOURCE_ADDRESS:
  ------------------
  |  |   94|   165k|#define OLD_STUN_ATTRIBUTE_SOURCE_ADDRESS (0x0004)
  ------------------
  |  Branch (1441:5): [True: 912, False: 373k]
  ------------------
 1442|   167k|    case OLD_STUN_ATTRIBUTE_CHANGED_ADDRESS:
  ------------------
  |  |   95|   167k|#define OLD_STUN_ATTRIBUTE_CHANGED_ADDRESS (0x0005)
  ------------------
  |  Branch (1442:5): [True: 2.39k, False: 371k]
  ------------------
 1443|   168k|    case OLD_STUN_ATTRIBUTE_REFLECTED_FROM:
  ------------------
  |  |  101|   168k|#define OLD_STUN_ATTRIBUTE_REFLECTED_FROM (0x000B)
  ------------------
  |  Branch (1443:5): [True: 954, False: 373k]
  ------------------
 1444|   169k|    case STUN_ATTRIBUTE_RESPONSE_ORIGIN:
  ------------------
  |  |  132|   169k|#define STUN_ATTRIBUTE_RESPONSE_ORIGIN (0x802B)
  ------------------
  |  Branch (1444:5): [True: 1.06k, False: 373k]
  ------------------
 1445|   170k|    case STUN_ATTRIBUTE_OTHER_ADDRESS:
  ------------------
  |  |  133|   170k|#define STUN_ATTRIBUTE_OTHER_ADDRESS (0x802C)
  ------------------
  |  Branch (1445:5): [True: 774, False: 373k]
  ------------------
 1446|   170k|      return true;
 1447|      0|      break;
 1448|   203k|    default:;
  ------------------
  |  Branch (1448:5): [True: 203k, False: 170k]
  ------------------
 1449|   374k|    };
 1450|   203k|  }
 1451|   203k|  return false;
 1452|   374k|}
stun_attr_get_first_by_type_str:
 1466|  39.2k|stun_attr_ref stun_attr_get_first_by_type_str(const uint8_t *buf, size_t len, uint16_t attr_type) {
 1467|  39.2k|  stun_attr_ref attr = stun_attr_get_first_str(buf, len);
 1468|  68.5k|  while (attr) {
  ------------------
  |  Branch (1468:10): [True: 63.7k, False: 4.85k]
  ------------------
 1469|  63.7k|    if (stun_attr_get_type(attr) == attr_type) {
  ------------------
  |  Branch (1469:9): [True: 34.3k, False: 29.3k]
  ------------------
 1470|  34.3k|      return attr;
 1471|  34.3k|    }
 1472|  29.3k|    attr = stun_attr_get_next_str(buf, len, attr);
 1473|  29.3k|  }
 1474|       |
 1475|  4.85k|  return NULL;
 1476|  39.2k|}
stun_attr_get_first_str:
 1499|   280k|stun_attr_ref stun_attr_get_first_str(const uint8_t *buf, size_t len) {
 1500|   280k|  const int bufLen = stun_get_command_message_len_str(buf, len);
 1501|   280k|  if (bufLen > STUN_HEADER_LENGTH) {
  ------------------
  |  |   46|   280k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (1501:7): [True: 228k, False: 52.2k]
  ------------------
 1502|   228k|    stun_attr_ref attr = (stun_attr_ref)(buf + STUN_HEADER_LENGTH);
  ------------------
  |  |   46|   228k|#define STUN_HEADER_LENGTH (20)
  ------------------
 1503|   228k|    return stun_attr_check_valid(attr, bufLen - STUN_HEADER_LENGTH);
  ------------------
  |  |   46|   228k|#define STUN_HEADER_LENGTH (20)
  ------------------
 1504|   228k|  }
 1505|       |
 1506|  52.2k|  return NULL;
 1507|   280k|}
stun_attr_get_next_str:
 1509|   472k|stun_attr_ref stun_attr_get_next_str(const uint8_t *buf, size_t len, stun_attr_ref prev) {
 1510|   472k|  if (!prev) {
  ------------------
  |  Branch (1510:7): [True: 0, False: 472k]
  ------------------
 1511|      0|    return stun_attr_get_first_str(buf, len);
 1512|   472k|  } else {
 1513|   472k|    const uint8_t *end = buf + stun_get_command_message_len_str(buf, len);
 1514|   472k|    int attrlen = stun_attr_get_len(prev);
 1515|   472k|    const uint16_t rem4 = ((uint16_t)attrlen) & 0x0003;
 1516|   472k|    if (rem4) {
  ------------------
  |  Branch (1516:9): [True: 55.7k, False: 416k]
  ------------------
 1517|  55.7k|      attrlen = attrlen + 4 - (int)rem4;
 1518|  55.7k|    }
 1519|       |    /* Note the order here: operations on attrlen are untrusted as they may overflow */
 1520|   472k|    if (attrlen < end - (const uint8_t *)prev - 4) {
  ------------------
  |  Branch (1520:9): [True: 325k, False: 146k]
  ------------------
 1521|   325k|      const uint8_t *attr_end = (const uint8_t *)prev + 4 + attrlen;
 1522|   325k|      return stun_attr_check_valid(attr_end, end - attr_end);
 1523|   325k|    }
 1524|   146k|    return NULL;
 1525|   472k|  }
 1526|   472k|}
stun_attr_add_str:
 1528|   125k|bool stun_attr_add_str(uint8_t *buf, size_t *len, uint16_t attr, const uint8_t *avalue, int alen) {
 1529|   125k|  if (alen < 0) {
  ------------------
  |  Branch (1529:7): [True: 0, False: 125k]
  ------------------
 1530|      0|    alen = 0;
 1531|      0|  }
 1532|   125k|  uint8_t tmp[1];
 1533|   125k|  if (!avalue) {
  ------------------
  |  Branch (1533:7): [True: 0, False: 125k]
  ------------------
 1534|      0|    alen = 0;
 1535|      0|    avalue = tmp;
 1536|      0|  }
 1537|   125k|  const int clen = stun_get_command_message_len_str(buf, *len);
 1538|   125k|  int newlen = clen + 4 + alen;
 1539|   125k|  const int newlenrem4 = newlen & 0x00000003;
 1540|   125k|  int paddinglen = 0;
 1541|   125k|  if (newlenrem4) {
  ------------------
  |  Branch (1541:7): [True: 9.98k, False: 115k]
  ------------------
 1542|  9.98k|    paddinglen = 4 - newlenrem4;
 1543|  9.98k|    newlen = newlen + paddinglen;
 1544|  9.98k|  }
 1545|       |
 1546|   125k|  if (newlen >= MAX_STUN_MESSAGE_SIZE) {
  ------------------
  |  |  179|   125k|#define MAX_STUN_MESSAGE_SIZE (65507)
  ------------------
  |  Branch (1546:7): [True: 0, False: 125k]
  ------------------
 1547|      0|    return false;
 1548|      0|  }
 1549|       |
 1550|   125k|  uint8_t *attr_start = buf + clen;
 1551|       |
 1552|   125k|  uint16_t *attr_start_16t = (uint16_t *)attr_start;
 1553|       |
 1554|   125k|  stun_set_command_message_len_str(buf, newlen);
 1555|   125k|  *len = newlen;
 1556|       |
 1557|   125k|  attr_start_16t[0] = nswap16(attr);
  ------------------
  |  |   86|   125k|#define nswap16(s) ntohs(s)
  ------------------
 1558|   125k|  attr_start_16t[1] = nswap16(alen);
  ------------------
  |  |   86|   125k|#define nswap16(s) ntohs(s)
  ------------------
 1559|   125k|  if (alen > 0) {
  ------------------
  |  Branch (1559:7): [True: 123k, False: 2.07k]
  ------------------
 1560|   123k|    memcpy(attr_start + 4, avalue, alen);
 1561|   123k|  }
 1562|       |
 1563|       |  // Write 0 padding to not leak data
 1564|   125k|  memset(attr_start + 4 + alen, 0, paddinglen);
 1565|       |
 1566|       |  return true;
 1567|   125k|}
stun_attr_add_addr_str:
 1569|  47.8k|bool stun_attr_add_addr_str(uint8_t *buf, size_t *len, uint16_t attr_type, const ioa_addr *ca) {
 1570|       |
 1571|  47.8k|  stun_tid tid;
 1572|  47.8k|  stun_tid_from_message_str(buf, *len, &tid);
 1573|       |
 1574|  47.8k|  int xor_ed = 0;
 1575|  47.8k|  switch (attr_type) {
 1576|  14.0k|  case STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS:
  ------------------
  |  |  105|  14.0k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (1576:3): [True: 14.0k, False: 33.8k]
  ------------------
 1577|  25.4k|  case STUN_ATTRIBUTE_XOR_PEER_ADDRESS:
  ------------------
  |  |  116|  25.4k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  |  Branch (1577:3): [True: 11.4k, False: 36.4k]
  ------------------
 1578|  40.6k|  case STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS:
  ------------------
  |  |  118|  40.6k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  |  Branch (1578:3): [True: 15.2k, False: 32.5k]
  ------------------
 1579|  40.6k|    xor_ed = 1;
 1580|  40.6k|    break;
 1581|  7.15k|  default:;
  ------------------
  |  Branch (1581:3): [True: 7.15k, False: 40.6k]
  ------------------
 1582|  47.8k|  };
 1583|       |
 1584|  47.8k|  ioa_addr public_addr;
 1585|  47.8k|  map_addr_from_private_to_public(ca, &public_addr);
 1586|       |
 1587|  47.8k|  uint8_t cfield[64];
 1588|  47.8k|  int clen = 0;
 1589|  47.8k|  if (stun_addr_encode(&public_addr, cfield, &clen, xor_ed, STUN_MAGIC_COOKIE, tid.tsx_id) < 0) {
  ------------------
  |  |   56|  47.8k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (1589:7): [True: 0, False: 47.8k]
  ------------------
 1590|      0|    return false;
 1591|      0|  }
 1592|       |
 1593|  47.8k|  if (!stun_attr_add_str(buf, len, attr_type, (uint8_t *)(&cfield), clen)) {
  ------------------
  |  Branch (1593:7): [True: 0, False: 47.8k]
  ------------------
 1594|      0|    return false;
 1595|      0|  }
 1596|       |
 1597|  47.8k|  return true;
 1598|  47.8k|}
stun_attr_get_addr_str:
 1601|  89.2k|                            const ioa_addr *default_addr) {
 1602|  89.2k|  stun_tid tid;
 1603|  89.2k|  stun_tid_from_message_str(buf, len, &tid);
 1604|  89.2k|  ioa_addr public_addr;
 1605|       |
 1606|  89.2k|  addr_set_any(ca);
 1607|  89.2k|  addr_set_any(&public_addr);
 1608|       |
 1609|  89.2k|  const int attr_type = stun_attr_get_type(attr);
 1610|  89.2k|  if (attr_type < 0) {
  ------------------
  |  Branch (1610:7): [True: 0, False: 89.2k]
  ------------------
 1611|      0|    return false;
 1612|      0|  }
 1613|       |
 1614|  89.2k|  int xor_ed = 0;
 1615|  89.2k|  switch (attr_type) {
 1616|  22.9k|  case STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS:
  ------------------
  |  |  105|  22.9k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (1616:3): [True: 22.9k, False: 66.3k]
  ------------------
 1617|  49.0k|  case STUN_ATTRIBUTE_XOR_PEER_ADDRESS:
  ------------------
  |  |  116|  49.0k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  |  Branch (1617:3): [True: 26.1k, False: 63.1k]
  ------------------
 1618|  77.0k|  case STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS:
  ------------------
  |  |  118|  77.0k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  |  Branch (1618:3): [True: 27.9k, False: 61.3k]
  ------------------
 1619|  77.0k|    xor_ed = 1;
 1620|  77.0k|    break;
 1621|  12.2k|  default:;
  ------------------
  |  Branch (1621:3): [True: 12.2k, False: 77.0k]
  ------------------
 1622|  89.2k|  };
 1623|       |
 1624|  89.2k|  const uint8_t *cfield = stun_attr_get_value(attr);
 1625|  89.2k|  if (!cfield) {
  ------------------
  |  Branch (1625:7): [True: 5.38k, False: 83.9k]
  ------------------
 1626|  5.38k|    return false;
 1627|  5.38k|  }
 1628|       |
 1629|  83.9k|  if (stun_addr_decode(&public_addr, cfield, stun_attr_get_len(attr), xor_ed, STUN_MAGIC_COOKIE, tid.tsx_id) < 0) {
  ------------------
  |  |   56|  83.9k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (1629:7): [True: 4.94k, False: 78.9k]
  ------------------
 1630|  4.94k|    return false;
 1631|  4.94k|  }
 1632|       |
 1633|  78.9k|  map_addr_from_public_to_private(&public_addr, ca);
 1634|       |
 1635|  78.9k|  if (default_addr && addr_any_no_port(ca) && !addr_any_no_port(default_addr)) {
  ------------------
  |  Branch (1635:7): [True: 78.7k, False: 250]
  |  Branch (1635:23): [True: 10.4k, False: 68.2k]
  |  Branch (1635:47): [True: 10.4k, False: 0]
  ------------------
 1636|  10.4k|    const uint16_t port = addr_get_port(ca);
 1637|  10.4k|    addr_cpy(ca, default_addr);
 1638|  10.4k|    addr_set_port(ca, port);
 1639|  10.4k|  }
 1640|       |
 1641|       |  return true;
 1642|  83.9k|}
stun_attr_get_first_addr_str:
 1645|  91.5k|                                  const ioa_addr *default_addr) {
 1646|  91.5k|  stun_attr_ref attr = stun_attr_get_first_str(buf, len);
 1647|       |
 1648|   309k|  while (attr) {
  ------------------
  |  Branch (1648:10): [True: 248k, False: 60.4k]
  ------------------
 1649|   248k|    if (stun_attr_is_addr(attr) && (attr_type == stun_attr_get_type(attr))) {
  ------------------
  |  Branch (1649:9): [True: 122k, False: 126k]
  |  Branch (1649:36): [True: 41.4k, False: 81.1k]
  ------------------
 1650|  41.4k|      if (stun_attr_get_addr_str(buf, len, attr, ca, default_addr)) {
  ------------------
  |  Branch (1650:11): [True: 31.1k, False: 10.3k]
  ------------------
 1651|  31.1k|        return true;
 1652|  31.1k|      }
 1653|  41.4k|    }
 1654|   217k|    attr = stun_attr_get_next_str(buf, len, attr);
 1655|   217k|  }
 1656|       |
 1657|  60.4k|  return false;
 1658|  91.5k|}
stun_attr_add_channel_number_str:
 1660|  11.4k|bool stun_attr_add_channel_number_str(uint8_t *buf, size_t *len, uint16_t chnumber) {
 1661|       |
 1662|  11.4k|  uint16_t field[2];
 1663|  11.4k|  field[0] = nswap16(chnumber);
  ------------------
  |  |   86|  11.4k|#define nswap16(s) ntohs(s)
  ------------------
 1664|  11.4k|  field[1] = 0;
 1665|       |
 1666|  11.4k|  return stun_attr_add_str(buf, len, STUN_ATTRIBUTE_CHANNEL_NUMBER, (uint8_t *)(field), sizeof(field));
  ------------------
  |  |  113|  11.4k|#define STUN_ATTRIBUTE_CHANNEL_NUMBER (0x000C)
  ------------------
 1667|  11.4k|}
stun_attr_get_first_channel_number_str:
 1701|  74.9k|uint16_t stun_attr_get_first_channel_number_str(const uint8_t *buf, size_t len) {
 1702|       |
 1703|  74.9k|  stun_attr_ref attr = stun_attr_get_first_str(buf, len);
 1704|   174k|  while (attr) {
  ------------------
  |  Branch (1704:10): [True: 110k, False: 63.5k]
  ------------------
 1705|   110k|    if (stun_attr_get_type(attr) == STUN_ATTRIBUTE_CHANNEL_NUMBER) {
  ------------------
  |  |  113|   110k|#define STUN_ATTRIBUTE_CHANNEL_NUMBER (0x000C)
  ------------------
  |  Branch (1705:9): [True: 11.4k, False: 99.4k]
  ------------------
 1706|  11.4k|      const uint16_t ret = stun_attr_get_channel_number(attr);
 1707|  11.4k|      if (STUN_VALID_CHANNEL(ret)) {
  ------------------
  |  |  144|  11.4k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (144:34): [True: 11.4k, False: 0]
  |  |  |  Branch (144:53): [True: 11.4k, False: 0]
  |  |  ------------------
  ------------------
 1708|  11.4k|        return ret;
 1709|  11.4k|      }
 1710|  11.4k|    }
 1711|  99.4k|    attr = stun_attr_get_next_str(buf, len, attr);
 1712|  99.4k|  }
 1713|       |
 1714|  63.5k|  return 0;
 1715|  74.9k|}
ns_turn_msg.c:fuzz_prng_next:
  112|   232k|static uint64_t fuzz_prng_next(void) {
  113|   232k|  static uint64_t state = UINT64_C(0x9e3779b97f4a7c15);
  114|       |
  115|   232k|  state += UINT64_C(0x9e3779b97f4a7c15);
  116|   232k|  uint64_t z = state;
  117|   232k|  z = (z ^ (z >> 30)) * UINT64_C(0xbf58476d1ce4e5b9);
  118|       |  z = (z ^ (z >> 27)) * UINT64_C(0x94d049bb133111eb);
  119|   232k|  return z ^ (z >> 31);
  120|   232k|}
ns_turn_msg.c:stun_init_error_response_common_str:
  752|  27.6k|                                                stun_tid *id, bool include_reason_string) {
  753|       |
  754|  27.6k|  if (include_reason_string && (!reason || !strcmp((const char *)reason, "Unknown error"))) {
  ------------------
  |  Branch (754:7): [True: 18.8k, False: 8.89k]
  |  Branch (754:33): [True: 1.00k, False: 17.7k]
  |  Branch (754:44): [True: 0, False: 17.7k]
  ------------------
  755|  1.00k|    reason = get_default_reason(error_code);
  756|  1.00k|  }
  757|       |
  758|  27.6k|  uint8_t avalue[513];
  759|  27.6k|  memset(avalue, 0, sizeof(avalue));
  760|  27.6k|  avalue[0] = 0;
  761|  27.6k|  avalue[1] = 0;
  762|  27.6k|  avalue[2] = (uint8_t)(error_code / 100);
  763|  27.6k|  avalue[3] = (uint8_t)(error_code % 100);
  764|  27.6k|  if (include_reason_string) {
  ------------------
  |  Branch (764:7): [True: 18.8k, False: 8.89k]
  ------------------
  765|  18.8k|    strncpy((char *)(avalue + 4), (const char *)reason, sizeof(avalue) - 4);
  766|  18.8k|  }
  767|  27.6k|  avalue[sizeof(avalue) - 1] = 0;
  768|  27.6k|  int alen = 4 + (int)strlen((const char *)(avalue + 4));
  769|       |
  770|       |  //"Manual" padding for compatibility with classic old stun:
  771|  27.6k|  {
  772|  27.6k|    const int rem = alen % 4;
  773|  27.6k|    if (rem) {
  ------------------
  |  Branch (773:9): [True: 10.8k, False: 16.8k]
  ------------------
  774|  10.8k|      alen += (4 - rem);
  775|  10.8k|    }
  776|  27.6k|  }
  777|       |
  778|  27.6k|  stun_attr_add_str(buf, len, STUN_ATTRIBUTE_ERROR_CODE, (uint8_t *)avalue, alen);
  ------------------
  |  |   99|  27.6k|#define STUN_ATTRIBUTE_ERROR_CODE (0x0009)
  ------------------
  779|  27.6k|  if (id) {
  ------------------
  |  Branch (779:7): [True: 27.6k, False: 0]
  ------------------
  780|  27.6k|    stun_tid_message_cpy(buf, id);
  781|  27.6k|  }
  782|  27.6k|}
ns_turn_msg.c:has_prefix:
  917|  6.80k|static inline bool has_prefix(const char *buf, size_t blen, const char *prefix, bool ignore_case) {
  918|  6.80k|  if (!buf || !prefix) {
  ------------------
  |  Branch (918:7): [True: 0, False: 6.80k]
  |  Branch (918:15): [True: 0, False: 6.80k]
  ------------------
  919|      0|    return false;
  920|      0|  }
  921|       |
  922|  6.80k|  const size_t prefix_len = strlen(prefix);
  923|  6.80k|  return (prefix_len <= blen) && sheadof(prefix, buf, ignore_case);
  ------------------
  |  Branch (923:10): [True: 6.80k, False: 0]
  |  Branch (923:34): [True: 730, False: 6.07k]
  ------------------
  924|  6.80k|}
ns_turn_msg.c:sheadof:
  882|   745k|static inline bool sheadof(const char *head, const char *full, bool ignore_case) {
  883|   804k|  while (*head) {
  ------------------
  |  Branch (883:10): [True: 802k, False: 2.41k]
  ------------------
  884|   802k|    if (*head != *full) {
  ------------------
  |  Branch (884:9): [True: 756k, False: 46.3k]
  ------------------
  885|   756k|      if (ignore_case && (tolower((unsigned char)*head) == tolower((unsigned char)*full))) {
  ------------------
  |  Branch (885:11): [True: 291k, False: 464k]
  |  Branch (885:26): [True: 13.0k, False: 278k]
  |  Branch (885:27): [True: 0, False: 0]
  |  Branch (885:27): [True: 0, False: 0]
  |  Branch (885:27): [Folded, False: 291k]
  |  Branch (885:60): [True: 0, False: 0]
  |  Branch (885:60): [True: 0, False: 0]
  |  Branch (885:60): [Folded, False: 291k]
  ------------------
  886|       |        // OK
  887|   743k|      } else {
  888|   743k|        return false;
  889|   743k|      }
  890|   756k|    }
  891|  59.3k|    ++head;
  892|  59.3k|    ++full;
  893|  59.3k|  }
  894|  2.41k|  return true;
  895|   745k|}
ns_turn_msg.c:findstr:
  897|  1.98k|static inline const char *findstr(const char *hay, size_t slen, const char *needle, bool ignore_case) {
  898|  1.98k|  const char *ret = NULL;
  899|       |
  900|  1.98k|  if (hay && slen && needle) {
  ------------------
  |  Branch (900:7): [True: 1.98k, False: 0]
  |  Branch (900:14): [True: 1.98k, False: 0]
  |  Branch (900:22): [True: 1.98k, False: 0]
  ------------------
  901|  1.98k|    const size_t nlen = strlen(needle);
  902|  1.98k|    if (nlen <= slen) {
  ------------------
  |  Branch (902:9): [True: 1.93k, False: 46]
  ------------------
  903|  1.93k|      const size_t smax = slen - nlen + 1;
  904|  1.93k|      const char *sp = hay;
  905|   738k|      for (size_t i = 0; i < smax; ++i) {
  ------------------
  |  Branch (905:26): [True: 738k, False: 254]
  ------------------
  906|   738k|        if (sheadof(needle, sp + i, ignore_case)) {
  ------------------
  |  Branch (906:13): [True: 1.68k, False: 736k]
  ------------------
  907|  1.68k|          ret = sp + i;
  908|  1.68k|          break;
  909|  1.68k|        }
  910|   738k|      }
  911|  1.93k|    }
  912|  1.98k|  }
  913|       |
  914|  1.98k|  return ret;
  915|  1.98k|}
ns_turn_msg.c:stun_tid_from_string:
 1290|   140k|static void stun_tid_from_string(const uint8_t *s, stun_tid *id) {
 1291|   140k|  if (s && id) {
  ------------------
  |  Branch (1291:7): [True: 140k, False: 0]
  |  Branch (1291:12): [True: 140k, False: 0]
  ------------------
 1292|   140k|    memcpy(id->tsx_id, s, STUN_TID_SIZE);
  ------------------
  |  |   53|   140k|#define STUN_TID_SIZE (12)
  ------------------
 1293|   140k|  }
 1294|   140k|}
ns_turn_msg.c:stun_tid_string_cpy:
 1284|   131k|static void stun_tid_string_cpy(uint8_t *s, const stun_tid *id) {
 1285|   131k|  if (s && id) {
  ------------------
  |  Branch (1285:7): [True: 131k, False: 0]
  |  Branch (1285:12): [True: 131k, False: 0]
  ------------------
 1286|   131k|    memcpy(s, id->tsx_id, STUN_TID_SIZE);
  ------------------
  |  |   53|   131k|#define STUN_TID_SIZE (12)
  ------------------
 1287|   131k|  }
 1288|   131k|}
ns_turn_msg.c:turn_random_tid_size:
  154|  76.5k|static void turn_random_tid_size(void *id) {
  155|  76.5k|  uint32_t *ar = (uint32_t *)id;
  156|  76.5k|#if defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
  157|  76.5k|  if (ar) {
  ------------------
  |  Branch (157:7): [True: 76.5k, False: 0]
  ------------------
  158|   306k|    for (size_t i = 0; i < 3; ++i) {
  ------------------
  |  Branch (158:24): [True: 229k, False: 76.5k]
  ------------------
  159|   229k|      ar[i] = (uint32_t)turn_random_number();
  160|   229k|    }
  161|  76.5k|  }
  162|       |#else
  163|       |  if (!RAND_bytes((unsigned char *)ar, 12)) {
  164|       |    for (size_t i = 0; i < 3; ++i) {
  165|       |      ar[i] = (uint32_t)turn_random_number();
  166|       |    }
  167|       |  }
  168|       |#endif
  169|  76.5k|}
ns_turn_msg.c:stun_attr_check_valid:
 1478|   553k|static stun_attr_ref stun_attr_check_valid(stun_attr_ref attr, size_t remaining) {
 1479|   553k|  if (remaining >= 4) {
  ------------------
  |  Branch (1479:7): [True: 552k, False: 947]
  ------------------
 1480|       |    /* Read the size of the attribute */
 1481|   552k|    size_t attrlen = stun_attr_get_len(attr);
 1482|   552k|    remaining -= 4;
 1483|       |
 1484|       |    /* Round to boundary */
 1485|   552k|    const uint16_t rem4 = ((uint16_t)attrlen) & 0x0003;
 1486|   552k|    if (rem4) {
  ------------------
  |  Branch (1486:9): [True: 60.6k, False: 492k]
  ------------------
 1487|  60.6k|      attrlen = attrlen + 4 - (int)rem4;
 1488|  60.6k|    }
 1489|       |
 1490|       |    /* Check that there's enough space remaining */
 1491|   552k|    if (attrlen <= remaining) {
  ------------------
  |  Branch (1491:9): [True: 548k, False: 3.91k]
  ------------------
 1492|   548k|      return attr;
 1493|   548k|    }
 1494|   552k|  }
 1495|       |
 1496|  4.85k|  return NULL;
 1497|   553k|}
ns_turn_msg.c:stun_set_command_message_len_str:
  408|   125k|static bool stun_set_command_message_len_str(uint8_t *buf, int len) {
  409|   125k|  if (len < STUN_HEADER_LENGTH) {
  ------------------
  |  |   46|   125k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (409:7): [True: 0, False: 125k]
  ------------------
  410|      0|    return false;
  411|      0|  }
  412|   125k|  ((uint16_t *)buf)[1] = nswap16((uint16_t)(len - STUN_HEADER_LENGTH));
  ------------------
  |  |   86|   125k|#define nswap16(s) ntohs(s)
  ------------------
  413|       |  return true;
  414|   125k|}

stun_addr_encode:
   42|  47.8k|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|  47.8k|  if (!cfield || !clen || !ca || !tsx_id) {
  ------------------
  |  Branch (44:7): [True: 0, False: 47.8k]
  |  Branch (44:18): [True: 0, False: 47.8k]
  |  Branch (44:27): [True: 0, False: 47.8k]
  |  Branch (44:34): [True: 0, False: 47.8k]
  ------------------
   45|      0|    return -1;
   46|      0|  }
   47|       |
   48|  47.8k|  if (ca->ss.sa_family == AF_INET || ca->ss.sa_family == 0) {
  ------------------
  |  Branch (48:7): [True: 25.4k, False: 22.3k]
  |  Branch (48:38): [True: 5.21k, False: 17.1k]
  ------------------
   49|       |
   50|       |    /* IPv4 address */
   51|       |
   52|  30.6k|    *clen = 8;
   53|       |
   54|  30.6k|    cfield[0] = 0;
   55|  30.6k|    cfield[1] = 1; // IPv4 family
   56|       |
   57|  30.6k|    if (xor_ed) {
  ------------------
  |  Branch (57:9): [True: 26.5k, False: 4.10k]
  ------------------
   58|       |
   59|       |      /* Port */
   60|  26.5k|      ((uint16_t *)cfield)[1] = (ca->s4.sin_port) ^ nswap16(mc >> 16);
  ------------------
  |  |   86|  26.5k|#define nswap16(s) ntohs(s)
  ------------------
   61|       |
   62|       |      /* Address */
   63|  26.5k|      ((uint32_t *)cfield)[1] = (ca->s4.sin_addr.s_addr) ^ nswap32(mc);
  ------------------
  |  |   87|  26.5k|#define nswap32(ul) ntohl(ul)
  ------------------
   64|       |
   65|  26.5k|    } else {
   66|       |
   67|       |      /* Port */
   68|  4.10k|      ((uint16_t *)cfield)[1] = ca->s4.sin_port;
   69|       |
   70|       |      /* Address */
   71|  4.10k|      ((uint32_t *)cfield)[1] = ca->s4.sin_addr.s_addr;
   72|  4.10k|    }
   73|       |
   74|  30.6k|  } else if (ca->ss.sa_family == AF_INET6) {
  ------------------
  |  Branch (74:14): [True: 17.1k, False: 0]
  ------------------
   75|       |
   76|       |    /* IPv6 address */
   77|       |
   78|  17.1k|    *clen = 20;
   79|       |
   80|  17.1k|    cfield[0] = 0;
   81|  17.1k|    cfield[1] = 2; // IPv6 family
   82|       |
   83|  17.1k|    if (xor_ed) {
  ------------------
  |  Branch (83:9): [True: 14.1k, False: 3.05k]
  ------------------
   84|       |
   85|  14.1k|      unsigned int i;
   86|  14.1k|      uint8_t *dst = ((uint8_t *)cfield) + 4;
   87|  14.1k|      const uint8_t *src = (const uint8_t *)&(ca->s6.sin6_addr);
   88|  14.1k|      uint32_t magic = nswap32(mc);
  ------------------
  |  |   87|  14.1k|#define nswap32(ul) ntohl(ul)
  ------------------
   89|       |
   90|       |      /* Port */
   91|  14.1k|      ((uint16_t *)cfield)[1] = ca->s6.sin6_port ^ nswap16(mc >> 16);
  ------------------
  |  |   86|  14.1k|#define nswap16(s) ntohs(s)
  ------------------
   92|       |
   93|       |      /* Address */
   94|       |
   95|  70.5k|      for (i = 0; i < 4; ++i) {
  ------------------
  |  Branch (95:19): [True: 56.4k, False: 14.1k]
  ------------------
   96|  56.4k|        dst[i] = (uint8_t)(src[i] ^ ((const uint8_t *)&magic)[i]);
   97|  56.4k|      }
   98|   183k|      for (i = 0; i < 12; ++i) {
  ------------------
  |  Branch (98:19): [True: 169k, False: 14.1k]
  ------------------
   99|   169k|        dst[i + 4] = (uint8_t)(src[i + 4] ^ tsx_id[i]);
  100|   169k|      }
  101|       |
  102|  14.1k|    } else {
  103|       |
  104|       |      /* Port */
  105|  3.05k|      ((uint16_t *)cfield)[1] = ca->s6.sin6_port;
  106|       |
  107|       |      /* Address */
  108|  3.05k|      memcpy(((uint8_t *)cfield) + 4, &ca->s6.sin6_addr, 16);
  109|  3.05k|    }
  110|       |
  111|  17.1k|  } else {
  112|      0|    return -1;
  113|      0|  }
  114|       |
  115|  47.8k|  return 0;
  116|  47.8k|}
stun_addr_decode:
  118|  87.5k|int stun_addr_decode(ioa_addr *ca, const uint8_t *cfield, int len, int xor_ed, uint32_t mc, const uint8_t *tsx_id) {
  119|       |
  120|  87.5k|  if (!cfield || !len || !ca || !tsx_id || (len < 8)) {
  ------------------
  |  Branch (120:7): [True: 0, False: 87.5k]
  |  Branch (120:18): [True: 0, False: 87.5k]
  |  Branch (120:26): [True: 0, False: 87.5k]
  |  Branch (120:33): [True: 0, False: 87.5k]
  |  Branch (120:44): [True: 3.84k, False: 83.6k]
  ------------------
  121|  3.84k|    return -1;
  122|  3.84k|  }
  123|       |
  124|  83.6k|  if (cfield[0] != 0) {
  ------------------
  |  Branch (124:7): [True: 2.36k, False: 81.3k]
  ------------------
  125|  2.36k|    return -1;
  126|  2.36k|  }
  127|       |
  128|  81.3k|  int sa_family;
  129|       |
  130|  81.3k|  if (cfield[1] == 1) {
  ------------------
  |  Branch (130:7): [True: 52.2k, False: 29.1k]
  ------------------
  131|  52.2k|    sa_family = AF_INET;
  132|  52.2k|  } else if (cfield[1] == 2) {
  ------------------
  |  Branch (132:14): [True: 27.9k, False: 1.15k]
  ------------------
  133|  27.9k|    sa_family = AF_INET6;
  134|  27.9k|  } else {
  135|  1.15k|    return -1;
  136|  1.15k|  }
  137|       |
  138|  80.1k|  ca->ss.sa_family = sa_family;
  139|       |
  140|  80.1k|  if (sa_family == AF_INET) {
  ------------------
  |  Branch (140:7): [True: 52.2k, False: 27.9k]
  ------------------
  141|       |
  142|  52.2k|    if (len != 8) {
  ------------------
  |  Branch (142:9): [True: 322, False: 51.8k]
  ------------------
  143|    322|      return -1;
  144|    322|    }
  145|       |
  146|       |    /* IPv4 address */
  147|       |
  148|       |    /* Port */
  149|  51.8k|    ca->s4.sin_port = ((const uint16_t *)cfield)[1];
  150|       |
  151|       |    /* Address */
  152|  51.8k|    ca->s4.sin_addr.s_addr = ((const uint32_t *)cfield)[1];
  153|       |
  154|  51.8k|    if (xor_ed) {
  ------------------
  |  Branch (154:9): [True: 46.3k, False: 5.49k]
  ------------------
  155|  46.3k|      ca->s4.sin_port ^= nswap16(mc >> 16);
  ------------------
  |  |   86|  46.3k|#define nswap16(s) ntohs(s)
  ------------------
  156|  46.3k|      ca->s4.sin_addr.s_addr ^= nswap32(mc);
  ------------------
  |  |   87|  46.3k|#define nswap32(ul) ntohl(ul)
  ------------------
  157|  46.3k|    }
  158|       |
  159|  51.8k|  } else if (sa_family == AF_INET6) {
  ------------------
  |  Branch (159:14): [True: 27.9k, False: 0]
  ------------------
  160|       |
  161|       |    /* IPv6 address */
  162|       |
  163|  27.9k|    if (len != 20) {
  ------------------
  |  Branch (163:9): [True: 818, False: 27.1k]
  ------------------
  164|    818|      return -1;
  165|    818|    }
  166|       |
  167|       |    /* Port */
  168|  27.1k|    ca->s6.sin6_port = ((const uint16_t *)cfield)[1];
  169|       |
  170|       |    /* Address */
  171|  27.1k|    memcpy(&ca->s6.sin6_addr, ((const uint8_t *)cfield) + 4, 16);
  172|       |
  173|  27.1k|    if (xor_ed) {
  ------------------
  |  Branch (173:9): [True: 23.1k, False: 4.00k]
  ------------------
  174|       |
  175|  23.1k|      unsigned int i;
  176|  23.1k|      uint8_t *dst;
  177|  23.1k|      const uint8_t *src;
  178|  23.1k|      uint32_t magic = nswap32(mc);
  ------------------
  |  |   87|  23.1k|#define nswap32(ul) ntohl(ul)
  ------------------
  179|       |
  180|       |      /* Port */
  181|  23.1k|      ca->s6.sin6_port ^= nswap16(mc >> 16);
  ------------------
  |  |   86|  23.1k|#define nswap16(s) ntohs(s)
  ------------------
  182|       |
  183|       |      /* Address */
  184|  23.1k|      src = ((const uint8_t *)cfield) + 4;
  185|  23.1k|      dst = (uint8_t *)&ca->s6.sin6_addr;
  186|   115k|      for (i = 0; i < 4; ++i) {
  ------------------
  |  Branch (186:19): [True: 92.5k, False: 23.1k]
  ------------------
  187|  92.5k|        dst[i] = (uint8_t)(src[i] ^ ((const uint8_t *)&magic)[i]);
  188|  92.5k|      }
  189|   300k|      for (i = 0; i < 12; ++i) {
  ------------------
  |  Branch (189:19): [True: 277k, False: 23.1k]
  ------------------
  190|   277k|        dst[i + 4] = (uint8_t)(src[i + 4] ^ tsx_id[i]);
  191|   277k|      }
  192|  23.1k|    }
  193|       |
  194|  27.1k|  } else {
  195|      0|    return -1;
  196|      0|  }
  197|       |
  198|  79.0k|  return 0;
  199|  80.1k|}

ns_turn_msg.c:_ioa_ntoh64:
   90|  6.39k|static inline uint64_t _ioa_ntoh64(uint64_t v) {
   91|  6.39k|#if BYTE_ORDER == LITTLE_ENDIAN
   92|  6.39k|  uint8_t *src = (uint8_t *)&v;
   93|  6.39k|  uint8_t *dst = src + 7;
   94|  31.9k|  while (src < dst) {
  ------------------
  |  Branch (94:10): [True: 25.5k, False: 6.39k]
  ------------------
   95|  25.5k|    uint8_t vdst = *dst;
   96|  25.5k|    *(dst--) = *src;
   97|  25.5k|    *(src++) = vdst;
   98|  25.5k|  }
   99|       |#elif BYTE_ORDER == BIG_ENDIAN
  100|       |  /* OK */
  101|       |#else
  102|       |#error WRONG BYTE_ORDER SETTING
  103|       |#endif
  104|  6.39k|  return v;
  105|  6.39k|}

