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

turn_malloc_impl:
  938|      8|void *turn_malloc_impl(size_t sz, const char *file, int line) {
  939|      8|  void *ptr = malloc(sz);
  940|      8|  if (!ptr && sz) {
  ------------------
  |  Branch (940:7): [True: 0, False: 8]
  |  Branch (940:15): [True: 0, False: 0]
  ------------------
  941|      0|    turn_out_of_memory(file, line, "malloc", sz);
  942|      0|  }
  943|      8|  return ptr;
  944|      8|}
turn_realloc_impl:
  954|      8|void *turn_realloc_impl(void *ptr, size_t sz, const char *file, int line) {
  955|      8|  void *newptr = realloc(ptr, sz);
  956|      8|  if (!newptr && sz) {
  ------------------
  |  Branch (956:7): [True: 0, False: 8]
  |  Branch (956:18): [True: 0, False: 0]
  ------------------
  957|      0|    turn_out_of_memory(file, line, "realloc", sz);
  958|      0|  }
  959|      8|  return newptr;
  960|      8|}

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

addr_set_any:
   48|   191k|void addr_set_any(ioa_addr *addr) {
   49|   191k|  if (addr) {
  ------------------
  |  Branch (49:7): [True: 191k, False: 0]
  ------------------
   50|   191k|    memset(addr, 0, sizeof(ioa_addr));
   51|   191k|  }
   52|   191k|}
addr_any_no_port:
   78|  95.9k|int addr_any_no_port(const ioa_addr *addr) {
   79|  95.9k|  if (!addr) {
  ------------------
  |  Branch (79:7): [True: 0, False: 95.9k]
  ------------------
   80|      0|    return 1;
   81|      0|  }
   82|       |
   83|  95.9k|  if (addr->ss.sa_family == AF_INET) {
  ------------------
  |  Branch (83:7): [True: 63.4k, False: 32.4k]
  ------------------
   84|  63.4k|    return (addr->s4.sin_addr.s_addr == 0);
   85|  63.4k|  } else if (addr->ss.sa_family == AF_INET6) {
  ------------------
  |  Branch (85:14): [True: 32.4k, False: 0]
  ------------------
   86|  32.4k|    size_t i;
   87|  56.6k|    for (i = 0; i < sizeof(addr->s6.sin6_addr); i++) {
  ------------------
  |  Branch (87:17): [True: 56.6k, False: 16]
  ------------------
   88|  56.6k|      if (((const char *)(&(addr->s6.sin6_addr)))[i]) {
  ------------------
  |  Branch (88:11): [True: 32.4k, False: 24.1k]
  ------------------
   89|  32.4k|        return 0;
   90|  32.4k|      }
   91|  56.6k|    }
   92|  32.4k|  }
   93|       |
   94|     16|  return 1;
   95|  95.9k|}
