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.81k|extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
  817|  1.81k|  harness_stun_client(Data, Size);
  818|  1.81k|  harness_channel_data(Data, Size);
  819|  1.81k|  harness_addr_codec(Data, Size);
  820|  1.81k|  harness_message_builders(Data, Size);
  821|  1.81k|  harness_attr_get_first_addr(Data, Size);
  822|  1.81k|  harness_response_matrix(Data, Size);
  823|  1.81k|  harness_stun_buffer_api(Data, Size);
  824|  1.81k|  return 0;
  825|  1.81k|}
FuzzStunClient.c:harness_stun_client:
  212|  1.81k|static void harness_stun_client(const uint8_t *Data, size_t Size) {
  213|  1.81k|  if (Size < 10 || Size > 5120) {
  ------------------
  |  Branch (213:7): [True: 489, False: 1.32k]
  |  Branch (213:20): [True: 95, False: 1.23k]
  ------------------
  214|    584|    return;
  215|    584|  }
  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.07k, False: 157]
  ------------------
  222|  1.07k|    return;
  223|  1.07k|  }
  224|       |
  225|    157|  (void)stun_get_method_str(buf.buf, buf.len);
  226|    157|  (void)stun_get_msg_type_str(buf.buf, buf.len);
  227|       |
  228|    157|  if (stun_is_response(&buf) && stun_is_success_response(&buf) && stun_is_binding_response(&buf)) {
  ------------------
  |  Branch (228:7): [True: 147, False: 10]
  |  Branch (228:33): [True: 53, False: 94]
  |  Branch (228:67): [True: 11, False: 42]
  ------------------
  229|     11|    return;
  230|     11|  }
  231|       |
  232|    146|  stun_is_indication_str(buf.buf, buf.len);
  233|       |
  234|    146|  int err_code = 0;
  235|    146|  uint8_t err_msg[256] = {0};
  236|    146|  stun_is_error_response_str(buf.buf, buf.len, &err_code, err_msg, sizeof(err_msg));
  237|    146|}
FuzzStunClient.c:harness_channel_data:
  242|  1.81k|static void harness_channel_data(const uint8_t *Data, size_t Size) {
  243|  1.81k|  if (Size < 4 || Size > 8192) {
  ------------------
  |  Branch (243:7): [True: 274, False: 1.54k]
  |  Branch (243:19): [True: 69, False: 1.47k]
  ------------------
  244|    343|    return;
  245|    343|  }
  246|       |
  247|  1.47k|  uint8_t buf[8192] = {0};
  248|  1.47k|  memcpy(buf, Data, Size);
  249|       |
  250|  1.47k|  size_t app_len_tcp = 0;
  251|  1.47k|  size_t app_len_udp = 0;
  252|       |
  253|  1.47k|  int mlen_tcp = stun_get_message_len_str(buf, Size, 1, &app_len_tcp);
  254|  1.47k|  int mlen_udp = stun_get_message_len_str(buf, Size, 0, &app_len_udp);
  255|       |
  256|  1.47k|  if (mlen_tcp > 0) {
  ------------------
  |  Branch (256:7): [True: 574, False: 899]
  ------------------
  257|    574|    if (app_len_tcp > Size) {
  ------------------
  |  Branch (257:9): [True: 0, False: 574]
  ------------------
  258|      0|      __builtin_trap();
  259|      0|    }
  260|    574|    if ((size_t)mlen_tcp > Size) {
  ------------------
  |  Branch (260:9): [True: 0, False: 574]
  ------------------
  261|      0|      __builtin_trap();
  262|      0|    }
  263|    574|    if ((size_t)mlen_tcp < app_len_tcp) {
  ------------------
  |  Branch (263:9): [True: 0, False: 574]
  ------------------
  264|      0|      __builtin_trap();
  265|      0|    }
  266|    574|  }
  267|       |
  268|  1.47k|  if (mlen_udp > 0) {
  ------------------
  |  Branch (268:7): [True: 591, False: 882]
  ------------------
  269|    591|    if (app_len_udp > Size) {
  ------------------
  |  Branch (269:9): [True: 0, False: 591]
  ------------------
  270|      0|      __builtin_trap();
  271|      0|    }
  272|    591|    if ((size_t)mlen_udp > Size) {
  ------------------
  |  Branch (272:9): [True: 0, False: 591]
  ------------------
  273|      0|      __builtin_trap();
  274|      0|    }
  275|    591|  }
  276|       |
  277|  1.47k|  size_t blen_tcp = Size;
  278|  1.47k|  uint16_t chn_tcp = 0;
  279|  1.47k|  bool is_chan_tcp = stun_is_channel_message_str(buf, &blen_tcp, &chn_tcp, true);
  280|       |
  281|  1.47k|  size_t blen_udp = Size;
  282|  1.47k|  uint16_t chn_udp = 0;
  283|  1.47k|  bool is_chan_udp = stun_is_channel_message_str(buf, &blen_udp, &chn_udp, false);
  284|       |
  285|  1.47k|  if (is_chan_tcp && (blen_tcp < 4 || blen_tcp > Size)) {
  ------------------
  |  Branch (285:7): [True: 113, False: 1.36k]
  |  Branch (285:23): [True: 0, False: 113]
  |  Branch (285:39): [True: 0, False: 113]
  ------------------
  286|      0|    __builtin_trap();
  287|      0|  }
  288|  1.47k|  if (is_chan_udp && (blen_udp < 4 || blen_udp > Size)) {
  ------------------
  |  Branch (288:7): [True: 130, False: 1.34k]
  |  Branch (288:23): [True: 0, False: 130]
  |  Branch (288:39): [True: 0, False: 130]
  ------------------
  289|      0|    __builtin_trap();
  290|      0|  }
  291|  1.47k|}
FuzzStunClient.c:harness_addr_codec:
  296|  1.81k|static void harness_addr_codec(const uint8_t *Data, size_t Size) {
  297|  1.81k|  if (Size < 2 || Size > 64) {
  ------------------
  |  Branch (297:7): [True: 73, False: 1.74k]
  |  Branch (297:19): [True: 531, False: 1.21k]
  ------------------
  298|    604|    return;
  299|    604|  }
  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|    705|#define STUN_TID_SIZE (12)
  ------------------
  |  Branch (302:22): [True: 705, False: 507]
  |  Branch (302:68): [True: 418, False: 89]
  ------------------
  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) {
  ------------------
  |  |   56|  1.21k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (310:7): [True: 10, False: 1.20k]
  ------------------
  311|     10|    uint8_t enc_buf[32] = {0};
  312|     10|    int enc_len = 0;
  313|     10|    if (stun_addr_encode(&addr, enc_buf, &enc_len, 1, STUN_MAGIC_COOKIE, tid) == 0) {
  ------------------
  |  |   56|     10|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (313:9): [True: 10, False: 0]
  ------------------
  314|     10|      ioa_addr addr2 = {0};
  315|     10|      stun_addr_decode(&addr2, enc_buf, enc_len, 1, STUN_MAGIC_COOKIE, tid);
  ------------------
  |  |   56|     10|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  316|     10|    }
  317|     10|  }
  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: 10, False: 1.20k]
  ------------------
  322|     10|    uint8_t enc_buf[32] = {0};
  323|     10|    int enc_len = 0;
  324|     10|    if (stun_addr_encode(&addr, enc_buf, &enc_len, 0, 0, tid) == 0) {
  ------------------
  |  Branch (324:9): [True: 10, False: 0]
  ------------------
  325|     10|      ioa_addr addr2 = {0};
  326|     10|      stun_addr_decode(&addr2, enc_buf, enc_len, 0, 0, tid);
  327|     10|    }
  328|     10|  }
  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.01k, False: 201]
  ------------------
  334|  1.01k|    memcpy(&alt_cookie, Data, 4);
  335|  1.01k|  }
  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.81k|static void harness_message_builders(const uint8_t *Data, size_t Size) {
  343|  1.81k|  if (!Size || Size > 4096) {
  ------------------
  |  Branch (343:7): [True: 0, False: 1.81k]
  |  Branch (343:16): [True: 141, False: 1.67k]
  ------------------
  344|    141|    return;
  345|    141|  }
  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,
  ------------------
  |  |   78|  1.67k|#define STUN_METHOD_ALLOCATE (0x0003)
  ------------------
                    STUN_METHOD_ALLOCATE, STUN_METHOD_BINDING, STUN_METHOD_CHANNEL_BIND, STUN_METHOD_REFRESH, STUN_METHOD_CONNECT,
  ------------------
  |  |   77|  1.67k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
                    STUN_METHOD_ALLOCATE, STUN_METHOD_BINDING, STUN_METHOD_CHANNEL_BIND, STUN_METHOD_REFRESH, STUN_METHOD_CONNECT,
  ------------------
  |  |   83|  1.67k|#define STUN_METHOD_CHANNEL_BIND (0x0009)
  ------------------
                    STUN_METHOD_ALLOCATE, STUN_METHOD_BINDING, STUN_METHOD_CHANNEL_BIND, STUN_METHOD_REFRESH, STUN_METHOD_CONNECT,
  ------------------
  |  |   79|  1.67k|#define STUN_METHOD_REFRESH (0x0004)
  ------------------
                    STUN_METHOD_ALLOCATE, STUN_METHOD_BINDING, STUN_METHOD_CHANNEL_BIND, STUN_METHOD_REFRESH, STUN_METHOD_CONNECT,
  ------------------
  |  |   86|  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.15k, False: 516]
  ------------------
  389|  1.67k|                             include_reason);
  390|  1.67k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_MAPPED_ADDRESS, &default_addr);
  ------------------
  |  |   91|  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);
  ------------------
  |  |  118|  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);
  ------------------
  |  |  118|  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.15k, False: 516]
  ------------------
  411|  1.67k|                                     include_reason);
  412|  1.67k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, &default_addr);
  ------------------
  |  |  118|  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.15k, False: 516]
  ------------------
  417|  1.67k|                                         include_reason);
  418|  1.67k|    inspect_raw_message(raw, raw_len, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, &default_addr);
  ------------------
  |  |  118|  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);
  ------------------
  |  |  105|  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,
  ------------------
  |  |   91|    682|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
                  inspect_raw_message(raw, raw_len, old_stun ? STUN_ATTRIBUTE_MAPPED_ADDRESS : STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS,
  ------------------
  |  |  105|  2.66k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (430:39): [True: 682, False: 993]
  ------------------
  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.15k, False: 516]
  ------------------
  435|  1.67k|                                    include_reason);
  436|  1.67k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_MAPPED_ADDRESS, &default_addr);
  ------------------
  |  |   91|  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.15k, False: 516]
  ------------------
  441|  1.67k|                                        stun_backward_compatibility, include_reason);
  442|  1.67k|    inspect_raw_message(raw, raw_len, STUN_ATTRIBUTE_MAPPED_ADDRESS, &default_addr);
  ------------------
  |  |   91|  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: 643, False: 1.03k]
  ------------------
  449|  1.67k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &default_addr);
  ------------------
  |  |  116|  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: 628, False: 1.04k]
  ------------------
  453|  1.67k|    inspect_raw_message(raw, raw_len, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &default_addr);
  ------------------
  |  |  116|  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);
  ------------------
  |  |  116|  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.15k, False: 516]
  ------------------
  461|  1.67k|                                       include_reason);
  462|  1.67k|    inspect_raw_message(raw, raw_len, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &default_addr);
  ------------------
  |  |  116|  1.67k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  463|  1.67k|  }
  464|  1.67k|}
FuzzStunClient.c:fuzz_tid:
   57|  5.02k|static void fuzz_tid(const uint8_t *Data, size_t Size, size_t idx, stun_tid *tid) {
   58|  5.02k|  if (!tid) {
  ------------------
  |  Branch (58:7): [True: 0, False: 5.02k]
  ------------------
   59|      0|    return;
   60|      0|  }
   61|       |
   62|  5.02k|  memset(tid, 0, sizeof(*tid));
   63|  65.3k|  for (size_t i = 0; i < STUN_TID_SIZE; ++i) {
  ------------------
  |  |   53|  65.3k|#define STUN_TID_SIZE (12)
  ------------------
  |  Branch (63:22): [True: 60.3k, False: 5.02k]
  ------------------
   64|  60.3k|    tid->tsx_id[i] = fuzz_byte(Data, Size, idx + i);
   65|  60.3k|  }
   66|  5.02k|}
FuzzStunClient.c:fuzz_addr:
   68|  21.1k|static void fuzz_addr(const uint8_t *Data, size_t Size, size_t idx, ioa_addr *addr) {
   69|  21.1k|  if (!addr) {
  ------------------
  |  Branch (69:7): [True: 0, False: 21.1k]
  ------------------
   70|      0|    return;
   71|      0|  }
   72|       |
   73|  21.1k|  memset(addr, 0, sizeof(*addr));
   74|       |
   75|  21.1k|  if (fuzz_flag(Data, Size, idx)) {
  ------------------
  |  Branch (75:7): [True: 8.56k, False: 12.6k]
  ------------------
   76|  8.56k|    addr->s6.sin6_family = AF_INET6;
   77|  8.56k|    addr->s6.sin6_port = htons(fuzz_u16(Data, Size, idx + 1));
   78|   145k|    for (size_t i = 0; i < 16; ++i) {
  ------------------
  |  Branch (78:24): [True: 136k, False: 8.56k]
  ------------------
   79|   136k|      addr->s6.sin6_addr.s6_addr[i] = fuzz_byte(Data, Size, idx + 3 + i);
   80|   136k|    }
   81|  8.56k|    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: 70, False: 8.49k]
  ------------------
   82|     70|      addr->s6.sin6_addr.s6_addr[15] = 1;
   83|     70|    }
   84|  12.6k|  } else {
   85|  12.6k|    addr->s4.sin_family = AF_INET;
   86|  12.6k|    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.6k|  }
   89|  21.1k|}
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|   268k|  for (size_t i = 0; i < len; ++i) {
  ------------------
  |  Branch (50:22): [True: 258k, False: 10.0k]
  ------------------
   51|   258k|    out[i] = (char)('A' + (fuzz_byte(Data, Size, idx + 1 + i) % 26));
   52|   258k|  }
   53|       |
   54|  10.0k|  out[len] = '\0';
   55|  10.0k|}
FuzzStunClient.c:fuzz_byte:
   26|   687k|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: 687k, False: 0]
  ------------------
FuzzStunClient.c:fuzz_u32:
   32|  29.3k|static uint32_t fuzz_u32(const uint8_t *Data, size_t Size, size_t idx) {
   33|  29.3k|  return ((uint32_t)fuzz_u16(Data, Size, idx) << 16) | (uint32_t)fuzz_u16(Data, Size, idx + 2);
   34|  29.3k|}
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|  86.6k|static uint16_t fuzz_u16(const uint8_t *Data, size_t Size, size_t idx) {
   29|  86.6k|  return (uint16_t)(((uint16_t)fuzz_byte(Data, Size, idx) << 8) | (uint16_t)fuzz_byte(Data, Size, idx + 1));
   30|  86.6k|}
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.8k|static void inspect_buffer_message(stun_buffer *msg, uint16_t addr_attr_type, const ioa_addr *default_addr) {
   92|  41.8k|  if (!msg) {
  ------------------
  |  Branch (92:7): [True: 0, False: 41.8k]
  ------------------
   93|      0|    return;
   94|      0|  }
   95|       |
   96|  41.8k|  (void)stun_get_command_message_len(msg);
   97|  41.8k|  (void)stun_is_command_message(msg);
   98|  41.8k|  (void)stun_is_request(msg);
   99|  41.8k|  (void)stun_is_response(msg);
  100|  41.8k|  (void)stun_is_success_response(msg);
  101|  41.8k|  (void)stun_is_binding_response(msg);
  102|  41.8k|  (void)stun_get_method(msg);
  103|  41.8k|  (void)stun_get_msg_type(msg);
  104|       |
  105|  41.8k|  {
  106|  41.8k|    int err_code = 0;
  107|  41.8k|    uint8_t err_msg[256] = {0};
  108|  41.8k|    (void)stun_is_error_response(msg, &err_code, err_msg, sizeof(err_msg));
  109|  41.8k|  }
  110|       |
  111|  41.8k|  {
  112|  41.8k|    ioa_addr parsed = {0};
  113|  41.8k|    (void)stun_attr_get_first_addr(msg, addr_attr_type, &parsed, default_addr);
  114|  41.8k|  }
  115|       |
  116|  41.8k|  {
  117|  41.8k|    stun_attr_ref attr = stun_attr_get_first(msg);
  118|   115k|    while (attr) {
  ------------------
  |  Branch (118:12): [True: 73.3k, False: 41.8k]
  ------------------
  119|  73.3k|      (void)stun_attr_get_type(attr);
  120|  73.3k|      (void)stun_attr_get_len(attr);
  121|  73.3k|      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.3k|      attr = stun_attr_get_next(msg, attr);
  126|  73.3k|    }
  127|  41.8k|  }
  128|       |
  129|  41.8k|  (void)stun_attr_get_first_channel_number(msg);
  130|  41.8k|}
