LLVMFuzzerInitialize:
   46|      1|int LLVMFuzzerInitialize(int *argc, char ***argv) {
   47|      1|  (void)argc;
   48|      1|  (void)argv;
   49|       |
   50|      1|#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|      1|  OPENSSL_init_crypto(OPENSSL_INIT_NO_LOAD_CONFIG, NULL);
   56|      1|#endif
   57|       |
   58|      1|  seed_addr_mappings();
   59|       |
   60|      1|  return 0;
   61|      1|}
FuzzOpenSSLInit.c:seed_addr_mappings:
   29|      1|static void seed_addr_mappings(void) {
   30|      1|  ioa_addr pub4 = {0};
   31|      1|  ioa_addr priv4 = {0};
   32|      1|  ioa_addr pub6 = {0};
   33|      1|  ioa_addr priv6 = {0};
   34|       |
   35|      1|  if (make_ioa_addr((const uint8_t *)"192.0.2.1", 0, &pub4) == 0 &&
  ------------------
  |  Branch (35:7): [True: 1, False: 0]
  ------------------
   36|      1|      make_ioa_addr((const uint8_t *)"10.0.0.1", 0, &priv4) == 0) {
  ------------------
  |  Branch (36:7): [True: 1, False: 0]
  ------------------
   37|      1|    ioa_addr_add_mapping(&pub4, &priv4);
   38|      1|  }
   39|       |
   40|      1|  if (make_ioa_addr((const uint8_t *)"2001:db8::1", 0, &pub6) == 0 &&
  ------------------
  |  Branch (40:7): [True: 1, False: 0]
  ------------------
   41|      1|      make_ioa_addr((const uint8_t *)"fd00::1", 0, &priv6) == 0) {
  ------------------
  |  Branch (41:7): [True: 1, False: 0]
  ------------------
   42|      1|    ioa_addr_add_mapping(&pub6, &priv6);
   43|      1|  }
   44|      1|}