addr_eq_no_port:
  180|   272k|int addr_eq_no_port(const ioa_addr *a1, const ioa_addr *a2) {
  181|       |
  182|   272k|  if (!a1) {
  ------------------
  |  Branch (182:7): [True: 0, False: 272k]
  ------------------
  183|      0|    return (!a2);
  184|   272k|  } else if (!a2) {
  ------------------
  |  Branch (184:14): [True: 0, False: 272k]
  ------------------
  185|      0|    return (!a1);
  186|      0|  }
  187|       |
  188|   272k|  if (a1->ss.sa_family == a2->ss.sa_family) {
  ------------------
  |  Branch (188:7): [True: 130k, False: 141k]
  ------------------
  189|   130k|    if (a1->ss.sa_family == AF_INET) {
  ------------------
  |  Branch (189:9): [True: 84.5k, False: 46.4k]
  ------------------
  190|  84.5k|      if ((int)a1->s4.sin_addr.s_addr == (int)a2->s4.sin_addr.s_addr) {
  ------------------
  |  Branch (190:11): [True: 413, False: 84.1k]
  ------------------
  191|    413|        return 1;
  192|    413|      }
  193|  84.5k|    } else if (a1->ss.sa_family == AF_INET6) {
  ------------------
  |  Branch (193:16): [True: 46.4k, False: 0]
  ------------------
  194|  46.4k|      if (memcmp(&(a1->s6.sin6_addr), &(a2->s6.sin6_addr), sizeof(struct in6_addr)) == 0) {
  ------------------
  |  Branch (194:11): [True: 155, False: 46.2k]
  ------------------
  195|    155|        return 1;
  196|    155|      }
  197|  46.4k|    }
  198|   130k|  }
  199|   271k|  return 0;
  200|   272k|}
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);
  ------------------
  |  |  240|      8|  do {                                                                                                                 \
  |  |  241|      8|    if ((const char *)(dst) != (const char *)(src)) {                                                                  \
  |  |  ------------------
  |  |  |  Branch (241:9): [True: 8, False: 0]
  |  |  ------------------
  |  |  242|      8|      if (sizeof(dst) == sizeof(char *))                                                                               \
  |  |  ------------------
  |  |  |  Branch (242:11): [Folded, False: 8]
  |  |  ------------------
  |  |  243|      8|        strcpy(((char *)(dst)), (const char *)(src));                                                                  \
  |  |  244|      8|      else {                                                                                                           \
  |  |  245|      8|        size_t szdst = sizeof((dst));                                                                                  \
  |  |  246|      8|        strncpy((char *)(dst), (const char *)(src), szdst);                                                            \
  |  |  247|      8|        ((char *)(dst))[szdst - 1] = 0;                                                                                \
  |  |  248|      8|      }                                                                                                                \
  |  |  249|      8|    }                                                                                                                  \
  |  |  250|      8|  } while (0)
  |  |  ------------------
  |  |  |  Branch (250: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.5k|void addr_set_port(ioa_addr *addr, uint16_t port) {
  408|  11.5k|  if (addr) {
  ------------------
  |  Branch (408:7): [True: 11.5k, False: 0]
  ------------------
  409|  11.5k|    if (addr->s4.sin_family == AF_INET) {
  ------------------
  |  Branch (409:9): [True: 7.45k, False: 4.06k]
  ------------------
  410|  7.45k|      addr->s4.sin_port = nswap16(port);
  ------------------
  |  |   86|  7.45k|#define nswap16(s) ntohs(s)
  ------------------
  411|  7.45k|    } else if (addr->s6.sin6_family == AF_INET6) {
  ------------------
  |  Branch (411:16): [True: 4.06k, False: 0]
  ------------------
  412|       |      addr->s6.sin6_port = nswap16(port);
  ------------------
  |  |   86|  4.06k|#define nswap16(s) ntohs(s)
  ------------------
  413|  4.06k|    }
  414|  11.5k|  }
  415|  11.5k|}
addr_get_port:
  417|  11.5k|uint16_t addr_get_port(const ioa_addr *addr) {
  418|  11.5k|  if (!addr) {
  ------------------
  |  Branch (418:7): [True: 0, False: 11.5k]
  ------------------
  419|      0|    return 0;
  420|      0|  }
  421|       |
  422|  11.5k|  if (addr->s4.sin_family == AF_INET) {
  ------------------
  |  Branch (422:7): [True: 11.3k, False: 171]
  ------------------
  423|  11.3k|    return nswap16(addr->s4.sin_port);
  ------------------
  |  |   86|  11.3k|#define nswap16(s) ntohs(s)
  ------------------
  424|  11.3k|  } else if (addr->s6.sin6_family == AF_INET6) {
  ------------------
  |  Branch (424:14): [True: 171, False: 0]
  ------------------
  425|    171|    return nswap16(addr->s6.sin6_port);
  ------------------
  |  |   86|    171|#define nswap16(s) ntohs(s)
  ------------------
  426|    171|  }
  427|      0|  return 0;
  428|  11.5k|}
ioa_addr_add_mapping:
  676|      4|void ioa_addr_add_mapping(ioa_addr *apub, ioa_addr *apriv) {
  677|      4|  const size_t new_size = msz + sizeof(ioa_addr *);
  678|      4|  public_addrs = (ioa_addr **)turn_realloc(public_addrs, new_size);
  ------------------
  |  |  121|      4|#define turn_realloc(ptr, sz) turn_realloc_impl((ptr), (sz), __FILE__, __LINE__)
  ------------------
  679|      4|  private_addrs = (ioa_addr **)turn_realloc(private_addrs, new_size);
  ------------------
  |  |  121|      4|#define turn_realloc(ptr, sz) turn_realloc_impl((ptr), (sz), __FILE__, __LINE__)
  ------------------
  680|      4|  public_addrs[mcount] = (ioa_addr *)turn_malloc(sizeof(ioa_addr));
  ------------------
  |  |  119|      4|#define turn_malloc(sz) turn_malloc_impl((sz), __FILE__, __LINE__)
  ------------------
  681|      4|  private_addrs[mcount] = (ioa_addr *)turn_malloc(sizeof(ioa_addr));
  ------------------
  |  |  119|      4|#define turn_malloc(sz) turn_malloc_impl((sz), __FILE__, __LINE__)
  ------------------
  682|      4|  addr_cpy(public_addrs[mcount], apub);
  683|      4|  addr_cpy(private_addrs[mcount], apriv);
  684|      4|  ++mcount;
  685|      4|  msz += sizeof(ioa_addr *);
  686|      4|}
map_addr_from_public_to_private:
  688|  85.2k|void map_addr_from_public_to_private(const ioa_addr *public_addr, ioa_addr *private_addr) {
  689|  85.2k|  size_t i;
  690|   255k|  for (i = 0; i < mcount; ++i) {
  ------------------
  |  Branch (690:15): [True: 170k, False: 84.8k]
  ------------------
  691|   170k|    if (addr_eq_no_port(public_addr, public_addrs[i])) {
  ------------------
  |  Branch (691:9): [True: 356, False: 169k]
  ------------------
  692|    356|      addr_cpy(private_addr, private_addrs[i]);
  693|    356|      addr_set_port(private_addr, addr_get_port(public_addr));
  694|    356|      return;
  695|    356|    }
  696|   170k|  }
  697|  84.8k|  addr_cpy(private_addr, public_addr);
  698|  84.8k|}
map_addr_from_private_to_public:
  700|  51.1k|void map_addr_from_private_to_public(const ioa_addr *private_addr, ioa_addr *public_addr) {
  701|  51.1k|  size_t i;
  702|   153k|  for (i = 0; i < mcount; ++i) {
  ------------------
  |  Branch (702:15): [True: 102k, False: 50.9k]
  ------------------
  703|   102k|    if (addr_eq_no_port(private_addr, private_addrs[i])) {
  ------------------
  |  Branch (703:9): [True: 212, False: 101k]
  ------------------
  704|    212|      addr_cpy(public_addr, public_addrs[i]);
  705|    212|      addr_set_port(public_addr, addr_get_port(private_addr));
  706|    212|      return;
  707|    212|    }
  708|   102k|  }
  709|  50.9k|  addr_cpy(public_addr, private_addr);
  710|  50.9k|}

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

turn_random_number:
  123|   243k|long turn_random_number(void) {
  124|   243k|  long ret = 0;
  125|   243k|#if defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
  126|   243k|  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|   243k|  return ret;
  136|   243k|}
stun_get_command_message_len_str:
  523|   929k|int stun_get_command_message_len_str(const uint8_t *buf, size_t len) {
  524|   929k|  if (len < STUN_HEADER_LENGTH) {
  ------------------
  |  |   46|   929k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (524:7): [True: 1.93k, False: 927k]
  ------------------
  525|  1.93k|    return -1;
  526|  1.93k|  }
  527|       |
  528|       |  /* Validate the size the buffer claims to be */
  529|   927k|  const size_t bufLen = (size_t)(turn_read_u16(buf + 2) + STUN_HEADER_LENGTH);
  ------------------
  |  |   46|   927k|#define STUN_HEADER_LENGTH (20)
  ------------------
  530|   927k|  if (bufLen > len) {
  ------------------
  |  Branch (530:7): [True: 9.09k, False: 918k]
  ------------------
  531|  9.09k|    return -1;
  532|  9.09k|  }
  533|       |
  534|   918k|  return bufLen;
  535|   927k|}
stun_make_type:
  547|  77.1k|uint16_t stun_make_type(uint16_t method) {
  548|  77.1k|  method = method & 0x0FFF;
  549|  77.1k|  return ((method & 0x000F) | ((method & 0x0070) << 1) | ((method & 0x0380) << 2) | ((method & 0x0C00) << 2));
  550|  77.1k|}
stun_get_method_str:
  552|   146k|uint16_t stun_get_method_str(const uint8_t *buf, size_t len) {
  553|   146k|  if (!buf || len < 2) {
  ------------------
  |  Branch (553:7): [True: 0, False: 146k]
  |  Branch (553:15): [True: 0, False: 146k]
  ------------------
  554|      0|    return (uint16_t)-1;
  555|      0|  }
  556|       |
  557|   146k|  const uint16_t tt = turn_read_u16(buf);
  558|       |
  559|   146k|  return (tt & 0x000F) | ((tt & 0x00E0) >> 1) | ((tt & 0x0E00) >> 2) | ((tt & 0x3000) >> 2);
  560|   146k|}
stun_get_msg_type_str:
  562|   474k|uint16_t stun_get_msg_type_str(const uint8_t *buf, size_t len) {
  563|   474k|  if (!buf || len < 2) {
  ------------------
  |  Branch (563:7): [True: 0, False: 474k]
  |  Branch (563:15): [True: 76, False: 474k]
  ------------------
  564|     76|    return (uint16_t)-1;
  565|     76|  }
  566|   474k|  return (turn_read_u16(buf) & 0x3FFF);
  567|   474k|}
is_channel_msg_str:
  569|   335k|bool is_channel_msg_str(const uint8_t *buf, size_t blen) {
  570|   335k|  return (buf && blen >= 4 && STUN_VALID_CHANNEL(turn_read_u16(buf)));
  ------------------
  |  |  163|   335k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (163:34): [True: 736, False: 334k]
  |  |  |  Branch (163:53): [True: 553, False: 183]
  |  |  ------------------
  ------------------
  |  Branch (570:11): [True: 335k, False: 0]
  |  Branch (570:18): [True: 335k, False: 281]
  ------------------
  571|   335k|}
stun_is_command_message_str:
  575|   155k|bool stun_is_command_message_str(const uint8_t *buf, size_t blen) {
  576|   155k|  if (buf && blen >= STUN_HEADER_LENGTH) {
  ------------------
  |  |   46|   155k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (576:7): [True: 155k, False: 0]
  |  Branch (576:14): [True: 155k, False: 133]
  ------------------
  577|   155k|    if (!STUN_VALID_CHANNEL(turn_read_u16(buf))) {
  ------------------
  |  |  163|   155k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (163:34): [True: 543, False: 154k]
  |  |  |  Branch (163:53): [True: 459, False: 84]
  |  |  ------------------
  ------------------
  578|   154k|      if ((((uint8_t)buf[0]) & ((uint8_t)(0xC0))) == 0) {
  ------------------
  |  Branch (578:11): [True: 154k, False: 84]
  ------------------
  579|   154k|        if (turn_read_u32(buf + 4) == STUN_MAGIC_COOKIE) {
  ------------------
  |  |   60|   154k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (579:13): [True: 138k, False: 16.1k]
  ------------------
  580|   138k|          const uint16_t len = turn_read_u16(buf + 2);
  581|   138k|          if ((len & 0x0003) == 0) {
  ------------------
  |  Branch (581:15): [True: 138k, False: 11]
  ------------------
  582|   138k|            if ((size_t)(len + STUN_HEADER_LENGTH) == blen) {
  ------------------
  |  |   46|   138k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (582:17): [True: 138k, False: 47]
  ------------------
  583|   138k|              return true;
  584|   138k|            }
  585|   138k|          }
  586|   138k|        }
  587|   154k|      }
  588|   154k|    }
  589|   155k|  }
  590|  16.9k|  return false;
  591|   155k|}
stun_is_request_str:
  643|  77.1k|bool stun_is_request_str(const uint8_t *buf, size_t len) {
  644|  77.1k|  if (is_channel_msg_str(buf, len)) {
  ------------------
  |  Branch (644:7): [True: 0, False: 77.1k]
  ------------------
  645|      0|    return false;
  646|      0|  }
  647|  77.1k|  return IS_STUN_REQUEST(stun_get_msg_type_str(buf, len));
  ------------------
  |  |   62|  77.1k|#define IS_STUN_REQUEST(msg_type) (((msg_type)&0x0110) == 0x0000)
  ------------------
  648|  77.1k|}
stun_is_success_response_str:
  650|  77.3k|bool stun_is_success_response_str(const uint8_t *buf, size_t len) {
  651|  77.3k|  if (is_channel_msg_str(buf, len)) {
  ------------------
  |  Branch (651:7): [True: 0, False: 77.3k]
  ------------------
  652|      0|    return false;
  653|      0|  }
  654|  77.3k|  return IS_STUN_SUCCESS_RESP(stun_get_msg_type_str(buf, len));
  ------------------
  |  |   64|  77.3k|#define IS_STUN_SUCCESS_RESP(msg_type) (((msg_type)&0x0110) == 0x0100)
  ------------------
  655|  77.3k|}
stun_is_error_response_str:
  657|  77.3k|bool stun_is_error_response_str(const uint8_t *buf, size_t len, int *err_code, uint8_t *err_msg, size_t err_msg_size) {
  658|  77.3k|  if (is_channel_msg_str(buf, len)) {
  ------------------
  |  Branch (658:7): [True: 0, False: 77.3k]
  ------------------
  659|      0|    return false;
  660|      0|  }
  661|  77.3k|  if (IS_STUN_ERR_RESP(stun_get_msg_type_str(buf, len))) {
  ------------------
  |  |   65|  77.3k|#define IS_STUN_ERR_RESP(msg_type) (((msg_type)&0x0110) == 0x0110)
  |  |  ------------------
  |  |  |  Branch (65:36): [True: 28.6k, False: 48.7k]
  |  |  ------------------
  ------------------
  662|  28.6k|    if (err_code) {
  ------------------
  |  Branch (662:9): [True: 28.6k, False: 0]
  ------------------
  663|  28.6k|      stun_attr_ref sar = stun_attr_get_first_by_type_str(buf, len, STUN_ATTRIBUTE_ERROR_CODE);
  ------------------
  |  |  103|  28.6k|#define STUN_ATTRIBUTE_ERROR_CODE (0x0009)
  ------------------
  664|  28.6k|      if (sar) {
  ------------------
  |  Branch (664:11): [True: 28.5k, False: 64]
  ------------------
  665|  28.5k|        if (stun_attr_get_len(sar) >= 4) {
  ------------------
  |  Branch (665:13): [True: 28.5k, False: 13]
  ------------------
  666|  28.5k|          const uint8_t *val = (const uint8_t *)stun_attr_get_value(sar);
  667|  28.5k|          *err_code = (int)(val[2] * 100 + val[3]);
  668|  28.5k|          if (err_msg && err_msg_size > 0) {
  ------------------
  |  Branch (668:15): [True: 28.5k, False: 0]
  |  Branch (668:26): [True: 28.5k, False: 0]
  ------------------
  669|  28.5k|            err_msg[0] = 0;
  670|  28.5k|            if (stun_attr_get_len(sar) > 4) {
  ------------------
  |  Branch (670:17): [True: 14.2k, False: 14.2k]
  ------------------
  671|  14.2k|              size_t msg_len = stun_attr_get_len(sar) - 4;
  672|  14.2k|              if (msg_len > (err_msg_size - 1)) {
  ------------------
  |  Branch (672:19): [True: 14, False: 14.2k]
  ------------------
  673|     14|                msg_len = err_msg_size - 1;
  674|     14|              }
  675|  14.2k|              memcpy(err_msg, val + 4, msg_len);
  676|  14.2k|              err_msg[msg_len] = 0;
  677|  14.2k|            }
  678|  28.5k|          }
  679|  28.5k|        }
  680|  28.5k|      }
  681|  28.6k|    }
  682|  28.6k|    return true;
  683|  28.6k|  }
  684|  48.7k|  return false;
  685|  77.3k|}
stun_is_response_str:
  748|  98.7k|bool stun_is_response_str(const uint8_t *buf, size_t len) {
  749|  98.7k|  if (is_channel_msg_str(buf, len)) {
  ------------------
  |  Branch (749:7): [True: 0, False: 98.7k]
  ------------------
  750|      0|    return false;
  751|      0|  }
  752|  98.7k|  if (IS_STUN_SUCCESS_RESP(stun_get_msg_type_str(buf, len))) {
  ------------------
  |  |   64|  98.7k|#define IS_STUN_SUCCESS_RESP(msg_type) (((msg_type)&0x0110) == 0x0100)
  |  |  ------------------
  |  |  |  Branch (64:40): [True: 36.5k, False: 62.2k]
  |  |  ------------------
  ------------------
  753|  36.5k|    return true;
  754|  36.5k|  }
  755|  62.2k|  if (IS_STUN_ERR_RESP(stun_get_msg_type_str(buf, len))) {
  ------------------
  |  |   65|  62.2k|#define IS_STUN_ERR_RESP(msg_type) (((msg_type)&0x0110) == 0x0110)
  |  |  ------------------
  |  |  |  Branch (65:36): [True: 38.3k, False: 23.8k]
  |  |  ------------------
  ------------------
  756|  38.3k|    return true;
  757|  38.3k|  }
  758|  23.8k|  return false;
  759|  62.2k|}
stun_is_indication_str:
  761|    174|bool stun_is_indication_str(const uint8_t *buf, size_t len) {
  762|    174|  if (is_channel_msg_str(buf, len)) {
  ------------------
  |  Branch (762:7): [True: 0, False: 174]
  ------------------
  763|      0|    return false;
  764|      0|  }
  765|    174|  return IS_STUN_INDICATION(stun_get_msg_type_str(buf, len));
  ------------------
  |  |   63|    174|#define IS_STUN_INDICATION(msg_type) (((msg_type)&0x0110) == 0x0010)
  ------------------
  766|    174|}
stun_make_request:
  768|  18.4k|uint16_t stun_make_request(uint16_t method) { return GET_STUN_REQUEST(stun_make_type(method)); }
  ------------------
  |  |   67|  18.4k|#define GET_STUN_REQUEST(msg_type) (msg_type & 0xFEEF)
  ------------------
stun_make_indication:
  770|  1.67k|uint16_t stun_make_indication(uint16_t method) { return GET_STUN_INDICATION(stun_make_type(method)); }
  ------------------
  |  |   68|  1.67k|#define GET_STUN_INDICATION(msg_type) ((msg_type & 0xFEEF) | 0x0010)
  ------------------
stun_make_success_response:
  772|  28.5k|uint16_t stun_make_success_response(uint16_t method) { return GET_STUN_SUCCESS_RESP(stun_make_type(method)); }
  ------------------
  |  |   69|  28.5k|#define GET_STUN_SUCCESS_RESP(msg_type) ((msg_type & 0xFEEF) | 0x0100)
  ------------------
stun_make_error_response:
  774|  28.5k|uint16_t stun_make_error_response(uint16_t method) { return GET_STUN_ERR_RESP(stun_make_type(method)); }
  ------------------
  |  |   70|  28.5k|#define GET_STUN_ERR_RESP(msg_type) (msg_type | 0x0110)
  ------------------
stun_init_buffer_str:
  778|  77.1k|void stun_init_buffer_str(uint8_t *buf, size_t *len) {
  779|  77.1k|  *len = STUN_HEADER_LENGTH;
  ------------------
  |  |   46|  77.1k|#define STUN_HEADER_LENGTH (20)
  ------------------
  780|  77.1k|  memset(buf, 0, *len);
  781|  77.1k|}
stun_init_command_str:
  783|  68.9k|void stun_init_command_str(uint16_t message_type, uint8_t *buf, size_t *len) {
  784|  68.9k|  stun_init_buffer_str(buf, len);
  785|  68.9k|  message_type &= (uint16_t)(0x3FFF);
  786|  68.9k|  turn_write_u16(buf, message_type);
  787|  68.9k|  turn_write_u16(buf + 2, 0);
  788|  68.9k|  turn_write_u32(buf + 4, STUN_MAGIC_COOKIE);
  ------------------
  |  |   60|  68.9k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  789|       |  stun_tid_generate_in_message_str(buf, NULL);
  790|  68.9k|}
old_stun_init_command_str:
  792|  8.14k|void old_stun_init_command_str(uint16_t message_type, uint8_t *buf, size_t *len, uint32_t cookie) {
  793|  8.14k|  stun_init_buffer_str(buf, len);
  794|  8.14k|  message_type &= (uint16_t)(0x3FFF);
  795|  8.14k|  turn_write_u16(buf, message_type);
  796|  8.14k|  turn_write_u16(buf + 2, 0);
  797|  8.14k|  turn_write_u32(buf + 4, cookie);
  798|       |  stun_tid_generate_in_message_str(buf, NULL);
  799|  8.14k|}
stun_init_request_str:
  801|  16.7k|void stun_init_request_str(uint16_t method, uint8_t *buf, size_t *len) {
  802|  16.7k|  stun_init_command_str(stun_make_request(method), buf, len);
  803|  16.7k|}
stun_init_success_response_str:
  809|  24.4k|void stun_init_success_response_str(uint16_t method, uint8_t *buf, size_t *len, stun_tid *id) {
  810|  24.4k|  stun_init_command_str(stun_make_success_response(method), buf, len);
  811|  24.4k|  if (id) {
  ------------------
  |  Branch (811:7): [True: 24.4k, False: 0]
  ------------------
  812|  24.4k|    stun_tid_message_cpy(buf, id);
  813|  24.4k|  }
  814|  24.4k|}
old_stun_init_success_response_str:
  816|  4.07k|void old_stun_init_success_response_str(uint16_t method, uint8_t *buf, size_t *len, stun_tid *id, uint32_t cookie) {
  817|  4.07k|  old_stun_init_command_str(stun_make_success_response(method), buf, len, cookie);
  818|  4.07k|  if (id) {
  ------------------
  |  Branch (818:7): [True: 4.07k, False: 0]
  ------------------
  819|  4.07k|    stun_tid_message_cpy(buf, id);
  820|  4.07k|  }
  821|  4.07k|}
get_default_reason:
  823|    858|const uint8_t *get_default_reason(int error_code) {
  824|    858|  const char *reason = "Unknown error";
  825|       |
  826|    858|  switch (error_code) {
  827|    354|  case 300:
  ------------------
  |  Branch (827:3): [True: 354, False: 504]
  ------------------
  828|    354|    reason = "Try Alternate";
  829|    354|    break;
  830|     48|  case 400:
  ------------------
  |  Branch (830:3): [True: 48, False: 810]
  ------------------
  831|     48|    reason = "Bad Request";
  832|     48|    break;
  833|     36|  case 401:
  ------------------
  |  Branch (833:3): [True: 36, False: 822]
  ------------------
  834|     36|    reason = "Unauthorized";
  835|     36|    break;
  836|     96|  case 403:
  ------------------
  |  Branch (836:3): [True: 96, False: 762]
  ------------------
  837|     96|    reason = "Forbidden";
  838|     96|    break;
  839|      0|  case 404:
  ------------------
  |  Branch (839:3): [True: 0, False: 858]
  ------------------
  840|      0|    reason = "Not Found";
  841|      0|    break;
  842|     24|  case 420:
  ------------------
  |  Branch (842:3): [True: 24, False: 834]
  ------------------
  843|     24|    reason = "Unknown Attribute";
  844|     24|    break;
  845|     18|  case 437:
  ------------------
  |  Branch (845:3): [True: 18, False: 840]
  ------------------
  846|     18|    reason = "Allocation Mismatch";
  847|     18|    break;
  848|     24|  case 438:
  ------------------
  |  Branch (848:3): [True: 24, False: 834]
  ------------------
  849|     24|    reason = "Stale Nonce";
  850|     24|    break;
  851|     18|  case 440:
  ------------------
  |  Branch (851:3): [True: 18, False: 840]
  ------------------
  852|     18|    reason = "Address Family not Supported";
  853|     18|    break;
  854|     24|  case 441:
  ------------------
  |  Branch (854:3): [True: 24, False: 834]
  ------------------
  855|     24|    reason = "Wrong Credentials";
  856|     24|    break;
  857|     18|  case 442:
  ------------------
  |  Branch (857:3): [True: 18, False: 840]
  ------------------
  858|     18|    reason = "Unsupported Transport Protocol";
  859|     18|    break;
  860|     30|  case 443:
  ------------------
  |  Branch (860:3): [True: 30, False: 828]
  ------------------
  861|     30|    reason = "Peer Address Family Mismatch";
  862|     30|    break;
  863|     18|  case 446:
  ------------------
  |  Branch (863:3): [True: 18, False: 840]
  ------------------
  864|     18|    reason = "Connection Already Exists";
  865|     18|    break;
  866|     18|  case 447:
  ------------------
  |  Branch (866:3): [True: 18, False: 840]
  ------------------
  867|     18|    reason = "Connection Timeout or Failure";
  868|     18|    break;
  869|     30|  case 486:
  ------------------
  |  Branch (869:3): [True: 30, False: 828]
  ------------------
  870|     30|    reason = "Allocation Quota Reached";
  871|     30|    break;
  872|     24|  case 487:
  ------------------
  |  Branch (872:3): [True: 24, False: 834]
  ------------------
  873|     24|    reason = "Role Conflict";
  874|     24|    break;
  875|     12|  case 500:
  ------------------
  |  Branch (875:3): [True: 12, False: 846]
  ------------------
  876|     12|    reason = "Server Error";
  877|     12|    break;
  878|     30|  case 508:
  ------------------
  |  Branch (878:3): [True: 30, False: 828]
  ------------------
  879|     30|    reason = "Insufficient Capacity";
  880|     30|    break;
  881|     36|  default:;
  ------------------
  |  Branch (881:3): [True: 36, False: 822]
  ------------------
  882|    858|  };
  883|       |
  884|    858|  return (const uint8_t *)reason;
  885|    858|}
old_stun_init_error_response_str:
  923|  4.07k|                                      bool include_reason_string) {
  924|       |
  925|  4.07k|  old_stun_init_command_str(stun_make_error_response(method), buf, len, cookie);
  926|       |
  927|       |  stun_init_error_response_common_str(buf, len, error_code, reason, id, include_reason_string, true);
  928|  4.07k|}