FuzzStunClient.c:inspect_raw_message:
  132|  35.1k|static void inspect_raw_message(const uint8_t *buf, size_t len, uint16_t addr_attr_type, const ioa_addr *default_addr) {
  133|  35.1k|  if (!buf || !len) {
  ------------------
  |  Branch (133:7): [True: 0, False: 35.1k]
  |  Branch (133:15): [True: 0, False: 35.1k]
  ------------------
  134|      0|    return;
  135|      0|  }
  136|       |
  137|  35.1k|  (void)stun_is_command_message_str((uint8_t *)buf, len);
  138|  35.1k|  (void)stun_is_request_str(buf, len);
  139|  35.1k|  (void)stun_is_response_str(buf, len);
  140|  35.1k|  (void)stun_is_success_response_str(buf, len);
  141|  35.1k|  (void)stun_is_binding_response_str(buf, len);
  142|  35.1k|  (void)stun_get_method_str(buf, len);
  143|  35.1k|  (void)stun_get_msg_type_str(buf, len);
  144|       |
  145|  35.1k|  {
  146|  35.1k|    int err_code = 0;
  147|  35.1k|    uint8_t err_msg[256] = {0};
  148|  35.1k|    (void)stun_is_error_response_str(buf, len, &err_code, err_msg, sizeof(err_msg));
  149|  35.1k|  }
  150|       |
  151|  35.1k|  {
  152|  35.1k|    ioa_addr parsed = {0};
  153|  35.1k|    (void)stun_attr_get_first_addr_str(buf, len, addr_attr_type, &parsed, default_addr);
  154|  35.1k|  }
  155|       |
  156|  35.1k|  {
  157|  35.1k|    stun_attr_ref attr = stun_attr_get_first_str(buf, len);
  158|  93.0k|    while (attr) {
  ------------------
  |  Branch (158:12): [True: 57.8k, False: 35.1k]
  ------------------
  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.0k, False: 30.8k]
  ------------------
  162|  27.0k|        ioa_addr parsed = {0};
  163|  27.0k|        (void)stun_attr_get_addr_str(buf, len, attr, &parsed, default_addr);
  164|  27.0k|      }
  165|  57.8k|      attr = stun_attr_get_next_str(buf, len, attr);
  166|  57.8k|    }
  167|  35.1k|  }
  168|       |
  169|  35.1k|  (void)stun_attr_get_first_channel_number_str(buf, len);
  170|  35.1k|}
FuzzStunClient.c:harness_attr_get_first_addr:
  187|  1.81k|static void harness_attr_get_first_addr(const uint8_t *Data, size_t Size) {
  188|  1.81k|  if (Size < STUN_HEADER_LENGTH || Size > 5120) {
  ------------------
  |  |   46|  3.63k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (188:7): [True: 628, False: 1.18k]
  |  Branch (188:36): [True: 95, False: 1.09k]
  ------------------
  189|    723|    return;
  190|    723|  }
  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.83k|  for (size_t i = 0; i < num_attrs; ++i) {
  ------------------
  |  Branch (200:22): [True: 8.74k, False: 1.09k]
  ------------------
  201|  8.74k|    ioa_addr parsed = {0};
  202|  8.74k|    (void)stun_attr_get_first_addr(&msg, kFirstAddrAttrs[i], &parsed, NULL);
  203|       |
  204|  8.74k|    memset(&parsed, 0, sizeof(parsed));
  205|  8.74k|    (void)stun_attr_get_first_addr(&msg, kFirstAddrAttrs[i], &parsed, &default_addr);
  206|  8.74k|  }
  207|  1.09k|}
FuzzStunClient.c:harness_response_matrix:
  477|  1.81k|static void harness_response_matrix(const uint8_t *Data, size_t Size) {
  478|  1.81k|  if (!Size || Size > 4096) {
  ------------------
  |  Branch (478:7): [True: 0, False: 1.81k]
  |  Branch (478:16): [True: 141, False: 1.67k]
  ------------------
  479|    141|    return;
  480|    141|  }
  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);
  ------------------
  |  |   78|  1.67k|#define STUN_METHOD_ALLOCATE (0x0003)
  ------------------
  511|  1.67k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_MAPPED_ADDRESS, &default_addr);
  ------------------
  |  |   91|  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);
  ------------------
  |  |   77|  1.67k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
  515|  1.67k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_MAPPED_ADDRESS, &default_addr);
  ------------------
  |  |   91|  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);
  ------------------
  |  |  118|  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);
  ------------------
  |  |  118|  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);
  ------------------
  |  |  118|  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);
  ------------------
  |  |  118|  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);
  ------------------
  |  |  118|  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);
  ------------------
  |  |  118|  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);
  ------------------
  |  |  105|  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);
  ------------------
  |  |   91|  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.02k|    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,
  ------------------
  |  |   91|  3.35k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
                                          matrix_old_stun[o] ? STUN_ATTRIBUTE_MAPPED_ADDRESS : STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS,
  ------------------
  |  |  105|  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);
  ------------------
  |  |   91|  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);
  ------------------
  |  |  116|  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);
  ------------------
  |  |  116|  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);
  ------------------
  |  |  116|  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);
  ------------------
  |  |  116|  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);
  ------------------
  |  |  116|  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);
  ------------------
  |  |  116|  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);
  ------------------
  |  |  116|  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);
  ------------------
  |  |  116|  1.67k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  628|  1.67k|  }
  629|  1.67k|}
FuzzStunClient.c:harness_stun_buffer_api:
  653|  1.81k|static void harness_stun_buffer_api(const uint8_t *Data, size_t Size) {
  654|  1.81k|  if (!Size || Size > 4096) {
  ------------------
  |  Branch (654:7): [True: 0, False: 1.81k]
  |  Branch (654:16): [True: 141, False: 1.67k]
  ------------------
  655|    141|    return;
  656|    141|  }
  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,
  ------------------
  |  |   78|  1.67k|#define STUN_METHOD_ALLOCATE (0x0003)
  ------------------
                    STUN_METHOD_ALLOCATE, STUN_METHOD_BINDING, STUN_METHOD_CHANNEL_BIND, STUN_METHOD_REFRESH, STUN_METHOD_CONNECT,
  ------------------
  |  |   77|  1.67k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
                    STUN_METHOD_ALLOCATE, STUN_METHOD_BINDING, STUN_METHOD_CHANNEL_BIND, STUN_METHOD_REFRESH, STUN_METHOD_CONNECT,
  ------------------
  |  |   83|  1.67k|#define STUN_METHOD_CHANNEL_BIND (0x0009)
  ------------------
                    STUN_METHOD_ALLOCATE, STUN_METHOD_BINDING, STUN_METHOD_CHANNEL_BIND, STUN_METHOD_REFRESH, STUN_METHOD_CONNECT,
  ------------------
  |  |   79|  1.67k|#define STUN_METHOD_REFRESH (0x0004)
  ------------------
                    STUN_METHOD_ALLOCATE, STUN_METHOD_BINDING, STUN_METHOD_CHANNEL_BIND, STUN_METHOD_REFRESH, STUN_METHOD_CONNECT,
  ------------------
  |  |   86|  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);
  ------------------
  |  |   96|  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);
  ------------------
  |  |  116|  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);
  ------------------
  |  |   96|  1.67k|#define STUN_ATTRIBUTE_USERNAME (0x0006)
  ------------------
  715|  1.67k|    (void)stun_attr_get_first_by_type(&msg, STUN_ATTRIBUTE_CHANNEL_NUMBER);
  ------------------
  |  |  113|  1.67k|#define STUN_ATTRIBUTE_CHANNEL_NUMBER (0x000C)
  ------------------
  716|  1.67k|    (void)stun_attr_get_first_by_type(&msg, STUN_ATTRIBUTE_XOR_PEER_ADDRESS);
  ------------------
  |  |  116|  1.67k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  717|  1.67k|    (void)stun_attr_get_first_by_type(&msg, STUN_ATTRIBUTE_EVEN_PORT);
  ------------------
  |  |  119|  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);
  ------------------
  |  |  116|  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);
  ------------------
  |  |  116|  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);
  ------------------
  |  |   91|  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.01k, False: 657]
  ------------------
  746|  1.67k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, &default_addr);
  ------------------
  |  |  118|  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);
  ------------------
  |  |  118|  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);
  ------------------
  |  |   91|  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);
  ------------------
  |  |   91|  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);
  ------------------
  |  |   96|  1.67k|#define STUN_ATTRIBUTE_USERNAME (0x0006)
  ------------------
  802|  1.67k|    (void)stun_attr_get_first_by_type(&msg, STUN_ATTRIBUTE_XOR_PEER_ADDRESS);
  ------------------
  |  |  116|  1.67k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  803|  1.67k|    (void)stun_attr_get_first_by_type(&msg, STUN_ATTRIBUTE_CHANNEL_NUMBER);
  ------------------
  |  |  113|  1.67k|#define STUN_ATTRIBUTE_CHANNEL_NUMBER (0x000C)
  ------------------
  804|  1.67k|  }
  805|  1.67k|}

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

stun_init_buffer:
   41|  45.2k|int stun_init_buffer(stun_buffer *buf) {
   42|  45.2k|  if (!buf) {
  ------------------
  |  Branch (42:7): [True: 1.67k, False: 43.5k]
  ------------------
   43|  1.67k|    return -1;
   44|  1.67k|  }
   45|  43.5k|  memset(buf->buf, 0, sizeof(buf->buf));
   46|  43.5k|  buf->len = 0;
   47|  43.5k|  buf->offset = 0;
   48|  43.5k|  buf->coffset = 0;
   49|  43.5k|  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.8k|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.8k|bool stun_is_error_response(const stun_buffer *buf, int *err_code, uint8_t *err_msg, size_t err_msg_size) {
   95|  41.8k|  return stun_is_error_response_str(buf->buf, (size_t)(buf->len), err_code, err_msg, err_msg_size);
   96|  41.8k|}
stun_is_response:
   98|  42.0k|bool stun_is_response(const stun_buffer *buf) { return stun_is_response_str(buf->buf, (size_t)(buf->len)); }
stun_is_indication:
  100|  5.02k|bool stun_is_indication(const stun_buffer *buf) {
  101|  5.02k|  if (is_channel_msg(buf)) {
  ------------------
  |  Branch (101:7): [True: 583, False: 4.44k]
  ------------------
  102|    583|    return false;
  103|    583|  }
  104|  4.44k|  return IS_STUN_INDICATION(stun_get_msg_type(buf));
  ------------------
  |  |   59|  4.44k|#define IS_STUN_INDICATION(msg_type) (((msg_type)&0x0110) == 0x0010)
  ------------------
  105|  5.02k|}
stun_get_method:
  107|  41.8k|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|  47.9k|uint16_t stun_get_msg_type(const stun_buffer *buf) {
  110|  47.9k|  if (!buf) {
  ------------------
  |  Branch (110:7): [True: 1.67k, False: 46.3k]
  ------------------
  111|  1.67k|    return (uint16_t)-1;
  112|  1.67k|  }
  113|  46.3k|  return stun_get_msg_type_str(buf->buf, (size_t)buf->len);
  114|  47.9k|}
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.02k|                              stun_tid *id, bool include_reason_string) {
  134|  5.02k|  buf->len = stun_get_size(buf);
  135|  5.02k|  stun_init_error_response_str(method, buf->buf, &(buf->len), error_code, reason, id, include_reason_string);
  136|  5.02k|}
stun_get_command_message_len:
  140|  41.8k|int stun_get_command_message_len(const stun_buffer *buf) {
  141|  41.8k|  return stun_get_command_message_len_str(buf->buf, buf->len);
  142|  41.8k|}
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.37k|bool stun_is_channel_message(stun_buffer *buf, uint16_t *chnumber, bool is_padding_mandatory) {
  151|  8.37k|  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.56k, False: 3.13k]
  ------------------
  157|  3.56k|    buf->len = blen;
  158|  3.56k|  }
  159|  6.70k|  return ret;
  160|  8.37k|}
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.37k|                                uint64_t reservation_token, char *mobile_id, bool include_reason_string) {
  173|       |
  174|  8.37k|  return stun_set_allocate_response_str(buf->buf, &(buf->len), tid, relayed_addr1, relayed_addr2, reflexive_addr,
  175|  8.37k|                                        lifetime, max_lifetime, error_code, reason, reservation_token, mobile_id,
  176|  8.37k|                                        include_reason_string);
  177|  8.37k|}
stun_set_channel_bind_request:
  181|  5.02k|uint16_t stun_set_channel_bind_request(stun_buffer *buf, const ioa_addr *peer_addr, uint16_t channel_number) {
  182|       |
  183|  5.02k|  return stun_set_channel_bind_request_str(buf->buf, &(buf->len), peer_addr, channel_number);
  184|  5.02k|}
stun_set_channel_bind_response:
  187|  5.02k|                                    bool include_reason_string) {
  188|  5.02k|  stun_set_channel_bind_response_str(buf->buf, &(buf->len), tid, error_code, reason, include_reason_string);
  189|  5.02k|}
stun_attr_get_first:
  193|  41.8k|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.3k|stun_attr_ref stun_attr_get_next(const stun_buffer *buf, stun_attr_ref prev) {
  196|  73.3k|  return stun_attr_get_next_str(buf->buf, buf->len, prev);
  197|  73.3k|}
stun_attr_add:
  203|  5.02k|bool stun_attr_add(stun_buffer *buf, uint16_t attr, const char *avalue, int alen) {
  204|  5.02k|  return stun_attr_add_str(buf->buf, &(buf->len), attr, (const uint8_t *)avalue, alen);
  205|  5.02k|}
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.3k|bool stun_attr_get_first_addr(const stun_buffer *buf, uint16_t attr_type, ioa_addr *ca, const ioa_addr *default_addr) {
  220|  59.3k|  return stun_attr_get_first_addr_str(buf->buf, buf->len, attr_type, ca, default_addr);
  221|  59.3k|}
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.23k, False: 2.12k]
  ------------------
  225|  1.23k|    value = 0x80;
  226|  1.23k|  }
  227|  3.35k|  return stun_attr_add(buf, STUN_ATTRIBUTE_EVEN_PORT, (const char *)&value, 1);
  ------------------
  |  |  119|  3.35k|#define STUN_ATTRIBUTE_EVEN_PORT (0x0018)
  ------------------
  228|  3.35k|}
stun_attr_get_first_channel_number:
  230|  41.8k|uint16_t stun_attr_get_first_channel_number(const stun_buffer *buf) {
  231|  41.8k|  return stun_attr_get_first_channel_number_str(buf->buf, buf->len);
  232|  41.8k|}
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.02k|static inline bool is_channel_msg(const stun_buffer *buf) {
   74|  5.02k|  if (buf && buf->len > 0) {
  ------------------
  |  Branch (74:7): [True: 5.02k, False: 0]
  |  Branch (74:14): [True: 5.02k, False: 0]
  ------------------
   75|  5.02k|    return is_channel_msg_str(buf->buf, (size_t)(buf->len));
   76|  5.02k|  }
   77|      0|  return false;
   78|  5.02k|}
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|   192k|void addr_set_any(ioa_addr *addr) {
   49|   192k|  if (addr) {
  ------------------
  |  Branch (49:7): [True: 192k, False: 0]
  ------------------
   50|   192k|    memset(addr, 0, sizeof(ioa_addr));
   51|   192k|  }
   52|   192k|}