make_ioa_addr:
  201|      4|int make_ioa_addr(const uint8_t *saddr0, uint16_t port, ioa_addr *addr) {
  202|       |
  203|      4|  if (!saddr0 || !addr) {
  ------------------
  |  Branch (203:7): [True: 0, False: 4]
  |  Branch (203:18): [True: 0, False: 4]
  ------------------
  204|      0|    return -1;
  205|      0|  }
  206|       |
  207|      4|  char ssaddr[257];
  208|      4|  STRCPY(ssaddr, saddr0);
  ------------------
  |  |  194|      4|  do {                                                                                                                 \
  |  |  195|      4|    if ((const char *)(dst) != (const char *)(src)) {                                                                  \
  |  |  ------------------
  |  |  |  Branch (195:9): [True: 4, False: 0]
  |  |  ------------------
  |  |  196|      4|      if (sizeof(dst) == sizeof(char *))                                                                               \
  |  |  ------------------
  |  |  |  Branch (196:11): [Folded, False: 4]
  |  |  ------------------
  |  |  197|      4|        strcpy(((char *)(dst)), (const char *)(src));                                                                  \
  |  |  198|      4|      else {                                                                                                           \
  |  |  199|      4|        size_t szdst = sizeof((dst));                                                                                  \
  |  |  200|      4|        strncpy((char *)(dst), (const char *)(src), szdst);                                                            \
  |  |  201|      4|        ((char *)(dst))[szdst - 1] = 0;                                                                                \
  |  |  202|      4|      }                                                                                                                \
  |  |  203|      4|    }                                                                                                                  \
  |  |  204|      4|  } while (0)
  |  |  ------------------
  |  |  |  Branch (204:12): [Folded, False: 4]
  |  |  ------------------
  ------------------
  209|       |
  210|      4|  char *saddr = ssaddr;
  211|      4|  while (*saddr == ' ') {
  ------------------
  |  Branch (211:10): [True: 0, False: 4]
  ------------------
  212|      0|    ++saddr;
  213|      0|  }
  214|       |
  215|      4|  size_t len = strlen(saddr);
  216|      4|  while (len > 0) {
  ------------------
  |  Branch (216:10): [True: 4, False: 0]
  ------------------
  217|      4|    if (saddr[len - 1] == ' ') {
  ------------------
  |  Branch (217:9): [True: 0, False: 4]
  ------------------
  218|      0|      saddr[len - 1] = 0;
  219|      0|      --len;
  220|      4|    } else {
  221|      4|      break;
  222|      4|    }
  223|      4|  }
  224|       |
  225|      4|  memset(addr, 0, sizeof(ioa_addr));
  226|      4|  if ((len == 0) || (inet_pton(AF_INET, saddr, &addr->s4.sin_addr) == 1)) {
  ------------------
  |  Branch (226:7): [True: 0, False: 4]
  |  Branch (226:21): [True: 2, False: 2]
  ------------------
  227|      2|    addr->s4.sin_family = AF_INET;
  228|       |#if defined(TURN_HAS_SIN_LEN) /* tested when configured */
  229|       |    addr->s4.sin_len = sizeof(struct sockaddr_in);
  230|       |#endif
  231|      2|    addr->s4.sin_port = nswap16(port);
  ------------------
  |  |   82|      2|#define nswap16(s) ntohs(s)
  ------------------
  232|      2|  } else if (inet_pton(AF_INET6, saddr, &addr->s6.sin6_addr) == 1) {
  ------------------
  |  Branch (232:14): [True: 2, False: 0]
  ------------------
  233|      2|    addr->s6.sin6_family = AF_INET6;
  234|       |#if defined(SIN6_LEN) /* this define is required by IPv6 if used */
  235|       |    addr->s6.sin6_len = sizeof(struct sockaddr_in6);
  236|       |#endif
  237|      2|    addr->s6.sin6_port = nswap16(port);
  ------------------
  |  |   82|      2|#define nswap16(s) ntohs(s)
  ------------------
  238|      2|  } else {
  239|      0|    struct addrinfo addr_hints;
  240|      0|    struct addrinfo *addr_result = NULL;
  241|      0|    int err;
  242|       |
  243|      0|    memset(&addr_hints, 0, sizeof(struct addrinfo));
  244|      0|    addr_hints.ai_family = AF_UNSPEC;    /* Allow IPv4 or IPv6 */
  245|      0|    addr_hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */
  246|      0|    addr_hints.ai_flags = AI_PASSIVE;    /* For wildcard IP address */
  247|      0|    addr_hints.ai_protocol = 0;          /* Any protocol */
  248|      0|    addr_hints.ai_canonname = NULL;
  249|      0|    addr_hints.ai_addr = NULL;
  250|      0|    addr_hints.ai_next = NULL;
  251|       |
  252|      0|    err = getaddrinfo(saddr, NULL, &addr_hints, &addr_result);
  253|      0|    if ((err != 0) || (!addr_result)) {
  ------------------
  |  Branch (253:9): [True: 0, False: 0]
  |  Branch (253:23): [True: 0, False: 0]
  ------------------
  254|      0|      fprintf(stderr, "error resolving '%s' hostname: %s\n", saddr, gai_strerror(err));
  255|      0|      return -1;
  256|      0|    }
  257|       |
  258|      0|    int family = AF_INET;
  259|      0|    struct addrinfo *addr_result_orig = addr_result;
  260|      0|    int found = 0;
  261|       |
  262|      0|  beg_af:
  263|       |
  264|      0|    while (addr_result) {
  ------------------
  |  Branch (264:12): [True: 0, False: 0]
  ------------------
  265|       |
  266|      0|      if (addr_result->ai_family == family) {
  ------------------
  |  Branch (266:11): [True: 0, False: 0]
  ------------------
  267|      0|        if (addr_result->ai_family == AF_INET) {
  ------------------
  |  Branch (267:13): [True: 0, False: 0]
  ------------------
  268|      0|          memcpy(addr, addr_result->ai_addr, addr_result->ai_addrlen);
  269|      0|          addr->s4.sin_port = nswap16(port);
  ------------------
  |  |   82|      0|#define nswap16(s) ntohs(s)
  ------------------
  270|       |#if defined(TURN_HAS_SIN_LEN) /* tested when configured */
  271|       |          addr->s4.sin_len = sizeof(struct sockaddr_in);
  272|       |#endif
  273|      0|          found = 1;
  274|      0|          break;
  275|      0|        } else if (addr_result->ai_family == AF_INET6) {
  ------------------
  |  Branch (275:20): [True: 0, False: 0]
  ------------------
  276|      0|          memcpy(addr, addr_result->ai_addr, addr_result->ai_addrlen);
  277|      0|          addr->s6.sin6_port = nswap16(port);
  ------------------
  |  |   82|      0|#define nswap16(s) ntohs(s)
  ------------------
  278|       |#if defined(SIN6_LEN) /* this define is required by IPv6 if used */
  279|       |          addr->s6.sin6_len = sizeof(struct sockaddr_in6);
  280|       |#endif
  281|      0|          found = 1;
  282|      0|          break;
  283|      0|        }
  284|      0|      }
  285|       |
  286|      0|      addr_result = addr_result->ai_next;
  287|      0|    }
  288|       |
  289|      0|    if (!found && family == AF_INET) {
  ------------------
  |  Branch (289:9): [True: 0, False: 0]
  |  Branch (289:19): [True: 0, False: 0]
  ------------------
  290|      0|      family = AF_INET6;
  291|      0|      addr_result = addr_result_orig;
  292|      0|      goto beg_af;
  293|      0|    }
  294|       |
  295|      0|    freeaddrinfo(addr_result_orig);
  296|      0|  }
  297|       |
  298|      4|  return 0;
  299|      4|}
ioa_addr_add_mapping:
  594|      2|void ioa_addr_add_mapping(ioa_addr *apub, ioa_addr *apriv) {
  595|      2|  const size_t new_size = msz + sizeof(ioa_addr *);
  596|      2|  public_addrs = (ioa_addr **)realloc(public_addrs, new_size);
  597|      2|  private_addrs = (ioa_addr **)realloc(private_addrs, new_size);
  598|      2|  public_addrs[mcount] = (ioa_addr *)malloc(sizeof(ioa_addr));
  599|      2|  private_addrs[mcount] = (ioa_addr *)malloc(sizeof(ioa_addr));
  600|      2|  addr_cpy(public_addrs[mcount], apub);
  601|      2|  addr_cpy(private_addrs[mcount], apriv);
  602|      2|  ++mcount;
  603|      2|  msz += sizeof(ioa_addr *);
  604|      2|}

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