stun_init_error_response_str:
  931|  24.4k|                                  const uint8_t *reason, stun_tid *id, bool include_reason_string) {
  932|       |
  933|  24.4k|  stun_init_command_str(stun_make_error_response(method), buf, len);
  934|       |
  935|       |  stun_init_error_response_common_str(buf, len, error_code, reason, id, include_reason_string, false);
  936|  24.4k|}
stun_init_channel_message_str:
  940|  1.67k|bool stun_init_channel_message_str(uint16_t chnumber, uint8_t *buf, size_t *len, int length, bool do_padding) {
  941|  1.67k|  uint16_t rlen = (uint16_t)length;
  942|       |
  943|  1.67k|  if (length < 0 || (MAX_STUN_MESSAGE_SIZE < (4 + length))) {
  ------------------
  |  |  221|  1.67k|#define MAX_STUN_MESSAGE_SIZE (65507)
  ------------------
  |  Branch (943:7): [True: 0, False: 1.67k]
  |  Branch (943:21): [True: 0, False: 1.67k]
  ------------------
  944|      0|    return false;
  945|      0|  }
  946|  1.67k|  turn_write_u16(buf, chnumber);
  947|  1.67k|  turn_write_u16(buf + 2, (uint16_t)length);
  948|       |
  949|  1.67k|  if (do_padding && (rlen & 0x0003)) {
  ------------------
  |  Branch (949:7): [True: 653, False: 1.02k]
  |  Branch (949:21): [True: 444, False: 209]
  ------------------
  950|    444|    const uint16_t padded = ((rlen >> 2) + 1) << 2;
  951|       |    // Zero the pad bytes so stale buffer contents are not leaked on the wire
  952|       |    // (matches the padding handling in stun_attr_add_str).
  953|    444|    memset(buf + 4 + rlen, 0, (size_t)(padded - rlen));
  954|    444|    rlen = padded;
  955|    444|  }
  956|       |
  957|  1.67k|  *len = 4 + rlen;
  958|       |
  959|       |  return true;
  960|  1.67k|}
stun_is_channel_message_str:
  962|  9.64k|bool stun_is_channel_message_str(const uint8_t *buf, size_t *blen, uint16_t *chnumber, bool mandatory_padding) {
  963|  9.64k|  uint16_t datalen_header;
  964|  9.64k|  uint16_t datalen_actual;
  965|       |
  966|  9.64k|  if (!blen || (*blen < 4)) {
  ------------------
  |  Branch (966:7): [True: 0, False: 9.64k]
  |  Branch (966:16): [True: 562, False: 9.08k]
  ------------------
  967|    562|    return false;
  968|    562|  }
  969|       |
  970|  9.08k|  const uint16_t chn = turn_read_u16(buf);
  971|  9.08k|  if (!STUN_VALID_CHANNEL(chn)) {
  ------------------
  |  |  163|  9.08k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (163:34): [True: 6.39k, False: 2.69k]
  |  |  |  Branch (163:53): [True: 5.65k, False: 738]
  |  |  ------------------
  ------------------
  972|  3.43k|    return false;
  973|  3.43k|  }
  974|       |
  975|       |  /* Clamp to uint16_t range for comparison without mutating the caller's
  976|       |   * *blen — the modification to *blen at the end of this function is
  977|       |   * intentional (it reports actual message length consumed), but clamping
  978|       |   * during validation must not alter the caller's view of the buffer size
  979|       |   * if the function later returns false (issue #1837). */
  980|  5.65k|  const uint16_t blen16 = (*blen > (uint16_t)-1) ? (uint16_t)-1 : (uint16_t)*blen;
  ------------------
  |  Branch (980:27): [True: 0, False: 5.65k]
  ------------------
  981|  5.65k|  datalen_actual = blen16 - 4;
  982|  5.65k|  datalen_header = turn_read_u16(buf + 2);
  983|       |
  984|  5.65k|  if (datalen_header > datalen_actual) {
  ------------------
  |  Branch (984:7): [True: 1.69k, False: 3.96k]
  ------------------
  985|  1.69k|    return false;
  986|  1.69k|  }
  987|       |
  988|  3.96k|  if (datalen_header != datalen_actual) {
  ------------------
  |  Branch (988:7): [True: 996, False: 2.96k]
  ------------------
  989|       |
  990|       |    /* maybe there are padding bytes for 32-bit alignment. Mandatory for TCP. Optional for UDP */
  991|       |
  992|    996|    if (datalen_actual & 0x0003) {
  ------------------
  |  Branch (992:9): [True: 260, False: 736]
  ------------------
  993|       |
  994|    260|      if (mandatory_padding) {
  ------------------
  |  Branch (994:11): [True: 130, False: 130]
  ------------------
  995|    130|        return false;
  996|    130|      } else if (datalen_header == 0) {
  ------------------
  |  Branch (996:18): [True: 27, False: 103]
  ------------------
  997|     27|        return false;
  998|    103|      } else {
  999|    103|        const uint16_t diff = datalen_actual - datalen_header;
 1000|    103|        if (diff > 3) {
  ------------------
  |  Branch (1000:13): [True: 73, False: 30]
  ------------------
 1001|     73|          return false;
 1002|     73|        }
 1003|    103|      }
 1004|    260|    }
 1005|    996|  }
 1006|       |
 1007|  3.73k|  *blen = datalen_header + 4;
 1008|       |
 1009|  3.73k|  if (chnumber) {
  ------------------
  |  Branch (1009:7): [True: 3.73k, False: 0]
  ------------------
 1010|  3.73k|    *chnumber = chn;
 1011|  3.73k|  }
 1012|       |
 1013|       |  return true;
 1014|  3.96k|}