addr_any_no_port:
   78|  95.8k|int addr_any_no_port(const ioa_addr *addr) {
   79|  95.8k|  if (!addr) {
  ------------------
  |  Branch (79:7): [True: 0, False: 95.8k]
  ------------------
   80|      0|    return 1;
   81|      0|  }
   82|       |
   83|  95.8k|  if (addr->ss.sa_family == AF_INET) {
  ------------------
  |  Branch (83:7): [True: 62.6k, False: 33.1k]
  ------------------
   84|  62.6k|    return (addr->s4.sin_addr.s_addr == 0);
   85|  62.6k|  } else if (addr->ss.sa_family == AF_INET6) {
  ------------------
  |  Branch (85:14): [True: 33.1k, False: 0]
  ------------------
   86|  33.1k|    size_t i;
   87|  57.0k|    for (i = 0; i < sizeof(addr->s6.sin6_addr); i++) {
  ------------------
  |  Branch (87:17): [True: 56.9k, False: 18]
  ------------------
   88|  56.9k|      if (((const char *)(&(addr->s6.sin6_addr)))[i]) {
  ------------------
  |  Branch (88:11): [True: 33.1k, False: 23.8k]
  ------------------
   89|  33.1k|        return 0;
   90|  33.1k|      }
   91|  56.9k|    }
   92|  33.1k|  }
   93|       |
   94|     18|  return 1;
   95|  95.8k|}
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: 83.8k, False: 47.0k]
  ------------------
  190|  83.8k|      if ((int)a1->s4.sin_addr.s_addr == (int)a2->s4.sin_addr.s_addr) {
  ------------------
  |  Branch (190:11): [True: 489, False: 83.3k]
  ------------------
  191|    489|        return 1;
  192|    489|      }
  193|  83.8k|    } else if (a1->ss.sa_family == AF_INET6) {
  ------------------
  |  Branch (193:16): [True: 47.0k, False: 0]
  ------------------
  194|  47.0k|      if (memcmp(&(a1->s6.sin6_addr), &(a2->s6.sin6_addr), sizeof(struct in6_addr)) == 0) {
  ------------------
  |  Branch (194:11): [True: 190, False: 46.8k]
  ------------------
  195|    190|        return 1;
  196|    190|      }
  197|  47.0k|    }
  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.6k|void addr_set_port(ioa_addr *addr, uint16_t port) {
  408|  11.6k|  if (addr) {
  ------------------
  |  Branch (408:7): [True: 11.6k, False: 0]
  ------------------
  409|  11.6k|    if (addr->s4.sin_family == AF_INET) {
  ------------------
  |  Branch (409:9): [True: 7.15k, False: 4.46k]
  ------------------
  410|  7.15k|      addr->s4.sin_port = nswap16(port);
  ------------------
  |  |   86|  7.15k|#define nswap16(s) ntohs(s)
  ------------------
  411|  7.15k|    } else if (addr->s6.sin6_family == AF_INET6) {
  ------------------
  |  Branch (411:16): [True: 4.46k, False: 0]
  ------------------
  412|       |      addr->s6.sin6_port = nswap16(port);
  ------------------
  |  |   86|  4.46k|#define nswap16(s) ntohs(s)
  ------------------
  413|  4.46k|    }
  414|  11.6k|  }
  415|  11.6k|}
addr_get_port:
  417|  11.6k|uint16_t addr_get_port(const ioa_addr *addr) {
  418|  11.6k|  if (!addr) {
  ------------------
  |  Branch (418:7): [True: 0, False: 11.6k]
  ------------------
  419|      0|    return 0;
  420|      0|  }
  421|       |
  422|  11.6k|  if (addr->s4.sin_family == AF_INET) {
  ------------------
  |  Branch (422:7): [True: 11.4k, False: 208]
  ------------------
  423|  11.4k|    return nswap16(addr->s4.sin_port);
  ------------------
  |  |   86|  11.4k|#define nswap16(s) ntohs(s)
  ------------------
  424|  11.4k|  } else if (addr->s6.sin6_family == AF_INET6) {
  ------------------
  |  Branch (424:14): [True: 208, False: 0]
  ------------------
  425|    208|    return nswap16(addr->s6.sin6_port);
  ------------------
  |  |   86|    208|#define nswap16(s) ntohs(s)
  ------------------
  426|    208|  }
  427|      0|  return 0;
  428|  11.6k|}
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.1k|void map_addr_from_public_to_private(const ioa_addr *public_addr, ioa_addr *private_addr) {
  689|  85.1k|  size_t i;
  690|   254k|  for (i = 0; i < mcount; ++i) {
  ------------------
  |  Branch (690:15): [True: 170k, False: 84.7k]
  ------------------
  691|   170k|    if (addr_eq_no_port(public_addr, public_addrs[i])) {
  ------------------
  |  Branch (691:9): [True: 419, False: 169k]
  ------------------
  692|    419|      addr_cpy(private_addr, private_addrs[i]);
  693|    419|      addr_set_port(private_addr, addr_get_port(public_addr));
  694|    419|      return;
  695|    419|    }
  696|   170k|  }
  697|  84.7k|  addr_cpy(private_addr, public_addr);
  698|  84.7k|}
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|   152k|  for (i = 0; i < mcount; ++i) {
  ------------------
  |  Branch (702:15): [True: 102k, False: 50.8k]
  ------------------
  703|   102k|    if (addr_eq_no_port(private_addr, private_addrs[i])) {
  ------------------
  |  Branch (703:9): [True: 260, False: 101k]
  ------------------
  704|    260|      addr_cpy(public_addr, public_addrs[i]);
  705|    260|      addr_set_port(public_addr, addr_get_port(private_addr));
  706|    260|      return;
  707|    260|    }
  708|   102k|  }
  709|  50.8k|  addr_cpy(public_addr, private_addr);
  710|  50.8k|}

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|   941k|int stun_get_command_message_len_str(const uint8_t *buf, size_t len) {
  524|   941k|  if (len < STUN_HEADER_LENGTH) {
  ------------------
  |  |   46|   941k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (524:7): [True: 1.94k, False: 939k]
  ------------------
  525|  1.94k|    return -1;
  526|  1.94k|  }
  527|       |
  528|       |  /* Validate the size the buffer claims to be */
  529|   939k|  const size_t bufLen = (size_t)(turn_read_u16(buf + 2) + STUN_HEADER_LENGTH);
  ------------------
  |  |   46|   939k|#define STUN_HEADER_LENGTH (20)
  ------------------
  530|   939k|  if (bufLen > len) {
  ------------------
  |  Branch (530:7): [True: 9.04k, False: 930k]
  ------------------
  531|  9.04k|    return -1;
  532|  9.04k|  }
  533|       |
  534|   930k|  return bufLen;
  535|   939k|}
stun_make_type:
  547|  77.0k|uint16_t stun_make_type(uint16_t method) {
  548|  77.0k|  method = method & 0x0FFF;
  549|  77.0k|  return ((method & 0x000F) | ((method & 0x0070) << 1) | ((method & 0x0380) << 2) | ((method & 0x0C00) << 2));
  550|  77.0k|}
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: 73, False: 474k]
  ------------------
  564|     73|    return (uint16_t)-1;
  565|     73|  }
  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)));
  ------------------
  |  |  159|   335k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (159:34): [True: 768, False: 334k]
  |  |  |  Branch (159:53): [True: 583, False: 185]
  |  |  ------------------
  ------------------
  |  Branch (570:11): [True: 335k, False: 0]
  |  Branch (570:18): [True: 335k, False: 274]
  ------------------
  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: 139]
  ------------------
  577|   155k|    if (!STUN_VALID_CHANNEL(turn_read_u16(buf))) {
  ------------------
  |  |  159|   155k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (159:34): [True: 571, False: 154k]
  |  |  |  Branch (159:53): [True: 489, False: 82]
  |  |  ------------------
  ------------------
  578|   154k|      if ((((uint8_t)buf[0]) & ((uint8_t)(0xC0))) == 0) {
  ------------------
  |  Branch (578:11): [True: 154k, False: 82]
  ------------------
  579|   154k|        if (turn_read_u32(buf + 4) == STUN_MAGIC_COOKIE) {
  ------------------
  |  |   56|   154k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (579:13): [True: 138k, False: 16.0k]
  ------------------
  580|   138k|          const uint16_t len = turn_read_u16(buf + 2);
  581|   138k|          if ((len & 0x0003) == 0) {
  ------------------
  |  Branch (581:15): [True: 138k, False: 10]
  ------------------
  582|   138k|            if ((size_t)(len + STUN_HEADER_LENGTH) == blen) {
  ------------------
  |  |   46|   138k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (582:17): [True: 138k, False: 45]
  ------------------
  583|   138k|              return true;
  584|   138k|            }
  585|   138k|          }
  586|   138k|        }
  587|   154k|      }
  588|   154k|    }
  589|   155k|  }
  590|  16.7k|  return false;
  591|   155k|}
stun_is_request_str:
  643|  77.0k|bool stun_is_request_str(const uint8_t *buf, size_t len) {
  644|  77.0k|  if (is_channel_msg_str(buf, len)) {
  ------------------
  |  Branch (644:7): [True: 0, False: 77.0k]
  ------------------
  645|      0|    return false;
  646|      0|  }
  647|  77.0k|  return IS_STUN_REQUEST(stun_get_msg_type_str(buf, len));
  ------------------
  |  |   58|  77.0k|#define IS_STUN_REQUEST(msg_type) (((msg_type)&0x0110) == 0x0000)
  ------------------
  648|  77.0k|}
stun_is_success_response_str:
  650|  77.1k|bool stun_is_success_response_str(const uint8_t *buf, size_t len) {
  651|  77.1k|  if (is_channel_msg_str(buf, len)) {
  ------------------
  |  Branch (651:7): [True: 0, False: 77.1k]
  ------------------
  652|      0|    return false;
  653|      0|  }
  654|  77.1k|  return IS_STUN_SUCCESS_RESP(stun_get_msg_type_str(buf, len));
  ------------------
  |  |   60|  77.1k|#define IS_STUN_SUCCESS_RESP(msg_type) (((msg_type)&0x0110) == 0x0100)
  ------------------
  655|  77.1k|}
stun_is_error_response_str:
  657|  77.1k|bool stun_is_error_response_str(const uint8_t *buf, size_t len, int *err_code, uint8_t *err_msg, size_t err_msg_size) {
  658|  77.1k|  if (is_channel_msg_str(buf, len)) {
  ------------------
  |  Branch (658:7): [True: 0, False: 77.1k]
  ------------------
  659|      0|    return false;
  660|      0|  }
  661|  77.1k|  if (IS_STUN_ERR_RESP(stun_get_msg_type_str(buf, len))) {
  ------------------
  |  |   61|  77.1k|#define IS_STUN_ERR_RESP(msg_type) (((msg_type)&0x0110) == 0x0110)
  |  |  ------------------
  |  |  |  Branch (61:36): [True: 28.5k, False: 48.6k]
  |  |  ------------------
  ------------------
  662|  28.5k|    if (err_code) {
  ------------------
  |  Branch (662:9): [True: 28.5k, False: 0]
  ------------------
  663|  28.5k|      stun_attr_ref sar = stun_attr_get_first_by_type_str(buf, len, STUN_ATTRIBUTE_ERROR_CODE);
  ------------------
  |  |   99|  28.5k|#define STUN_ATTRIBUTE_ERROR_CODE (0x0009)
  ------------------
  664|  28.5k|      if (sar) {
  ------------------
  |  Branch (664:11): [True: 28.5k, False: 54]
  ------------------
  665|  28.5k|        if (stun_attr_get_len(sar) >= 4) {
  ------------------
  |  Branch (665:13): [True: 28.5k, False: 11]
  ------------------
  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.4k, False: 14.0k]
  ------------------
  671|  14.4k|              size_t msg_len = stun_attr_get_len(sar) - 4;
  672|  14.4k|              if (msg_len > (err_msg_size - 1)) {
  ------------------
  |  Branch (672:19): [True: 13, False: 14.4k]
  ------------------
  673|     13|                msg_len = err_msg_size - 1;
  674|     13|              }
  675|  14.4k|              memcpy(err_msg, val + 4, msg_len);
  676|  14.4k|              err_msg[msg_len] = 0;
  677|  14.4k|            }
  678|  28.5k|          }
  679|  28.5k|        }
  680|  28.5k|      }
  681|  28.5k|    }
  682|  28.5k|    return true;
  683|  28.5k|  }
  684|  48.6k|  return false;
  685|  77.1k|}
stun_is_response_str:
  742|  98.7k|bool stun_is_response_str(const uint8_t *buf, size_t len) {
  743|  98.7k|  if (is_channel_msg_str(buf, len)) {
  ------------------
  |  Branch (743:7): [True: 0, False: 98.7k]
  ------------------
  744|      0|    return false;
  745|      0|  }
  746|  98.7k|  if (IS_STUN_SUCCESS_RESP(stun_get_msg_type_str(buf, len))) {
  ------------------
  |  |   60|  98.7k|#define IS_STUN_SUCCESS_RESP(msg_type) (((msg_type)&0x0110) == 0x0100)
  |  |  ------------------
  |  |  |  Branch (60:40): [True: 36.5k, False: 62.2k]
  |  |  ------------------
  ------------------
  747|  36.5k|    return true;
  748|  36.5k|  }
  749|  62.2k|  if (IS_STUN_ERR_RESP(stun_get_msg_type_str(buf, len))) {
  ------------------
  |  |   61|  62.2k|#define IS_STUN_ERR_RESP(msg_type) (((msg_type)&0x0110) == 0x0110)
  |  |  ------------------
  |  |  |  Branch (61:36): [True: 38.3k, False: 23.9k]
  |  |  ------------------
  ------------------
  750|  38.3k|    return true;
  751|  38.3k|  }
  752|  23.9k|  return false;
  753|  62.2k|}
stun_is_indication_str:
  755|    146|bool stun_is_indication_str(const uint8_t *buf, size_t len) {
  756|    146|  if (is_channel_msg_str(buf, len)) {
  ------------------
  |  Branch (756:7): [True: 0, False: 146]
  ------------------
  757|      0|    return false;
  758|      0|  }
  759|    146|  return IS_STUN_INDICATION(stun_get_msg_type_str(buf, len));
  ------------------
  |  |   59|    146|#define IS_STUN_INDICATION(msg_type) (((msg_type)&0x0110) == 0x0010)
  ------------------
  760|    146|}
stun_make_request:
  762|  18.4k|uint16_t stun_make_request(uint16_t method) { return GET_STUN_REQUEST(stun_make_type(method)); }
  ------------------
  |  |   63|  18.4k|#define GET_STUN_REQUEST(msg_type) (msg_type & 0xFEEF)
  ------------------
stun_make_indication:
  764|  1.67k|uint16_t stun_make_indication(uint16_t method) { return GET_STUN_INDICATION(stun_make_type(method)); }
  ------------------
  |  |   64|  1.67k|#define GET_STUN_INDICATION(msg_type) ((msg_type & 0xFEEF) | 0x0010)
  ------------------
stun_make_success_response:
  766|  28.4k|uint16_t stun_make_success_response(uint16_t method) { return GET_STUN_SUCCESS_RESP(stun_make_type(method)); }
  ------------------
  |  |   65|  28.4k|#define GET_STUN_SUCCESS_RESP(msg_type) ((msg_type & 0xFEEF) | 0x0100)
  ------------------
stun_make_error_response:
  768|  28.4k|uint16_t stun_make_error_response(uint16_t method) { return GET_STUN_ERR_RESP(stun_make_type(method)); }
  ------------------
  |  |   66|  28.4k|#define GET_STUN_ERR_RESP(msg_type) (msg_type | 0x0110)
  ------------------
stun_init_buffer_str:
  772|  77.0k|void stun_init_buffer_str(uint8_t *buf, size_t *len) {
  773|  77.0k|  *len = STUN_HEADER_LENGTH;
  ------------------
  |  |   46|  77.0k|#define STUN_HEADER_LENGTH (20)
  ------------------
  774|  77.0k|  memset(buf, 0, *len);
  775|  77.0k|}
stun_init_command_str:
  777|  68.9k|void stun_init_command_str(uint16_t message_type, uint8_t *buf, size_t *len) {
  778|  68.9k|  stun_init_buffer_str(buf, len);
  779|  68.9k|  message_type &= (uint16_t)(0x3FFF);
  780|  68.9k|  turn_write_u16(buf, message_type);
  781|  68.9k|  turn_write_u16(buf + 2, 0);
  782|  68.9k|  turn_write_u32(buf + 4, STUN_MAGIC_COOKIE);
  ------------------
  |  |   56|  68.9k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  783|       |  stun_tid_generate_in_message_str(buf, NULL);
  784|  68.9k|}
old_stun_init_command_str:
  786|  8.06k|void old_stun_init_command_str(uint16_t message_type, uint8_t *buf, size_t *len, uint32_t cookie) {
  787|  8.06k|  stun_init_buffer_str(buf, len);
  788|  8.06k|  message_type &= (uint16_t)(0x3FFF);
  789|  8.06k|  turn_write_u16(buf, message_type);
  790|  8.06k|  turn_write_u16(buf + 2, 0);
  791|  8.06k|  turn_write_u32(buf + 4, cookie);
  792|       |  stun_tid_generate_in_message_str(buf, NULL);
  793|  8.06k|}