is_http:
 1062|  2.51k|int is_http(const char *s, size_t blen) {
 1063|  2.51k|  if (s && blen >= 12) {
  ------------------
  |  Branch (1063:7): [True: 2.51k, False: 0]
  |  Branch (1063:12): [True: 2.04k, False: 462]
  ------------------
 1064|  2.04k|    if (has_prefix(s, blen, "GET ", false) || has_prefix(s, blen, "POST ", false) ||
  ------------------
  |  Branch (1064:9): [True: 82, False: 1.96k]
  |  Branch (1064:47): [True: 278, False: 1.68k]
  ------------------
 1065|  1.68k|        has_prefix(s, blen, "DELETE ", false) || has_prefix(s, blen, "PUT ", false)) {
  ------------------
  |  Branch (1065:9): [True: 4, False: 1.68k]
  |  Branch (1065:50): [True: 416, False: 1.26k]
  ------------------
 1066|    780|      const char *sp = findstr(s + 4, blen - 4, " HTTP/", false);
 1067|    780|      if (sp) {
  ------------------
  |  Branch (1067:11): [True: 734, False: 46]
  ------------------
 1068|    734|        sp += 6;
 1069|    734|        const size_t diff_blen = sp - s;
 1070|    734|        if (diff_blen + 4 <= blen) {
  ------------------
  |  Branch (1070:13): [True: 702, False: 32]
  ------------------
 1071|    702|          sp = findstr(sp, blen - diff_blen, "\r\n\r\n", false);
 1072|    702|          if (sp) {
  ------------------
  |  Branch (1072:15): [True: 642, False: 60]
  ------------------
 1073|    642|            int ret_len = (int)(sp - s + 4);
 1074|    642|            const char *clheader = "content-length: ";
 1075|    642|            const char *cl = findstr(s, sp - s, clheader, true);
 1076|    642|            if (cl) {
  ------------------
  |  Branch (1076:17): [True: 438, False: 204]
  ------------------
 1077|    438|              const unsigned long clen = strtoul(cl + strlen(clheader), NULL, 10);
 1078|    438|              if (clen > 0 && clen < (0x0FFFFFFF)) {
  ------------------
  |  Branch (1078:19): [True: 426, False: 12]
  |  Branch (1078:31): [True: 184, False: 242]
  ------------------
 1079|    184|                ret_len += (int)clen;
 1080|    184|              }
 1081|    438|            }
 1082|    642|            return ret_len;
 1083|    642|          }
 1084|    702|        }
 1085|    734|      }
 1086|    780|    }
 1087|  2.04k|  }
 1088|  1.86k|  return 0;
 1089|  2.51k|}
stun_get_message_len_str:
 1091|  2.93k|int stun_get_message_len_str(uint8_t *buf, size_t blen, int padding, size_t *app_len) {
 1092|  2.93k|  if (buf && blen) {
  ------------------
  |  Branch (1092:7): [True: 2.93k, False: 0]
  |  Branch (1092:14): [True: 2.93k, False: 0]
  ------------------
 1093|       |    /* STUN request/response ? */
 1094|  2.93k|    if (buf && blen >= STUN_HEADER_LENGTH) {
  ------------------
  |  |   46|  2.93k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (1094:9): [True: 2.93k, False: 0]
  |  Branch (1094:16): [True: 2.24k, False: 694]
  ------------------
 1095|  2.24k|      if (!STUN_VALID_CHANNEL(turn_read_u16(buf))) {
  ------------------
  |  |  163|  2.24k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (163:34): [True: 1.12k, False: 1.11k]
  |  |  |  Branch (163:53): [True: 960, False: 168]
  |  |  ------------------
  ------------------
 1096|  1.28k|        if ((((uint8_t)buf[0]) & ((uint8_t)(0xC0))) == 0) {
  ------------------
  |  Branch (1096:13): [True: 1.11k, False: 168]
  ------------------
 1097|  1.11k|          if (turn_read_u32(buf + 4) == STUN_MAGIC_COOKIE) {
  ------------------
  |  |   60|  1.11k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (1097:15): [True: 490, False: 626]
  ------------------
 1098|       |            /* Use uint32_t to avoid uint16_t truncation overflow when the body
 1099|       |             * length is near 0xFFFF: e.g. 65532 + STUN_HEADER_LENGTH (20) =
 1100|       |             * 65552, which wraps to 16 in uint16_t and lets the truncated value
 1101|       |             * pass the bounds check, desynchronizing TCP/TLS framing. Mirrors
 1102|       |             * the channel-data path below. */
 1103|    490|            uint32_t len = (uint32_t)turn_read_u16(buf + 2);
 1104|    490|            if ((len & 0x0003u) == 0) {
  ------------------
  |  Branch (1104:17): [True: 468, False: 22]
  ------------------
 1105|    468|              len += STUN_HEADER_LENGTH;
  ------------------
  |  |   46|    468|#define STUN_HEADER_LENGTH (20)
  ------------------
 1106|    468|              if (len <= blen) {
  ------------------
  |  Branch (1106:19): [True: 428, False: 40]
  ------------------
 1107|    428|                *app_len = len;
 1108|    428|                return (int)len;
 1109|    428|              }
 1110|    468|            }
 1111|    490|          }
 1112|  1.11k|        }
 1113|  1.28k|      }
 1114|  2.24k|    }
 1115|       |
 1116|       |    // HTTP request ?
 1117|  2.51k|    {
 1118|  2.51k|      const int http_len = is_http(((char *)buf), blen);
 1119|  2.51k|      if ((http_len > 0) && ((size_t)http_len <= blen)) {
  ------------------
  |  Branch (1119:11): [True: 642, False: 1.86k]
  |  Branch (1119:29): [True: 460, False: 182]
  ------------------
 1120|    460|        *app_len = (size_t)http_len;
 1121|    460|        return http_len;
 1122|    460|      }
 1123|  2.51k|    }
 1124|       |
 1125|       |    /* STUN channel ? */
 1126|  2.05k|    if (blen >= 4) {
  ------------------
  |  Branch (1126:9): [True: 2.05k, False: 0]
  ------------------
 1127|  2.05k|      const uint16_t chn = turn_read_u16(buf);
 1128|  2.05k|      if (STUN_VALID_CHANNEL(chn)) {
  ------------------
  |  |  163|  2.05k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (163:34): [True: 1.10k, False: 944]
  |  |  |  Branch (163:53): [True: 734, False: 372]
  |  |  ------------------
  ------------------
 1129|       |
 1130|       |        /* Use uint32_t to avoid uint16_t truncation overflow when data_len is
 1131|       |         * near 0xFFFF: 4 + 0xFFFF = 65539, which wraps to 3 in uint16_t and
 1132|       |         * causes TCP framing bypass (CVE candidate, issue #1837). */
 1133|    734|        uint32_t bret = 4u + (uint32_t)turn_read_u16(buf + 2);
 1134|       |
 1135|    734|        *app_len = bret;
 1136|       |
 1137|    734|        if (padding && (bret & 0x0003u)) {
  ------------------
  |  Branch (1137:13): [True: 367, False: 367]
  |  Branch (1137:24): [True: 119, False: 248]
  ------------------
 1138|    119|          bret = ((bret >> 2) + 1u) << 2;
 1139|    119|        }
 1140|       |
 1141|    734|        if (bret <= blen) {
  ------------------
  |  Branch (1141:13): [True: 310, False: 424]
  ------------------
 1142|    310|          return (int)bret;
 1143|    310|        }
 1144|    734|      }
 1145|  2.05k|    }
 1146|  2.05k|  }
 1147|       |
 1148|  1.74k|  return -1;
 1149|  2.93k|}
stun_set_allocate_request_str:
 1154|  3.35k|                                   bool mobile, const char *rt, int ep) {
 1155|       |
 1156|  3.35k|  stun_init_request_str(STUN_METHOD_ALLOCATE, buf, len);
  ------------------
  |  |   82|  3.35k|#define STUN_METHOD_ALLOCATE (0x0003)
  ------------------
 1157|       |
 1158|       |  // REQUESTED-TRANSPORT
 1159|  3.35k|  {
 1160|  3.35k|    uint8_t field[4];
 1161|  3.35k|    field[0] = transport;
 1162|  3.35k|    field[1] = 0;
 1163|  3.35k|    field[2] = 0;
 1164|  3.35k|    field[3] = 0;
 1165|  3.35k|    if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_REQUESTED_TRANSPORT, field, sizeof(field))) {
  ------------------
  |  |  124|  3.35k|#define STUN_ATTRIBUTE_REQUESTED_TRANSPORT (0x0019)
  ------------------
  |  Branch (1165:9): [True: 0, False: 3.35k]
  ------------------
 1166|      0|      return false;
 1167|      0|    }
 1168|  3.35k|  }
 1169|       |
 1170|       |  // LIFETIME
 1171|  3.35k|  {
 1172|  3.35k|    if (lifetime < 1) {
  ------------------
  |  Branch (1172:9): [True: 268, False: 3.08k]
  ------------------
 1173|    268|      lifetime = STUN_DEFAULT_ALLOCATE_LIFETIME;
  ------------------
  |  |   73|    268|#define STUN_DEFAULT_ALLOCATE_LIFETIME (600)
  ------------------
 1174|    268|    }
 1175|  3.35k|    uint32_t field = nswap32(lifetime);
  ------------------
  |  |   87|  3.35k|#define nswap32(ul) ntohl(ul)
  ------------------
 1176|  3.35k|    if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_LIFETIME, (uint8_t *)(&field), sizeof(field))) {
  ------------------
  |  |  118|  3.35k|#define STUN_ATTRIBUTE_LIFETIME (0x000D)
  ------------------
  |  Branch (1176:9): [True: 0, False: 3.35k]
  ------------------
 1177|      0|      return false;
 1178|      0|    }
 1179|  3.35k|  }
 1180|       |
 1181|       |  // MICE
 1182|  3.35k|  if (mobile) {
  ------------------
  |  Branch (1182:7): [True: 1.67k, False: 1.67k]
  ------------------
 1183|  1.67k|    if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_MOBILITY_TICKET, (const uint8_t *)"", 0)) {
  ------------------
  |  |   47|  1.67k|#define STUN_ATTRIBUTE_MOBILITY_TICKET (0x8030)
  ------------------
  |  Branch (1183:9): [True: 0, False: 1.67k]
  ------------------
 1184|      0|      return false;
 1185|      0|    }
 1186|  1.67k|  }
 1187|       |
 1188|  3.35k|  if (ep > -1) {
  ------------------
  |  Branch (1188:7): [True: 2.55k, False: 800]
  ------------------
 1189|  2.55k|    uint8_t value = ep ? 0x80 : 0x00;
  ------------------
  |  Branch (1189:21): [True: 1.56k, False: 994]
  ------------------
 1190|  2.55k|    if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_EVEN_PORT, (const uint8_t *)&value, 1)) {
  ------------------
  |  |  123|  2.55k|#define STUN_ATTRIBUTE_EVEN_PORT (0x0018)
  ------------------
  |  Branch (1190:9): [True: 0, False: 2.55k]
  ------------------
 1191|      0|      return false;
 1192|      0|    }
 1193|  2.55k|  }
 1194|       |
 1195|       |  // RESERVATION-TOKEN, EVEN-PORT and DUAL-ALLOCATION are mutually exclusive:
 1196|  3.35k|  if (rt) {
  ------------------
  |  Branch (1196:7): [True: 1.00k, False: 2.35k]
  ------------------
 1197|       |
 1198|  1.00k|    stun_attr_add_str(buf, len, STUN_ATTRIBUTE_RESERVATION_TOKEN, (const uint8_t *)rt, 8);
  ------------------
  |  |  127|  1.00k|#define STUN_ATTRIBUTE_RESERVATION_TOKEN (0x0022)
  ------------------
 1199|       |
 1200|  2.35k|  } else {
 1201|       |
 1202|       |    // ADRESS-FAMILY
 1203|  2.35k|    if (af4 && !af6) {
  ------------------
  |  Branch (1203:9): [True: 1.15k, False: 1.20k]
  |  Branch (1203:16): [True: 360, False: 791]
  ------------------
 1204|    360|      uint8_t field[4];
 1205|    360|      field[0] = (uint8_t)STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV4;
  ------------------
  |  |  168|    360|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV4 (0x01)
  ------------------
 1206|    360|      field[1] = 0;
 1207|    360|      field[2] = 0;
 1208|    360|      field[3] = 0;
 1209|    360|      if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY, field, sizeof(field))) {
  ------------------
  |  |  108|    360|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY (0x0017)
  ------------------
  |  Branch (1209:11): [True: 0, False: 360]
  ------------------
 1210|      0|        return false;
 1211|      0|      }
 1212|    360|    }
 1213|       |
 1214|  2.35k|    if (af6 && !af4) {
  ------------------
  |  Branch (1214:9): [True: 1.23k, False: 1.11k]
  |  Branch (1214:16): [True: 442, False: 791]
  ------------------
 1215|    442|      uint8_t field[4];
 1216|    442|      field[0] = (uint8_t)STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6;
  ------------------
  |  |  169|    442|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6 (0x02)
  ------------------
 1217|    442|      field[1] = 0;
 1218|    442|      field[2] = 0;
 1219|    442|      field[3] = 0;
 1220|    442|      if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY, field, sizeof(field))) {
  ------------------
  |  |  108|    442|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY (0x0017)
  ------------------
  |  Branch (1220:11): [True: 0, False: 442]
  ------------------
 1221|      0|        return false;
 1222|      0|      }
 1223|    442|    }
 1224|       |
 1225|  2.35k|    if (af4 && af6) {
  ------------------
  |  Branch (1225:9): [True: 1.15k, False: 1.20k]
  |  Branch (1225:16): [True: 791, False: 360]
  ------------------
 1226|    791|      uint8_t field[4];
 1227|    791|      field[0] = (uint8_t)STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6;
  ------------------
  |  |  169|    791|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6 (0x02)
  ------------------
 1228|    791|      field[1] = 0;
 1229|    791|      field[2] = 0;
 1230|    791|      field[3] = 0;
 1231|    791|      if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_ADDITIONAL_ADDRESS_FAMILY, field, sizeof(field))) {
  ------------------
  |  |  144|    791|#define STUN_ATTRIBUTE_ADDITIONAL_ADDRESS_FAMILY (0x8000)
  ------------------
  |  Branch (1231:11): [True: 0, False: 791]
  ------------------
 1232|      0|        return false;
 1233|      0|      }
 1234|    791|    }
 1235|  2.35k|  }
 1236|       |
 1237|  3.35k|  return true;
 1238|  3.35k|}
stun_set_allocate_response_str:
 1243|  16.7k|                                    uint64_t reservation_token, char *mobile_id, bool include_reason_string) {
 1244|       |
 1245|  16.7k|  if (!error_code) {
  ------------------
  |  Branch (1245:7): [True: 10.0k, False: 6.70k]
  ------------------
 1246|       |
 1247|  10.0k|    stun_init_success_response_str(STUN_METHOD_ALLOCATE, buf, len, tid);
  ------------------
  |  |   82|  10.0k|#define STUN_METHOD_ALLOCATE (0x0003)
  ------------------
 1248|       |
 1249|  10.0k|    if (relayed_addr1) {
  ------------------
  |  Branch (1249:9): [True: 10.0k, False: 0]
  ------------------
 1250|  10.0k|      if (!stun_attr_add_addr_str(buf, len, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, relayed_addr1)) {
  ------------------
  |  |  122|  10.0k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  |  Branch (1250:11): [True: 0, False: 10.0k]
  ------------------
 1251|      0|        return false;
 1252|      0|      }
 1253|  10.0k|    }
 1254|       |
 1255|  10.0k|    if (relayed_addr2) {
  ------------------
  |  Branch (1255:9): [True: 5.63k, False: 4.43k]
  ------------------
 1256|  5.63k|      if (!stun_attr_add_addr_str(buf, len, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, relayed_addr2)) {
  ------------------
  |  |  122|  5.63k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  |  Branch (1256:11): [True: 0, False: 5.63k]
  ------------------
 1257|      0|        return false;
 1258|      0|      }
 1259|  5.63k|    }
 1260|       |
 1261|  10.0k|    if (reflexive_addr) {
  ------------------
  |  Branch (1261:9): [True: 6.70k, False: 3.35k]
  ------------------
 1262|  6.70k|      if (!stun_attr_add_addr_str(buf, len, STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS, reflexive_addr)) {
  ------------------
  |  |  109|  6.70k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (1262:11): [True: 0, False: 6.70k]
  ------------------
 1263|      0|        return false;
 1264|      0|      }
 1265|  6.70k|    }
 1266|       |
 1267|  10.0k|    if (reservation_token) {
  ------------------
  |  Branch (1267:9): [True: 6.57k, False: 3.49k]
  ------------------
 1268|  6.57k|      reservation_token = nswap64(reservation_token);
  ------------------
  |  |   88|  6.57k|#define nswap64(ull) ioa_ntoh64(ull)
  |  |  ------------------
  |  |  |  |  115|  6.57k|#define ioa_ntoh64 _ioa_ntoh64
  |  |  ------------------
  ------------------
 1269|  6.57k|      stun_attr_add_str(buf, len, STUN_ATTRIBUTE_RESERVATION_TOKEN, (uint8_t *)(&reservation_token), 8);
  ------------------
  |  |  127|  6.57k|#define STUN_ATTRIBUTE_RESERVATION_TOKEN (0x0022)
  ------------------
 1270|  6.57k|    }
 1271|       |
 1272|  10.0k|    {
 1273|  10.0k|      if (lifetime < 1) {
  ------------------
  |  Branch (1273:11): [True: 3.72k, False: 6.33k]
  ------------------
 1274|  3.72k|        lifetime = STUN_DEFAULT_ALLOCATE_LIFETIME;
  ------------------
  |  |   73|  3.72k|#define STUN_DEFAULT_ALLOCATE_LIFETIME (600)
  ------------------
 1275|  6.33k|      } else if (lifetime > max_lifetime) {
  ------------------
  |  Branch (1275:18): [True: 4.61k, False: 1.72k]
  ------------------
 1276|  4.61k|        lifetime = max_lifetime;
 1277|  4.61k|      }
 1278|       |
 1279|  10.0k|      uint32_t field = nswap32(lifetime);
  ------------------
  |  |   87|  10.0k|#define nswap32(ul) ntohl(ul)
  ------------------
 1280|  10.0k|      if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_LIFETIME, (uint8_t *)(&field), sizeof(field))) {
  ------------------
  |  |  118|  10.0k|#define STUN_ATTRIBUTE_LIFETIME (0x000D)
  ------------------
  |  Branch (1280:11): [True: 0, False: 10.0k]
  ------------------
 1281|      0|        return false;
 1282|      0|      }
 1283|  10.0k|    }
 1284|       |
 1285|  10.0k|    if (mobile_id && *mobile_id) {
  ------------------
  |  Branch (1285:9): [True: 6.70k, False: 3.35k]
  |  Branch (1285:22): [True: 4.66k, False: 2.04k]
  ------------------
 1286|  4.66k|      if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_MOBILITY_TICKET, (uint8_t *)mobile_id, (int)strlen(mobile_id))) {
  ------------------
  |  |   47|  4.66k|#define STUN_ATTRIBUTE_MOBILITY_TICKET (0x8030)
  ------------------
  |  Branch (1286:11): [True: 0, False: 4.66k]
  ------------------
 1287|      0|        return false;
 1288|      0|      }
 1289|  4.66k|    }
 1290|       |
 1291|  10.0k|  } else {
 1292|  6.70k|    stun_init_error_response_str(STUN_METHOD_ALLOCATE, buf, len, error_code, reason, tid, include_reason_string);
  ------------------
  |  |   82|  6.70k|#define STUN_METHOD_ALLOCATE (0x0003)
  ------------------
 1293|  6.70k|  }
 1294|       |
 1295|  16.7k|  return true;
 1296|  16.7k|}
stun_set_channel_bind_request_str:
 1301|  10.0k|                                           uint16_t channel_number) {
 1302|       |
 1303|  10.0k|  if (!STUN_VALID_CHANNEL_BIND(channel_number)) {
  ------------------
  |  |  162|  10.0k|#define STUN_VALID_CHANNEL_BIND(chn) ((chn) >= 0x4000 && (chn) <= 0x4FFF)
  |  |  ------------------
  |  |  |  Branch (162:39): [True: 8.13k, False: 1.92k]
  |  |  |  Branch (162:58): [True: 2.92k, False: 5.20k]
  |  |  ------------------
  ------------------
 1304|  7.13k|    channel_number = 0x4000 + ((uint16_t)(((uint32_t)turn_random_number()) % (0x4FFF - 0x4000 + 1)));
 1305|  7.13k|  }
 1306|       |
 1307|  10.0k|  stun_init_request_str(STUN_METHOD_CHANNEL_BIND, buf, len);
  ------------------
  |  |   87|  10.0k|#define STUN_METHOD_CHANNEL_BIND (0x0009)
  ------------------
 1308|       |
 1309|  10.0k|  if (!stun_attr_add_channel_number_str(buf, len, channel_number)) {
  ------------------
  |  Branch (1309:7): [True: 0, False: 10.0k]
  ------------------
 1310|      0|    return 0;
 1311|      0|  }
 1312|       |
 1313|  10.0k|  if (!peer_addr) {
  ------------------
  |  Branch (1313:7): [True: 5.43k, False: 4.62k]
  ------------------
 1314|  5.43k|    ioa_addr ca;
 1315|  5.43k|    memset(&ca, 0, sizeof(ioa_addr));
 1316|       |
 1317|  5.43k|    if (!stun_attr_add_addr_str(buf, len, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &ca)) {
  ------------------
  |  |  120|  5.43k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  |  Branch (1317:9): [True: 0, False: 5.43k]
  ------------------
 1318|      0|      return 0;
 1319|      0|    }
 1320|  5.43k|  } else {
 1321|  4.62k|    if (!stun_attr_add_addr_str(buf, len, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, peer_addr)) {
  ------------------
  |  |  120|  4.62k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  |  Branch (1321:9): [True: 0, False: 4.62k]
  ------------------
 1322|      0|      return 0;
 1323|      0|    }
 1324|  4.62k|  }
 1325|       |
 1326|  10.0k|  return channel_number;
 1327|  10.0k|}
stun_set_channel_bind_response_str:
 1330|  10.0k|                                        bool include_reason_string) {
 1331|  10.0k|  if (!error_code) {
  ------------------
  |  Branch (1331:7): [True: 5.03k, False: 5.03k]
  ------------------
 1332|  5.03k|    stun_init_success_response_str(STUN_METHOD_CHANNEL_BIND, buf, len, tid);
  ------------------
  |  |   87|  5.03k|#define STUN_METHOD_CHANNEL_BIND (0x0009)
  ------------------
 1333|  5.03k|  } else {
 1334|  5.03k|    stun_init_error_response_str(STUN_METHOD_CHANNEL_BIND, buf, len, error_code, reason, tid, include_reason_string);
  ------------------
  |  |   87|  5.03k|#define STUN_METHOD_CHANNEL_BIND (0x0009)
  ------------------
 1335|  5.03k|  }
 1336|  10.0k|}
stun_set_binding_request_str:
 1340|  3.35k|void stun_set_binding_request_str(uint8_t *buf, size_t *len) { stun_init_request_str(STUN_METHOD_BINDING, buf, len); }
  ------------------
  |  |   81|  3.35k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
stun_set_binding_response_str:
 1346|  23.4k|{
 1347|  23.4k|  if (!error_code) {
  ------------------
  |  Branch (1347:7): [True: 11.7k, False: 11.7k]
  ------------------
 1348|  11.7k|    if (!old_stun) {
  ------------------
  |  Branch (1348:9): [True: 7.66k, False: 4.07k]
  ------------------
 1349|  7.66k|      stun_init_success_response_str(STUN_METHOD_BINDING, buf, len, tid);
  ------------------
  |  |   81|  7.66k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
 1350|  7.66k|    } else {
 1351|  4.07k|      old_stun_init_success_response_str(STUN_METHOD_BINDING, buf, len, tid, cookie);
  ------------------
  |  |   81|  4.07k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
 1352|  4.07k|    }
 1353|  11.7k|    if (!old_stun && reflexive_addr) {
  ------------------
  |  Branch (1353:9): [True: 7.66k, False: 4.07k]
  |  Branch (1353:22): [True: 7.66k, False: 0]
  ------------------
 1354|  7.66k|      if (!stun_attr_add_addr_str(buf, len, STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS, reflexive_addr)) {
  ------------------
  |  |  109|  7.66k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (1354:11): [True: 0, False: 7.66k]
  ------------------
 1355|      0|        return false;
 1356|      0|      }
 1357|  7.66k|    }
 1358|       |    /* MAPPED-ADDRESS is the only address attribute RFC 3489 defines, so the old-STUN
 1359|       |     * path always needs it. On the modern path it is purely a backward-compatibility
 1360|       |     * courtesy for clients that cannot parse XOR-MAPPED-ADDRESS, and it widens the
 1361|       |     * response, so it stays opt-in there. */
 1362|  11.7k|    if (reflexive_addr) {
  ------------------
  |  Branch (1362:9): [True: 11.7k, False: 0]
  ------------------
 1363|  11.7k|      if ((old_stun || stun_backward_compatibility) &&
  ------------------
  |  Branch (1363:12): [True: 4.07k, False: 7.66k]
  |  Branch (1363:24): [True: 5.30k, False: 2.36k]
  ------------------
 1364|  9.37k|          !stun_attr_add_addr_str(buf, len, STUN_ATTRIBUTE_MAPPED_ADDRESS, reflexive_addr)) {
  ------------------
  |  |   95|  9.37k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
  |  Branch (1364:11): [True: 0, False: 9.37k]
  ------------------
 1365|      0|        return false;
 1366|      0|      }
 1367|  11.7k|    }
 1368|  11.7k|  } else if (!old_stun) {
  ------------------
  |  Branch (1368:14): [True: 7.66k, False: 4.07k]
  ------------------
 1369|  7.66k|    stun_init_error_response_str(STUN_METHOD_BINDING, buf, len, error_code, reason, tid, include_reason_string);
  ------------------
  |  |   81|  7.66k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
 1370|  7.66k|  } else {
 1371|  4.07k|    old_stun_init_error_response_str(STUN_METHOD_BINDING, buf, len, error_code, reason, tid, cookie,
  ------------------
  |  |   81|  4.07k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
 1372|  4.07k|                                     include_reason_string);
 1373|  4.07k|  }
 1374|       |
 1375|  23.4k|  return true;
 1376|  23.4k|}