stun_init_request_str:
  795|  16.7k|void stun_init_request_str(uint16_t method, uint8_t *buf, size_t *len) {
  796|  16.7k|  stun_init_command_str(stun_make_request(method), buf, len);
  797|  16.7k|}
stun_init_success_response_str:
  803|  24.4k|void stun_init_success_response_str(uint16_t method, uint8_t *buf, size_t *len, stun_tid *id) {
  804|  24.4k|  stun_init_command_str(stun_make_success_response(method), buf, len);
  805|  24.4k|  if (id) {
  ------------------
  |  Branch (805:7): [True: 24.4k, False: 0]
  ------------------
  806|  24.4k|    stun_tid_message_cpy(buf, id);
  807|  24.4k|  }
  808|  24.4k|}
old_stun_init_success_response_str:
  810|  4.03k|void old_stun_init_success_response_str(uint16_t method, uint8_t *buf, size_t *len, stun_tid *id, uint32_t cookie) {
  811|  4.03k|  old_stun_init_command_str(stun_make_success_response(method), buf, len, cookie);
  812|  4.03k|  if (id) {
  ------------------
  |  Branch (812:7): [True: 4.03k, False: 0]
  ------------------
  813|  4.03k|    stun_tid_message_cpy(buf, id);
  814|  4.03k|  }
  815|  4.03k|}
get_default_reason:
  817|    978|const uint8_t *get_default_reason(int error_code) {
  818|    978|  const char *reason = "Unknown error";
  819|       |
  820|    978|  switch (error_code) {
  821|    414|  case 300:
  ------------------
  |  Branch (821:3): [True: 414, False: 564]
  ------------------
  822|    414|    reason = "Try Alternate";
  823|    414|    break;
  824|     84|  case 400:
  ------------------
  |  Branch (824:3): [True: 84, False: 894]
  ------------------
  825|     84|    reason = "Bad Request";
  826|     84|    break;
  827|     36|  case 401:
  ------------------
  |  Branch (827:3): [True: 36, False: 942]
  ------------------
  828|     36|    reason = "Unauthorized";
  829|     36|    break;
  830|     66|  case 403:
  ------------------
  |  Branch (830:3): [True: 66, False: 912]
  ------------------
  831|     66|    reason = "Forbidden";
  832|     66|    break;
  833|      0|  case 404:
  ------------------
  |  Branch (833:3): [True: 0, False: 978]
  ------------------
  834|      0|    reason = "Not Found";
  835|      0|    break;
  836|     36|  case 420:
  ------------------
  |  Branch (836:3): [True: 36, False: 942]
  ------------------
  837|     36|    reason = "Unknown Attribute";
  838|     36|    break;
  839|     48|  case 437:
  ------------------
  |  Branch (839:3): [True: 48, False: 930]
  ------------------
  840|     48|    reason = "Allocation Mismatch";
  841|     48|    break;
  842|     18|  case 438:
  ------------------
  |  Branch (842:3): [True: 18, False: 960]
  ------------------
  843|     18|    reason = "Stale Nonce";
  844|     18|    break;
  845|     30|  case 440:
  ------------------
  |  Branch (845:3): [True: 30, False: 948]
  ------------------
  846|     30|    reason = "Address Family not Supported";
  847|     30|    break;
  848|     12|  case 441:
  ------------------
  |  Branch (848:3): [True: 12, False: 966]
  ------------------
  849|     12|    reason = "Wrong Credentials";
  850|     12|    break;
  851|     42|  case 442:
  ------------------
  |  Branch (851:3): [True: 42, False: 936]
  ------------------
  852|     42|    reason = "Unsupported Transport Protocol";
  853|     42|    break;
  854|     30|  case 443:
  ------------------
  |  Branch (854:3): [True: 30, False: 948]
  ------------------
  855|     30|    reason = "Peer Address Family Mismatch";
  856|     30|    break;
  857|     30|  case 446:
  ------------------
  |  Branch (857:3): [True: 30, False: 948]
  ------------------
  858|     30|    reason = "Connection Already Exists";
  859|     30|    break;
  860|     24|  case 447:
  ------------------
  |  Branch (860:3): [True: 24, False: 954]
  ------------------
  861|     24|    reason = "Connection Timeout or Failure";
  862|     24|    break;
  863|     30|  case 486:
  ------------------
  |  Branch (863:3): [True: 30, False: 948]
  ------------------
  864|     30|    reason = "Allocation Quota Reached";
  865|     30|    break;
  866|     36|  case 487:
  ------------------
  |  Branch (866:3): [True: 36, False: 942]
  ------------------
  867|     36|    reason = "Role Conflict";
  868|     36|    break;
  869|     24|  case 500:
  ------------------
  |  Branch (869:3): [True: 24, False: 954]
  ------------------
  870|     24|    reason = "Server Error";
  871|     24|    break;
  872|      6|  case 508:
  ------------------
  |  Branch (872:3): [True: 6, False: 972]
  ------------------
  873|      6|    reason = "Insufficient Capacity";
  874|      6|    break;
  875|     12|  default:;
  ------------------
  |  Branch (875:3): [True: 12, False: 966]
  ------------------
  876|    978|  };
  877|       |
  878|    978|  return (const uint8_t *)reason;
  879|    978|}
old_stun_init_error_response_str:
  917|  4.03k|                                      bool include_reason_string) {
  918|       |
  919|  4.03k|  old_stun_init_command_str(stun_make_error_response(method), buf, len, cookie);
  920|       |
  921|       |  stun_init_error_response_common_str(buf, len, error_code, reason, id, include_reason_string, true);
  922|  4.03k|}
stun_init_error_response_str:
  925|  24.4k|                                  const uint8_t *reason, stun_tid *id, bool include_reason_string) {
  926|       |
  927|  24.4k|  stun_init_command_str(stun_make_error_response(method), buf, len);
  928|       |
  929|       |  stun_init_error_response_common_str(buf, len, error_code, reason, id, include_reason_string, false);
  930|  24.4k|}
stun_init_channel_message_str:
  934|  1.67k|bool stun_init_channel_message_str(uint16_t chnumber, uint8_t *buf, size_t *len, int length, bool do_padding) {
  935|  1.67k|  uint16_t rlen = (uint16_t)length;
  936|       |
  937|  1.67k|  if (length < 0 || (MAX_STUN_MESSAGE_SIZE < (4 + length))) {
  ------------------
  |  |  221|  1.67k|#define MAX_STUN_MESSAGE_SIZE (65507)
  ------------------
  |  Branch (937:7): [True: 0, False: 1.67k]
  |  Branch (937:21): [True: 0, False: 1.67k]
  ------------------
  938|      0|    return false;
  939|      0|  }
  940|  1.67k|  turn_write_u16(buf, chnumber);
  941|  1.67k|  turn_write_u16(buf + 2, (uint16_t)length);
  942|       |
  943|  1.67k|  if (do_padding && (rlen & 0x0003)) {
  ------------------
  |  Branch (943:7): [True: 668, False: 1.00k]
  |  Branch (943:21): [True: 450, False: 218]
  ------------------
  944|    450|    const uint16_t padded = ((rlen >> 2) + 1) << 2;
  945|       |    // Zero the pad bytes so stale buffer contents are not leaked on the wire
  946|       |    // (matches the padding handling in stun_attr_add_str).
  947|    450|    memset(buf + 4 + rlen, 0, (size_t)(padded - rlen));
  948|    450|    rlen = padded;
  949|    450|  }
  950|       |
  951|  1.67k|  *len = 4 + rlen;
  952|       |
  953|       |  return true;
  954|  1.67k|}
stun_is_channel_message_str:
  956|  9.64k|bool stun_is_channel_message_str(const uint8_t *buf, size_t *blen, uint16_t *chnumber, bool mandatory_padding) {
  957|  9.64k|  uint16_t datalen_header;
  958|  9.64k|  uint16_t datalen_actual;
  959|       |
  960|  9.64k|  if (!blen || (*blen < 4)) {
  ------------------
  |  Branch (960:7): [True: 0, False: 9.64k]
  |  Branch (960:16): [True: 548, False: 9.09k]
  ------------------
  961|    548|    return false;
  962|    548|  }
  963|       |
  964|  9.09k|  const uint16_t chn = turn_read_u16(buf);
  965|  9.09k|  if (!STUN_VALID_CHANNEL(chn)) {
  ------------------
  |  |  159|  9.09k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (159:34): [True: 6.52k, False: 2.57k]
  |  |  |  Branch (159:53): [True: 5.77k, False: 750]
  |  |  ------------------
  ------------------
  966|  3.32k|    return false;
  967|  3.32k|  }
  968|       |
  969|       |  /* Clamp to uint16_t range for comparison without mutating the caller's
  970|       |   * *blen — the modification to *blen at the end of this function is
  971|       |   * intentional (it reports actual message length consumed), but clamping
  972|       |   * during validation must not alter the caller's view of the buffer size
  973|       |   * if the function later returns false (issue #1837). */
  974|  5.77k|  const uint16_t blen16 = (*blen > (uint16_t)-1) ? (uint16_t)-1 : (uint16_t)*blen;
  ------------------
  |  Branch (974:27): [True: 0, False: 5.77k]
  ------------------
  975|  5.77k|  datalen_actual = blen16 - 4;
  976|  5.77k|  datalen_header = turn_read_u16(buf + 2);
  977|       |
  978|  5.77k|  if (datalen_header > datalen_actual) {
  ------------------
  |  Branch (978:7): [True: 1.75k, False: 4.02k]
  ------------------
  979|  1.75k|    return false;
  980|  1.75k|  }
  981|       |
  982|  4.02k|  if (datalen_header != datalen_actual) {
  ------------------
  |  Branch (982:7): [True: 1.06k, False: 2.96k]
  ------------------
  983|       |
  984|       |    /* maybe there are padding bytes for 32-bit alignment. Mandatory for TCP. Optional for UDP */
  985|       |
  986|  1.06k|    if (datalen_actual & 0x0003) {
  ------------------
  |  Branch (986:9): [True: 246, False: 816]
  ------------------
  987|       |
  988|    246|      if (mandatory_padding) {
  ------------------
  |  Branch (988:11): [True: 123, False: 123]
  ------------------
  989|    123|        return false;
  990|    123|      } else if (datalen_header == 0) {
  ------------------
  |  Branch (990:18): [True: 23, False: 100]
  ------------------
  991|     23|        return false;
  992|    100|      } else {
  993|    100|        const uint16_t diff = datalen_actual - datalen_header;
  994|    100|        if (diff > 3) {
  ------------------
  |  Branch (994:13): [True: 68, False: 32]
  ------------------
  995|     68|          return false;
  996|     68|        }
  997|    100|      }
  998|    246|    }
  999|  1.06k|  }
 1000|       |
 1001|  3.81k|  *blen = datalen_header + 4;
 1002|       |
 1003|  3.81k|  if (chnumber) {
  ------------------
  |  Branch (1003:7): [True: 3.81k, False: 0]
  ------------------
 1004|  3.81k|    *chnumber = chn;
 1005|  3.81k|  }
 1006|       |
 1007|       |  return true;
 1008|  4.02k|}
is_http:
 1056|  2.57k|int is_http(const char *s, size_t blen) {
 1057|  2.57k|  if (s && blen >= 12) {
  ------------------
  |  Branch (1057:7): [True: 2.57k, False: 0]
  |  Branch (1057:12): [True: 2.11k, False: 462]
  ------------------
 1058|  2.11k|    if (has_prefix(s, blen, "GET ", false) || has_prefix(s, blen, "POST ", false) ||
  ------------------
  |  Branch (1058:9): [True: 128, False: 1.98k]
  |  Branch (1058:47): [True: 298, False: 1.68k]
  ------------------
 1059|  1.68k|        has_prefix(s, blen, "DELETE ", false) || has_prefix(s, blen, "PUT ", false)) {
  ------------------
  |  Branch (1059:9): [True: 2, False: 1.68k]
  |  Branch (1059:50): [True: 362, False: 1.32k]
  ------------------
 1060|    790|      const char *sp = findstr(s + 4, blen - 4, " HTTP/", false);
 1061|    790|      if (sp) {
  ------------------
  |  Branch (1061:11): [True: 736, False: 54]
  ------------------
 1062|    736|        sp += 6;
 1063|    736|        const size_t diff_blen = sp - s;
 1064|    736|        if (diff_blen + 4 <= blen) {
  ------------------
  |  Branch (1064:13): [True: 706, False: 30]
  ------------------
 1065|    706|          sp = findstr(sp, blen - diff_blen, "\r\n\r\n", false);
 1066|    706|          if (sp) {
  ------------------
  |  Branch (1066:15): [True: 644, False: 62]
  ------------------
 1067|    644|            int ret_len = (int)(sp - s + 4);
 1068|    644|            const char *clheader = "content-length: ";
 1069|    644|            const char *cl = findstr(s, sp - s, clheader, true);
 1070|    644|            if (cl) {
  ------------------
  |  Branch (1070:17): [True: 446, False: 198]
  ------------------
 1071|    446|              const unsigned long clen = strtoul(cl + strlen(clheader), NULL, 10);
 1072|    446|              if (clen > 0 && clen < (0x0FFFFFFF)) {
  ------------------
  |  Branch (1072:19): [True: 430, False: 16]
  |  Branch (1072:31): [True: 196, False: 234]
  ------------------
 1073|    196|                ret_len += (int)clen;
 1074|    196|              }
 1075|    446|            }
 1076|    644|            return ret_len;
 1077|    644|          }
 1078|    706|        }
 1079|    736|      }
 1080|    790|    }
 1081|  2.11k|  }
 1082|  1.92k|  return 0;
 1083|  2.57k|}
stun_get_message_len_str:
 1085|  2.94k|int stun_get_message_len_str(uint8_t *buf, size_t blen, int padding, size_t *app_len) {
 1086|  2.94k|  if (buf && blen) {
  ------------------
  |  Branch (1086:7): [True: 2.94k, False: 0]
  |  Branch (1086:14): [True: 2.94k, False: 0]
  ------------------
 1087|       |    /* STUN request/response ? */
 1088|  2.94k|    if (buf && blen >= STUN_HEADER_LENGTH) {
  ------------------
  |  |   46|  2.94k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (1088:9): [True: 2.94k, False: 0]
  |  Branch (1088:16): [True: 2.23k, False: 708]
  ------------------
 1089|  2.23k|      if (!STUN_VALID_CHANNEL(turn_read_u16(buf))) {
  ------------------
  |  |  159|  2.23k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (159:34): [True: 1.18k, False: 1.05k]
  |  |  |  Branch (159:53): [True: 1.02k, False: 168]
  |  |  ------------------
  ------------------
 1090|  1.21k|        if ((((uint8_t)buf[0]) & ((uint8_t)(0xC0))) == 0) {
  ------------------
  |  Branch (1090:13): [True: 1.05k, False: 168]
  ------------------
 1091|  1.05k|          if (turn_read_u32(buf + 4) == STUN_MAGIC_COOKIE) {
  ------------------
  |  |   56|  1.05k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (1091:15): [True: 430, False: 620]
  ------------------
 1092|       |            /* Use uint32_t to avoid uint16_t truncation overflow when the body
 1093|       |             * length is near 0xFFFF: e.g. 65532 + STUN_HEADER_LENGTH (20) =
 1094|       |             * 65552, which wraps to 16 in uint16_t and lets the truncated value
 1095|       |             * pass the bounds check, desynchronizing TCP/TLS framing. Mirrors
 1096|       |             * the channel-data path below. */
 1097|    430|            uint32_t len = (uint32_t)turn_read_u16(buf + 2);
 1098|    430|            if ((len & 0x0003u) == 0) {
  ------------------
  |  Branch (1098:17): [True: 408, False: 22]
  ------------------
 1099|    408|              len += STUN_HEADER_LENGTH;
  ------------------
  |  |   46|    408|#define STUN_HEADER_LENGTH (20)
  ------------------
 1100|    408|              if (len <= blen) {
  ------------------
  |  Branch (1100:19): [True: 374, False: 34]
  ------------------
 1101|    374|                *app_len = len;
 1102|    374|                return (int)len;
 1103|    374|              }
 1104|    408|            }
 1105|    430|          }
 1106|  1.05k|        }
 1107|  1.21k|      }
 1108|  2.23k|    }
 1109|       |
 1110|       |    // HTTP request ?
 1111|  2.57k|    {
 1112|  2.57k|      const int http_len = is_http(((char *)buf), blen);
 1113|  2.57k|      if ((http_len > 0) && ((size_t)http_len <= blen)) {
  ------------------
  |  Branch (1113:11): [True: 644, False: 1.92k]
  |  Branch (1113:29): [True: 448, False: 196]
  ------------------
 1114|    448|        *app_len = (size_t)http_len;
 1115|    448|        return http_len;
 1116|    448|      }
 1117|  2.57k|    }
 1118|       |
 1119|       |    /* STUN channel ? */
 1120|  2.12k|    if (blen >= 4) {
  ------------------
  |  Branch (1120:9): [True: 2.12k, False: 0]
  ------------------
 1121|  2.12k|      const uint16_t chn = turn_read_u16(buf);
 1122|  2.12k|      if (STUN_VALID_CHANNEL(chn)) {
  ------------------
  |  |  159|  2.12k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (159:34): [True: 1.19k, False: 932]
  |  |  |  Branch (159:53): [True: 812, False: 380]
  |  |  ------------------
  ------------------
 1123|       |
 1124|       |        /* Use uint32_t to avoid uint16_t truncation overflow when data_len is
 1125|       |         * near 0xFFFF: 4 + 0xFFFF = 65539, which wraps to 3 in uint16_t and
 1126|       |         * causes TCP framing bypass (CVE candidate, issue #1837). */
 1127|    812|        uint32_t bret = 4u + (uint32_t)turn_read_u16(buf + 2);
 1128|       |
 1129|    812|        *app_len = bret;
 1130|       |
 1131|    812|        if (padding && (bret & 0x0003u)) {
  ------------------
  |  Branch (1131:13): [True: 406, False: 406]
  |  Branch (1131:24): [True: 126, False: 280]
  ------------------
 1132|    126|          bret = ((bret >> 2) + 1u) << 2;
 1133|    126|        }
 1134|       |
 1135|    812|        if (bret <= blen) {
  ------------------
  |  Branch (1135:13): [True: 343, False: 469]
  ------------------
 1136|    343|          return (int)bret;
 1137|    343|        }
 1138|    812|      }
 1139|  2.12k|    }
 1140|  2.12k|  }
 1141|       |
 1142|  1.78k|  return -1;
 1143|  2.94k|}
stun_set_allocate_request_str:
 1148|  3.35k|                                   bool mobile, const char *rt, int ep) {
 1149|       |
 1150|  3.35k|  stun_init_request_str(STUN_METHOD_ALLOCATE, buf, len);
  ------------------
  |  |   78|  3.35k|#define STUN_METHOD_ALLOCATE (0x0003)
  ------------------
 1151|       |
 1152|       |  // REQUESTED-TRANSPORT
 1153|  3.35k|  {
 1154|  3.35k|    uint8_t field[4];
 1155|  3.35k|    field[0] = transport;
 1156|  3.35k|    field[1] = 0;
 1157|  3.35k|    field[2] = 0;
 1158|  3.35k|    field[3] = 0;
 1159|  3.35k|    if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_REQUESTED_TRANSPORT, field, sizeof(field))) {
  ------------------
  |  |  120|  3.35k|#define STUN_ATTRIBUTE_REQUESTED_TRANSPORT (0x0019)
  ------------------
  |  Branch (1159:9): [True: 0, False: 3.35k]
  ------------------
 1160|      0|      return false;
 1161|      0|    }
 1162|  3.35k|  }
 1163|       |
 1164|       |  // LIFETIME
 1165|  3.35k|  {
 1166|  3.35k|    if (lifetime < 1) {
  ------------------
  |  Branch (1166:9): [True: 306, False: 3.04k]
  ------------------
 1167|    306|      lifetime = STUN_DEFAULT_ALLOCATE_LIFETIME;
  ------------------
  |  |   69|    306|#define STUN_DEFAULT_ALLOCATE_LIFETIME (600)
  ------------------
 1168|    306|    }
 1169|  3.35k|    uint32_t field = nswap32(lifetime);
  ------------------
  |  |   87|  3.35k|#define nswap32(ul) ntohl(ul)
  ------------------
 1170|  3.35k|    if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_LIFETIME, (uint8_t *)(&field), sizeof(field))) {
  ------------------
  |  |  114|  3.35k|#define STUN_ATTRIBUTE_LIFETIME (0x000D)
  ------------------
  |  Branch (1170:9): [True: 0, False: 3.35k]
  ------------------
 1171|      0|      return false;
 1172|      0|    }
 1173|  3.35k|  }
 1174|       |
 1175|       |  // MICE
 1176|  3.35k|  if (mobile) {
  ------------------
  |  Branch (1176:7): [True: 1.67k, False: 1.67k]
  ------------------
 1177|  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 (1177:9): [True: 0, False: 1.67k]
  ------------------
 1178|      0|      return false;
 1179|      0|    }
 1180|  1.67k|  }
 1181|       |
 1182|  3.35k|  if (ep > -1) {
  ------------------
  |  Branch (1182:7): [True: 2.56k, False: 790]
  ------------------
 1183|  2.56k|    uint8_t value = ep ? 0x80 : 0x00;
  ------------------
  |  Branch (1183:21): [True: 1.56k, False: 996]
  ------------------
 1184|  2.56k|    if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_EVEN_PORT, (const uint8_t *)&value, 1)) {
  ------------------
  |  |  119|  2.56k|#define STUN_ATTRIBUTE_EVEN_PORT (0x0018)
  ------------------
  |  Branch (1184:9): [True: 0, False: 2.56k]
  ------------------
 1185|      0|      return false;
 1186|      0|    }
 1187|  2.56k|  }
 1188|       |
 1189|       |  // RESERVATION-TOKEN, EVEN-PORT and DUAL-ALLOCATION are mutually exclusive:
 1190|  3.35k|  if (rt) {
  ------------------
  |  Branch (1190:7): [True: 1.01k, False: 2.33k]
  ------------------
 1191|       |
 1192|  1.01k|    stun_attr_add_str(buf, len, STUN_ATTRIBUTE_RESERVATION_TOKEN, (const uint8_t *)rt, 8);
  ------------------
  |  |  123|  1.01k|#define STUN_ATTRIBUTE_RESERVATION_TOKEN (0x0022)
  ------------------
 1193|       |
 1194|  2.33k|  } else {
 1195|       |
 1196|       |    // ADRESS-FAMILY
 1197|  2.33k|    if (af4 && !af6) {
  ------------------
  |  Branch (1197:9): [True: 1.15k, False: 1.17k]
  |  Branch (1197:16): [True: 342, False: 815]
  ------------------
 1198|    342|      uint8_t field[4];
 1199|    342|      field[0] = (uint8_t)STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV4;
  ------------------
  |  |  164|    342|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV4 (0x01)
  ------------------
 1200|    342|      field[1] = 0;
 1201|    342|      field[2] = 0;
 1202|    342|      field[3] = 0;
 1203|    342|      if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY, field, sizeof(field))) {
  ------------------
  |  |  104|    342|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY (0x0017)
  ------------------
  |  Branch (1203:11): [True: 0, False: 342]
  ------------------
 1204|      0|        return false;
 1205|      0|      }
 1206|    342|    }
 1207|       |
 1208|  2.33k|    if (af6 && !af4) {
  ------------------
  |  Branch (1208:9): [True: 1.21k, False: 1.12k]
  |  Branch (1208:16): [True: 395, False: 815]
  ------------------
 1209|    395|      uint8_t field[4];
 1210|    395|      field[0] = (uint8_t)STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6;
  ------------------
  |  |  165|    395|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6 (0x02)
  ------------------
 1211|    395|      field[1] = 0;
 1212|    395|      field[2] = 0;
 1213|    395|      field[3] = 0;
 1214|    395|      if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY, field, sizeof(field))) {
  ------------------
  |  |  104|    395|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY (0x0017)
  ------------------
  |  Branch (1214:11): [True: 0, False: 395]
  ------------------
 1215|      0|        return false;
 1216|      0|      }
 1217|    395|    }
 1218|       |
 1219|  2.33k|    if (af4 && af6) {
  ------------------
  |  Branch (1219:9): [True: 1.15k, False: 1.17k]
  |  Branch (1219:16): [True: 815, False: 342]
  ------------------
 1220|    815|      uint8_t field[4];
 1221|    815|      field[0] = (uint8_t)STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6;
  ------------------
  |  |  165|    815|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6 (0x02)
  ------------------
 1222|    815|      field[1] = 0;
 1223|    815|      field[2] = 0;
 1224|    815|      field[3] = 0;
 1225|    815|      if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_ADDITIONAL_ADDRESS_FAMILY, field, sizeof(field))) {
  ------------------
  |  |  140|    815|#define STUN_ATTRIBUTE_ADDITIONAL_ADDRESS_FAMILY (0x8000)
  ------------------
  |  Branch (1225:11): [True: 0, False: 815]
  ------------------
 1226|      0|        return false;
 1227|      0|      }
 1228|    815|    }
 1229|  2.33k|  }
 1230|       |
 1231|  3.35k|  return true;
 1232|  3.35k|}
stun_set_allocate_response_str:
 1237|  16.7k|                                    uint64_t reservation_token, char *mobile_id, bool include_reason_string) {
 1238|       |
 1239|  16.7k|  if (!error_code) {
  ------------------
  |  Branch (1239:7): [True: 10.0k, False: 6.70k]
  ------------------
 1240|       |
 1241|  10.0k|    stun_init_success_response_str(STUN_METHOD_ALLOCATE, buf, len, tid);
  ------------------
  |  |   78|  10.0k|#define STUN_METHOD_ALLOCATE (0x0003)
  ------------------
 1242|       |
 1243|  10.0k|    if (relayed_addr1) {
  ------------------
  |  Branch (1243:9): [True: 10.0k, False: 0]
  ------------------
 1244|  10.0k|      if (!stun_attr_add_addr_str(buf, len, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, relayed_addr1)) {
  ------------------
  |  |  118|  10.0k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  |  Branch (1244:11): [True: 0, False: 10.0k]
  ------------------
 1245|      0|        return false;
 1246|      0|      }
 1247|  10.0k|    }
 1248|       |
 1249|  10.0k|    if (relayed_addr2) {
  ------------------
  |  Branch (1249:9): [True: 5.62k, False: 4.42k]
  ------------------
 1250|  5.62k|      if (!stun_attr_add_addr_str(buf, len, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, relayed_addr2)) {
  ------------------
  |  |  118|  5.62k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  |  Branch (1250:11): [True: 0, False: 5.62k]
  ------------------
 1251|      0|        return false;
 1252|      0|      }
 1253|  5.62k|    }
 1254|       |
 1255|  10.0k|    if (reflexive_addr) {
  ------------------
  |  Branch (1255:9): [True: 6.70k, False: 3.35k]
  ------------------
 1256|  6.70k|      if (!stun_attr_add_addr_str(buf, len, STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS, reflexive_addr)) {
  ------------------
  |  |  105|  6.70k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (1256:11): [True: 0, False: 6.70k]
  ------------------
 1257|      0|        return false;
 1258|      0|      }
 1259|  6.70k|    }
 1260|       |
 1261|  10.0k|    if (reservation_token) {
  ------------------
  |  Branch (1261:9): [True: 6.55k, False: 3.49k]
  ------------------
 1262|  6.55k|      reservation_token = nswap64(reservation_token);
  ------------------
  |  |   88|  6.55k|#define nswap64(ull) ioa_ntoh64(ull)
  |  |  ------------------
  |  |  |  |  115|  6.55k|#define ioa_ntoh64 _ioa_ntoh64
  |  |  ------------------
  ------------------
 1263|  6.55k|      stun_attr_add_str(buf, len, STUN_ATTRIBUTE_RESERVATION_TOKEN, (uint8_t *)(&reservation_token), 8);
  ------------------
  |  |  123|  6.55k|#define STUN_ATTRIBUTE_RESERVATION_TOKEN (0x0022)
  ------------------
 1264|  6.55k|    }
 1265|       |
 1266|  10.0k|    {
 1267|  10.0k|      if (lifetime < 1) {
  ------------------
  |  Branch (1267:11): [True: 3.75k, False: 6.29k]
  ------------------
 1268|  3.75k|        lifetime = STUN_DEFAULT_ALLOCATE_LIFETIME;
  ------------------
  |  |   69|  3.75k|#define STUN_DEFAULT_ALLOCATE_LIFETIME (600)
  ------------------
 1269|  6.29k|      } else if (lifetime > max_lifetime) {
  ------------------
  |  Branch (1269:18): [True: 4.59k, False: 1.70k]
  ------------------
 1270|  4.59k|        lifetime = max_lifetime;
 1271|  4.59k|      }
 1272|       |
 1273|  10.0k|      uint32_t field = nswap32(lifetime);
  ------------------
  |  |   87|  10.0k|#define nswap32(ul) ntohl(ul)
  ------------------
 1274|  10.0k|      if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_LIFETIME, (uint8_t *)(&field), sizeof(field))) {
  ------------------
  |  |  114|  10.0k|#define STUN_ATTRIBUTE_LIFETIME (0x000D)
  ------------------
  |  Branch (1274:11): [True: 0, False: 10.0k]
  ------------------
 1275|      0|        return false;
 1276|      0|      }
 1277|  10.0k|    }
 1278|       |
 1279|  10.0k|    if (mobile_id && *mobile_id) {
  ------------------
  |  Branch (1279:9): [True: 6.70k, False: 3.35k]
  |  Branch (1279:22): [True: 4.80k, False: 1.89k]
  ------------------
 1280|  4.80k|      if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_MOBILITY_TICKET, (uint8_t *)mobile_id, (int)strlen(mobile_id))) {
  ------------------
  |  |   47|  4.80k|#define STUN_ATTRIBUTE_MOBILITY_TICKET (0x8030)
  ------------------
  |  Branch (1280:11): [True: 0, False: 4.80k]
  ------------------
 1281|      0|        return false;
 1282|      0|      }
 1283|  4.80k|    }
 1284|       |
 1285|  10.0k|  } else {
 1286|  6.70k|    stun_init_error_response_str(STUN_METHOD_ALLOCATE, buf, len, error_code, reason, tid, include_reason_string);
  ------------------
  |  |   78|  6.70k|#define STUN_METHOD_ALLOCATE (0x0003)
  ------------------
 1287|  6.70k|  }
 1288|       |
 1289|  16.7k|  return true;
 1290|  16.7k|}
stun_set_channel_bind_request_str:
 1295|  10.0k|                                           uint16_t channel_number) {
 1296|       |
 1297|  10.0k|  if (!STUN_VALID_CHANNEL_BIND(channel_number)) {
  ------------------
  |  |  158|  10.0k|#define STUN_VALID_CHANNEL_BIND(chn) ((chn) >= 0x4000 && (chn) <= 0x4FFF)
  |  |  ------------------
  |  |  |  Branch (158:39): [True: 8.18k, False: 1.86k]
  |  |  |  Branch (158:58): [True: 3.13k, False: 5.05k]
  |  |  ------------------
  ------------------
 1298|  6.92k|    channel_number = 0x4000 + ((uint16_t)(((uint32_t)turn_random_number()) % (0x4FFF - 0x4000 + 1)));
 1299|  6.92k|  }
 1300|       |
 1301|  10.0k|  stun_init_request_str(STUN_METHOD_CHANNEL_BIND, buf, len);
  ------------------
  |  |   83|  10.0k|#define STUN_METHOD_CHANNEL_BIND (0x0009)
  ------------------
 1302|       |
 1303|  10.0k|  if (!stun_attr_add_channel_number_str(buf, len, channel_number)) {
  ------------------
  |  Branch (1303:7): [True: 0, False: 10.0k]
  ------------------
 1304|      0|    return 0;
 1305|      0|  }
 1306|       |
 1307|  10.0k|  if (!peer_addr) {
  ------------------
  |  Branch (1307:7): [True: 5.42k, False: 4.62k]
  ------------------
 1308|  5.42k|    ioa_addr ca;
 1309|  5.42k|    memset(&ca, 0, sizeof(ioa_addr));
 1310|       |
 1311|  5.42k|    if (!stun_attr_add_addr_str(buf, len, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &ca)) {
  ------------------
  |  |  116|  5.42k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  |  Branch (1311:9): [True: 0, False: 5.42k]
  ------------------
 1312|      0|      return 0;
 1313|      0|    }
 1314|  5.42k|  } else {
 1315|  4.62k|    if (!stun_attr_add_addr_str(buf, len, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, peer_addr)) {
  ------------------
  |  |  116|  4.62k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  |  Branch (1315:9): [True: 0, False: 4.62k]
  ------------------
 1316|      0|      return 0;
 1317|      0|    }
 1318|  4.62k|  }
 1319|       |
 1320|  10.0k|  return channel_number;
 1321|  10.0k|}