stun_is_binding_response_str:
 1391|  77.2k|bool stun_is_binding_response_str(const uint8_t *buf, size_t len) {
 1392|  77.2k|  if (stun_is_command_message_str(buf, len) && (stun_get_method_str(buf, len) == STUN_METHOD_BINDING)) {
  ------------------
  |  |   81|  69.2k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
  |  Branch (1392:7): [True: 69.2k, False: 7.94k]
  |  Branch (1392:48): [True: 21.4k, False: 47.8k]
  ------------------
 1393|  21.4k|    if (stun_is_response_str(buf, len)) {
  ------------------
  |  Branch (1393:9): [True: 17.6k, False: 3.75k]
  ------------------
 1394|  17.6k|      return true;
 1395|  17.6k|    }
 1396|  21.4k|  }
 1397|  59.5k|  return false;
 1398|  77.2k|}
stun_tid_from_message_str:
 1436|   150k|void stun_tid_from_message_str(const uint8_t *buf, size_t len, stun_tid *id) {
 1437|   150k|  UNUSED_ARG(len);
  ------------------
  |  |  216|   150k|  do {                                                                                                                 \
  |  |  217|   150k|    A = A;                                                                                                             \
  |  |  218|   150k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (218:12): [Folded, False: 150k]
  |  |  ------------------
  ------------------
 1438|   150k|  stun_tid_from_string(buf + 8, id);
 1439|   150k|}
stun_tid_message_cpy:
 1441|   135k|void stun_tid_message_cpy(uint8_t *buf, const stun_tid *id) {
 1442|   135k|  if (buf && id) {
  ------------------
  |  Branch (1442:7): [True: 135k, False: 0]
  |  Branch (1442:14): [True: 135k, False: 0]
  ------------------
 1443|   135k|    stun_tid_string_cpy(buf + 8, id);
 1444|   135k|  }
 1445|   135k|}
stun_tid_generate:
 1447|  78.8k|void stun_tid_generate(stun_tid *id) {
 1448|  78.8k|  if (id) {
  ------------------
  |  Branch (1448:7): [True: 78.8k, False: 0]
  ------------------
 1449|  78.8k|    turn_random_tid_size(id->tsx_id);
 1450|  78.8k|  }
 1451|  78.8k|}
stun_tid_generate_in_message_str:
 1453|  78.8k|void stun_tid_generate_in_message_str(uint8_t *buf, stun_tid *id) {
 1454|  78.8k|  stun_tid tmp;
 1455|  78.8k|  if (!id) {
  ------------------
  |  Branch (1455:7): [True: 77.1k, False: 1.67k]
  ------------------
 1456|  77.1k|    id = &tmp;
 1457|  77.1k|  }
 1458|  78.8k|  stun_tid_generate(id);
 1459|  78.8k|  stun_tid_message_cpy(buf, id);
 1460|  78.8k|}
stun_attr_get_type:
 1484|   901k|int stun_attr_get_type(stun_attr_ref attr) {
 1485|   901k|  if (attr) {
  ------------------
  |  Branch (1485:7): [True: 901k, False: 0]
  ------------------
 1486|   901k|    return (int)turn_read_u16(attr);
 1487|   901k|  }
 1488|      0|  return -1;
 1489|   901k|}
stun_attr_get_len:
 1491|  1.32M|int stun_attr_get_len(stun_attr_ref attr) {
 1492|  1.32M|  if (attr) {
  ------------------
  |  Branch (1492:7): [True: 1.32M, False: 0]
  ------------------
 1493|  1.32M|    return (int)turn_read_u16((const uint8_t *)attr + 2);
 1494|  1.32M|  }
 1495|      0|  return -1;
 1496|  1.32M|}
stun_attr_get_value:
 1498|   136k|const uint8_t *stun_attr_get_value(stun_attr_ref attr) {
 1499|   136k|  if (attr) {
  ------------------
  |  Branch (1499:7): [True: 136k, False: 0]
  ------------------
 1500|   136k|    const int len = (int)turn_read_u16((const uint8_t *)attr + 2);
 1501|   136k|    if (len < 1) {
  ------------------
  |  Branch (1501:9): [True: 5.17k, False: 130k]
  ------------------
 1502|  5.17k|      return NULL;
 1503|  5.17k|    }
 1504|   130k|    return ((const uint8_t *)attr) + 4;
 1505|   136k|  }
 1506|      0|  return NULL;
 1507|   136k|}
stun_attr_get_channel_number:
 1527|  11.7k|uint16_t stun_attr_get_channel_number(stun_attr_ref attr) {
 1528|  11.7k|  if (attr) {
  ------------------
  |  Branch (1528:7): [True: 11.7k, False: 0]
  ------------------
 1529|  11.7k|    const uint8_t *value = stun_attr_get_value(attr);
 1530|  11.7k|    if (value && (stun_attr_get_len(attr) >= 2)) {
  ------------------
  |  Branch (1530:9): [True: 11.7k, False: 0]
  |  Branch (1530:18): [True: 11.7k, False: 0]
  ------------------
 1531|  11.7k|      const uint16_t cn = turn_read_u16(value);
 1532|  11.7k|      if (STUN_VALID_CHANNEL(cn)) {
  ------------------
  |  |  163|  11.7k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (163:34): [True: 11.7k, False: 0]
  |  |  |  Branch (163:53): [True: 11.7k, False: 0]
  |  |  ------------------
  ------------------
 1533|  11.7k|        return cn;
 1534|  11.7k|      }
 1535|  11.7k|    }
 1536|  11.7k|  }
 1537|      0|  return 0;
 1538|  11.7k|}
stun_attr_is_addr:
 1561|   365k|bool stun_attr_is_addr(stun_attr_ref attr) {
 1562|       |
 1563|   365k|  if (attr) {
  ------------------
  |  Branch (1563:7): [True: 365k, False: 0]
  ------------------
 1564|   365k|    switch (stun_attr_get_type(attr)) {
 1565|  32.8k|    case STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS:
  ------------------
  |  |  109|  32.8k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (1565:5): [True: 32.8k, False: 332k]
  ------------------
 1566|  81.3k|    case STUN_ATTRIBUTE_XOR_PEER_ADDRESS:
  ------------------
  |  |  120|  81.3k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  |  Branch (1566:5): [True: 48.4k, False: 316k]
  ------------------
 1567|   132k|    case STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS:
  ------------------
  |  |  122|   132k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  |  Branch (1567:5): [True: 51.5k, False: 313k]
  ------------------
 1568|   166k|    case STUN_ATTRIBUTE_MAPPED_ADDRESS:
  ------------------
  |  |   95|   166k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
  |  Branch (1568:5): [True: 33.3k, False: 331k]
  ------------------
 1569|   170k|    case STUN_ATTRIBUTE_ALTERNATE_SERVER:
  ------------------
  |  |  114|   170k|#define STUN_ATTRIBUTE_ALTERNATE_SERVER (0x8023)
  ------------------
  |  Branch (1569:5): [True: 4.32k, False: 360k]
  ------------------
 1570|   172k|    case OLD_STUN_ATTRIBUTE_RESPONSE_ADDRESS:
  ------------------
  |  |   96|   172k|#define OLD_STUN_ATTRIBUTE_RESPONSE_ADDRESS (0x0002)
  ------------------
  |  Branch (1570:5): [True: 1.71k, False: 363k]
  ------------------
 1571|   173k|    case OLD_STUN_ATTRIBUTE_SOURCE_ADDRESS:
  ------------------
  |  |   98|   173k|#define OLD_STUN_ATTRIBUTE_SOURCE_ADDRESS (0x0004)
  ------------------
  |  Branch (1571:5): [True: 1.38k, False: 363k]
  ------------------
 1572|   174k|    case OLD_STUN_ATTRIBUTE_CHANGED_ADDRESS:
  ------------------
  |  |   99|   174k|#define OLD_STUN_ATTRIBUTE_CHANGED_ADDRESS (0x0005)
  ------------------
  |  Branch (1572:5): [True: 834, False: 364k]
  ------------------
 1573|   175k|    case OLD_STUN_ATTRIBUTE_REFLECTED_FROM:
  ------------------
  |  |  105|   175k|#define OLD_STUN_ATTRIBUTE_REFLECTED_FROM (0x000B)
  ------------------
  |  Branch (1573:5): [True: 612, False: 364k]
  ------------------
 1574|   177k|    case STUN_ATTRIBUTE_RESPONSE_ORIGIN:
  ------------------
  |  |  136|   177k|#define STUN_ATTRIBUTE_RESPONSE_ORIGIN (0x802B)
  ------------------
  |  Branch (1574:5): [True: 1.99k, False: 363k]
  ------------------
 1575|   178k|    case STUN_ATTRIBUTE_OTHER_ADDRESS:
  ------------------
  |  |  137|   178k|#define STUN_ATTRIBUTE_OTHER_ADDRESS (0x802C)
  ------------------
  |  Branch (1575:5): [True: 1.09k, False: 364k]
  ------------------
 1576|   178k|      return true;
 1577|      0|      break;
 1578|   187k|    default:;
  ------------------
  |  Branch (1578:5): [True: 187k, False: 178k]
  ------------------
 1579|   365k|    };
 1580|   187k|  }
 1581|   187k|  return false;
 1582|   365k|}
stun_attr_get_first_by_type_str:
 1604|  40.3k|stun_attr_ref stun_attr_get_first_by_type_str(const uint8_t *buf, size_t len, uint16_t attr_type) {
 1605|  40.3k|  stun_attr_ref attr = stun_attr_get_first_str(buf, len);
 1606|  71.1k|  while (attr) {
  ------------------
  |  Branch (1606:10): [True: 66.1k, False: 5.00k]
  ------------------
 1607|  66.1k|    if (stun_attr_get_type(attr) == attr_type) {
  ------------------
  |  Branch (1607:9): [True: 35.3k, False: 30.8k]
  ------------------
 1608|  35.3k|      return attr;
 1609|  35.3k|    }
 1610|  30.8k|    attr = stun_attr_get_next_str(buf, len, attr);
 1611|  30.8k|  }
 1612|       |
 1613|  5.00k|  return NULL;
 1614|  40.3k|}
stun_attr_get_first_str:
 1637|   289k|stun_attr_ref stun_attr_get_first_str(const uint8_t *buf, size_t len) {
 1638|   289k|  const int bufLen = stun_get_command_message_len_str(buf, len);
 1639|   289k|  if (bufLen > STUN_HEADER_LENGTH) {
  ------------------
  |  |   46|   289k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (1639:7): [True: 241k, False: 47.8k]
  ------------------
 1640|   241k|    stun_attr_ref attr = (stun_attr_ref)(buf + STUN_HEADER_LENGTH);
  ------------------
  |  |   46|   241k|#define STUN_HEADER_LENGTH (20)
  ------------------
 1641|   241k|    return stun_attr_check_valid(attr, bufLen - STUN_HEADER_LENGTH);
  ------------------
  |  |   46|   241k|#define STUN_HEADER_LENGTH (20)
  ------------------
 1642|   241k|  }
 1643|       |
 1644|  47.8k|  return NULL;
 1645|   289k|}
stun_attr_get_next_str:
 1647|   466k|stun_attr_ref stun_attr_get_next_str(const uint8_t *buf, size_t len, stun_attr_ref prev) {
 1648|   466k|  if (!prev) {
  ------------------
  |  Branch (1648:7): [True: 0, False: 466k]
  ------------------
 1649|      0|    return stun_attr_get_first_str(buf, len);
 1650|   466k|  } else {
 1651|   466k|    const uint8_t *end = buf + stun_get_command_message_len_str(buf, len);
 1652|   466k|    int attrlen = stun_attr_get_len(prev);
 1653|   466k|    const uint16_t rem4 = ((uint16_t)attrlen) & 0x0003;
 1654|   466k|    if (rem4) {
  ------------------
  |  Branch (1654:9): [True: 90.9k, False: 375k]
  ------------------
 1655|  90.9k|      attrlen = attrlen + 4 - (int)rem4;
 1656|  90.9k|    }
 1657|       |    /* Note the order here: operations on attrlen are untrusted as they may overflow */
 1658|   466k|    if (attrlen < end - (const uint8_t *)prev - 4) {
  ------------------
  |  Branch (1658:9): [True: 310k, False: 155k]
  ------------------
 1659|   310k|      const uint8_t *attr_end = (const uint8_t *)prev + 4 + attrlen;
 1660|   310k|      return stun_attr_check_valid(attr_end, end - attr_end);
 1661|   310k|    }
 1662|   155k|    return NULL;
 1663|   466k|  }
 1664|   466k|}
stun_attr_add_str:
 1666|   131k|bool stun_attr_add_str(uint8_t *buf, size_t *len, uint16_t attr, const uint8_t *avalue, int alen) {
 1667|   131k|  if (alen < 0) {
  ------------------
  |  Branch (1667:7): [True: 0, False: 131k]
  ------------------
 1668|      0|    alen = 0;
 1669|      0|  }
 1670|   131k|  uint8_t tmp[1];
 1671|   131k|  if (!avalue) {
  ------------------
  |  Branch (1671:7): [True: 0, False: 131k]
  ------------------
 1672|      0|    alen = 0;
 1673|      0|    avalue = tmp;
 1674|      0|  }
 1675|   131k|  const int clen = stun_get_command_message_len_str(buf, *len);
 1676|   131k|  int newlen = clen + 4 + alen;
 1677|   131k|  const int newlenrem4 = newlen & 0x00000003;
 1678|   131k|  int paddinglen = 0;
 1679|   131k|  if (newlenrem4) {
  ------------------
  |  Branch (1679:7): [True: 19.0k, False: 112k]
  ------------------
 1680|  19.0k|    paddinglen = 4 - newlenrem4;
 1681|  19.0k|    newlen = newlen + paddinglen;
 1682|  19.0k|  }
 1683|       |
 1684|   131k|  if (newlen >= MAX_STUN_MESSAGE_SIZE) {
  ------------------
  |  |  221|   131k|#define MAX_STUN_MESSAGE_SIZE (65507)
  ------------------
  |  Branch (1684:7): [True: 0, False: 131k]
  ------------------
 1685|      0|    return false;
 1686|      0|  }
 1687|       |
 1688|   131k|  uint8_t *attr_start = buf + clen;
 1689|       |
 1690|   131k|  stun_set_command_message_len_str(buf, newlen);
 1691|   131k|  *len = newlen;
 1692|       |
 1693|   131k|  turn_write_u16(attr_start, attr);
 1694|   131k|  turn_write_u16(attr_start + 2, (uint16_t)alen);
 1695|   131k|  if (alen > 0) {
  ------------------
  |  Branch (1695:7): [True: 129k, False: 2.16k]
  ------------------
 1696|   129k|    memcpy(attr_start + 4, avalue, alen);
 1697|   129k|  }
 1698|       |
 1699|       |  // Write 0 padding to not leak data
 1700|   131k|  memset(attr_start + 4 + alen, 0, paddinglen);
 1701|       |
 1702|       |  return true;
 1703|   131k|}
stun_attr_add_addr_str:
 1705|  51.1k|bool stun_attr_add_addr_str(uint8_t *buf, size_t *len, uint16_t attr_type, const ioa_addr *ca) {
 1706|       |
 1707|  51.1k|  stun_tid tid;
 1708|  51.1k|  stun_tid_from_message_str(buf, *len, &tid);
 1709|       |
 1710|  51.1k|  int xor_ed = 0;
 1711|  51.1k|  switch (attr_type) {
 1712|  14.3k|  case STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS:
  ------------------
  |  |  109|  14.3k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (1712:3): [True: 14.3k, False: 36.8k]
  ------------------
 1713|  26.1k|  case STUN_ATTRIBUTE_XOR_PEER_ADDRESS:
  ------------------
  |  |  120|  26.1k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  |  Branch (1713:3): [True: 11.7k, False: 39.4k]
  ------------------
 1714|  41.8k|  case STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS:
  ------------------
  |  |  122|  41.8k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  |  Branch (1714:3): [True: 15.6k, False: 35.4k]
  ------------------
 1715|  41.8k|    xor_ed = 1;
 1716|  41.8k|    break;
 1717|  9.37k|  default:;
  ------------------
  |  Branch (1717:3): [True: 9.37k, False: 41.8k]
  ------------------
 1718|  51.1k|  };
 1719|       |
 1720|  51.1k|  ioa_addr public_addr;
 1721|  51.1k|  map_addr_from_private_to_public(ca, &public_addr);
 1722|       |
 1723|  51.1k|  uint8_t cfield[64];
 1724|  51.1k|  int clen = 0;
 1725|  51.1k|  if (stun_addr_encode(&public_addr, cfield, &clen, xor_ed, STUN_MAGIC_COOKIE, tid.tsx_id) < 0) {
  ------------------
  |  |   60|  51.1k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (1725:7): [True: 0, False: 51.1k]
  ------------------
 1726|      0|    return false;
 1727|      0|  }
 1728|       |
 1729|  51.1k|  if (!stun_attr_add_str(buf, len, attr_type, (uint8_t *)(&cfield), clen)) {
  ------------------
  |  Branch (1729:7): [True: 0, False: 51.1k]
  ------------------
 1730|      0|    return false;
 1731|      0|  }
 1732|       |
 1733|  51.1k|  return true;
 1734|  51.1k|}
stun_attr_get_addr_str:
 1737|  95.7k|                            const ioa_addr *default_addr) {
 1738|  95.7k|  stun_tid tid;
 1739|  95.7k|  stun_tid_from_message_str(buf, len, &tid);
 1740|  95.7k|  ioa_addr public_addr;
 1741|       |
 1742|  95.7k|  addr_set_any(ca);
 1743|  95.7k|  addr_set_any(&public_addr);
 1744|       |
 1745|  95.7k|  const int attr_type = stun_attr_get_type(attr);
 1746|  95.7k|  if (attr_type < 0) {
  ------------------
  |  Branch (1746:7): [True: 0, False: 95.7k]
  ------------------
 1747|      0|    return false;
 1748|      0|  }
 1749|       |
 1750|  95.7k|  int xor_ed = 0;
 1751|  95.7k|  switch (attr_type) {
 1752|  23.4k|  case STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS:
  ------------------
  |  |  109|  23.4k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (1752:3): [True: 23.4k, False: 72.3k]
  ------------------
 1753|  50.1k|  case STUN_ATTRIBUTE_XOR_PEER_ADDRESS:
  ------------------
  |  |  120|  50.1k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  |  Branch (1753:3): [True: 26.7k, False: 69.0k]
  ------------------
 1754|  79.0k|  case STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS:
  ------------------
  |  |  122|  79.0k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  |  Branch (1754:3): [True: 28.8k, False: 66.8k]
  ------------------
 1755|  79.0k|    xor_ed = 1;
 1756|  79.0k|    break;
 1757|  16.7k|  default:;
  ------------------
  |  Branch (1757:3): [True: 16.7k, False: 79.0k]
  ------------------
 1758|  95.7k|  };
 1759|       |
 1760|  95.7k|  const uint8_t *cfield = stun_attr_get_value(attr);
 1761|  95.7k|  if (!cfield) {
  ------------------
  |  Branch (1761:7): [True: 5.17k, False: 90.5k]
  ------------------
 1762|  5.17k|    return false;
 1763|  5.17k|  }
 1764|       |
 1765|  90.5k|  if (stun_addr_decode(&public_addr, cfield, stun_attr_get_len(attr), xor_ed, STUN_MAGIC_COOKIE, tid.tsx_id) < 0) {
  ------------------
  |  |   60|  90.5k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (1765:7): [True: 5.29k, False: 85.2k]
  ------------------
 1766|  5.29k|    return false;
 1767|  5.29k|  }
 1768|       |
 1769|  85.2k|  map_addr_from_public_to_private(&public_addr, ca);
 1770|       |
 1771|  85.2k|  if (default_addr && addr_any_no_port(ca) && !addr_any_no_port(default_addr)) {
  ------------------
  |  Branch (1771:7): [True: 84.9k, False: 267]
  |  Branch (1771:23): [True: 10.9k, False: 74.0k]
  |  Branch (1771:47): [True: 10.9k, False: 0]
  ------------------
 1772|  10.9k|    const uint16_t port = addr_get_port(ca);
 1773|  10.9k|    addr_cpy(ca, default_addr);
 1774|  10.9k|    addr_set_port(ca, port);
 1775|  10.9k|  }
 1776|       |
 1777|       |  return true;
 1778|  90.5k|}
stun_attr_get_first_addr_str:
 1781|  94.6k|                                  const ioa_addr *default_addr) {
 1782|  94.6k|  stun_attr_ref attr = stun_attr_get_first_str(buf, len);
 1783|       |
 1784|   294k|  while (attr) {
  ------------------
  |  Branch (1784:10): [True: 234k, False: 60.6k]
  ------------------
 1785|   234k|    if (stun_attr_is_addr(attr) && (attr_type == stun_attr_get_type(attr))) {
  ------------------
  |  Branch (1785:9): [True: 127k, False: 107k]
  |  Branch (1785:36): [True: 44.5k, False: 82.4k]
  ------------------
 1786|  44.5k|      if (stun_attr_get_addr_str(buf, len, attr, ca, default_addr)) {
  ------------------
  |  Branch (1786:11): [True: 34.0k, False: 10.4k]
  ------------------
 1787|  34.0k|        return true;
 1788|  34.0k|      }
 1789|  44.5k|    }
 1790|   199k|    attr = stun_attr_get_next_str(buf, len, attr);
 1791|   199k|  }
 1792|       |
 1793|  60.6k|  return false;
 1794|  94.6k|}
stun_attr_add_channel_number_str:
 1796|  11.7k|bool stun_attr_add_channel_number_str(uint8_t *buf, size_t *len, uint16_t chnumber) {
 1797|       |
 1798|  11.7k|  uint16_t field[2];
 1799|  11.7k|  field[0] = nswap16(chnumber);
  ------------------
  |  |   86|  11.7k|#define nswap16(s) ntohs(s)
  ------------------
 1800|  11.7k|  field[1] = 0;
 1801|       |
 1802|  11.7k|  return stun_attr_add_str(buf, len, STUN_ATTRIBUTE_CHANNEL_NUMBER, (uint8_t *)(field), sizeof(field));
  ------------------
  |  |  117|  11.7k|#define STUN_ATTRIBUTE_CHANNEL_NUMBER (0x000C)
  ------------------
 1803|  11.7k|}