stun_set_channel_bind_response_str:
 1324|  10.0k|                                        bool include_reason_string) {
 1325|  10.0k|  if (!error_code) {
  ------------------
  |  Branch (1325:7): [True: 5.02k, False: 5.02k]
  ------------------
 1326|  5.02k|    stun_init_success_response_str(STUN_METHOD_CHANNEL_BIND, buf, len, tid);
  ------------------
  |  |   83|  5.02k|#define STUN_METHOD_CHANNEL_BIND (0x0009)
  ------------------
 1327|  5.02k|  } else {
 1328|  5.02k|    stun_init_error_response_str(STUN_METHOD_CHANNEL_BIND, buf, len, error_code, reason, tid, include_reason_string);
  ------------------
  |  |   83|  5.02k|#define STUN_METHOD_CHANNEL_BIND (0x0009)
  ------------------
 1329|  5.02k|  }
 1330|  10.0k|}
stun_set_binding_request_str:
 1334|  3.35k|void stun_set_binding_request_str(uint8_t *buf, size_t *len) { stun_init_request_str(STUN_METHOD_BINDING, buf, len); }
  ------------------
  |  |   77|  3.35k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
stun_set_binding_response_str:
 1340|  23.4k|{
 1341|  23.4k|  if (!error_code) {
  ------------------
  |  Branch (1341:7): [True: 11.7k, False: 11.7k]
  ------------------
 1342|  11.7k|    if (!old_stun) {
  ------------------
  |  Branch (1342:9): [True: 7.69k, False: 4.03k]
  ------------------
 1343|  7.69k|      stun_init_success_response_str(STUN_METHOD_BINDING, buf, len, tid);
  ------------------
  |  |   77|  7.69k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
 1344|  7.69k|    } else {
 1345|  4.03k|      old_stun_init_success_response_str(STUN_METHOD_BINDING, buf, len, tid, cookie);
  ------------------
  |  |   77|  4.03k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
 1346|  4.03k|    }
 1347|  11.7k|    if (!old_stun && reflexive_addr) {
  ------------------
  |  Branch (1347:9): [True: 7.69k, False: 4.03k]
  |  Branch (1347:22): [True: 7.69k, False: 0]
  ------------------
 1348|  7.69k|      if (!stun_attr_add_addr_str(buf, len, STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS, reflexive_addr)) {
  ------------------
  |  |  105|  7.69k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (1348:11): [True: 0, False: 7.69k]
  ------------------
 1349|      0|        return false;
 1350|      0|      }
 1351|  7.69k|    }
 1352|       |    /* MAPPED-ADDRESS is the only address attribute RFC 3489 defines, so the old-STUN
 1353|       |     * path always needs it. On the modern path it is purely a backward-compatibility
 1354|       |     * courtesy for clients that cannot parse XOR-MAPPED-ADDRESS, and it widens the
 1355|       |     * response, so it stays opt-in there. */
 1356|  11.7k|    if (reflexive_addr) {
  ------------------
  |  Branch (1356:9): [True: 11.7k, False: 0]
  ------------------
 1357|  11.7k|      if ((old_stun || stun_backward_compatibility) &&
  ------------------
  |  Branch (1357:12): [True: 4.03k, False: 7.69k]
  |  Branch (1357:24): [True: 5.31k, False: 2.37k]
  ------------------
 1358|  9.35k|          !stun_attr_add_addr_str(buf, len, STUN_ATTRIBUTE_MAPPED_ADDRESS, reflexive_addr)) {
  ------------------
  |  |   91|  9.35k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
  |  Branch (1358:11): [True: 0, False: 9.35k]
  ------------------
 1359|      0|        return false;
 1360|      0|      }
 1361|  11.7k|    }
 1362|  11.7k|  } else if (!old_stun) {
  ------------------
  |  Branch (1362:14): [True: 7.69k, False: 4.03k]
  ------------------
 1363|  7.69k|    stun_init_error_response_str(STUN_METHOD_BINDING, buf, len, error_code, reason, tid, include_reason_string);
  ------------------
  |  |   77|  7.69k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
 1364|  7.69k|  } else {
 1365|  4.03k|    old_stun_init_error_response_str(STUN_METHOD_BINDING, buf, len, error_code, reason, tid, cookie,
  ------------------
  |  |   77|  4.03k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
 1366|  4.03k|                                     include_reason_string);
 1367|  4.03k|  }
 1368|       |
 1369|  23.4k|  return true;
 1370|  23.4k|}
stun_is_binding_response_str:
 1385|  77.1k|bool stun_is_binding_response_str(const uint8_t *buf, size_t len) {
 1386|  77.1k|  if (stun_is_command_message_str(buf, len) && (stun_get_method_str(buf, len) == STUN_METHOD_BINDING)) {
  ------------------
  |  |   77|  69.2k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
  |  Branch (1386:7): [True: 69.2k, False: 7.84k]
  |  Branch (1386:48): [True: 21.5k, False: 47.6k]
  ------------------
 1387|  21.5k|    if (stun_is_response_str(buf, len)) {
  ------------------
  |  Branch (1387:9): [True: 17.7k, False: 3.79k]
  ------------------
 1388|  17.7k|      return true;
 1389|  17.7k|    }
 1390|  21.5k|  }
 1391|  59.3k|  return false;
 1392|  77.1k|}
stun_tid_from_message_str:
 1430|   150k|void stun_tid_from_message_str(const uint8_t *buf, size_t len, stun_tid *id) {
 1431|   150k|  UNUSED_ARG(len);
  ------------------
  |  |  216|   150k|  do {                                                                                                                 \
  |  |  217|   150k|    A = A;                                                                                                             \
  |  |  218|   150k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (218:12): [Folded, False: 150k]
  |  |  ------------------
  ------------------
 1432|   150k|  stun_tid_from_string(buf + 8, id);
 1433|   150k|}
stun_tid_message_cpy:
 1435|   135k|void stun_tid_message_cpy(uint8_t *buf, const stun_tid *id) {
 1436|   135k|  if (buf && id) {
  ------------------
  |  Branch (1436:7): [True: 135k, False: 0]
  |  Branch (1436:14): [True: 135k, False: 0]
  ------------------
 1437|   135k|    stun_tid_string_cpy(buf + 8, id);
 1438|   135k|  }
 1439|   135k|}
stun_tid_generate:
 1441|  78.7k|void stun_tid_generate(stun_tid *id) {
 1442|  78.7k|  if (id) {
  ------------------
  |  Branch (1442:7): [True: 78.7k, False: 0]
  ------------------
 1443|  78.7k|    turn_random_tid_size(id->tsx_id);
 1444|  78.7k|  }
 1445|  78.7k|}
stun_tid_generate_in_message_str:
 1447|  78.7k|void stun_tid_generate_in_message_str(uint8_t *buf, stun_tid *id) {
 1448|  78.7k|  stun_tid tmp;
 1449|  78.7k|  if (!id) {
  ------------------
  |  Branch (1449:7): [True: 77.0k, False: 1.67k]
  ------------------
 1450|  77.0k|    id = &tmp;
 1451|  77.0k|  }
 1452|  78.7k|  stun_tid_generate(id);
 1453|  78.7k|  stun_tid_message_cpy(buf, id);
 1454|  78.7k|}
stun_attr_get_type:
 1478|   921k|int stun_attr_get_type(stun_attr_ref attr) {
 1479|   921k|  if (attr) {
  ------------------
  |  Branch (1479:7): [True: 921k, False: 0]
  ------------------
 1480|   921k|    return (int)turn_read_u16(attr);
 1481|   921k|  }
 1482|      0|  return -1;
 1483|   921k|}
stun_attr_get_len:
 1485|  1.35M|int stun_attr_get_len(stun_attr_ref attr) {
 1486|  1.35M|  if (attr) {
  ------------------
  |  Branch (1486:7): [True: 1.35M, False: 0]
  ------------------
 1487|  1.35M|    return (int)turn_read_u16((const uint8_t *)attr + 2);
 1488|  1.35M|  }
 1489|      0|  return -1;
 1490|  1.35M|}
stun_attr_get_value:
 1492|   136k|const uint8_t *stun_attr_get_value(stun_attr_ref attr) {
 1493|   136k|  if (attr) {
  ------------------
  |  Branch (1493:7): [True: 136k, False: 0]
  ------------------
 1494|   136k|    const int len = (int)turn_read_u16((const uint8_t *)attr + 2);
 1495|   136k|    if (len < 1) {
  ------------------
  |  Branch (1495:9): [True: 5.12k, False: 131k]
  ------------------
 1496|  5.12k|      return NULL;
 1497|  5.12k|    }
 1498|   131k|    return ((const uint8_t *)attr) + 4;
 1499|   136k|  }
 1500|      0|  return NULL;
 1501|   136k|}
stun_attr_get_channel_number:
 1521|  11.7k|uint16_t stun_attr_get_channel_number(stun_attr_ref attr) {
 1522|  11.7k|  if (attr) {
  ------------------
  |  Branch (1522:7): [True: 11.7k, False: 0]
  ------------------
 1523|  11.7k|    const uint8_t *value = stun_attr_get_value(attr);
 1524|  11.7k|    if (value && (stun_attr_get_len(attr) >= 2)) {
  ------------------
  |  Branch (1524:9): [True: 11.7k, False: 0]
  |  Branch (1524:18): [True: 11.7k, False: 0]
  ------------------
 1525|  11.7k|      const uint16_t cn = turn_read_u16(value);
 1526|  11.7k|      if (STUN_VALID_CHANNEL(cn)) {
  ------------------
  |  |  159|  11.7k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (159:34): [True: 11.7k, False: 0]
  |  |  |  Branch (159:53): [True: 11.7k, False: 0]
  |  |  ------------------
  ------------------
 1527|  11.7k|        return cn;
 1528|  11.7k|      }
 1529|  11.7k|    }
 1530|  11.7k|  }
 1531|      0|  return 0;
 1532|  11.7k|}
stun_attr_is_addr:
 1555|   381k|bool stun_attr_is_addr(stun_attr_ref attr) {
 1556|       |
 1557|   381k|  if (attr) {
  ------------------
  |  Branch (1557:7): [True: 381k, False: 0]
  ------------------
 1558|   381k|    switch (stun_attr_get_type(attr)) {
 1559|  32.5k|    case STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS:
  ------------------
  |  |  105|  32.5k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (1559:5): [True: 32.5k, False: 348k]
  ------------------
 1560|  83.3k|    case STUN_ATTRIBUTE_XOR_PEER_ADDRESS:
  ------------------
  |  |  116|  83.3k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  |  Branch (1560:5): [True: 50.8k, False: 330k]
  ------------------
 1561|   136k|    case STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS:
  ------------------
  |  |  118|   136k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  |  Branch (1561:5): [True: 52.8k, False: 328k]
  ------------------
 1562|   171k|    case STUN_ATTRIBUTE_MAPPED_ADDRESS:
  ------------------
  |  |   91|   171k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
  |  Branch (1562:5): [True: 35.2k, False: 345k]
  ------------------
 1563|   176k|    case STUN_ATTRIBUTE_ALTERNATE_SERVER:
  ------------------
  |  |  110|   176k|#define STUN_ATTRIBUTE_ALTERNATE_SERVER (0x8023)
  ------------------
  |  Branch (1563:5): [True: 4.64k, False: 376k]
  ------------------
 1564|   178k|    case OLD_STUN_ATTRIBUTE_RESPONSE_ADDRESS:
  ------------------
  |  |   92|   178k|#define OLD_STUN_ATTRIBUTE_RESPONSE_ADDRESS (0x0002)
  ------------------
  |  Branch (1564:5): [True: 2.17k, False: 378k]
  ------------------
 1565|   179k|    case OLD_STUN_ATTRIBUTE_SOURCE_ADDRESS:
  ------------------
  |  |   94|   179k|#define OLD_STUN_ATTRIBUTE_SOURCE_ADDRESS (0x0004)
  ------------------
  |  Branch (1565:5): [True: 1.68k, False: 379k]
  ------------------
 1566|   180k|    case OLD_STUN_ATTRIBUTE_CHANGED_ADDRESS:
  ------------------
  |  |   95|   180k|#define OLD_STUN_ATTRIBUTE_CHANGED_ADDRESS (0x0005)
  ------------------
  |  Branch (1566:5): [True: 790, False: 380k]
  ------------------
 1567|   181k|    case OLD_STUN_ATTRIBUTE_REFLECTED_FROM:
  ------------------
  |  |  101|   181k|#define OLD_STUN_ATTRIBUTE_REFLECTED_FROM (0x000B)
  ------------------
  |  Branch (1567:5): [True: 530, False: 380k]
  ------------------
 1568|   183k|    case STUN_ATTRIBUTE_RESPONSE_ORIGIN:
  ------------------
  |  |  132|   183k|#define STUN_ATTRIBUTE_RESPONSE_ORIGIN (0x802B)
  ------------------
  |  Branch (1568:5): [True: 1.93k, False: 379k]
  ------------------
 1569|   184k|    case STUN_ATTRIBUTE_OTHER_ADDRESS:
  ------------------
  |  |  133|   184k|#define STUN_ATTRIBUTE_OTHER_ADDRESS (0x802C)
  ------------------
  |  Branch (1569:5): [True: 854, False: 380k]
  ------------------
 1570|   184k|      return true;
 1571|      0|      break;
 1572|   197k|    default:;
  ------------------
  |  Branch (1572:5): [True: 197k, False: 184k]
  ------------------
 1573|   381k|    };
 1574|   197k|  }
 1575|   197k|  return false;
 1576|   381k|}
stun_attr_get_first_by_type_str:
 1598|  40.2k|stun_attr_ref stun_attr_get_first_by_type_str(const uint8_t *buf, size_t len, uint16_t attr_type) {
 1599|  40.2k|  stun_attr_ref attr = stun_attr_get_first_str(buf, len);
 1600|  68.3k|  while (attr) {
  ------------------
  |  Branch (1600:10): [True: 63.3k, False: 4.99k]
  ------------------
 1601|  63.3k|    if (stun_attr_get_type(attr) == attr_type) {
  ------------------
  |  Branch (1601:9): [True: 35.2k, False: 28.1k]
  ------------------
 1602|  35.2k|      return attr;
 1603|  35.2k|    }
 1604|  28.1k|    attr = stun_attr_get_next_str(buf, len, attr);
 1605|  28.1k|  }
 1606|       |
 1607|  4.99k|  return NULL;
 1608|  40.2k|}
stun_attr_get_first_str:
 1631|   288k|stun_attr_ref stun_attr_get_first_str(const uint8_t *buf, size_t len) {
 1632|   288k|  const int bufLen = stun_get_command_message_len_str(buf, len);
 1633|   288k|  if (bufLen > STUN_HEADER_LENGTH) {
  ------------------
  |  |   46|   288k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (1633:7): [True: 241k, False: 47.9k]
  ------------------
 1634|   241k|    stun_attr_ref attr = (stun_attr_ref)(buf + STUN_HEADER_LENGTH);
  ------------------
  |  |   46|   241k|#define STUN_HEADER_LENGTH (20)
  ------------------
 1635|   241k|    return stun_attr_check_valid(attr, bufLen - STUN_HEADER_LENGTH);
  ------------------
  |  |   46|   241k|#define STUN_HEADER_LENGTH (20)
  ------------------
 1636|   241k|  }
 1637|       |
 1638|  47.9k|  return NULL;
 1639|   288k|}
stun_attr_get_next_str:
 1641|   479k|stun_attr_ref stun_attr_get_next_str(const uint8_t *buf, size_t len, stun_attr_ref prev) {
 1642|   479k|  if (!prev) {
  ------------------
  |  Branch (1642:7): [True: 0, False: 479k]
  ------------------
 1643|      0|    return stun_attr_get_first_str(buf, len);
 1644|   479k|  } else {
 1645|   479k|    const uint8_t *end = buf + stun_get_command_message_len_str(buf, len);
 1646|   479k|    int attrlen = stun_attr_get_len(prev);
 1647|   479k|    const uint16_t rem4 = ((uint16_t)attrlen) & 0x0003;
 1648|   479k|    if (rem4) {
  ------------------
  |  Branch (1648:9): [True: 98.4k, False: 381k]
  ------------------
 1649|  98.4k|      attrlen = attrlen + 4 - (int)rem4;
 1650|  98.4k|    }
 1651|       |    /* Note the order here: operations on attrlen are untrusted as they may overflow */
 1652|   479k|    if (attrlen < end - (const uint8_t *)prev - 4) {
  ------------------
  |  Branch (1652:9): [True: 324k, False: 155k]
  ------------------
 1653|   324k|      const uint8_t *attr_end = (const uint8_t *)prev + 4 + attrlen;
 1654|   324k|      return stun_attr_check_valid(attr_end, end - attr_end);
 1655|   324k|    }
 1656|   155k|    return NULL;
 1657|   479k|  }
 1658|   479k|}
stun_attr_add_str:
 1660|   131k|bool stun_attr_add_str(uint8_t *buf, size_t *len, uint16_t attr, const uint8_t *avalue, int alen) {
 1661|   131k|  if (alen < 0) {
  ------------------
  |  Branch (1661:7): [True: 0, False: 131k]
  ------------------
 1662|      0|    alen = 0;
 1663|      0|  }
 1664|   131k|  uint8_t tmp[1];
 1665|   131k|  if (!avalue) {
  ------------------
  |  Branch (1665:7): [True: 0, False: 131k]
  ------------------
 1666|      0|    alen = 0;
 1667|      0|    avalue = tmp;
 1668|      0|  }
 1669|   131k|  const int clen = stun_get_command_message_len_str(buf, *len);
 1670|   131k|  int newlen = clen + 4 + alen;
 1671|   131k|  const int newlenrem4 = newlen & 0x00000003;
 1672|   131k|  int paddinglen = 0;
 1673|   131k|  if (newlenrem4) {
  ------------------
  |  Branch (1673:7): [True: 19.1k, False: 112k]
  ------------------
 1674|  19.1k|    paddinglen = 4 - newlenrem4;
 1675|  19.1k|    newlen = newlen + paddinglen;
 1676|  19.1k|  }
 1677|       |
 1678|   131k|  if (newlen >= MAX_STUN_MESSAGE_SIZE) {
  ------------------
  |  |  221|   131k|#define MAX_STUN_MESSAGE_SIZE (65507)
  ------------------
  |  Branch (1678:7): [True: 0, False: 131k]
  ------------------
 1679|      0|    return false;
 1680|      0|  }
 1681|       |
 1682|   131k|  uint8_t *attr_start = buf + clen;
 1683|       |
 1684|   131k|  stun_set_command_message_len_str(buf, newlen);
 1685|   131k|  *len = newlen;
 1686|       |
 1687|   131k|  turn_write_u16(attr_start, attr);
 1688|   131k|  turn_write_u16(attr_start + 2, (uint16_t)alen);
 1689|   131k|  if (alen > 0) {
  ------------------
  |  Branch (1689:7): [True: 129k, False: 2.14k]
  ------------------
 1690|   129k|    memcpy(attr_start + 4, avalue, alen);
 1691|   129k|  }
 1692|       |
 1693|       |  // Write 0 padding to not leak data
 1694|   131k|  memset(attr_start + 4 + alen, 0, paddinglen);
 1695|       |
 1696|       |  return true;
 1697|   131k|}
stun_attr_add_addr_str:
 1699|  51.1k|bool stun_attr_add_addr_str(uint8_t *buf, size_t *len, uint16_t attr_type, const ioa_addr *ca) {
 1700|       |
 1701|  51.1k|  stun_tid tid;
 1702|  51.1k|  stun_tid_from_message_str(buf, *len, &tid);
 1703|       |
 1704|  51.1k|  int xor_ed = 0;
 1705|  51.1k|  switch (attr_type) {
 1706|  14.3k|  case STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS:
  ------------------
  |  |  105|  14.3k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (1706:3): [True: 14.3k, False: 36.7k]
  ------------------
 1707|  26.1k|  case STUN_ATTRIBUTE_XOR_PEER_ADDRESS:
  ------------------
  |  |  116|  26.1k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  |  Branch (1707:3): [True: 11.7k, False: 39.4k]
  ------------------
 1708|  41.7k|  case STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS:
  ------------------
  |  |  118|  41.7k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  |  Branch (1708:3): [True: 15.6k, False: 35.4k]
  ------------------
 1709|  41.7k|    xor_ed = 1;
 1710|  41.7k|    break;
 1711|  9.35k|  default:;
  ------------------
  |  Branch (1711:3): [True: 9.35k, False: 41.7k]
  ------------------
 1712|  51.1k|  };
 1713|       |
 1714|  51.1k|  ioa_addr public_addr;
 1715|  51.1k|  map_addr_from_private_to_public(ca, &public_addr);
 1716|       |
 1717|  51.1k|  uint8_t cfield[64];
 1718|  51.1k|  int clen = 0;
 1719|  51.1k|  if (stun_addr_encode(&public_addr, cfield, &clen, xor_ed, STUN_MAGIC_COOKIE, tid.tsx_id) < 0) {
  ------------------
  |  |   56|  51.1k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (1719:7): [True: 0, False: 51.1k]
  ------------------
 1720|      0|    return false;
 1721|      0|  }
 1722|       |
 1723|  51.1k|  if (!stun_attr_add_str(buf, len, attr_type, (uint8_t *)(&cfield), clen)) {
  ------------------
  |  Branch (1723:7): [True: 0, False: 51.1k]
  ------------------
 1724|      0|    return false;
 1725|      0|  }
 1726|       |
 1727|  51.1k|  return true;
 1728|  51.1k|}
stun_attr_get_addr_str:
 1731|  96.4k|                            const ioa_addr *default_addr) {
 1732|  96.4k|  stun_tid tid;
 1733|  96.4k|  stun_tid_from_message_str(buf, len, &tid);
 1734|  96.4k|  ioa_addr public_addr;
 1735|       |
 1736|  96.4k|  addr_set_any(ca);
 1737|  96.4k|  addr_set_any(&public_addr);
 1738|       |
 1739|  96.4k|  const int attr_type = stun_attr_get_type(attr);
 1740|  96.4k|  if (attr_type < 0) {
  ------------------
  |  Branch (1740:7): [True: 0, False: 96.4k]
  ------------------
 1741|      0|    return false;
 1742|      0|  }
 1743|       |
 1744|  96.4k|  int xor_ed = 0;
 1745|  96.4k|  switch (attr_type) {
 1746|  23.4k|  case STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS:
  ------------------
  |  |  105|  23.4k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (1746:3): [True: 23.4k, False: 73.0k]
  ------------------
 1747|  50.4k|  case STUN_ATTRIBUTE_XOR_PEER_ADDRESS:
  ------------------
  |  |  116|  50.4k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  |  Branch (1747:3): [True: 27.0k, False: 69.4k]
  ------------------
 1748|  79.6k|  case STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS:
  ------------------
  |  |  118|  79.6k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  |  Branch (1748:3): [True: 29.1k, False: 67.2k]
  ------------------
 1749|  79.6k|    xor_ed = 1;
 1750|  79.6k|    break;
 1751|  16.8k|  default:;
  ------------------
  |  Branch (1751:3): [True: 16.8k, False: 79.6k]
  ------------------
 1752|  96.4k|  };
 1753|       |
 1754|  96.4k|  const uint8_t *cfield = stun_attr_get_value(attr);
 1755|  96.4k|  if (!cfield) {
  ------------------
  |  Branch (1755:7): [True: 5.12k, False: 91.3k]
  ------------------
 1756|  5.12k|    return false;
 1757|  5.12k|  }
 1758|       |
 1759|  91.3k|  if (stun_addr_decode(&public_addr, cfield, stun_attr_get_len(attr), xor_ed, STUN_MAGIC_COOKIE, tid.tsx_id) < 0) {
  ------------------
  |  |   56|  91.3k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (1759:7): [True: 6.16k, False: 85.1k]
  ------------------
 1760|  6.16k|    return false;
 1761|  6.16k|  }
 1762|       |
 1763|  85.1k|  map_addr_from_public_to_private(&public_addr, ca);
 1764|       |
 1765|  85.1k|  if (default_addr && addr_any_no_port(ca) && !addr_any_no_port(default_addr)) {
  ------------------
  |  Branch (1765:7): [True: 84.9k, False: 265]
  |  Branch (1765:23): [True: 10.9k, False: 73.9k]
  |  Branch (1765:47): [True: 10.9k, False: 0]
  ------------------
 1766|  10.9k|    const uint16_t port = addr_get_port(ca);
 1767|  10.9k|    addr_cpy(ca, default_addr);
 1768|  10.9k|    addr_set_port(ca, port);
 1769|  10.9k|  }
 1770|       |
 1771|       |  return true;
 1772|  91.3k|}