stun_attr_get_first_channel_number_str:
 1831|  77.1k|uint16_t stun_attr_get_first_channel_number_str(const uint8_t *buf, size_t len) {
 1832|       |
 1833|  77.1k|  stun_attr_ref attr = stun_attr_get_first_str(buf, len);
 1834|   181k|  while (attr) {
  ------------------
  |  Branch (1834:10): [True: 116k, False: 65.4k]
  ------------------
 1835|   116k|    if (stun_attr_get_type(attr) == STUN_ATTRIBUTE_CHANNEL_NUMBER) {
  ------------------
  |  |  117|   116k|#define STUN_ATTRIBUTE_CHANNEL_NUMBER (0x000C)
  ------------------
  |  Branch (1835:9): [True: 11.7k, False: 104k]
  ------------------
 1836|  11.7k|      const uint16_t ret = stun_attr_get_channel_number(attr);
 1837|  11.7k|      if (STUN_VALID_CHANNEL(ret)) {
  ------------------
  |  |  163|  11.7k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (163:34): [True: 11.7k, False: 0]
  |  |  |  Branch (163:53): [True: 11.7k, False: 0]
  |  |  ------------------
  ------------------
 1838|  11.7k|        return ret;
 1839|  11.7k|      }
 1840|  11.7k|    }
 1841|   104k|    attr = stun_attr_get_next_str(buf, len, attr);
 1842|   104k|  }
 1843|       |
 1844|  65.4k|  return 0;
 1845|  77.1k|}
ns_turn_msg.c:fuzz_prng_next:
  112|   243k|static uint64_t fuzz_prng_next(void) {
  113|   243k|  static uint64_t state = UINT64_C(0x9e3779b97f4a7c15);
  114|       |
  115|   243k|  state += UINT64_C(0x9e3779b97f4a7c15);
  116|   243k|  uint64_t z = state;
  117|   243k|  z = (z ^ (z >> 30)) * UINT64_C(0xbf58476d1ce4e5b9);
  118|       |  z = (z ^ (z >> 27)) * UINT64_C(0x94d049bb133111eb);
  119|   243k|  return z ^ (z >> 31);
  120|   243k|}
ns_turn_msg.c:stun_init_error_response_common_str:
  888|  28.5k|                                                stun_tid *id, bool include_reason_string, bool pad_reason_phrase) {
  889|       |
  890|  28.5k|  if (include_reason_string && (!reason || !strcmp((const char *)reason, "Unknown error"))) {
  ------------------
  |  Branch (890:7): [True: 19.0k, False: 9.46k]
  |  Branch (890:33): [True: 858, False: 18.1k]
  |  Branch (890:44): [True: 0, False: 18.1k]
  ------------------
  891|    858|    reason = get_default_reason(error_code);
  892|    858|  }
  893|       |
  894|  28.5k|  uint8_t avalue[513];
  895|  28.5k|  memset(avalue, 0, sizeof(avalue));
  896|  28.5k|  avalue[0] = 0;
  897|  28.5k|  avalue[1] = 0;
  898|  28.5k|  avalue[2] = (uint8_t)(error_code / 100);
  899|  28.5k|  avalue[3] = (uint8_t)(error_code % 100);
  900|  28.5k|  if (include_reason_string) {
  ------------------
  |  Branch (900:7): [True: 19.0k, False: 9.46k]
  ------------------
  901|  19.0k|    strncpy((char *)(avalue + 4), (const char *)reason, sizeof(avalue) - 4);
  902|  19.0k|  }
  903|  28.5k|  avalue[sizeof(avalue) - 1] = 0;
  904|  28.5k|  int alen = 4 + (int)strlen((const char *)(avalue + 4));
  905|       |
  906|       |  /* RFC 3489 Section 11.2.9 requires a reason phrase length that is a multiple of 4;
  907|       |   * RFC 8489 Section 14 requires the declared length to exclude padding. */
  908|  28.5k|  if (pad_reason_phrase) {
  ------------------
  |  Branch (908:7): [True: 4.07k, False: 24.4k]
  ------------------
  909|  4.07k|    const int rem = alen % 4;
  910|  4.07k|    if (rem) {
  ------------------
  |  Branch (910:9): [True: 1.95k, False: 2.11k]
  ------------------
  911|  1.95k|      alen += (4 - rem);
  912|  1.95k|    }
  913|  4.07k|  }
  914|       |
  915|  28.5k|  stun_attr_add_str(buf, len, STUN_ATTRIBUTE_ERROR_CODE, (uint8_t *)avalue, alen);
  ------------------
  |  |  103|  28.5k|#define STUN_ATTRIBUTE_ERROR_CODE (0x0009)
  ------------------
  916|  28.5k|  if (id) {
  ------------------
  |  Branch (916:7): [True: 28.5k, False: 0]
  ------------------
  917|  28.5k|    stun_tid_message_cpy(buf, id);
  918|  28.5k|  }
  919|  28.5k|}
ns_turn_msg.c:has_prefix:
 1053|  7.38k|static inline bool has_prefix(const char *buf, size_t blen, const char *prefix, bool ignore_case) {
 1054|  7.38k|  if (!buf || !prefix) {
  ------------------
  |  Branch (1054:7): [True: 0, False: 7.38k]
  |  Branch (1054:15): [True: 0, False: 7.38k]
  ------------------
 1055|      0|    return false;
 1056|      0|  }
 1057|       |
 1058|  7.38k|  const size_t prefix_len = strlen(prefix);
 1059|  7.38k|  return (prefix_len <= blen) && sheadof(prefix, buf, ignore_case);
  ------------------
  |  Branch (1059:10): [True: 7.38k, False: 0]
  |  Branch (1059:34): [True: 780, False: 6.60k]
  ------------------
 1060|  7.38k|}
ns_turn_msg.c:sheadof:
 1018|   723k|static inline bool sheadof(const char *head, const char *full, bool ignore_case) {
 1019|   792k|  while (*head) {
  ------------------
  |  Branch (1019:10): [True: 789k, False: 2.59k]
  ------------------
 1020|   789k|    if (*head != *full) {
  ------------------
  |  Branch (1020:9): [True: 725k, False: 64.5k]
  ------------------
 1021|   725k|      if (ignore_case && (tolower((unsigned char)*head) == tolower((unsigned char)*full))) {
  ------------------
  |  Branch (1021:11): [True: 287k, False: 437k]
  |  Branch (1021:26): [True: 4.74k, False: 282k]
  |  Branch (1021:27): [True: 0, False: 0]
  |  Branch (1021:27): [True: 0, False: 0]
  |  Branch (1021:27): [Folded, False: 287k]
  |  Branch (1021:60): [True: 0, False: 0]
  |  Branch (1021:60): [True: 0, False: 0]
  |  Branch (1021:60): [Folded, False: 287k]
  ------------------
 1022|       |        // OK
 1023|   720k|      } else {
 1024|   720k|        return false;
 1025|   720k|      }
 1026|   725k|    }
 1027|  69.2k|    ++head;
 1028|  69.2k|    ++full;
 1029|  69.2k|  }
 1030|  2.59k|  return true;
 1031|   723k|}
ns_turn_msg.c:findstr:
 1033|  2.12k|static inline const char *findstr(const char *hay, size_t slen, const char *needle, bool ignore_case) {
 1034|  2.12k|  const char *ret = NULL;
 1035|       |
 1036|  2.12k|  if (hay && slen && needle) {
  ------------------
  |  Branch (1036:7): [True: 2.12k, False: 0]
  |  Branch (1036:14): [True: 2.12k, False: 0]
  |  Branch (1036:22): [True: 2.12k, False: 0]
  ------------------
 1037|  2.12k|    const size_t nlen = strlen(needle);
 1038|  2.12k|    if (nlen <= slen) {
  ------------------
  |  Branch (1038:9): [True: 2.07k, False: 48]
  ------------------
 1039|  2.07k|      const size_t smax = slen - nlen + 1;
 1040|  2.07k|      const char *sp = hay;
 1041|   715k|      for (size_t i = 0; i < smax; ++i) {
  ------------------
  |  Branch (1041:26): [True: 715k, False: 262]
  ------------------
 1042|   715k|        if (sheadof(needle, sp + i, ignore_case)) {
  ------------------
  |  Branch (1042:13): [True: 1.81k, False: 713k]
  ------------------
 1043|  1.81k|          ret = sp + i;
 1044|  1.81k|          break;
 1045|  1.81k|        }
 1046|   715k|      }
 1047|  2.07k|    }
 1048|  2.12k|  }
 1049|       |
 1050|  2.12k|  return ret;
 1051|  2.12k|}
ns_turn_msg.c:stun_tid_from_string:
 1430|   150k|static void stun_tid_from_string(const uint8_t *s, stun_tid *id) {
 1431|   150k|  if (s && id) {
  ------------------
  |  Branch (1431:7): [True: 150k, False: 0]
  |  Branch (1431:12): [True: 150k, False: 0]
  ------------------
 1432|   150k|    memcpy(id->tsx_id, s, STUN_TID_SIZE);
  ------------------
  |  |   53|   150k|#define STUN_TID_SIZE (12)
  ------------------
 1433|   150k|  }
 1434|   150k|}
ns_turn_msg.c:stun_tid_string_cpy:
 1424|   135k|static void stun_tid_string_cpy(uint8_t *s, const stun_tid *id) {
 1425|   135k|  if (s && id) {
  ------------------
  |  Branch (1425:7): [True: 135k, False: 0]
  |  Branch (1425:12): [True: 135k, False: 0]
  ------------------
 1426|   135k|    memcpy(s, id->tsx_id, STUN_TID_SIZE);
  ------------------
  |  |   53|   135k|#define STUN_TID_SIZE (12)
  ------------------
 1427|   135k|  }
 1428|   135k|}
ns_turn_msg.c:turn_random_tid_size:
  154|  78.8k|static void turn_random_tid_size(void *id) {
  155|  78.8k|  uint8_t *ar = (uint8_t *)id;
  156|  78.8k|#if defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
  157|  78.8k|  if (ar) {
  ------------------
  |  Branch (157:7): [True: 78.8k, False: 0]
  ------------------
  158|   315k|    for (size_t i = 0; i < 3; ++i) {
  ------------------
  |  Branch (158:24): [True: 236k, False: 78.8k]
  ------------------
  159|   236k|      const uint32_t r = (uint32_t)turn_random_number();
  160|   236k|      memcpy(ar + i * sizeof(r), &r, sizeof(r));
  161|   236k|    }
  162|  78.8k|  }
  163|       |#else
  164|       |  if (!RAND_bytes((unsigned char *)ar, 12)) {
  165|       |    for (size_t i = 0; i < 3; ++i) {
  166|       |      const uint32_t r = (uint32_t)turn_random_number();
  167|       |      memcpy(ar + i * sizeof(r), &r, sizeof(r));
  168|       |    }
  169|       |  }
  170|       |#endif
  171|  78.8k|}
ns_turn_msg.c:stun_attr_check_valid:
 1616|   552k|static stun_attr_ref stun_attr_check_valid(stun_attr_ref attr, size_t remaining) {
 1617|   552k|  if (remaining >= 4) {
  ------------------
  |  Branch (1617:7): [True: 551k, False: 923]
  ------------------
 1618|       |    /* Read the size of the attribute */
 1619|   551k|    size_t attrlen = stun_attr_get_len(attr);
 1620|   551k|    remaining -= 4;
 1621|       |
 1622|       |    /* Round to boundary */
 1623|   551k|    const uint16_t rem4 = ((uint16_t)attrlen) & 0x0003;
 1624|   551k|    if (rem4) {
  ------------------
  |  Branch (1624:9): [True: 104k, False: 446k]
  ------------------
 1625|   104k|      attrlen = attrlen + 4 - (int)rem4;
 1626|   104k|    }
 1627|       |
 1628|       |    /* Check that there's enough space remaining */
 1629|   551k|    if (attrlen <= remaining) {
  ------------------
  |  Branch (1629:9): [True: 547k, False: 3.83k]
  ------------------
 1630|   547k|      return attr;
 1631|   547k|    }
 1632|   551k|  }
 1633|       |
 1634|  4.75k|  return NULL;
 1635|   552k|}
ns_turn_msg.c:stun_set_command_message_len_str:
  537|   131k|static bool stun_set_command_message_len_str(uint8_t *buf, int len) {
  538|   131k|  if (len < STUN_HEADER_LENGTH) {
  ------------------
  |  |   46|   131k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (538:7): [True: 0, False: 131k]
  ------------------
  539|      0|    return false;
  540|      0|  }
  541|   131k|  turn_write_u16(buf + 2, (uint16_t)(len - STUN_HEADER_LENGTH));
  ------------------
  |  |   46|   131k|#define STUN_HEADER_LENGTH (20)
  ------------------
  542|       |  return true;
  543|   131k|}

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

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