stun_attr_get_first_addr_str:
 1775|  94.5k|                                  const ioa_addr *default_addr) {
 1776|  94.5k|  stun_attr_ref attr = stun_attr_get_first_str(buf, len);
 1777|       |
 1778|   310k|  while (attr) {
  ------------------
  |  Branch (1778:10): [True: 249k, False: 60.5k]
  ------------------
 1779|   249k|    if (stun_attr_is_addr(attr) && (attr_type == stun_attr_get_type(attr))) {
  ------------------
  |  Branch (1779:9): [True: 132k, False: 116k]
  |  Branch (1779:36): [True: 45.3k, False: 87.6k]
  ------------------
 1780|  45.3k|      if (stun_attr_get_addr_str(buf, len, attr, ca, default_addr)) {
  ------------------
  |  Branch (1780:11): [True: 34.0k, False: 11.2k]
  ------------------
 1781|  34.0k|        return true;
 1782|  34.0k|      }
 1783|  45.3k|    }
 1784|   215k|    attr = stun_attr_get_next_str(buf, len, attr);
 1785|   215k|  }
 1786|       |
 1787|  60.5k|  return false;
 1788|  94.5k|}
stun_attr_add_channel_number_str:
 1790|  11.7k|bool stun_attr_add_channel_number_str(uint8_t *buf, size_t *len, uint16_t chnumber) {
 1791|       |
 1792|  11.7k|  uint16_t field[2];
 1793|  11.7k|  field[0] = nswap16(chnumber);
  ------------------
  |  |   86|  11.7k|#define nswap16(s) ntohs(s)
  ------------------
 1794|  11.7k|  field[1] = 0;
 1795|       |
 1796|  11.7k|  return stun_attr_add_str(buf, len, STUN_ATTRIBUTE_CHANNEL_NUMBER, (uint8_t *)(field), sizeof(field));
  ------------------
  |  |  113|  11.7k|#define STUN_ATTRIBUTE_CHANNEL_NUMBER (0x000C)
  ------------------
 1797|  11.7k|}
stun_attr_get_first_channel_number_str:
 1825|  77.0k|uint16_t stun_attr_get_first_channel_number_str(const uint8_t *buf, size_t len) {
 1826|       |
 1827|  77.0k|  stun_attr_ref attr = stun_attr_get_first_str(buf, len);
 1828|   181k|  while (attr) {
  ------------------
  |  Branch (1828:10): [True: 116k, False: 65.3k]
  ------------------
 1829|   116k|    if (stun_attr_get_type(attr) == STUN_ATTRIBUTE_CHANNEL_NUMBER) {
  ------------------
  |  |  113|   116k|#define STUN_ATTRIBUTE_CHANNEL_NUMBER (0x000C)
  ------------------
  |  Branch (1829:9): [True: 11.7k, False: 104k]
  ------------------
 1830|  11.7k|      const uint16_t ret = stun_attr_get_channel_number(attr);
 1831|  11.7k|      if (STUN_VALID_CHANNEL(ret)) {
  ------------------
  |  |  159|  11.7k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (159:34): [True: 11.7k, False: 0]
  |  |  |  Branch (159:53): [True: 11.7k, False: 0]
  |  |  ------------------
  ------------------
 1832|  11.7k|        return ret;
 1833|  11.7k|      }
 1834|  11.7k|    }
 1835|   104k|    attr = stun_attr_get_next_str(buf, len, attr);
 1836|   104k|  }
 1837|       |
 1838|  65.3k|  return 0;
 1839|  77.0k|}
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:
  882|  28.4k|                                                stun_tid *id, bool include_reason_string, bool pad_reason_phrase) {
  883|       |
  884|  28.4k|  if (include_reason_string && (!reason || !strcmp((const char *)reason, "Unknown error"))) {
  ------------------
  |  Branch (884:7): [True: 19.0k, False: 9.39k]
  |  Branch (884:33): [True: 978, False: 18.0k]
  |  Branch (884:44): [True: 0, False: 18.0k]
  ------------------
  885|    978|    reason = get_default_reason(error_code);
  886|    978|  }
  887|       |
  888|  28.4k|  uint8_t avalue[513];
  889|  28.4k|  memset(avalue, 0, sizeof(avalue));
  890|  28.4k|  avalue[0] = 0;
  891|  28.4k|  avalue[1] = 0;
  892|  28.4k|  avalue[2] = (uint8_t)(error_code / 100);
  893|  28.4k|  avalue[3] = (uint8_t)(error_code % 100);
  894|  28.4k|  if (include_reason_string) {
  ------------------
  |  Branch (894:7): [True: 19.0k, False: 9.39k]
  ------------------
  895|  19.0k|    strncpy((char *)(avalue + 4), (const char *)reason, sizeof(avalue) - 4);
  896|  19.0k|  }
  897|  28.4k|  avalue[sizeof(avalue) - 1] = 0;
  898|  28.4k|  int alen = 4 + (int)strlen((const char *)(avalue + 4));
  899|       |
  900|       |  /* RFC 3489 Section 11.2.9 requires a reason phrase length that is a multiple of 4;
  901|       |   * RFC 8489 Section 14 requires the declared length to exclude padding. */
  902|  28.4k|  if (pad_reason_phrase) {
  ------------------
  |  Branch (902:7): [True: 4.03k, False: 24.4k]
  ------------------
  903|  4.03k|    const int rem = alen % 4;
  904|  4.03k|    if (rem) {
  ------------------
  |  Branch (904:9): [True: 1.94k, False: 2.08k]
  ------------------
  905|  1.94k|      alen += (4 - rem);
  906|  1.94k|    }
  907|  4.03k|  }
  908|       |
  909|  28.4k|  stun_attr_add_str(buf, len, STUN_ATTRIBUTE_ERROR_CODE, (uint8_t *)avalue, alen);
  ------------------
  |  |   99|  28.4k|#define STUN_ATTRIBUTE_ERROR_CODE (0x0009)
  ------------------
  910|  28.4k|  if (id) {
  ------------------
  |  Branch (910:7): [True: 28.4k, False: 0]
  ------------------
  911|  28.4k|    stun_tid_message_cpy(buf, id);
  912|  28.4k|  }
  913|  28.4k|}
ns_turn_msg.c:has_prefix:
 1047|  7.45k|static inline bool has_prefix(const char *buf, size_t blen, const char *prefix, bool ignore_case) {
 1048|  7.45k|  if (!buf || !prefix) {
  ------------------
  |  Branch (1048:7): [True: 0, False: 7.45k]
  |  Branch (1048:15): [True: 0, False: 7.45k]
  ------------------
 1049|      0|    return false;
 1050|      0|  }
 1051|       |
 1052|  7.45k|  const size_t prefix_len = strlen(prefix);
 1053|  7.45k|  return (prefix_len <= blen) && sheadof(prefix, buf, ignore_case);
  ------------------
  |  Branch (1053:10): [True: 7.45k, False: 0]
  |  Branch (1053:34): [True: 790, False: 6.66k]
  ------------------
 1054|  7.45k|}
ns_turn_msg.c:sheadof:
 1012|   626k|static inline bool sheadof(const char *head, const char *full, bool ignore_case) {
 1013|   675k|  while (*head) {
  ------------------
  |  Branch (1013:10): [True: 673k, False: 2.61k]
  ------------------
 1014|   673k|    if (*head != *full) {
  ------------------
  |  Branch (1014:9): [True: 627k, False: 46.1k]
  ------------------
 1015|   627k|      if (ignore_case && (tolower((unsigned char)*head) == tolower((unsigned char)*full))) {
  ------------------
  |  Branch (1015:11): [True: 227k, False: 399k]
  |  Branch (1015:26): [True: 3.56k, False: 223k]
  |  Branch (1015:27): [True: 0, False: 0]
  |  Branch (1015:27): [True: 0, False: 0]
  |  Branch (1015:27): [Folded, False: 227k]
  |  Branch (1015:60): [True: 0, False: 0]
  |  Branch (1015:60): [True: 0, False: 0]
  |  Branch (1015:60): [Folded, False: 227k]
  ------------------
 1016|       |        // OK
 1017|   623k|      } else {
 1018|   623k|        return false;
 1019|   623k|      }
 1020|   627k|    }
 1021|  49.6k|    ++head;
 1022|  49.6k|    ++full;
 1023|  49.6k|  }
 1024|  2.61k|  return true;
 1025|   626k|}
ns_turn_msg.c:findstr:
 1027|  2.14k|static inline const char *findstr(const char *hay, size_t slen, const char *needle, bool ignore_case) {
 1028|  2.14k|  const char *ret = NULL;
 1029|       |
 1030|  2.14k|  if (hay && slen && needle) {
  ------------------
  |  Branch (1030:7): [True: 2.14k, False: 0]
  |  Branch (1030:14): [True: 2.14k, False: 0]
  |  Branch (1030:22): [True: 2.14k, False: 0]
  ------------------
 1031|  2.14k|    const size_t nlen = strlen(needle);
 1032|  2.14k|    if (nlen <= slen) {
  ------------------
  |  Branch (1032:9): [True: 2.09k, False: 50]
  ------------------
 1033|  2.09k|      const size_t smax = slen - nlen + 1;
 1034|  2.09k|      const char *sp = hay;
 1035|   618k|      for (size_t i = 0; i < smax; ++i) {
  ------------------
  |  Branch (1035:26): [True: 618k, False: 264]
  ------------------
 1036|   618k|        if (sheadof(needle, sp + i, ignore_case)) {
  ------------------
  |  Branch (1036:13): [True: 1.82k, False: 616k]
  ------------------
 1037|  1.82k|          ret = sp + i;
 1038|  1.82k|          break;
 1039|  1.82k|        }
 1040|   618k|      }
 1041|  2.09k|    }
 1042|  2.14k|  }
 1043|       |
 1044|  2.14k|  return ret;
 1045|  2.14k|}
ns_turn_msg.c:stun_tid_from_string:
 1424|   150k|static void stun_tid_from_string(const uint8_t *s, stun_tid *id) {
 1425|   150k|  if (s && id) {
  ------------------
  |  Branch (1425:7): [True: 150k, False: 0]
  |  Branch (1425:12): [True: 150k, False: 0]
  ------------------
 1426|   150k|    memcpy(id->tsx_id, s, STUN_TID_SIZE);
  ------------------
  |  |   53|   150k|#define STUN_TID_SIZE (12)
  ------------------
 1427|   150k|  }
 1428|   150k|}
ns_turn_msg.c:stun_tid_string_cpy:
 1418|   135k|static void stun_tid_string_cpy(uint8_t *s, const stun_tid *id) {
 1419|   135k|  if (s && id) {
  ------------------
  |  Branch (1419:7): [True: 135k, False: 0]
  |  Branch (1419:12): [True: 135k, False: 0]
  ------------------
 1420|   135k|    memcpy(s, id->tsx_id, STUN_TID_SIZE);
  ------------------
  |  |   53|   135k|#define STUN_TID_SIZE (12)
  ------------------
 1421|   135k|  }
 1422|   135k|}
ns_turn_msg.c:turn_random_tid_size:
  154|  78.7k|static void turn_random_tid_size(void *id) {
  155|  78.7k|  uint8_t *ar = (uint8_t *)id;
  156|  78.7k|#if defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
  157|  78.7k|  if (ar) {
  ------------------
  |  Branch (157:7): [True: 78.7k, False: 0]
  ------------------
  158|   314k|    for (size_t i = 0; i < 3; ++i) {
  ------------------
  |  Branch (158:24): [True: 236k, False: 78.7k]
  ------------------
  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.7k|  }
  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.7k|}
ns_turn_msg.c:stun_attr_check_valid:
 1610|   565k|static stun_attr_ref stun_attr_check_valid(stun_attr_ref attr, size_t remaining) {
 1611|   565k|  if (remaining >= 4) {
  ------------------
  |  Branch (1611:7): [True: 564k, False: 877]
  ------------------
 1612|       |    /* Read the size of the attribute */
 1613|   564k|    size_t attrlen = stun_attr_get_len(attr);
 1614|   564k|    remaining -= 4;
 1615|       |
 1616|       |    /* Round to boundary */
 1617|   564k|    const uint16_t rem4 = ((uint16_t)attrlen) & 0x0003;
 1618|   564k|    if (rem4) {
  ------------------
  |  Branch (1618:9): [True: 112k, False: 452k]
  ------------------
 1619|   112k|      attrlen = attrlen + 4 - (int)rem4;
 1620|   112k|    }
 1621|       |
 1622|       |    /* Check that there's enough space remaining */
 1623|   564k|    if (attrlen <= remaining) {
  ------------------
  |  Branch (1623:9): [True: 560k, False: 4.01k]
  ------------------
 1624|   560k|      return attr;
 1625|   560k|    }
 1626|   564k|  }
 1627|       |
 1628|  4.89k|  return NULL;
 1629|   565k|}
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.6k, False: 23.5k]
  |  Branch (48:38): [True: 5.42k, False: 18.1k]
  ------------------
   49|       |
   50|       |    /* IPv4 address */
   51|       |
   52|  33.0k|    *clen = 8;
   53|       |
   54|  33.0k|    cfield[0] = 0;
   55|  33.0k|    cfield[1] = 1; // IPv4 family
   56|       |
   57|  33.0k|    if (xor_ed) {
  ------------------
  |  Branch (57:9): [True: 27.5k, False: 5.51k]
  ------------------
   58|       |
   59|       |      /* Port */
   60|  27.5k|      const uint16_t port = (ca->s4.sin_port) ^ nswap16(mc >> 16);
  ------------------
  |  |   86|  27.5k|#define nswap16(s) ntohs(s)
  ------------------
   61|  27.5k|      memcpy(cfield + 2, &port, sizeof(port));
   62|       |
   63|       |      /* Address */
   64|  27.5k|      const uint32_t addr = (ca->s4.sin_addr.s_addr) ^ nswap32(mc);
  ------------------
  |  |   87|  27.5k|#define nswap32(ul) ntohl(ul)
  ------------------
   65|  27.5k|      memcpy(cfield + 4, &addr, sizeof(addr));
   66|       |
   67|  27.5k|    } else {
   68|       |
   69|       |      /* Port */
   70|  5.51k|      const uint16_t port = ca->s4.sin_port;
   71|  5.51k|      memcpy(cfield + 2, &port, sizeof(port));
   72|       |
   73|       |      /* Address */
   74|  5.51k|      const uint32_t addr = ca->s4.sin_addr.s_addr;
   75|  5.51k|      memcpy(cfield + 4, &addr, sizeof(addr));
   76|  5.51k|    }
   77|       |
   78|  33.0k|  } else if (ca->ss.sa_family == AF_INET6) {
  ------------------
  |  Branch (78:14): [True: 18.1k, False: 0]
  ------------------
   79|       |
   80|       |    /* IPv6 address */
   81|       |
   82|  18.1k|    *clen = 20;
   83|       |
   84|  18.1k|    cfield[0] = 0;
   85|  18.1k|    cfield[1] = 2; // IPv6 family
   86|       |
   87|  18.1k|    if (xor_ed) {
  ------------------
  |  Branch (87:9): [True: 14.2k, False: 3.85k]
  ------------------
   88|       |
   89|  14.2k|      unsigned int i;
   90|  14.2k|      uint8_t *dst = ((uint8_t *)cfield) + 4;
   91|  14.2k|      const uint8_t *src = (const uint8_t *)&(ca->s6.sin6_addr);
   92|  14.2k|      uint32_t magic = nswap32(mc);
  ------------------
  |  |   87|  14.2k|#define nswap32(ul) ntohl(ul)
  ------------------
   93|       |
   94|       |      /* Port */
   95|  14.2k|      const uint16_t port = ca->s6.sin6_port ^ nswap16(mc >> 16);
  ------------------
  |  |   86|  14.2k|#define nswap16(s) ntohs(s)
  ------------------
   96|  14.2k|      memcpy(cfield + 2, &port, sizeof(port));
   97|       |
   98|       |      /* Address */
   99|       |
  100|  71.2k|      for (i = 0; i < 4; ++i) {
  ------------------
  |  Branch (100:19): [True: 57.0k, False: 14.2k]
  ------------------
  101|  57.0k|        dst[i] = (uint8_t)(src[i] ^ ((const uint8_t *)&magic)[i]);
  102|  57.0k|      }
  103|   185k|      for (i = 0; i < 12; ++i) {
  ------------------
  |  Branch (103:19): [True: 171k, False: 14.2k]
  ------------------
  104|   171k|        dst[i + 4] = (uint8_t)(src[i + 4] ^ tsx_id[i]);
  105|   171k|      }
  106|       |
  107|  14.2k|    } else {
  108|       |
  109|       |      /* Port */
  110|  3.85k|      const uint16_t port = ca->s6.sin6_port;
  111|  3.85k|      memcpy(cfield + 2, &port, sizeof(port));
  112|       |
  113|       |      /* Address */
  114|  3.85k|      memcpy(((uint8_t *)cfield) + 4, &ca->s6.sin6_addr, 16);
  115|  3.85k|    }
  116|       |
  117|  18.1k|  } else {
  118|      0|    return -1;
  119|      0|  }
  120|       |
  121|  51.1k|  return 0;
  122|  51.1k|}
stun_addr_decode:
  124|  94.9k|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.9k|  if (!cfield || !len || !ca || !tsx_id || (len < 8)) {
  ------------------
  |  Branch (126:7): [True: 0, False: 94.9k]
  |  Branch (126:18): [True: 0, False: 94.9k]
  |  Branch (126:26): [True: 0, False: 94.9k]
  |  Branch (126:33): [True: 0, False: 94.9k]
  |  Branch (126:44): [True: 4.81k, False: 90.1k]
  ------------------
  127|  4.81k|    return -1;
  128|  4.81k|  }
  129|       |
  130|  90.1k|  if (cfield[0] != 0) {
  ------------------
  |  Branch (130:7): [True: 2.20k, False: 87.9k]
  ------------------
  131|  2.20k|    return -1;
  132|  2.20k|  }
  133|       |
  134|  87.9k|  int sa_family;
  135|       |
  136|  87.9k|  if (cfield[1] == 1) {
  ------------------
  |  Branch (136:7): [True: 57.4k, False: 30.5k]
  ------------------
  137|  57.4k|    sa_family = AF_INET;
  138|  57.4k|  } else if (cfield[1] == 2) {
  ------------------
  |  Branch (138:14): [True: 29.5k, False: 1.00k]
  ------------------
  139|  29.5k|    sa_family = AF_INET6;
  140|  29.5k|  } else {
  141|  1.00k|    return -1;
  142|  1.00k|  }
  143|       |
  144|  86.9k|  ca->ss.sa_family = sa_family;
  145|       |
  146|  86.9k|  if (sa_family == AF_INET) {
  ------------------
  |  Branch (146:7): [True: 57.4k, False: 29.5k]
  ------------------
  147|       |
  148|  57.4k|    if (len != 8) {
  ------------------
  |  Branch (148:9): [True: 1.17k, False: 56.2k]
  ------------------
  149|  1.17k|      return -1;
  150|  1.17k|    }
  151|       |
  152|       |    /* IPv4 address */
  153|       |
  154|       |    /* Port */
  155|  56.2k|    memcpy(&ca->s4.sin_port, cfield + 2, sizeof(ca->s4.sin_port));
  156|       |
  157|       |    /* Address */
  158|  56.2k|    memcpy(&ca->s4.sin_addr.s_addr, cfield + 4, sizeof(ca->s4.sin_addr.s_addr));
  159|       |
  160|  56.2k|    if (xor_ed) {
  ------------------
  |  Branch (160:9): [True: 48.0k, False: 8.16k]
  ------------------
  161|  48.0k|      ca->s4.sin_port ^= nswap16(mc >> 16);
  ------------------
  |  |   86|  48.0k|#define nswap16(s) ntohs(s)
  ------------------
  162|  48.0k|      ca->s4.sin_addr.s_addr ^= nswap32(mc);
  ------------------
  |  |   87|  48.0k|#define nswap32(ul) ntohl(ul)
  ------------------
  163|  48.0k|    }
  164|       |
  165|  56.2k|  } else if (sa_family == AF_INET6) {
  ------------------
  |  Branch (165:14): [True: 29.5k, False: 0]
  ------------------
  166|       |
  167|       |    /* IPv6 address */
  168|       |
  169|  29.5k|    if (len != 20) {
  ------------------
  |  Branch (169:9): [True: 567, False: 28.9k]
  ------------------
  170|    567|      return -1;
  171|    567|    }
  172|       |
  173|       |    /* Port */
  174|  28.9k|    memcpy(&ca->s6.sin6_port, cfield + 2, sizeof(ca->s6.sin6_port));
  175|       |
  176|       |    /* Address */
  177|  28.9k|    memcpy(&ca->s6.sin6_addr, ((const uint8_t *)cfield) + 4, 16);
  178|       |
  179|  28.9k|    if (xor_ed) {
  ------------------
  |  Branch (179:9): [True: 23.3k, False: 5.59k]
  ------------------
  180|       |
  181|  23.3k|      unsigned int i;
  182|  23.3k|      uint8_t *dst;
  183|  23.3k|      const uint8_t *src;
  184|  23.3k|      uint32_t magic = nswap32(mc);
  ------------------
  |  |   87|  23.3k|#define nswap32(ul) ntohl(ul)
  ------------------
  185|       |
  186|       |      /* Port */
  187|  23.3k|      ca->s6.sin6_port ^= nswap16(mc >> 16);
  ------------------
  |  |   86|  23.3k|#define nswap16(s) ntohs(s)
  ------------------
  188|       |
  189|       |      /* Address */
  190|  23.3k|      src = ((const uint8_t *)cfield) + 4;
  191|  23.3k|      dst = (uint8_t *)&ca->s6.sin6_addr;
  192|   116k|      for (i = 0; i < 4; ++i) {
  ------------------
  |  Branch (192:19): [True: 93.4k, False: 23.3k]
  ------------------
  193|  93.4k|        dst[i] = (uint8_t)(src[i] ^ ((const uint8_t *)&magic)[i]);
  194|  93.4k|      }
  195|   303k|      for (i = 0; i < 12; ++i) {
  ------------------
  |  Branch (195:19): [True: 280k, False: 23.3k]
  ------------------
  196|   280k|        dst[i + 4] = (uint8_t)(src[i + 4] ^ tsx_id[i]);
  197|   280k|      }
  198|  23.3k|    }
  199|       |
  200|  28.9k|  } else {
  201|      0|    return -1;
  202|      0|  }
  203|       |
  204|  85.2k|  return 0;
  205|  86.9k|}

ns_turn_msg.c:turn_read_u16:
  127|  4.63M|static inline uint16_t turn_read_u16(const void *field) {
  128|  4.63M|  uint16_t v;
  129|  4.63M|  memcpy(&v, field, sizeof(v));
  130|       |  return nswap16(v);
  ------------------
  |  |   86|  4.63M|#define nswap16(s) ntohs(s)
  ------------------
  131|  4.63M|}
ns_turn_msg.c:turn_read_u32:
  133|   155k|static inline uint32_t turn_read_u32(const void *field) {
  134|   155k|  uint32_t v;
  135|   155k|  memcpy(&v, field, sizeof(v));
  136|       |  return nswap32(v);
  ------------------
  |  |   87|   155k|#define nswap32(ul) ntohl(ul)
  ------------------
  137|   155k|}
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.0k|static inline void turn_write_u32(void *field, uint32_t v) {
  151|       |  const uint32_t raw = nswap32(v);
  ------------------
  |  |   87|  77.0k|#define nswap32(ul) ntohl(ul)
  ------------------
  152|  77.0k|  memcpy(field, &raw, sizeof(raw));
  153|  77.0k|}
ns_turn_msg.c:_ioa_ntoh64:
   90|  6.55k|static inline uint64_t _ioa_ntoh64(uint64_t v) {
   91|  6.55k|#if BYTE_ORDER == LITTLE_ENDIAN
   92|  6.55k|  uint8_t *src = (uint8_t *)&v;
   93|  6.55k|  uint8_t *dst = src + 7;
   94|  32.7k|  while (src < dst) {
  ------------------
  |  Branch (94:10): [True: 26.2k, False: 6.55k]
  ------------------
   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.55k|  return v;
  105|  6.55k|}

