ssh_bind_new:
  136|    269|{
  137|    269|    ssh_bind ptr = NULL;
  138|       |
  139|    269|    ptr = calloc(1, sizeof(struct ssh_bind_struct));
  140|    269|    if (ptr == NULL) {
  ------------------
  |  Branch (140:9): [True: 0, False: 269]
  ------------------
  141|      0|        return NULL;
  142|      0|    }
  143|    269|    ptr->bindfd = SSH_INVALID_SOCKET;
  ------------------
  |  |  123|    269|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  144|    269|    ptr->bindport = 22;
  145|    269|    ptr->common.log_verbosity = 0;
  146|       |
  147|    269|    return ptr;
  148|    269|}
ssh_bind_free:
  372|    269|void ssh_bind_free(ssh_bind sshbind){
  373|    269|  int i;
  374|       |
  375|    269|  if (sshbind == NULL) {
  ------------------
  |  Branch (375:7): [True: 0, False: 269]
  ------------------
  376|      0|    return;
  377|      0|  }
  378|       |
  379|    269|  if (sshbind->bindfd >= 0) {
  ------------------
  |  Branch (379:7): [True: 0, False: 269]
  ------------------
  380|      0|      CLOSE_SOCKET(sshbind->bindfd);
  ------------------
  |  |  474|      0|#define CLOSE_SOCKET(s) do { if ((s) != SSH_INVALID_SOCKET) { _XCLOSESOCKET(s); (s) = SSH_INVALID_SOCKET;} } while(0)
  |  |  ------------------
  |  |  |  |  123|      0|#define SSH_INVALID_SOCKET ((socket_t) -1)
  |  |  ------------------
  |  |               #define CLOSE_SOCKET(s) do { if ((s) != SSH_INVALID_SOCKET) { _XCLOSESOCKET(s); (s) = SSH_INVALID_SOCKET;} } while(0)
  |  |  ------------------
  |  |  |  |  199|      0|#define _XCLOSESOCKET close
  |  |  ------------------
  |  |               #define CLOSE_SOCKET(s) do { if ((s) != SSH_INVALID_SOCKET) { _XCLOSESOCKET(s); (s) = SSH_INVALID_SOCKET;} } while(0)
  |  |  ------------------
  |  |  |  |  123|      0|#define SSH_INVALID_SOCKET ((socket_t) -1)
  |  |  ------------------
  |  |  |  Branch (474:34): [True: 0, False: 0]
  |  |  |  Branch (474:116): [Folded, False: 0]
  |  |  ------------------
  ------------------
  381|      0|  }
  382|    269|  sshbind->bindfd = SSH_INVALID_SOCKET;
  ------------------
  |  |  123|    269|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  383|       |
  384|       |  /* options */
  385|    269|  SAFE_FREE(sshbind->banner);
  ------------------
  |  |  375|    269|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 269]
  |  |  |  Branch (375:71): [Folded, False: 269]
  |  |  ------------------
  ------------------
  386|    269|  SAFE_FREE(sshbind->moduli_file);
  ------------------
  |  |  375|    269|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 269]
  |  |  |  Branch (375:71): [Folded, False: 269]
  |  |  ------------------
  ------------------
  387|    269|  SAFE_FREE(sshbind->bindaddr);
  ------------------
  |  |  375|    269|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 269]
  |  |  |  Branch (375:71): [Folded, False: 269]
  |  |  ------------------
  ------------------
  388|    269|  SAFE_FREE(sshbind->config_dir);
  ------------------
  |  |  375|    269|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 269]
  |  |  |  Branch (375:71): [Folded, False: 269]
  |  |  ------------------
  ------------------
  389|    269|  SAFE_FREE(sshbind->pubkey_accepted_key_types);
  ------------------
  |  |  375|    269|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 13, False: 256]
  |  |  |  Branch (375:71): [Folded, False: 269]
  |  |  ------------------
  ------------------
  390|       |
  391|    269|  SAFE_FREE(sshbind->rsakey);
  ------------------
  |  |  375|    269|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 269]
  |  |  |  Branch (375:71): [Folded, False: 269]
  |  |  ------------------
  ------------------
  392|    269|  SAFE_FREE(sshbind->ecdsakey);
  ------------------
  |  |  375|    269|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 269]
  |  |  |  Branch (375:71): [Folded, False: 269]
  |  |  ------------------
  ------------------
  393|    269|  SAFE_FREE(sshbind->ed25519key);
  ------------------
  |  |  375|    269|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 269]
  |  |  |  Branch (375:71): [Folded, False: 269]
  |  |  ------------------
  ------------------
  394|    269|  SAFE_FREE(sshbind->gssapi_key_exchange_algs);
  ------------------
  |  |  375|    269|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 269]
  |  |  |  Branch (375:71): [Folded, False: 269]
  |  |  ------------------
  ------------------
  395|       |
  396|    269|  ssh_key_free(sshbind->rsa);
  397|    269|  sshbind->rsa = NULL;
  398|    269|  ssh_key_free(sshbind->ecdsa);
  399|    269|  sshbind->ecdsa = NULL;
  400|    269|  ssh_key_free(sshbind->ed25519);
  401|    269|  sshbind->ed25519 = NULL;
  402|       |
  403|  2.95k|  for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  2.95k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (403:15): [True: 2.69k, False: 269]
  ------------------
  404|  2.69k|    if (sshbind->wanted_methods[i]) {
  ------------------
  |  Branch (404:9): [True: 267, False: 2.42k]
  ------------------
  405|    267|      SAFE_FREE(sshbind->wanted_methods[i]);
  ------------------
  |  |  375|    267|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 267, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 267]
  |  |  ------------------
  ------------------
  406|    267|    }
  407|  2.69k|  }
  408|       |
  409|       |  SAFE_FREE(sshbind);
  ------------------
  |  |  375|    269|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 269, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 269]
  |  |  ------------------
  ------------------
  410|    269|}

ssh_bind_config_parse_string:
  693|    269|{
  694|    269|    char line[MAX_LINE_SIZE] = {0};
  695|    269|    const char *c = input, *line_start = input;
  696|    269|    unsigned int line_num = 0;
  697|    269|    size_t line_len;
  698|    269|    uint32_t parser_flags;
  699|    269|    int rv;
  700|       |
  701|       |    /* This local table is used during the parsing of the current file (and
  702|       |     * files included recursively in this file) to prevent an option to be
  703|       |     * redefined, i.e. the first value set is kept. But this DO NOT prevent the
  704|       |     * option to be redefined later by another file. */
  705|    269|    uint8_t seen[BIND_CFG_MAX] = {0};
  706|       |
  707|    269|    SSH_LOG(SSH_LOG_DEBUG, "Reading bind configuration data from string:");
  ------------------
  |  |  283|    269|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  708|    269|    SSH_LOG(SSH_LOG_DEBUG, "START\n%s\nEND", input);
  ------------------
  |  |  283|    269|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  709|       |
  710|    269|    parser_flags = PARSING;
  ------------------
  |  |   44|    269|#define PARSING     1
  ------------------
  711|  2.16k|    while (1) {
  ------------------
  |  Branch (711:12): [True: 2.16k, Folded]
  ------------------
  712|  2.16k|        line_num++;
  713|  2.16k|        line_start = c;
  714|  2.16k|        c = strchr(line_start, '\n');
  715|  2.16k|        if (c == NULL) {
  ------------------
  |  Branch (715:13): [True: 268, False: 1.90k]
  ------------------
  716|       |            /* if there is no newline at the end of the string */
  717|    268|            c = strchr(line_start, '\0');
  718|    268|        }
  719|  2.16k|        if (c == NULL) {
  ------------------
  |  Branch (719:13): [True: 0, False: 2.16k]
  ------------------
  720|       |            /* should not happen, would mean a string without trailing '\0' */
  721|      0|            ssh_set_error(bind,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  722|      0|                          SSH_FATAL,
  723|      0|                          "No trailing '\\0' in config string");
  724|      0|            return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  725|      0|        }
  726|  2.16k|        line_len = c - line_start;
  727|  2.16k|        if (line_len > MAX_LINE_SIZE - 1) {
  ------------------
  |  |   37|  2.16k|#define MAX_LINE_SIZE 1024
  ------------------
  |  Branch (727:13): [True: 8, False: 2.16k]
  ------------------
  728|      8|            ssh_set_error(bind,
  ------------------
  |  |  313|      8|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  729|      8|                          SSH_FATAL,
  730|      8|                          "Line %u too long: %zu characters",
  731|      8|                          line_num,
  732|      8|                          line_len);
  733|      8|            return SSH_ERROR;
  ------------------
  |  |  316|      8|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  734|      8|        }
  735|  2.16k|        memcpy(line, line_start, line_len);
  736|  2.16k|        line[line_len] = '\0';
  737|  2.16k|        SSH_LOG(SSH_LOG_DEBUG, "Line %u: %s", line_num, line);
  ------------------
  |  |  283|  2.16k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  738|  2.16k|        rv = ssh_bind_config_parse_line(bind,
  739|  2.16k|                                        line,
  740|  2.16k|                                        line_num,
  741|  2.16k|                                        &parser_flags,
  742|  2.16k|                                        seen,
  743|  2.16k|                                        0);
  744|  2.16k|        if (rv < 0) {
  ------------------
  |  Branch (744:13): [True: 13, False: 2.14k]
  ------------------
  745|     13|            return SSH_ERROR;
  ------------------
  |  |  316|     13|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  746|     13|        }
  747|  2.14k|        if (*c == '\0') {
  ------------------
  |  Branch (747:13): [True: 248, False: 1.89k]
  ------------------
  748|    248|            break;
  749|    248|        }
  750|  1.89k|        c++;
  751|  1.89k|    }
  752|       |
  753|    248|    return SSH_OK;
  ------------------
  |  |  315|    248|#define SSH_OK 0     /* No error */
  ------------------
  754|    269|}
bind_config.c:ssh_bind_config_parse_line:
  292|  2.03M|{
  293|  2.03M|    enum ssh_bind_config_opcode_e opcode;
  294|  2.03M|    const char *p = NULL;
  295|  2.03M|    char *s = NULL, *x = NULL;
  296|  2.03M|    char *keyword = NULL;
  297|  2.03M|    long l;
  298|  2.03M|    size_t len;
  299|       |
  300|  2.03M|    int rc = 0;
  301|       |
  302|  2.03M|    if (bind == NULL) {
  ------------------
  |  Branch (302:9): [True: 0, False: 2.03M]
  ------------------
  303|      0|        return -1;
  304|      0|    }
  305|       |
  306|       |    /* Ignore empty lines */
  307|  2.03M|    if (line == NULL || *line == '\0') {
  ------------------
  |  Branch (307:9): [True: 0, False: 2.03M]
  |  Branch (307:25): [True: 578k, False: 1.45M]
  ------------------
  308|   578k|        return 0;
  309|   578k|    }
  310|       |
  311|  1.45M|    if (parser_flags == NULL) {
  ------------------
  |  Branch (311:9): [True: 0, False: 1.45M]
  ------------------
  312|      0|        ssh_set_error_invalid(bind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  313|      0|        return -1;
  314|      0|    }
  315|       |
  316|  1.45M|    x = s = strdup(line);
  317|  1.45M|    if (s == NULL) {
  ------------------
  |  Branch (317:9): [True: 0, False: 1.45M]
  ------------------
  318|      0|        ssh_set_error_oom(bind);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  319|      0|        return -1;
  320|      0|    }
  321|       |
  322|       |    /* Remove trailing spaces */
  323|  2.49M|    for (len = strlen(s) - 1; len > 0; len--) {
  ------------------
  |  Branch (323:31): [True: 2.13M, False: 359k]
  ------------------
  324|  2.13M|        if (! isspace(s[len])) {
  ------------------
  |  Branch (324:13): [True: 1.09M, False: 1.04M]
  ------------------
  325|  1.09M|            break;
  326|  1.09M|        }
  327|  1.04M|        s[len] = '\0';
  328|  1.04M|    }
  329|       |
  330|  1.45M|    keyword = ssh_config_get_token(&s);
  331|  1.45M|    if (keyword == NULL || *keyword == '#' ||
  ------------------
  |  Branch (331:9): [True: 0, False: 1.45M]
  |  Branch (331:28): [True: 154k, False: 1.29M]
  ------------------
  332|  1.29M|            *keyword == '\0' || *keyword == '\n') {
  ------------------
  |  Branch (332:13): [True: 285k, False: 1.01M]
  |  Branch (332:33): [True: 0, False: 1.01M]
  ------------------
  333|   440k|        SAFE_FREE(x);
  ------------------
  |  |  375|   440k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 440k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 440k]
  |  |  ------------------
  ------------------
  334|   440k|        return 0;
  335|   440k|    }
  336|       |
  337|  1.01M|    opcode = ssh_bind_config_get_opcode(keyword, parser_flags);
  338|  1.01M|    if ((*parser_flags & PARSING) &&
  ------------------
  |  |   44|  1.01M|#define PARSING     1
  ------------------
  |  Branch (338:9): [True: 32.0k, False: 980k]
  ------------------
  339|  32.0k|            opcode != BIND_CFG_HOSTKEY &&
  ------------------
  |  Branch (339:13): [True: 31.8k, False: 176]
  ------------------
  340|  31.8k|            opcode != BIND_CFG_INCLUDE &&
  ------------------
  |  Branch (340:13): [True: 31.4k, False: 380]
  ------------------
  341|  31.4k|            opcode != BIND_CFG_MATCH &&
  ------------------
  |  Branch (341:13): [True: 31.4k, False: 24]
  ------------------
  342|  31.4k|            opcode > BIND_CFG_UNSUPPORTED) { /* Ignore all unknown types here */
  ------------------
  |  Branch (342:13): [True: 292, False: 31.1k]
  ------------------
  343|       |        /* Skip all the options that were already applied */
  344|    292|        if (seen[opcode] != 0) {
  ------------------
  |  Branch (344:13): [True: 67, False: 225]
  ------------------
  345|     67|            SAFE_FREE(x);
  ------------------
  |  |  375|     67|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 67, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 67]
  |  |  ------------------
  ------------------
  346|     67|            return 0;
  347|     67|        }
  348|    225|        seen[opcode] = 1;
  349|    225|    }
  350|       |
  351|  1.01M|    switch (opcode) {
  352|    380|    case BIND_CFG_INCLUDE:
  ------------------
  |  Branch (352:5): [True: 380, False: 1.01M]
  ------------------
  353|    380|        p = ssh_config_get_str_tok(&s, NULL);
  354|    380|        if (p && (*parser_flags & PARSING)) {
  ------------------
  |  |   44|    185|#define PARSING     1
  ------------------
  |  Branch (354:13): [True: 185, False: 195]
  |  Branch (354:18): [True: 185, False: 0]
  ------------------
  355|    185|#if defined(HAVE_GLOB) && defined(HAVE_GLOB_GL_FLAGS_MEMBER)
  356|    185|            local_parse_glob(bind, p, parser_flags, seen, depth + 1);
  357|       |#else
  358|       |            local_parse_file(bind, p, parser_flags, seen, depth + 1);
  359|       |#endif /* HAVE_GLOB */
  360|    185|        }
  361|    380|        break;
  362|       |
  363|    176|    case BIND_CFG_HOSTKEY:
  ------------------
  |  Branch (363:5): [True: 176, False: 1.01M]
  ------------------
  364|    176|        p = ssh_config_get_str_tok(&s, NULL);
  365|    176|        if (p && (*parser_flags & PARSING)) {
  ------------------
  |  |   44|      0|#define PARSING     1
  ------------------
  |  Branch (365:13): [True: 0, False: 176]
  |  Branch (365:18): [True: 0, False: 0]
  ------------------
  366|      0|            rc = ssh_bind_options_set(bind, SSH_BIND_OPTIONS_HOSTKEY, p);
  367|      0|            if (rc != 0) {
  ------------------
  |  Branch (367:17): [True: 0, False: 0]
  ------------------
  368|      0|                SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  369|      0|                        "line %d: Failed to set Hostkey value '%s'",
  370|      0|                        count, p);
  371|      0|            }
  372|      0|        }
  373|    176|        break;
  374|      1|    case BIND_CFG_LISTENADDRESS:
  ------------------
  |  Branch (374:5): [True: 1, False: 1.01M]
  ------------------
  375|      1|        p = ssh_config_get_str_tok(&s, NULL);
  376|      1|        if (p && (*parser_flags & PARSING)) {
  ------------------
  |  |   44|      0|#define PARSING     1
  ------------------
  |  Branch (376:13): [True: 0, False: 1]
  |  Branch (376:18): [True: 0, False: 0]
  ------------------
  377|      0|            rc = ssh_bind_options_set(bind, SSH_BIND_OPTIONS_BINDADDR, p);
  378|      0|            if (rc != 0) {
  ------------------
  |  Branch (378:17): [True: 0, False: 0]
  ------------------
  379|      0|                SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  380|      0|                        "line %d: Failed to set ListenAddress value '%s'",
  381|      0|                        count, p);
  382|      0|            }
  383|      0|        }
  384|      1|        break;
  385|      6|    case BIND_CFG_PORT:
  ------------------
  |  Branch (385:5): [True: 6, False: 1.01M]
  ------------------
  386|      6|        p = ssh_config_get_str_tok(&s, NULL);
  387|      6|        if (p && (*parser_flags & PARSING)) {
  ------------------
  |  |   44|      4|#define PARSING     1
  ------------------
  |  Branch (387:13): [True: 4, False: 2]
  |  Branch (387:18): [True: 4, False: 0]
  ------------------
  388|      4|            rc = ssh_bind_options_set(bind, SSH_BIND_OPTIONS_BINDPORT_STR, p);
  389|      4|            if (rc != 0) {
  ------------------
  |  Branch (389:17): [True: 4, False: 0]
  ------------------
  390|      4|                SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      4|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  391|      4|                        "line %d: Failed to set Port value '%s'",
  392|      4|                        count, p);
  393|      4|            }
  394|      4|        }
  395|      6|        break;
  396|     33|    case BIND_CFG_CIPHERS:
  ------------------
  |  Branch (396:5): [True: 33, False: 1.01M]
  ------------------
  397|     33|        p = ssh_config_get_str_tok(&s, NULL);
  398|     33|        if (p && (*parser_flags & PARSING)) {
  ------------------
  |  |   44|     33|#define PARSING     1
  ------------------
  |  Branch (398:13): [True: 33, False: 0]
  |  Branch (398:18): [True: 33, False: 0]
  ------------------
  399|     33|            rc = ssh_bind_options_set(bind, SSH_BIND_OPTIONS_CIPHERS_C_S, p);
  400|     33|            if (rc != 0) {
  ------------------
  |  Branch (400:17): [True: 1, False: 32]
  ------------------
  401|      1|                SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      1|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  402|      1|                        "line %d: Failed to set C->S Ciphers value '%s'",
  403|      1|                        count, p);
  404|      1|                break;
  405|      1|            }
  406|       |
  407|     32|            rc = ssh_bind_options_set(bind, SSH_BIND_OPTIONS_CIPHERS_S_C, p);
  408|     32|            if (rc != 0) {
  ------------------
  |  Branch (408:17): [True: 0, False: 32]
  ------------------
  409|      0|                SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  410|      0|                        "line %d: Failed to set S->C Ciphers value '%s'",
  411|      0|                        count, p);
  412|      0|            }
  413|     32|        }
  414|     32|        break;
  415|     88|    case BIND_CFG_MACS:
  ------------------
  |  Branch (415:5): [True: 88, False: 1.01M]
  ------------------
  416|     88|        p = ssh_config_get_str_tok(&s, NULL);
  417|     88|        if (p && (*parser_flags & PARSING)) {
  ------------------
  |  |   44|     88|#define PARSING     1
  ------------------
  |  Branch (417:13): [True: 88, False: 0]
  |  Branch (417:18): [True: 88, False: 0]
  ------------------
  418|     88|            rc = ssh_bind_options_set(bind, SSH_BIND_OPTIONS_HMAC_C_S, p);
  419|     88|            if (rc != 0) {
  ------------------
  |  Branch (419:17): [True: 4, False: 84]
  ------------------
  420|      4|                SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      4|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  421|      4|                        "line %d: Failed to set C->S MAC value '%s'",
  422|      4|                        count, p);
  423|      4|                break;
  424|      4|            }
  425|       |
  426|     84|            rc = ssh_bind_options_set(bind, SSH_BIND_OPTIONS_HMAC_S_C, p);
  427|     84|            if (rc != 0) {
  ------------------
  |  Branch (427:17): [True: 0, False: 84]
  ------------------
  428|      0|                SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  429|      0|                        "line %d: Failed to set S->C MAC value '%s'",
  430|      0|                        count, p);
  431|      0|            }
  432|     84|        }
  433|     84|        break;
  434|    311|    case BIND_CFG_LOGLEVEL:
  ------------------
  |  Branch (434:5): [True: 311, False: 1.01M]
  ------------------
  435|    311|        p = ssh_config_get_str_tok(&s, NULL);
  436|    311|        if (p && (*parser_flags & PARSING)) {
  ------------------
  |  |   44|    284|#define PARSING     1
  ------------------
  |  Branch (436:13): [True: 284, False: 27]
  |  Branch (436:18): [True: 27, False: 257]
  ------------------
  437|     27|            int value = -1;
  438|       |
  439|     27|            if (strcasecmp(p, "quiet") == 0) {
  ------------------
  |  Branch (439:17): [True: 0, False: 27]
  ------------------
  440|      0|                value = SSH_LOG_NONE;
  ------------------
  |  |  354|      0|#define SSH_LOG_NONE 0
  ------------------
  441|     27|            } else if (strcasecmp(p, "fatal") == 0 ||
  ------------------
  |  Branch (441:24): [True: 0, False: 27]
  ------------------
  442|     27|                    strcasecmp(p, "error")== 0) {
  ------------------
  |  Branch (442:21): [True: 0, False: 27]
  ------------------
  443|      0|                value = SSH_LOG_WARN;
  ------------------
  |  |  356|      0|#define SSH_LOG_WARN 1
  ------------------
  444|     27|            } else if (strcasecmp(p, "verbose") == 0 ||
  ------------------
  |  Branch (444:24): [True: 0, False: 27]
  ------------------
  445|     27|                    strcasecmp(p, "info") == 0) {
  ------------------
  |  Branch (445:21): [True: 0, False: 27]
  ------------------
  446|      0|                value = SSH_LOG_INFO;
  ------------------
  |  |  358|      0|#define SSH_LOG_INFO 2
  ------------------
  447|     27|            } else if (strcasecmp(p, "DEBUG") == 0 ||
  ------------------
  |  Branch (447:24): [True: 2, False: 25]
  ------------------
  448|     25|                    strcasecmp(p, "DEBUG1") == 0) {
  ------------------
  |  Branch (448:21): [True: 2, False: 23]
  ------------------
  449|      4|                value = SSH_LOG_DEBUG;
  ------------------
  |  |  360|      4|#define SSH_LOG_DEBUG 3
  ------------------
  450|     23|            } else if (strcasecmp(p, "DEBUG2") == 0 ||
  ------------------
  |  Branch (450:24): [True: 2, False: 21]
  ------------------
  451|     21|                    strcasecmp(p, "DEBUG3") == 0) {
  ------------------
  |  Branch (451:21): [True: 4, False: 17]
  ------------------
  452|      6|                value = SSH_LOG_TRACE;
  ------------------
  |  |  362|      6|#define SSH_LOG_TRACE 4
  ------------------
  453|      6|            }
  454|     27|            if (value != -1) {
  ------------------
  |  Branch (454:17): [True: 10, False: 17]
  ------------------
  455|     10|                rc = ssh_bind_options_set(bind, SSH_BIND_OPTIONS_LOG_VERBOSITY,
  456|     10|                        &value);
  457|     10|                if (rc != 0) {
  ------------------
  |  Branch (457:21): [True: 0, False: 10]
  ------------------
  458|      0|                    SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  459|      0|                            "line %d: Failed to set LogLevel value '%s'",
  460|      0|                            count, p);
  461|      0|                }
  462|     10|            }
  463|     27|        }
  464|    311|        break;
  465|      7|    case BIND_CFG_KEXALGORITHMS:
  ------------------
  |  Branch (465:5): [True: 7, False: 1.01M]
  ------------------
  466|      7|        p = ssh_config_get_str_tok(&s, NULL);
  467|      7|        if (p && (*parser_flags & PARSING)) {
  ------------------
  |  |   44|      7|#define PARSING     1
  ------------------
  |  Branch (467:13): [True: 7, False: 0]
  |  Branch (467:18): [True: 7, False: 0]
  ------------------
  468|      7|            rc = ssh_bind_options_set(bind, SSH_BIND_OPTIONS_KEY_EXCHANGE, p);
  469|      7|            if (rc != 0) {
  ------------------
  |  Branch (469:17): [True: 0, False: 7]
  ------------------
  470|      0|                SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  471|      0|                        "line %d: Failed to set KexAlgorithms value '%s'",
  472|      0|                        count, p);
  473|      0|            }
  474|      7|        }
  475|      7|        break;
  476|    560|    case BIND_CFG_MATCH: {
  ------------------
  |  Branch (476:5): [True: 560, False: 1.01M]
  ------------------
  477|    560|        bool negate;
  478|    560|        int result = PARSING;
  ------------------
  |  |   44|    560|#define PARSING     1
  ------------------
  479|    560|        size_t args = 0;
  480|    560|        enum ssh_bind_config_match_e opt;
  481|    560|        const char *p2 = NULL;
  482|       |
  483|       |        /* The options set in Match blocks should be applied when a connection
  484|       |         * is accepted, and not right away when parsing the file (as it is
  485|       |         * currently done). This means the configuration files should be parsed
  486|       |         * again or the options set in the Match blocks should be stored and
  487|       |         * applied as necessary. */
  488|       |
  489|       |        /* If this is the first Match block, erase the seen table to allow
  490|       |         * options to be overridden. Erasing the seen table was the easiest way
  491|       |         * to allow overriding an option, but only for the first occurrence of
  492|       |         * an option in a Match block. This is sufficient for the current
  493|       |         * implementation which supports only the 'All' criterion, meaning the
  494|       |         * options can be applied right away. */
  495|    560|        if (!(*parser_flags & IN_MATCH)) {
  ------------------
  |  |   45|    560|#define IN_MATCH    (1<<1)
  ------------------
  |  Branch (495:13): [True: 10, False: 550]
  ------------------
  496|     10|            memset(seen, 0x00, BIND_CFG_MAX * sizeof(uint8_t));
  497|     10|        }
  498|       |
  499|       |        /* In this line the PARSING bit is cleared from the flags */
  500|    560|        *parser_flags = IN_MATCH;
  ------------------
  |  |   45|    560|#define IN_MATCH    (1<<1)
  ------------------
  501|    725|        do {
  502|    725|            p = p2 = ssh_config_get_str_tok(&s, NULL);
  503|    725|            if (p == NULL || p[0] == '\0') {
  ------------------
  |  Branch (503:17): [True: 178, False: 547]
  |  Branch (503:30): [True: 0, False: 547]
  ------------------
  504|    178|                break;
  505|    178|            }
  506|    547|            args++;
  507|    547|            SSH_LOG(SSH_LOG_TRACE, "line %d: Processing Match keyword '%s'",
  ------------------
  |  |  283|    547|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  508|    547|                    count, p);
  509|       |
  510|       |            /* If the option is prefixed with ! the result should be negated */
  511|    547|            negate = false;
  512|    547|            if (p[0] == '!') {
  ------------------
  |  Branch (512:17): [True: 80, False: 467]
  ------------------
  513|     80|                negate = true;
  514|     80|                p++;
  515|     80|            }
  516|       |
  517|    547|            opt = ssh_bind_config_get_match_opcode(p);
  518|    547|            switch (opt) {
  519|     46|            case BIND_MATCH_ALL:
  ------------------
  |  Branch (519:13): [True: 46, False: 501]
  ------------------
  520|     46|                p = ssh_config_get_str_tok(&s, NULL);
  521|     46|                if ((args == 1) && (p == NULL || p[0] == '\0')) {
  ------------------
  |  Branch (521:21): [True: 46, False: 0]
  |  Branch (521:37): [True: 40, False: 6]
  |  Branch (521:50): [True: 0, False: 6]
  ------------------
  522|       |                    /* The "all" keyword does not accept arguments or modifiers
  523|       |                     */
  524|     40|                    if (negate == true) {
  ------------------
  |  Branch (524:25): [True: 20, False: 20]
  ------------------
  525|     20|                        result = 0;
  526|     20|                    }
  527|     40|                    break;
  528|     40|                }
  529|      6|                ssh_set_error(bind, SSH_FATAL,
  ------------------
  |  |  313|      6|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  530|      6|                              "line %d: ERROR - Match all cannot be combined with "
  531|      6|                              "other Match attributes", count);
  532|      6|                SAFE_FREE(x);
  ------------------
  |  |  375|      6|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 6, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 6]
  |  |  ------------------
  ------------------
  533|      6|                return -1;
  534|     32|            case BIND_MATCH_USER:
  ------------------
  |  Branch (534:13): [True: 32, False: 515]
  ------------------
  535|     43|            case BIND_MATCH_GROUP:
  ------------------
  |  Branch (535:13): [True: 11, False: 536]
  ------------------
  536|     81|            case BIND_MATCH_HOST:
  ------------------
  |  Branch (536:13): [True: 38, False: 509]
  ------------------
  537|    149|            case BIND_MATCH_LOCALADDRESS:
  ------------------
  |  Branch (537:13): [True: 68, False: 479]
  ------------------
  538|    149|            case BIND_MATCH_LOCALPORT:
  ------------------
  |  Branch (538:13): [True: 0, False: 547]
  ------------------
  539|    149|            case BIND_MATCH_RDOMAIN:
  ------------------
  |  Branch (539:13): [True: 0, False: 547]
  ------------------
  540|    167|            case BIND_MATCH_ADDRESS:
  ------------------
  |  Branch (540:13): [True: 18, False: 529]
  ------------------
  541|       |                /* Only "All" is supported for now */
  542|       |                /* Skip one argument */
  543|    167|                p = ssh_config_get_str_tok(&s, NULL);
  544|    167|                if (p == NULL || p[0] == '\0') {
  ------------------
  |  Branch (544:21): [True: 2, False: 165]
  |  Branch (544:34): [True: 0, False: 165]
  ------------------
  545|      2|                    SSH_LOG(SSH_LOG_TRACE, "line %d: Match keyword "
  ------------------
  |  |  283|      2|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  546|      2|                            "'%s' requires argument\n", count, p2);
  547|      2|                    SAFE_FREE(x);
  ------------------
  |  |  375|      2|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 2, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 2]
  |  |  ------------------
  ------------------
  548|      2|                    return -1;
  549|      2|                }
  550|    165|                args++;
  551|    165|                SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  283|    165|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  552|    165|                        "line %d: Unsupported Match keyword '%s', ignoring\n",
  553|    165|                        count,
  554|    165|                        p2);
  555|    165|                result = 0;
  556|    165|                break;
  557|    334|            case BIND_MATCH_UNKNOWN:
  ------------------
  |  Branch (557:13): [True: 334, False: 213]
  ------------------
  558|    334|            default:
  ------------------
  |  Branch (558:13): [True: 0, False: 547]
  ------------------
  559|    334|                ssh_set_error(bind, SSH_FATAL,
  ------------------
  |  |  313|    334|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  560|    334|                              "ERROR - Unknown argument '%s' for Match keyword", p);
  561|    334|                SAFE_FREE(x);
  ------------------
  |  |  375|    334|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 334, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 334]
  |  |  ------------------
  ------------------
  562|    334|                return -1;
  563|    547|            }
  564|    547|        } while (p != NULL && p[0] != '\0');
  ------------------
  |  Branch (564:18): [True: 165, False: 40]
  |  Branch (564:31): [True: 165, False: 0]
  ------------------
  565|    218|        if (args == 0) {
  ------------------
  |  Branch (565:13): [True: 89, False: 129]
  ------------------
  566|     89|            ssh_set_error(bind, SSH_FATAL,
  ------------------
  |  |  313|     89|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  567|     89|                          "ERROR - Match keyword requires an argument");
  568|     89|            SAFE_FREE(x);
  ------------------
  |  |  375|     89|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 89, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 89]
  |  |  ------------------
  ------------------
  569|     89|            return -1;
  570|     89|        }
  571|       |        /* This line only sets the PARSING flag if all checks passed */
  572|    129|        *parser_flags |= result;
  573|    129|        break;
  574|    218|    }
  575|     60|    case BIND_CFG_PUBKEY_ACCEPTED_KEY_TYPES:
  ------------------
  |  Branch (575:5): [True: 60, False: 1.01M]
  ------------------
  576|     60|        p = ssh_config_get_str_tok(&s, NULL);
  577|     60|        if (p && (*parser_flags & PARSING)) {
  ------------------
  |  |   44|     39|#define PARSING     1
  ------------------
  |  Branch (577:13): [True: 39, False: 21]
  |  Branch (577:18): [True: 16, False: 23]
  ------------------
  578|     16|            rc = ssh_bind_options_set(bind,
  579|     16|                                 SSH_BIND_OPTIONS_PUBKEY_ACCEPTED_KEY_TYPES, p);
  580|     16|            if (rc != 0) {
  ------------------
  |  Branch (580:17): [True: 1, False: 15]
  ------------------
  581|      1|                SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      1|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  582|      1|                        "line %d: Failed to set PubKeyAcceptedKeyTypes value '%s'",
  583|      1|                        count, p);
  584|      1|            }
  585|     16|        }
  586|     60|        break;
  587|     66|    case BIND_CFG_HOSTKEY_ALGORITHMS:
  ------------------
  |  Branch (587:5): [True: 66, False: 1.01M]
  ------------------
  588|     66|        p = ssh_config_get_str_tok(&s, NULL);
  589|     66|        if (p && (*parser_flags & PARSING)) {
  ------------------
  |  |   44|     62|#define PARSING     1
  ------------------
  |  Branch (589:13): [True: 62, False: 4]
  |  Branch (589:18): [True: 32, False: 30]
  ------------------
  590|     32|            rc = ssh_bind_options_set(bind,
  591|     32|                                 SSH_BIND_OPTIONS_HOSTKEY_ALGORITHMS, p);
  592|     32|            if (rc != 0) {
  ------------------
  |  Branch (592:17): [True: 2, False: 30]
  ------------------
  593|      2|                SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      2|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  594|      2|                        "line %d: Failed to set HostkeyAlgorithms value '%s'",
  595|      2|                        count, p);
  596|      2|            }
  597|     32|        }
  598|     66|        break;
  599|    533|    case BIND_CFG_REQUIRED_RSA_SIZE:
  ------------------
  |  Branch (599:5): [True: 533, False: 1.01M]
  ------------------
  600|    533|        l = ssh_config_get_long(&s, -1);
  601|    533|        if (l >= 0 && l <= INT_MAX && (*parser_flags & PARSING)) {
  ------------------
  |  |   44|    383|#define PARSING     1
  ------------------
  |  Branch (601:13): [True: 467, False: 66]
  |  Branch (601:23): [True: 383, False: 84]
  |  Branch (601:39): [True: 10, False: 373]
  ------------------
  602|     10|            int i = (int)l;
  603|     10|            rc = ssh_bind_options_set(bind, SSH_BIND_OPTIONS_RSA_MIN_SIZE, &i);
  604|     10|            if (rc != 0) {
  ------------------
  |  Branch (604:17): [True: 2, False: 8]
  ------------------
  605|      2|                SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      2|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  606|      2|                        "line %d: Failed to set RequiredRSASize value '%ld'",
  607|      2|                        count,
  608|      2|                        l);
  609|      2|            }
  610|     10|        }
  611|    533|        break;
  612|  3.79k|    case BIND_CFG_NOT_ALLOWED_IN_MATCH:
  ------------------
  |  Branch (612:5): [True: 3.79k, False: 1.00M]
  ------------------
  613|  3.79k|        SSH_LOG(SSH_LOG_DEBUG, "Option not allowed in Match block: %s, line: %d",
  ------------------
  |  |  283|  3.79k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  614|  3.79k|                keyword, count);
  615|  3.79k|        break;
  616|  1.00M|    case BIND_CFG_UNKNOWN:
  ------------------
  |  Branch (616:5): [True: 1.00M, False: 6.01k]
  ------------------
  617|  1.00M|        SSH_LOG(SSH_LOG_TRACE, "Unknown option: %s, line: %d",
  ------------------
  |  |  283|  1.00M|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  618|  1.00M|                keyword, count);
  619|  1.00M|        break;
  620|      0|    case BIND_CFG_UNSUPPORTED:
  ------------------
  |  Branch (620:5): [True: 0, False: 1.01M]
  ------------------
  621|      0|        SSH_LOG(SSH_LOG_TRACE, "Unsupported option: %s, line: %d",
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  622|      0|                keyword, count);
  623|      0|        break;
  624|      0|    case BIND_CFG_NA:
  ------------------
  |  Branch (624:5): [True: 0, False: 1.01M]
  ------------------
  625|      0|        SSH_LOG(SSH_LOG_TRACE, "Option not applicable: %s, line: %d",
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  626|      0|                keyword, count);
  627|      0|        break;
  628|      0|    default:
  ------------------
  |  Branch (628:5): [True: 0, False: 1.01M]
  ------------------
  629|      0|        ssh_set_error(bind, SSH_FATAL, "ERROR - unimplemented opcode: %d",
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  630|      0|                opcode);
  631|      0|        SAFE_FREE(x);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  632|      0|        return -1;
  633|      0|        break;
  634|  1.01M|    }
  635|       |
  636|  1.01M|    SAFE_FREE(x);
  ------------------
  |  |  375|  1.01M|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 1.01M, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 1.01M]
  |  |  ------------------
  ------------------
  637|  1.01M|    return rc;
  638|  1.01M|}
bind_config.c:ssh_bind_config_get_opcode:
  171|  1.01M|{
  172|  1.01M|    int i;
  173|       |
  174|  13.1M|    for (i = 0; ssh_bind_config_keyword_table[i].name != NULL; i++) {
  ------------------
  |  Branch (174:17): [True: 12.1M, False: 1.00M]
  ------------------
  175|  12.1M|        if (strcasecmp(keyword, ssh_bind_config_keyword_table[i].name) == 0) {
  ------------------
  |  Branch (175:13): [True: 6.08k, False: 12.0M]
  ------------------
  176|  6.08k|            if ((*parser_flags & IN_MATCH) &&
  ------------------
  |  |   45|  6.08k|#define IN_MATCH    (1<<1)
  ------------------
  |  Branch (176:17): [True: 5.28k, False: 797]
  ------------------
  177|  5.28k|                !(ssh_bind_config_keyword_table[i].allowed_in_match))
  ------------------
  |  Branch (177:17): [True: 3.79k, False: 1.49k]
  ------------------
  178|  3.79k|            {
  179|  3.79k|                return BIND_CFG_NOT_ALLOWED_IN_MATCH;
  180|  3.79k|            }
  181|  2.28k|            return ssh_bind_config_keyword_table[i].opcode;
  182|  6.08k|        }
  183|  12.1M|    }
  184|       |
  185|  1.00M|    return BIND_CFG_UNKNOWN;
  186|  1.01M|}
bind_config.c:local_parse_glob:
  245|    185|{
  246|    185|    glob_t globbuf = {
  247|    185|        .gl_flags = 0,
  248|    185|    };
  249|    185|    int rt;
  250|    185|    u_int i;
  251|       |
  252|    185|    rt = glob(fileglob, GLOB_TILDE, NULL, &globbuf);
  253|    185|    if (rt == GLOB_NOMATCH) {
  ------------------
  |  Branch (253:9): [True: 107, False: 78]
  ------------------
  254|    107|        globfree(&globbuf);
  255|    107|        return;
  256|    107|    } else if (rt != 0) {
  ------------------
  |  Branch (256:16): [True: 0, False: 78]
  ------------------
  257|      0|        SSH_LOG(SSH_LOG_RARE, "Glob error: %s",
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  258|      0|                fileglob);
  259|      0|        globfree(&globbuf);
  260|      0|        return;
  261|      0|    }
  262|       |
  263|  11.6k|    for (i = 0; i < globbuf.gl_pathc; i++) {
  ------------------
  |  Branch (263:17): [True: 11.5k, False: 78]
  ------------------
  264|  11.5k|        local_parse_file(bind, globbuf.gl_pathv[i], parser_flags, seen, depth);
  265|  11.5k|    }
  266|       |
  267|     78|    globfree(&globbuf);
  268|     78|}
bind_config.c:local_parse_file:
  203|  11.5k|{
  204|  11.5k|    FILE *f = NULL;
  205|  11.5k|    char line[MAX_LINE_SIZE] = {0};
  206|  11.5k|    unsigned int count = 0;
  207|  11.5k|    int rv;
  208|       |
  209|  11.5k|    if (depth > LIBSSH_BIND_CONF_MAX_DEPTH) {
  ------------------
  |  |  196|  11.5k|#define LIBSSH_BIND_CONF_MAX_DEPTH 16
  ------------------
  |  Branch (209:9): [True: 0, False: 11.5k]
  ------------------
  210|      0|        ssh_set_error(bind, SSH_FATAL,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  211|      0|                      "ERROR - Too many levels of configuration includes "
  212|      0|                      "when processing file '%s'", filename);
  213|      0|        return;
  214|      0|    }
  215|       |
  216|  11.5k|    f = ssh_strict_fopen(filename, SSH_MAX_CONFIG_FILE_SIZE);
  ------------------
  |  |  530|  11.5k|#define SSH_MAX_CONFIG_FILE_SIZE 16 * 1024 * 1024
  ------------------
  217|  11.5k|    if (f == NULL) {
  ------------------
  |  Branch (217:9): [True: 559, False: 10.9k]
  ------------------
  218|    559|        SSH_LOG(SSH_LOG_RARE, "Cannot find file %s to load",
  ------------------
  |  |  283|    559|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  219|    559|                filename);
  220|    559|        return;
  221|    559|    }
  222|       |
  223|  10.9k|    SSH_LOG(SSH_LOG_PACKET, "Reading additional configuration data from %s",
  ------------------
  |  |  283|  10.9k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  224|  10.9k|            filename);
  225|       |
  226|  2.03M|    while (fgets(line, sizeof(line), f)) {
  ------------------
  |  Branch (226:12): [True: 2.02M, False: 10.5k]
  ------------------
  227|  2.02M|        count++;
  228|  2.02M|        rv = ssh_bind_config_parse_line(bind, line, count, parser_flags, seen, depth);
  229|  2.02M|        if (rv < 0) {
  ------------------
  |  Branch (229:13): [True: 432, False: 2.02M]
  ------------------
  230|    432|            fclose(f);
  231|    432|            return;
  232|    432|        }
  233|  2.02M|    }
  234|       |
  235|  10.5k|    fclose(f);
  236|  10.5k|    return;
  237|  10.9k|}
bind_config.c:ssh_bind_config_get_match_opcode:
  273|    547|{
  274|    547|    size_t i;
  275|       |
  276|  3.78k|    for (i = 0; ssh_bind_config_match_keyword_table[i].name != NULL; i++) {
  ------------------
  |  Branch (276:17): [True: 3.45k, False: 334]
  ------------------
  277|  3.45k|        if (strcasecmp(keyword, ssh_bind_config_match_keyword_table[i].name) == 0) {
  ------------------
  |  Branch (277:13): [True: 213, False: 3.23k]
  ------------------
  278|    213|            return ssh_bind_config_match_keyword_table[i].opcode;
  279|    213|        }
  280|  3.45k|    }
  281|       |
  282|    334|    return BIND_MATCH_UNKNOWN;
  283|    547|}

ssh_config_get_token_info:
   69|  1.45M|{
   70|  1.45M|    register char *c = NULL;
   71|       |    /* Write cursor for the normalized token. Quotes and selected escape
   72|       |     * characters are dropped while still returning a pointer into the original
   73|       |     * buffer.
   74|       |     */
   75|  1.45M|    char *dst = NULL;
   76|  1.45M|    bool had_equal = false;
   77|  1.45M|    bool found = false;
   78|  1.45M|    bool invalid = false;
   79|  1.45M|    char *r = NULL;
   80|  1.45M|    char inquote = '\0';
   81|       |
   82|  1.45M|    if (info != NULL) {
  ------------------
  |  Branch (82:9): [True: 0, False: 1.45M]
  ------------------
   83|      0|        info->found = false;
   84|      0|        info->had_equal = false;
   85|      0|        info->invalid = false;
   86|      0|    }
   87|       |
   88|       |    /* Ignore leading spaces */
   89|  4.56M|    for (c = *str; *c; c++) {
  ------------------
  |  Branch (89:20): [True: 4.27M, False: 285k]
  ------------------
   90|  4.27M|        if (!isspace((unsigned char)*c)) {
  ------------------
  |  Branch (90:13): [True: 1.17M, False: 3.10M]
  ------------------
   91|  1.17M|            break;
   92|  1.17M|        }
   93|  4.27M|    }
   94|       |
   95|       |    /* End of string or a bare newline means there is no token here, not an
   96|       |     * explicit empty token (""). Keep found=false in both cases; the newline
   97|       |     * branch also consumes the line boundary.
   98|       |     */
   99|  1.45M|    if (*c == '\0') {
  ------------------
  |  Branch (99:9): [True: 285k, False: 1.17M]
  ------------------
  100|   285k|        r = c;
  101|   285k|        goto out;
  102|   285k|    }
  103|  1.17M|    if (*c == '\n') {
  ------------------
  |  Branch (103:9): [True: 0, False: 1.17M]
  ------------------
  104|      0|        r = c;
  105|      0|        *c = '\0';
  106|      0|        c++;
  107|      0|        goto out;
  108|      0|    }
  109|       |
  110|  1.17M|    found = true;
  111|       |
  112|       |    /* Terminate on space, equal or newline.
  113|       |     * Embedded quotes are stripped and used to protect spaces from being
  114|       |     * seen as delimiters.
  115|       |     */
  116|  1.17M|    r = dst = c;
  117|  20.6M|    for (; *c; c++) {
  ------------------
  |  Branch (117:12): [True: 20.2M, False: 420k]
  ------------------
  118|       |        /* Process backslash escapes matching OpenSSH's argv_split():
  119|       |         * \\, \', \", and \<blank> are recognized. The backslash is
  120|       |         * dropped and the escaped character is kept. Unrecognized
  121|       |         * escapes preserve the backslash literally.
  122|       |         */
  123|  20.2M|        if (*c == '\\' &&
  ------------------
  |  Branch (123:13): [True: 25.8k, False: 20.2M]
  ------------------
  124|  25.8k|            (c[1] == '\\' || c[1] == '\'' || c[1] == '\"' ||
  ------------------
  |  Branch (124:14): [True: 2.05k, False: 23.8k]
  |  Branch (124:30): [True: 366, False: 23.4k]
  |  Branch (124:46): [True: 2.21k, False: 21.2k]
  ------------------
  125|  25.8k|             isspace((unsigned char)c[1]))) {
  ------------------
  |  Branch (125:14): [True: 174, False: 21.0k]
  ------------------
  126|  4.80k|            c++;
  127|  4.80k|            *dst++ = *c;
  128|  20.2M|        } else if (*c == '\n' || (!inquote && (isspace((unsigned char)*c) || *c == '='))) {
  ------------------
  |  Branch (128:20): [True: 0, False: 20.2M]
  |  Branch (128:35): [True: 18.9M, False: 1.30M]
  |  Branch (128:48): [True: 725k, False: 18.1M]
  |  Branch (128:78): [True: 23.6k, False: 18.1M]
  ------------------
  129|   749k|            had_equal = (*c == '=');
  130|   749k|            *dst = '\0';
  131|   749k|            c++;
  132|   749k|            break;
  133|  19.4M|        } else if (inquote) {
  ------------------
  |  Branch (133:20): [True: 1.30M, False: 18.1M]
  ------------------
  134|  1.30M|            if (*c == inquote) {
  ------------------
  |  Branch (134:17): [True: 45.2k, False: 1.26M]
  ------------------
  135|  45.2k|                inquote = '\0';
  136|  1.26M|            } else {
  137|  1.26M|                *dst++ = *c;
  138|  1.26M|            }
  139|  18.1M|        } else if (*c == '\'' || *c == '\"') {
  ------------------
  |  Branch (139:20): [True: 5.13k, False: 18.1M]
  |  Branch (139:34): [True: 45.1k, False: 18.1M]
  ------------------
  140|  50.2k|            inquote = *c;
  141|  18.1M|        } else {
  142|  18.1M|            *dst++ = *c;
  143|  18.1M|        }
  144|  20.2M|    }
  145|  1.17M|    if (inquote) {
  ------------------
  |  Branch (145:9): [True: 5.00k, False: 1.16M]
  ------------------
  146|  5.00k|        invalid = true;
  147|  5.00k|    }
  148|  1.17M|    if (*c == '\0') {
  ------------------
  |  Branch (148:9): [True: 428k, False: 741k]
  ------------------
  149|   428k|        *dst = '\0';
  150|   428k|    }
  151|       |
  152|       |    /* Skip any other remaining whitespace */
  153|  1.51M|    while (isspace((unsigned char)*c) || *c == '\n' ||
  ------------------
  |  Branch (153:12): [True: 300k, False: 1.21M]
  |  Branch (153:42): [True: 0, False: 1.21M]
  ------------------
  154|  1.21M|           (!had_equal && *c == '=')) {
  ------------------
  |  Branch (154:13): [True: 1.14M, False: 68.6k]
  |  Branch (154:27): [True: 45.0k, False: 1.10M]
  ------------------
  155|   345k|        if (*c == '=') {
  ------------------
  |  Branch (155:13): [True: 45.0k, False: 300k]
  ------------------
  156|  45.0k|            had_equal = true;
  157|  45.0k|        }
  158|   345k|        c++;
  159|   345k|    }
  160|  1.45M|out:
  161|  1.45M|    *str = c;
  162|  1.45M|    if (info != NULL) {
  ------------------
  |  Branch (162:9): [True: 0, False: 1.45M]
  ------------------
  163|      0|        info->found = found;
  164|      0|        info->had_equal = had_equal;
  165|      0|        info->invalid = invalid;
  166|      0|    }
  167|  1.45M|    return r;
  168|  1.17M|}
ssh_config_get_token:
  171|  1.45M|{
  172|       |    return ssh_config_get_token_info(str, NULL);
  173|  1.45M|}
ssh_config_get_long:
  176|    533|{
  177|    533|    char *p = NULL, *endp = NULL;
  178|    533|    long i;
  179|       |
  180|    533|    p = ssh_config_get_token(str);
  181|    533|    if (p && *p) {
  ------------------
  |  Branch (181:9): [True: 533, False: 0]
  |  Branch (181:14): [True: 529, False: 4]
  ------------------
  182|    529|        i = strtol(p, &endp, 10);
  183|    529|        if (p == endp || *endp != '\0') {
  ------------------
  |  Branch (183:13): [True: 15, False: 514]
  |  Branch (183:26): [True: 7, False: 507]
  ------------------
  184|     22|            return notfound;
  185|     22|        }
  186|    507|        return i;
  187|    529|    }
  188|       |
  189|      4|    return notfound;
  190|    533|}
ssh_config_get_str_tok:
  193|  2.06k|{
  194|  2.06k|    char *p = NULL;
  195|       |
  196|  2.06k|    p = ssh_config_get_token(str);
  197|  2.06k|    if (p && *p) {
  ------------------
  |  Branch (197:9): [True: 2.06k, False: 0]
  |  Branch (197:14): [True: 1.42k, False: 646]
  ------------------
  198|  1.42k|        return p;
  199|  1.42k|    }
  200|       |
  201|    646|    return def;
  202|  2.06k|}

ssh_dh_init:
  235|      2|{
  236|      2|    unsigned long g_int = 2 ;	/* G is defined as 2 by the ssh2 standards */
  237|      2|    int rc;
  238|      2|    if (dh_crypto_initialized) {
  ------------------
  |  Branch (238:9): [True: 0, False: 2]
  ------------------
  239|      0|        return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  240|      0|    }
  241|      2|    dh_crypto_initialized = 1;
  242|       |
  243|      2|    ssh_dh_generator = bignum_new();
  ------------------
  |  |   70|      2|#define bignum_new() BN_new()
  ------------------
  244|      2|    if (ssh_dh_generator == NULL) {
  ------------------
  |  Branch (244:9): [True: 0, False: 2]
  ------------------
  245|      0|        goto error;
  246|      0|    }
  247|      2|    rc = bignum_set_word(ssh_dh_generator, g_int);
  ------------------
  |  |   77|      2|#define bignum_set_word(bn,n) BN_set_word(bn,n)
  ------------------
  248|      2|    if (rc != 1) {
  ------------------
  |  Branch (248:9): [True: 0, False: 2]
  ------------------
  249|      0|        goto error;
  250|      0|    }
  251|       |
  252|      2|    bignum_bin2bn(p_group1_value, P_GROUP1_LEN, &ssh_dh_group1);
  ------------------
  |  |   79|      2|    do {                                     \
  |  |   80|      2|        (*dest) = BN_new();                  \
  |  |   81|      2|        if ((*dest) != NULL) {               \
  |  |  ------------------
  |  |  |  Branch (81:13): [True: 2, False: 0]
  |  |  ------------------
  |  |   82|      2|            BN_bin2bn(data,datalen,(*dest)); \
  |  |   83|      2|        }                                    \
  |  |   84|      2|    } while(0)
  |  |  ------------------
  |  |  |  Branch (84:13): [Folded, False: 2]
  |  |  ------------------
  ------------------
  253|      2|    if (ssh_dh_group1 == NULL) {
  ------------------
  |  Branch (253:9): [True: 0, False: 2]
  ------------------
  254|      0|        goto error;
  255|      0|    }
  256|      2|    bignum_bin2bn(p_group14_value, P_GROUP14_LEN, &ssh_dh_group14);
  ------------------
  |  |   79|      2|    do {                                     \
  |  |   80|      2|        (*dest) = BN_new();                  \
  |  |   81|      2|        if ((*dest) != NULL) {               \
  |  |  ------------------
  |  |  |  Branch (81:13): [True: 2, False: 0]
  |  |  ------------------
  |  |   82|      2|            BN_bin2bn(data,datalen,(*dest)); \
  |  |   83|      2|        }                                    \
  |  |   84|      2|    } while(0)
  |  |  ------------------
  |  |  |  Branch (84:13): [Folded, False: 2]
  |  |  ------------------
  ------------------
  257|      2|    if (ssh_dh_group14 == NULL) {
  ------------------
  |  Branch (257:9): [True: 0, False: 2]
  ------------------
  258|      0|        goto error;
  259|      0|    }
  260|      2|    bignum_bin2bn(p_group16_value, P_GROUP16_LEN, &ssh_dh_group16);
  ------------------
  |  |   79|      2|    do {                                     \
  |  |   80|      2|        (*dest) = BN_new();                  \
  |  |   81|      2|        if ((*dest) != NULL) {               \
  |  |  ------------------
  |  |  |  Branch (81:13): [True: 2, False: 0]
  |  |  ------------------
  |  |   82|      2|            BN_bin2bn(data,datalen,(*dest)); \
  |  |   83|      2|        }                                    \
  |  |   84|      2|    } while(0)
  |  |  ------------------
  |  |  |  Branch (84:13): [Folded, False: 2]
  |  |  ------------------
  ------------------
  261|      2|    if (ssh_dh_group16 == NULL) {
  ------------------
  |  Branch (261:9): [True: 0, False: 2]
  ------------------
  262|      0|        goto error;
  263|      0|    }
  264|      2|    bignum_bin2bn(p_group18_value, P_GROUP18_LEN, &ssh_dh_group18);
  ------------------
  |  |   79|      2|    do {                                     \
  |  |   80|      2|        (*dest) = BN_new();                  \
  |  |   81|      2|        if ((*dest) != NULL) {               \
  |  |  ------------------
  |  |  |  Branch (81:13): [True: 2, False: 0]
  |  |  ------------------
  |  |   82|      2|            BN_bin2bn(data,datalen,(*dest)); \
  |  |   83|      2|        }                                    \
  |  |   84|      2|    } while(0)
  |  |  ------------------
  |  |  |  Branch (84:13): [Folded, False: 2]
  |  |  ------------------
  ------------------
  265|      2|    if (ssh_dh_group18 == NULL) {
  ------------------
  |  Branch (265:9): [True: 0, False: 2]
  ------------------
  266|      0|        goto error;
  267|      0|    }
  268|       |
  269|      2|    return 0;
  270|      0|error:
  271|      0|    ssh_dh_finalize();
  272|      0|    return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  273|      2|}

_ssh_set_error:
   55|    447|{
   56|    447|    struct ssh_common_struct *err = error;
   57|    447|    va_list va;
   58|       |
   59|    447|    va_start(va, descr);
   60|    447|    vsnprintf(err->error.error_buffer, ERROR_BUFFERLEN, descr, va);
  ------------------
  |  |  219|    447|#define ERROR_BUFFERLEN 1024
  ------------------
   61|    447|    va_end(va);
   62|       |
   63|    447|    err->error.error_code = code;
   64|    447|    if (ssh_get_log_level() == SSH_LOG_TRACE) {
  ------------------
  |  |  362|    447|#define SSH_LOG_TRACE 4
  ------------------
  |  Branch (64:9): [True: 438, False: 9]
  ------------------
   65|    438|        ssh_log_function(SSH_LOG_TRACE,
  ------------------
  |  |  362|    438|#define SSH_LOG_TRACE 4
  ------------------
   66|    438|                         function,
   67|    438|                         err->error.error_buffer);
   68|    438|    }
   69|    447|}

libssh_constructor:
  114|      2|{
  115|       |
  116|      2|    int rc;
  117|       |
  118|      2|    rc = _ssh_init(1);
  119|       |
  120|      2|    if (rc < 0) {
  ------------------
  |  Branch (120:9): [True: 0, False: 2]
  ------------------
  121|      0|        fprintf(stderr, "Error in auto_init()\n");
  122|      0|    }
  123|       |
  124|      2|    return;
  125|      2|}
ssh_init:
  156|      2|int ssh_init(void) {
  157|      2|    return _ssh_init(0);
  158|      2|}
ssh_finalize:
  241|      2|int ssh_finalize(void) {
  242|      2|    return _ssh_finalize(0);
  243|      2|}
init.c:_ssh_init:
   62|      4|static int _ssh_init(unsigned constructor) {
   63|       |
   64|      4|    int rc = 0;
   65|       |
   66|      4|    if (!constructor) {
  ------------------
  |  Branch (66:9): [True: 2, False: 2]
  ------------------
   67|      2|        ssh_mutex_lock(&ssh_init_mutex);
   68|      2|    }
   69|       |
   70|      4|    _ssh_initialized++;
   71|       |
   72|      4|    if (_ssh_initialized > 1) {
  ------------------
  |  Branch (72:9): [True: 2, False: 2]
  ------------------
   73|      2|        rc = _ssh_init_ret;
   74|      2|        goto _ret;
   75|      2|    }
   76|       |
   77|      2|    rc = ssh_threads_init();
   78|      2|    if (rc) {
  ------------------
  |  Branch (78:9): [True: 0, False: 2]
  ------------------
   79|      0|        goto _ret;
   80|      0|    }
   81|       |
   82|      2|    rc = ssh_crypto_init();
   83|      2|    if (rc) {
  ------------------
  |  Branch (83:9): [True: 0, False: 2]
  ------------------
   84|      0|        goto _ret;
   85|      0|    }
   86|       |
   87|      2|    rc = ssh_dh_init();
   88|      2|    if (rc) {
  ------------------
  |  Branch (88:9): [True: 0, False: 2]
  ------------------
   89|      0|        goto _ret;
   90|      0|    }
   91|       |
   92|      2|    rc = ssh_socket_init();
   93|      2|    if (rc) {
  ------------------
  |  Branch (93:9): [True: 0, False: 2]
  ------------------
   94|      0|        goto _ret;
   95|      0|    }
   96|       |
   97|      4|_ret:
   98|      4|    _ssh_init_ret = rc;
   99|       |
  100|      4|    if (!constructor) {
  ------------------
  |  Branch (100:9): [True: 2, False: 2]
  ------------------
  101|      2|        ssh_mutex_unlock(&ssh_init_mutex);
  102|      2|    }
  103|       |
  104|      4|    return rc;
  105|      2|}
init.c:_ssh_finalize:
  160|      2|static int _ssh_finalize(unsigned destructor) {
  161|       |
  162|      2|    if (!destructor) {
  ------------------
  |  Branch (162:9): [True: 2, False: 0]
  ------------------
  163|      2|        ssh_mutex_lock(&ssh_init_mutex);
  164|       |
  165|      2|        if (_ssh_initialized > 1) {
  ------------------
  |  Branch (165:13): [True: 2, False: 0]
  ------------------
  166|      2|            _ssh_initialized--;
  167|      2|            ssh_mutex_unlock(&ssh_init_mutex);
  168|      2|            return 0;
  169|      2|        }
  170|       |
  171|      0|        if (_ssh_initialized == 1) {
  ------------------
  |  Branch (171:13): [True: 0, False: 0]
  ------------------
  172|      0|            if (_ssh_init_ret < 0) {
  ------------------
  |  Branch (172:17): [True: 0, False: 0]
  ------------------
  173|      0|                ssh_mutex_unlock(&ssh_init_mutex);
  174|      0|                return 0;
  175|      0|            }
  176|      0|        }
  177|      0|    }
  178|       |
  179|       |    /* If the counter reaches zero or it is the destructor calling, finalize */
  180|      0|    ssh_dh_finalize();
  181|      0|    ssh_crypto_finalize();
  182|      0|    ssh_socket_cleanup();
  183|       |    /* It is important to finalize threading after CRYPTO because
  184|       |     * it still depends on it */
  185|      0|    ssh_threads_finalize();
  186|       |
  187|      0|    _ssh_initialized = 0;
  188|       |
  189|      0|    if (!destructor) {
  ------------------
  |  Branch (189:9): [True: 0, False: 0]
  ------------------
  190|      0|        ssh_mutex_unlock(&ssh_init_mutex);
  191|      0|    }
  192|       |
  193|       |#if (defined(_WIN32) && !defined(HAVE_PTHREAD))
  194|       |    if (ssh_init_mutex != NULL) {
  195|       |        DeleteCriticalSection(ssh_init_mutex);
  196|       |        SAFE_FREE(ssh_init_mutex);
  197|       |    }
  198|       |#endif
  199|       |
  200|      0|    return 0;
  201|      2|}

ssh_kex_get_description:
  317|      8|{
  318|      8|    if (type >= SSH_KEX_METHODS) {
  ------------------
  |  |   27|      8|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (318:9): [True: 0, False: 8]
  ------------------
  319|      0|        return NULL;
  320|      0|    }
  321|       |
  322|      8|    return ssh_kex_descriptions[type];
  323|      8|}
ssh_keep_known_algos:
 1324|     21|{
 1325|     21|    if (algo > SSH_LANG_S_C) {
  ------------------
  |  Branch (1325:9): [True: 0, False: 21]
  ------------------
 1326|      0|        return NULL;
 1327|      0|    }
 1328|       |
 1329|     21|    return ssh_find_all_matching(supported_methods[algo], list);
 1330|     21|}
ssh_add_to_default_algos:
 1368|     90|{
 1369|     90|    char *tmp = NULL, *ret = NULL;
 1370|       |
 1371|     90|    if (algo > SSH_LANG_S_C || list == NULL || list[0] == '\0') {
  ------------------
  |  Branch (1371:9): [True: 0, False: 90]
  |  Branch (1371:32): [True: 0, False: 90]
  |  Branch (1371:48): [True: 0, False: 90]
  ------------------
 1372|      0|        return NULL;
 1373|      0|    }
 1374|       |
 1375|     90|    if (ssh_fips_mode()) {
  ------------------
  |  |  115|     90|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 90]
  |  |  ------------------
  ------------------
 1376|      0|        tmp = ssh_append_without_duplicates(fips_methods[algo], list);
 1377|      0|        ret = ssh_find_all_matching(fips_methods[algo], tmp);
 1378|     90|    } else {
 1379|     90|        tmp = ssh_append_without_duplicates(default_methods[algo], list);
 1380|     90|        ret = ssh_find_all_matching(supported_methods[algo], tmp);
 1381|     90|    }
 1382|       |
 1383|     90|    free(tmp);
 1384|     90|    return ret;
 1385|     90|}
ssh_remove_from_default_algos:
 1401|     64|{
 1402|     64|    if (algo > SSH_LANG_S_C) {
  ------------------
  |  Branch (1402:9): [True: 0, False: 64]
  ------------------
 1403|      0|        return NULL;
 1404|      0|    }
 1405|       |
 1406|     64|    if (list == NULL || list[0] == '\0') {
  ------------------
  |  Branch (1406:9): [True: 0, False: 64]
  |  Branch (1406:25): [True: 0, False: 64]
  ------------------
 1407|      0|        if (ssh_fips_mode()) {
  ------------------
  |  |  115|      0|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1408|      0|            return strdup(fips_methods[algo]);
 1409|      0|        } else {
 1410|      0|            return strdup(default_methods[algo]);
 1411|      0|        }
 1412|      0|    }
 1413|       |
 1414|     64|    if (ssh_fips_mode()) {
  ------------------
  |  |  115|     64|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 64]
  |  |  ------------------
  ------------------
 1415|      0|        return ssh_remove_all_matching(fips_methods[algo], list);
 1416|     64|    } else {
 1417|     64|        return ssh_remove_all_matching(default_methods[algo], list);
 1418|     64|    }
 1419|     64|}
ssh_prefix_default_algos:
 1439|    117|{
 1440|    117|    char *ret = NULL, *tmp = NULL;
 1441|       |
 1442|    117|    if (algo > SSH_LANG_S_C || list == NULL || list[0] == '\0') {
  ------------------
  |  Branch (1442:9): [True: 0, False: 117]
  |  Branch (1442:32): [True: 0, False: 117]
  |  Branch (1442:48): [True: 0, False: 117]
  ------------------
 1443|      0|        return NULL;
 1444|      0|    }
 1445|       |
 1446|    117|    if (ssh_fips_mode()) {
  ------------------
  |  |  115|    117|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 117]
  |  |  ------------------
  ------------------
 1447|      0|        tmp = ssh_prefix_without_duplicates(fips_methods[algo], list);
 1448|      0|        ret = ssh_find_all_matching(fips_methods[algo], tmp);
 1449|    117|    } else {
 1450|    117|        tmp = ssh_prefix_without_duplicates(default_methods[algo], list);
 1451|    117|        ret = ssh_find_all_matching(supported_methods[algo], tmp);
 1452|    117|    }
 1453|       |
 1454|    117|    free(tmp);
 1455|    117|    return ret;
 1456|    117|}

ssh_crypto_init:
 1391|      2|{
 1392|       |#ifndef HAVE_OPENSSL_EVP_CHACHA20
 1393|       |    size_t i;
 1394|       |#endif
 1395|       |
 1396|      2|    if (libcrypto_initialized) {
  ------------------
  |  Branch (1396:9): [True: 0, False: 2]
  ------------------
 1397|      0|        return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
 1398|      0|    }
 1399|      2|    if (OpenSSL_version_num() != OPENSSL_VERSION_NUMBER) {
  ------------------
  |  Branch (1399:9): [True: 0, False: 2]
  ------------------
 1400|      0|        SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1401|      0|                "libssh compiled with %s "
 1402|      0|                "headers, currently running with %s.",
 1403|      0|                OPENSSL_VERSION_TEXT,
 1404|      0|                OpenSSL_version(OpenSSL_version_num()));
 1405|      0|    }
 1406|       |#ifdef CAN_DISABLE_AESNI
 1407|       |    /*
 1408|       |     * disable AES-NI when running within Valgrind, because they generate
 1409|       |     * too many "uninitialized memory access" false positives
 1410|       |     */
 1411|       |    if (RUNNING_ON_VALGRIND) {
 1412|       |        SSH_LOG(SSH_LOG_INFO, "Running within Valgrind, disabling AES-NI");
 1413|       |        /* Bit #57 denotes AES-NI instruction set extension */
 1414|       |        OPENSSL_ia32cap &= ~(1LL << 57);
 1415|       |    }
 1416|       |#endif /* CAN_DISABLE_AESNI */
 1417|       |
 1418|       |#ifndef HAVE_OPENSSL_EVP_CHACHA20
 1419|       |    for (i = 0; ssh_ciphertab[i].name != NULL; i++) {
 1420|       |        int cmp;
 1421|       |
 1422|       |        cmp = strcmp(ssh_ciphertab[i].name, "chacha20-poly1305@openssh.com");
 1423|       |        if (cmp == 0) {
 1424|       |            memcpy(&ssh_ciphertab[i],
 1425|       |                   ssh_get_chacha20poly1305_cipher(),
 1426|       |                   sizeof(struct ssh_cipher_struct));
 1427|       |            break;
 1428|       |        }
 1429|       |    }
 1430|       |#endif /* HAVE_OPENSSL_EVP_CHACHA20 */
 1431|       |
 1432|      2|    libcrypto_initialized = 1;
 1433|       |
 1434|      2|    return SSH_OK;
  ------------------
  |  |  315|      2|#define SSH_OK 0     /* No error */
  ------------------
 1435|      2|}

ssh_log_function:
  125|  1.00M|{
  126|  1.00M|    ssh_logging_callback log_fn = ssh_get_log_callback();
  127|       |
  128|  1.00M|    if (log_fn) {
  ------------------
  |  Branch (128:9): [True: 0, False: 1.00M]
  ------------------
  129|      0|        ssh_log_custom(log_fn, verbosity, function, buffer);
  130|      0|        return;
  131|      0|    }
  132|       |
  133|  1.00M|    ssh_log_stderr(verbosity, function, buffer);
  134|  1.00M|}
ssh_vlog:
  149|  1.00M|{
  150|  1.00M|    char buffer[LOG_SIZE];
  151|       |
  152|  1.00M|    vsnprintf(buffer, sizeof(buffer), format, *va);
  153|  1.00M|    ssh_log_function(verbosity, function, buffer);
  154|  1.00M|}
_ssh_log:
  168|  1.02M|{
  169|  1.02M|    va_list va;
  170|       |
  171|  1.02M|    if (verbosity <= ssh_get_log_level()) {
  ------------------
  |  Branch (171:9): [True: 1.00M, False: 24.5k]
  ------------------
  172|  1.00M|        va_start(va, format);
  173|  1.00M|        ssh_vlog(verbosity, function, format, &va);
  174|       |        va_end(va);
  175|  1.00M|    }
  176|  1.02M|}
ssh_set_log_level:
  237|     10|int ssh_set_log_level(int level) {
  238|     10|  if (level < 0) {
  ------------------
  |  Branch (238:7): [True: 0, False: 10]
  ------------------
  239|      0|    return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  240|      0|  }
  241|       |
  242|     10|  ssh_log_level = level;
  243|       |
  244|     10|  return SSH_OK;
  ------------------
  |  |  315|     10|#define SSH_OK 0     /* No error */
  ------------------
  245|     10|}
ssh_get_log_level:
  252|  1.02M|int ssh_get_log_level(void) {
  253|  1.02M|  return ssh_log_level;
  254|  1.02M|}
ssh_get_log_callback:
  275|  1.00M|ssh_logging_callback ssh_get_log_callback(void) {
  276|  1.00M|  return ssh_log_cb;
  277|  1.00M|}
log.c:ssh_log_stderr:
   87|  1.00M|{
   88|  1.00M|    char date[128] = {0};
   89|  1.00M|    int rc;
   90|       |
   91|  1.00M|    rc = current_timestring(1, date, sizeof(date));
   92|  1.00M|    if (rc == 0) {
  ------------------
  |  Branch (92:9): [True: 1.00M, False: 0]
  ------------------
   93|  1.00M|        fprintf(stderr, "[%s, %d] %s:", date, verbosity, function);
   94|  1.00M|    } else {
   95|      0|        fprintf(stderr, "[%d] %s", verbosity, function);
   96|      0|    }
   97|       |
   98|       |    fprintf(stderr, "  %s\n", buffer);
   99|  1.00M|}
log.c:current_timestring:
   59|  1.00M|{
   60|  1.00M|    char tbuf[64];
   61|  1.00M|    struct timeval tv;
   62|  1.00M|    struct tm tm, *tm_ptr = NULL;
   63|  1.00M|    time_t t;
   64|       |
   65|  1.00M|    gettimeofday(&tv, NULL);
   66|  1.00M|    t = (time_t) tv.tv_sec;
   67|       |
   68|  1.00M|    tm_ptr = localtime_r(&t, &tm);
   69|  1.00M|    if (tm_ptr == NULL) {
  ------------------
  |  Branch (69:9): [True: 0, False: 1.00M]
  ------------------
   70|      0|        return -1;
   71|      0|    }
   72|       |
   73|  1.00M|    if (hires) {
  ------------------
  |  Branch (73:9): [True: 1.00M, False: 0]
  ------------------
   74|  1.00M|        strftime(tbuf, sizeof(tbuf), "%Y/%m/%d %H:%M:%S", &tm);
   75|  1.00M|        snprintf(buf, len, "%s.%06ld", tbuf, (long)tv.tv_usec);
   76|  1.00M|    } else {
   77|      0|        strftime(tbuf, sizeof(tbuf), "%Y/%m/%d %H:%M:%S", &tm);
   78|      0|        snprintf(buf, len, "%s", tbuf);
   79|      0|    }
   80|       |
   81|  1.00M|    return 0;
   82|  1.00M|}

ssh_strerror:
 2417|     38|{
 2418|       |#if ((defined(__linux__) && defined(__GLIBC__)) || defined(__CYGWIN__)) && defined(_GNU_SOURCE)
 2419|       |    /* GNU extension on Linux */
 2420|       |    return strerror_r(err_num, buf, buflen);
 2421|       |#else
 2422|     38|    int rv;
 2423|       |
 2424|       |#if defined(_WIN32)
 2425|       |    rv = strerror_s(buf, buflen, err_num);
 2426|       |#else
 2427|       |    /* POSIX version available for example on FreeBSD or in musl libc */
 2428|     38|    rv = strerror_r(err_num, buf, buflen);
 2429|     38|#endif /* _WIN32 */
 2430|       |
 2431|       |    /* make sure the buffer is initialized and terminated with NULL */
 2432|     38|    if (-rv == ERANGE) {
  ------------------
  |  Branch (2432:9): [True: 0, False: 38]
  ------------------
 2433|      0|        buf[0] = '\0';
 2434|      0|    }
 2435|     38|    return buf;
 2436|     38|#endif /* ((defined(__linux__) && defined(__GLIBC__)) || defined(__CYGWIN__)) && defined(_GNU_SOURCE) */
 2437|     38|}
ssh_strict_fopen:
 2705|  11.5k|{
 2706|  11.5k|    FILE *f = NULL;
 2707|  11.5k|    struct stat sb;
 2708|  11.5k|    int r, fd;
 2709|       |
 2710|       |    /* open first to avoid TOCTOU */
 2711|  11.5k|    fd = open(filename, O_RDONLY);
 2712|  11.5k|    if (fd == -1) {
  ------------------
  |  Branch (2712:9): [True: 38, False: 11.4k]
  ------------------
 2713|     38|        SSH_LOG_STRERROR(SSH_LOG_TRACE,
  ------------------
  |  |  285|     38|    do {                                                            \
  |  |  286|     38|        char err_msg[SSH_ERRNO_MSG_MAX] = {0};                      \
  |  |  287|     38|        _ssh_log(priority,                                          \
  |  |  288|     38|                 __func__,                                          \
  |  |  289|     38|                 __VA_ARGS__,                                       \
  |  |  290|     38|                 ssh_strerror(errnum, err_msg, SSH_ERRNO_MSG_MAX)); \
  |  |  ------------------
  |  |  |  |  522|     38|#define SSH_ERRNO_MSG_MAX   1024
  |  |  ------------------
  |  |  291|     38|    } while (0)
  |  |  ------------------
  |  |  |  Branch (291:14): [Folded, False: 38]
  |  |  ------------------
  ------------------
 2714|     38|                         errno,
 2715|     38|                         "Failed to open a file %s for reading: %s",
 2716|     38|                         filename);
 2717|     38|        return NULL;
 2718|     38|    }
 2719|       |
 2720|       |    /* Check the file is sensible for a configuration file */
 2721|  11.4k|    r = fstat(fd, &sb);
 2722|  11.4k|    if (r != 0) {
  ------------------
  |  Branch (2722:9): [True: 0, False: 11.4k]
  ------------------
 2723|      0|        SSH_LOG_STRERROR(SSH_LOG_TRACE,
  ------------------
  |  |  285|      0|    do {                                                            \
  |  |  286|      0|        char err_msg[SSH_ERRNO_MSG_MAX] = {0};                      \
  |  |  287|      0|        _ssh_log(priority,                                          \
  |  |  288|      0|                 __func__,                                          \
  |  |  289|      0|                 __VA_ARGS__,                                       \
  |  |  290|      0|                 ssh_strerror(errnum, err_msg, SSH_ERRNO_MSG_MAX)); \
  |  |  ------------------
  |  |  |  |  522|      0|#define SSH_ERRNO_MSG_MAX   1024
  |  |  ------------------
  |  |  291|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (291:14): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2724|      0|                         errno,
 2725|      0|                         "Failed to stat %s: %s",
 2726|      0|                         filename);
 2727|      0|        close(fd);
 2728|      0|        return NULL;
 2729|      0|    }
 2730|  11.4k|    if ((sb.st_mode & S_IFMT) != S_IFREG) {
  ------------------
  |  Branch (2730:9): [True: 517, False: 10.9k]
  ------------------
 2731|    517|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|    517|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2732|    517|                "The file %s is not a regular file: skipping",
 2733|    517|                filename);
 2734|    517|        close(fd);
 2735|    517|        return NULL;
 2736|    517|    }
 2737|       |
 2738|  10.9k|    if ((size_t)sb.st_size > max_file_size) {
  ------------------
  |  Branch (2738:9): [True: 4, False: 10.9k]
  ------------------
 2739|      4|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      4|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2740|      4|                "The file %s is too large (%jd MB > %zu MB): skipping",
 2741|      4|                filename,
 2742|      4|                (intmax_t)sb.st_size / 1024 / 1024,
 2743|      4|                max_file_size / 1024 / 1024);
 2744|      4|        close(fd);
 2745|      4|        return NULL;
 2746|      4|    }
 2747|       |
 2748|  10.9k|    f = fdopen(fd, "r");
 2749|  10.9k|    if (f == NULL) {
  ------------------
  |  Branch (2749:9): [True: 0, False: 10.9k]
  ------------------
 2750|      0|        SSH_LOG_STRERROR(SSH_LOG_TRACE,
  ------------------
  |  |  285|      0|    do {                                                            \
  |  |  286|      0|        char err_msg[SSH_ERRNO_MSG_MAX] = {0};                      \
  |  |  287|      0|        _ssh_log(priority,                                          \
  |  |  288|      0|                 __func__,                                          \
  |  |  289|      0|                 __VA_ARGS__,                                       \
  |  |  290|      0|                 ssh_strerror(errnum, err_msg, SSH_ERRNO_MSG_MAX)); \
  |  |  ------------------
  |  |  |  |  522|      0|#define SSH_ERRNO_MSG_MAX   1024
  |  |  ------------------
  |  |  291|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (291:14): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2751|      0|                         errno,
 2752|      0|                         "Failed to open a file %s for reading: %s",
 2753|      0|                         filename);
 2754|      0|        close(fd);
 2755|      0|        return NULL;
 2756|      0|    }
 2757|       |
 2758|       |    /* the flcose() will close also the underlying fd */
 2759|  10.9k|    return f;
 2760|  10.9k|}
strlcat:
 2787|  8.25k|{
 2788|  8.25k|    size_t dst_len;
 2789|  8.25k|    const char *p = memchr(dst, '\0', size);
 2790|  8.25k|    size_t src_len = strlen(src);
 2791|       |
 2792|  8.25k|    dst_len = (p != NULL) ? (size_t)(p - dst) : size;
  ------------------
  |  Branch (2792:15): [True: 8.25k, False: 0]
  ------------------
 2793|       |
 2794|  8.25k|    if (dst_len < size) {
  ------------------
  |  Branch (2794:9): [True: 8.25k, False: 0]
  ------------------
 2795|  8.25k|        size_t copy_len =
 2796|  8.25k|            (src_len >= size - dst_len) ? size - dst_len - 1 : src_len;
  ------------------
  |  Branch (2796:13): [True: 0, False: 8.25k]
  ------------------
 2797|  8.25k|        memcpy(dst + dst_len, src, copy_len);
 2798|  8.25k|        dst[dst_len + copy_len] = '\0';
 2799|  8.25k|    }
 2800|       |
 2801|  8.25k|    return dst_len + src_len;
 2802|  8.25k|}

ssh_options_set_algo:
  468|    292|{
  469|       |    /* When the list start with +,-,^ the filtration of unknown algorithms
  470|       |     * gets handled inside the helper functions, otherwise the list is taken
  471|       |     * as it is. */
  472|    292|    char *p = (char *)list;
  473|       |
  474|    292|    if (algo < SSH_COMP_C_S) {
  ------------------
  |  Branch (474:9): [True: 292, False: 0]
  ------------------
  475|    292|        if (list[0] == '+') {
  ------------------
  |  Branch (475:13): [True: 90, False: 202]
  ------------------
  476|     90|            p = ssh_add_to_default_algos(algo, list+1);
  477|    202|        } else if (list[0] == '-') {
  ------------------
  |  Branch (477:20): [True: 64, False: 138]
  ------------------
  478|     64|            p = ssh_remove_from_default_algos(algo, list+1);
  479|    138|        } else if (list[0] == '^') {
  ------------------
  |  Branch (479:20): [True: 117, False: 21]
  ------------------
  480|    117|            p = ssh_prefix_default_algos(algo, list+1);
  481|    117|        }
  482|    292|    }
  483|       |
  484|    292|    if (p == list) {
  ------------------
  |  Branch (484:9): [True: 21, False: 271]
  ------------------
  485|     21|        if (ssh_fips_mode()) {
  ------------------
  |  |  115|     21|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 21]
  |  |  ------------------
  ------------------
  486|      0|            p = ssh_keep_fips_algos(algo, list);
  487|     21|        } else {
  488|     21|            p = ssh_keep_known_algos(algo, list);
  489|     21|        }
  490|     21|    }
  491|       |
  492|    292|    if (p == NULL) {
  ------------------
  |  Branch (492:9): [True: 8, False: 284]
  ------------------
  493|      8|        ssh_set_error(session, SSH_REQUEST_DENIED,
  ------------------
  |  |  313|      8|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  494|      8|                "Setting method: no allowed algorithm for method \"%s\" (%s)",
  495|      8|                ssh_kex_get_description(algo), list);
  496|      8|        return -1;
  497|      8|    }
  498|       |
  499|    284|    SAFE_FREE(*place);
  ------------------
  |  |  375|    284|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 4, False: 280]
  |  |  |  Branch (375:71): [Folded, False: 284]
  |  |  ------------------
  ------------------
  500|    284|    *place = p;
  501|       |
  502|    284|    return 0;
  503|    292|}
ssh_bind_options_set:
 3682|    316|{
 3683|    316|    bool allowed;
 3684|    316|    char *p = NULL, *q = NULL;
 3685|    316|    const char *v = NULL;
 3686|    316|    int i, rc;
 3687|    316|    char **wanted_methods = sshbind->wanted_methods;
 3688|       |
 3689|    316|    if (sshbind == NULL) {
  ------------------
  |  Branch (3689:9): [True: 0, False: 316]
  ------------------
 3690|      0|        return -1;
 3691|      0|    }
 3692|       |
 3693|    316|    switch (type) {
 3694|      0|    case SSH_BIND_OPTIONS_RSAKEY:
  ------------------
  |  Branch (3694:5): [True: 0, False: 316]
  ------------------
 3695|      0|    case SSH_BIND_OPTIONS_ECDSAKEY:
  ------------------
  |  Branch (3695:5): [True: 0, False: 316]
  ------------------
 3696|       |        /* deprecated */
 3697|      0|    case SSH_BIND_OPTIONS_HOSTKEY:
  ------------------
  |  Branch (3697:5): [True: 0, False: 316]
  ------------------
 3698|      0|    case SSH_BIND_OPTIONS_IMPORT_KEY:
  ------------------
  |  Branch (3698:5): [True: 0, False: 316]
  ------------------
 3699|      0|    case SSH_BIND_OPTIONS_IMPORT_KEY_STR:
  ------------------
  |  Branch (3699:5): [True: 0, False: 316]
  ------------------
 3700|      0|        if (value == NULL) {
  ------------------
  |  Branch (3700:13): [True: 0, False: 0]
  ------------------
 3701|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3702|      0|            return -1;
 3703|      0|        } else {
 3704|      0|            int key_type;
 3705|      0|            ssh_key *bind_key_loc = NULL;
 3706|      0|            ssh_key key = NULL;
 3707|      0|            char **bind_key_path_loc = NULL;
 3708|       |
 3709|      0|            if (type == SSH_BIND_OPTIONS_IMPORT_KEY_STR) {
  ------------------
  |  Branch (3709:17): [True: 0, False: 0]
  ------------------
 3710|      0|                const char *key_str = (const char *)value;
 3711|      0|                rc = ssh_pki_import_privkey_base64(key_str,
 3712|      0|                                                   NULL,
 3713|      0|                                                   NULL,
 3714|      0|                                                   NULL,
 3715|      0|                                                   &key);
 3716|      0|                if (rc == SSH_ERROR) {
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (3716:21): [True: 0, False: 0]
  ------------------
 3717|      0|                    ssh_set_error(sshbind,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 3718|      0|                                  SSH_FATAL,
 3719|      0|                                  "Failed to import key from buffer");
 3720|      0|                    return -1;
 3721|      0|                }
 3722|      0|            } else if (type == SSH_BIND_OPTIONS_IMPORT_KEY) {
  ------------------
  |  Branch (3722:24): [True: 0, False: 0]
  ------------------
 3723|      0|                key = (ssh_key)value;
 3724|      0|            } else {
 3725|      0|                rc = ssh_pki_import_privkey_file(value, NULL, NULL, NULL, &key);
 3726|      0|                if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (3726:21): [True: 0, False: 0]
  ------------------
 3727|      0|                    return -1;
 3728|      0|                }
 3729|      0|            }
 3730|      0|            allowed = ssh_bind_key_size_allowed(sshbind, key);
 3731|      0|            if (!allowed) {
  ------------------
  |  Branch (3731:17): [True: 0, False: 0]
  ------------------
 3732|      0|                ssh_set_error(sshbind,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 3733|      0|                              SSH_FATAL,
 3734|      0|                              "The host key size %d is too small.",
 3735|      0|                              ssh_key_size(key));
 3736|      0|                if (type != SSH_BIND_OPTIONS_IMPORT_KEY) {
  ------------------
  |  Branch (3736:21): [True: 0, False: 0]
  ------------------
 3737|      0|                    SSH_KEY_FREE(key);
  ------------------
  |  |  740|      0|    do { if ((x) != NULL) { ssh_key_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (740:14): [True: 0, False: 0]
  |  |  |  Branch (740:66): [Folded, False: 0]
  |  |  ------------------
  ------------------
 3738|      0|                }
 3739|      0|                return -1;
 3740|      0|            }
 3741|      0|            key_type = ssh_key_type(key);
 3742|      0|            switch (key_type) {
 3743|      0|            case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (3743:13): [True: 0, False: 0]
  ------------------
 3744|      0|            case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (3744:13): [True: 0, False: 0]
  ------------------
 3745|      0|            case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (3745:13): [True: 0, False: 0]
  ------------------
 3746|      0|#ifdef HAVE_ECC
 3747|      0|                bind_key_loc = &sshbind->ecdsa;
 3748|      0|                bind_key_path_loc = &sshbind->ecdsakey;
 3749|       |#else
 3750|       |                ssh_set_error(sshbind,
 3751|       |                              SSH_FATAL,
 3752|       |                              "ECDSA key used and libssh compiled "
 3753|       |                              "without ECDSA support");
 3754|       |#endif
 3755|      0|                break;
 3756|      0|            case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (3756:13): [True: 0, False: 0]
  ------------------
 3757|      0|                bind_key_loc = &sshbind->rsa;
 3758|      0|                bind_key_path_loc = &sshbind->rsakey;
 3759|      0|                break;
 3760|      0|            case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (3760:13): [True: 0, False: 0]
  ------------------
 3761|      0|                bind_key_loc = &sshbind->ed25519;
 3762|      0|                bind_key_path_loc = &sshbind->ed25519key;
 3763|      0|                break;
 3764|      0|            default:
  ------------------
  |  Branch (3764:13): [True: 0, False: 0]
  ------------------
 3765|      0|                ssh_set_error(sshbind,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 3766|      0|                              SSH_FATAL,
 3767|      0|                              "Unsupported key type %d",
 3768|      0|                              key_type);
 3769|      0|            }
 3770|      0|            if (type == SSH_BIND_OPTIONS_RSAKEY ||
  ------------------
  |  Branch (3770:17): [True: 0, False: 0]
  ------------------
 3771|      0|                type == SSH_BIND_OPTIONS_ECDSAKEY ||
  ------------------
  |  Branch (3771:17): [True: 0, False: 0]
  ------------------
 3772|      0|                type == SSH_BIND_OPTIONS_HOSTKEY) {
  ------------------
  |  Branch (3772:17): [True: 0, False: 0]
  ------------------
 3773|      0|                if (bind_key_loc == NULL) {
  ------------------
  |  Branch (3773:21): [True: 0, False: 0]
  ------------------
 3774|      0|                    ssh_key_free(key);
 3775|      0|                    return -1;
 3776|      0|                }
 3777|       |                /* Set the location of the key on disk even though we don't
 3778|       |                   need it in case some other function wants it */
 3779|      0|                rc = ssh_bind_set_key(sshbind, bind_key_path_loc, value);
 3780|      0|                if (rc < 0) {
  ------------------
  |  Branch (3780:21): [True: 0, False: 0]
  ------------------
 3781|      0|                    ssh_key_free(key);
 3782|      0|                    return -1;
 3783|      0|                }
 3784|      0|            } else if (type == SSH_BIND_OPTIONS_IMPORT_KEY_STR) {
  ------------------
  |  Branch (3784:24): [True: 0, False: 0]
  ------------------
 3785|      0|                if (bind_key_loc == NULL) {
  ------------------
  |  Branch (3785:21): [True: 0, False: 0]
  ------------------
 3786|      0|                    ssh_key_free(key);
 3787|      0|                    return -1;
 3788|      0|                }
 3789|      0|            } else {
 3790|      0|                if (bind_key_loc == NULL) {
  ------------------
  |  Branch (3790:21): [True: 0, False: 0]
  ------------------
 3791|      0|                    return -1;
 3792|      0|                }
 3793|      0|            }
 3794|      0|            ssh_key_free(*bind_key_loc);
 3795|      0|            *bind_key_loc = key;
 3796|      0|        }
 3797|      0|        break;
 3798|      0|    case SSH_BIND_OPTIONS_BINDADDR:
  ------------------
  |  Branch (3798:5): [True: 0, False: 316]
  ------------------
 3799|      0|        if (value == NULL) {
  ------------------
  |  Branch (3799:13): [True: 0, False: 0]
  ------------------
 3800|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3801|      0|            return -1;
 3802|      0|        } else {
 3803|      0|            SAFE_FREE(sshbind->bindaddr);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 3804|      0|            sshbind->bindaddr = strdup(value);
 3805|      0|            if (sshbind->bindaddr == NULL) {
  ------------------
  |  Branch (3805:17): [True: 0, False: 0]
  ------------------
 3806|      0|                ssh_set_error_oom(sshbind);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 3807|      0|                return -1;
 3808|      0|            }
 3809|      0|        }
 3810|      0|        break;
 3811|      0|    case SSH_BIND_OPTIONS_BINDPORT:
  ------------------
  |  Branch (3811:5): [True: 0, False: 316]
  ------------------
 3812|      0|        if (value == NULL) {
  ------------------
  |  Branch (3812:13): [True: 0, False: 0]
  ------------------
 3813|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3814|      0|            return -1;
 3815|      0|        } else {
 3816|      0|            int *x = (int *)value;
 3817|      0|            sshbind->bindport = *x & 0xffffU;
 3818|      0|        }
 3819|      0|        break;
 3820|      4|    case SSH_BIND_OPTIONS_BINDPORT_STR:
  ------------------
  |  Branch (3820:5): [True: 4, False: 312]
  ------------------
 3821|      4|        if (value == NULL) {
  ------------------
  |  Branch (3821:13): [True: 0, False: 4]
  ------------------
 3822|      0|            sshbind->bindport = 22 & 0xffffU;
 3823|      4|        } else {
 3824|      4|            q = strdup(value);
 3825|      4|            if (q == NULL) {
  ------------------
  |  Branch (3825:17): [True: 0, False: 4]
  ------------------
 3826|      0|                ssh_set_error_oom(sshbind);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 3827|      0|                return -1;
 3828|      0|            }
 3829|      4|            i = strtol(q, &p, 10);
 3830|      4|            if (q == p) {
  ------------------
  |  Branch (3830:17): [True: 4, False: 0]
  ------------------
 3831|      4|                SSH_LOG(SSH_LOG_DEBUG, "No bind port was parsed");
  ------------------
  |  |  283|      4|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3832|      4|                SAFE_FREE(q);
  ------------------
  |  |  375|      4|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 4, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 4]
  |  |  ------------------
  ------------------
 3833|      4|                return -1;
 3834|      4|            }
 3835|      0|            SAFE_FREE(q);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 3836|       |
 3837|      0|            sshbind->bindport = i & 0xffffU;
 3838|      0|        }
 3839|      0|        break;
 3840|     10|    case SSH_BIND_OPTIONS_LOG_VERBOSITY:
  ------------------
  |  Branch (3840:5): [True: 10, False: 306]
  ------------------
 3841|     10|        if (value == NULL) {
  ------------------
  |  Branch (3841:13): [True: 0, False: 10]
  ------------------
 3842|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3843|      0|            return -1;
 3844|     10|        } else {
 3845|     10|            int *x = (int *)value;
 3846|     10|            ssh_set_log_level(*x & 0xffffU);
 3847|     10|        }
 3848|     10|        break;
 3849|     10|    case SSH_BIND_OPTIONS_LOG_VERBOSITY_STR:
  ------------------
  |  Branch (3849:5): [True: 0, False: 316]
  ------------------
 3850|      0|        if (value == NULL) {
  ------------------
  |  Branch (3850:13): [True: 0, False: 0]
  ------------------
 3851|      0|            ssh_set_log_level(0);
 3852|      0|        } else {
 3853|      0|            q = strdup(value);
 3854|      0|            if (q == NULL) {
  ------------------
  |  Branch (3854:17): [True: 0, False: 0]
  ------------------
 3855|      0|                ssh_set_error_oom(sshbind);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 3856|      0|                return -1;
 3857|      0|            }
 3858|      0|            i = strtol(q, &p, 10);
 3859|      0|            if (q == p) {
  ------------------
  |  Branch (3859:17): [True: 0, False: 0]
  ------------------
 3860|      0|                SSH_LOG(SSH_LOG_DEBUG, "No log verbositiy was parsed");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3861|      0|                SAFE_FREE(q);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 3862|      0|                return -1;
 3863|      0|            }
 3864|      0|            SAFE_FREE(q);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 3865|       |
 3866|      0|            ssh_set_log_level(i & 0xffffU);
 3867|      0|        }
 3868|      0|        break;
 3869|      0|    case SSH_BIND_OPTIONS_BANNER:
  ------------------
  |  Branch (3869:5): [True: 0, False: 316]
  ------------------
 3870|      0|        if (value == NULL) {
  ------------------
  |  Branch (3870:13): [True: 0, False: 0]
  ------------------
 3871|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3872|      0|            return -1;
 3873|      0|        } else {
 3874|      0|            SAFE_FREE(sshbind->banner);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 3875|      0|            sshbind->banner = strdup(value);
 3876|      0|            if (sshbind->banner == NULL) {
  ------------------
  |  Branch (3876:17): [True: 0, False: 0]
  ------------------
 3877|      0|                ssh_set_error_oom(sshbind);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 3878|      0|                return -1;
 3879|      0|            }
 3880|      0|        }
 3881|      0|        break;
 3882|     33|    case SSH_BIND_OPTIONS_CIPHERS_C_S:
  ------------------
  |  Branch (3882:5): [True: 33, False: 283]
  ------------------
 3883|     33|        v = value;
 3884|     33|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (3884:13): [True: 0, False: 33]
  |  Branch (3884:26): [True: 0, False: 33]
  ------------------
 3885|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3886|      0|            return -1;
 3887|     33|        } else {
 3888|     33|            rc = ssh_bind_set_algo(sshbind,
 3889|     33|                                   SSH_CRYPT_C_S,
 3890|     33|                                   v,
 3891|     33|                                   &wanted_methods[SSH_CRYPT_C_S]);
 3892|     33|            if (rc < 0) {
  ------------------
  |  Branch (3892:17): [True: 1, False: 32]
  ------------------
 3893|      1|                return -1;
 3894|      1|            }
 3895|     33|        }
 3896|     32|        break;
 3897|     32|    case SSH_BIND_OPTIONS_CIPHERS_S_C:
  ------------------
  |  Branch (3897:5): [True: 32, False: 284]
  ------------------
 3898|     32|        v = value;
 3899|     32|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (3899:13): [True: 0, False: 32]
  |  Branch (3899:26): [True: 0, False: 32]
  ------------------
 3900|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3901|      0|            return -1;
 3902|     32|        } else {
 3903|     32|            rc = ssh_bind_set_algo(sshbind,
 3904|     32|                                   SSH_CRYPT_S_C,
 3905|     32|                                   v,
 3906|     32|                                   &wanted_methods[SSH_CRYPT_S_C]);
 3907|     32|            if (rc < 0) {
  ------------------
  |  Branch (3907:17): [True: 0, False: 32]
  ------------------
 3908|      0|                return -1;
 3909|      0|            }
 3910|     32|        }
 3911|     32|        break;
 3912|     32|    case SSH_BIND_OPTIONS_KEY_EXCHANGE:
  ------------------
  |  Branch (3912:5): [True: 7, False: 309]
  ------------------
 3913|      7|        v = value;
 3914|      7|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (3914:13): [True: 0, False: 7]
  |  Branch (3914:26): [True: 0, False: 7]
  ------------------
 3915|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3916|      0|            return -1;
 3917|      7|        } else {
 3918|      7|            rc = ssh_bind_set_algo(sshbind,
 3919|      7|                                   SSH_KEX,
 3920|      7|                                   v,
 3921|      7|                                   &wanted_methods[SSH_KEX]);
 3922|      7|            if (rc < 0) {
  ------------------
  |  Branch (3922:17): [True: 0, False: 7]
  ------------------
 3923|      0|                return -1;
 3924|      0|            }
 3925|      7|        }
 3926|      7|        break;
 3927|     88|    case SSH_BIND_OPTIONS_HMAC_C_S:
  ------------------
  |  Branch (3927:5): [True: 88, False: 228]
  ------------------
 3928|     88|        v = value;
 3929|     88|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (3929:13): [True: 0, False: 88]
  |  Branch (3929:26): [True: 0, False: 88]
  ------------------
 3930|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3931|      0|            return -1;
 3932|     88|        } else {
 3933|     88|            rc = ssh_bind_set_algo(sshbind,
 3934|     88|                                   SSH_MAC_C_S,
 3935|     88|                                   v,
 3936|     88|                                   &wanted_methods[SSH_MAC_C_S]);
 3937|     88|            if (rc < 0) {
  ------------------
  |  Branch (3937:17): [True: 4, False: 84]
  ------------------
 3938|      4|                return -1;
 3939|      4|            }
 3940|     88|        }
 3941|     84|        break;
 3942|     84|    case SSH_BIND_OPTIONS_HMAC_S_C:
  ------------------
  |  Branch (3942:5): [True: 84, False: 232]
  ------------------
 3943|     84|        v = value;
 3944|     84|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (3944:13): [True: 0, False: 84]
  |  Branch (3944:26): [True: 0, False: 84]
  ------------------
 3945|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3946|      0|            return -1;
 3947|     84|        } else {
 3948|     84|            rc = ssh_bind_set_algo(sshbind,
 3949|     84|                                   SSH_MAC_S_C,
 3950|     84|                                   v,
 3951|     84|                                   &wanted_methods[SSH_MAC_S_C]);
 3952|     84|            if (rc < 0) {
  ------------------
  |  Branch (3952:17): [True: 0, False: 84]
  ------------------
 3953|      0|                return -1;
 3954|      0|            }
 3955|     84|        }
 3956|     84|        break;
 3957|     84|    case SSH_BIND_OPTIONS_CONFIG_DIR:
  ------------------
  |  Branch (3957:5): [True: 0, False: 316]
  ------------------
 3958|      0|        v = value;
 3959|      0|        SAFE_FREE(sshbind->config_dir);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 3960|      0|        if (v == NULL) {
  ------------------
  |  Branch (3960:13): [True: 0, False: 0]
  ------------------
 3961|      0|            break;
 3962|      0|        } else if (v[0] == '\0') {
  ------------------
  |  Branch (3962:20): [True: 0, False: 0]
  ------------------
 3963|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3964|      0|            return -1;
 3965|      0|        } else {
 3966|      0|            sshbind->config_dir = ssh_path_expand_tilde(v);
 3967|      0|            if (sshbind->config_dir == NULL) {
  ------------------
  |  Branch (3967:17): [True: 0, False: 0]
  ------------------
 3968|      0|                ssh_set_error_oom(sshbind);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 3969|      0|                return -1;
 3970|      0|            }
 3971|      0|        }
 3972|      0|        break;
 3973|     16|    case SSH_BIND_OPTIONS_PUBKEY_ACCEPTED_KEY_TYPES:
  ------------------
  |  Branch (3973:5): [True: 16, False: 300]
  ------------------
 3974|     16|        v = value;
 3975|     16|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (3975:13): [True: 0, False: 16]
  |  Branch (3975:26): [True: 0, False: 16]
  ------------------
 3976|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3977|      0|            return -1;
 3978|     16|        } else {
 3979|     16|            rc = ssh_bind_set_algo(sshbind,
 3980|     16|                                   SSH_HOSTKEYS,
 3981|     16|                                   v,
 3982|     16|                                   &sshbind->pubkey_accepted_key_types);
 3983|     16|            if (rc < 0) {
  ------------------
  |  Branch (3983:17): [True: 1, False: 15]
  ------------------
 3984|      1|                return -1;
 3985|      1|            }
 3986|     16|        }
 3987|     15|        break;
 3988|     32|    case SSH_BIND_OPTIONS_HOSTKEY_ALGORITHMS:
  ------------------
  |  Branch (3988:5): [True: 32, False: 284]
  ------------------
 3989|     32|        v = value;
 3990|     32|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (3990:13): [True: 0, False: 32]
  |  Branch (3990:26): [True: 0, False: 32]
  ------------------
 3991|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3992|      0|            return -1;
 3993|     32|        } else {
 3994|     32|            rc = ssh_bind_set_algo(sshbind,
 3995|     32|                                   SSH_HOSTKEYS,
 3996|     32|                                   v,
 3997|     32|                                   &wanted_methods[SSH_HOSTKEYS]);
 3998|     32|            if (rc < 0) {
  ------------------
  |  Branch (3998:17): [True: 2, False: 30]
  ------------------
 3999|      2|                return -1;
 4000|      2|            }
 4001|     32|        }
 4002|     30|        break;
 4003|     30|    case SSH_BIND_OPTIONS_PROCESS_CONFIG:
  ------------------
  |  Branch (4003:5): [True: 0, False: 316]
  ------------------
 4004|      0|        if (value == NULL) {
  ------------------
  |  Branch (4004:13): [True: 0, False: 0]
  ------------------
 4005|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 4006|      0|            return -1;
 4007|      0|        } else {
 4008|      0|            bool *x = (bool *)value;
 4009|      0|            sshbind->config_processed = !(*x);
 4010|      0|        }
 4011|      0|        break;
 4012|      0|    case SSH_BIND_OPTIONS_MODULI:
  ------------------
  |  Branch (4012:5): [True: 0, False: 316]
  ------------------
 4013|      0|        if (value == NULL) {
  ------------------
  |  Branch (4013:13): [True: 0, False: 0]
  ------------------
 4014|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 4015|      0|            return -1;
 4016|      0|        } else {
 4017|      0|            SAFE_FREE(sshbind->moduli_file);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 4018|      0|            sshbind->moduli_file = strdup(value);
 4019|      0|            if (sshbind->moduli_file == NULL) {
  ------------------
  |  Branch (4019:17): [True: 0, False: 0]
  ------------------
 4020|      0|                ssh_set_error_oom(sshbind);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 4021|      0|                return -1;
 4022|      0|            }
 4023|      0|        }
 4024|      0|        break;
 4025|     10|    case SSH_BIND_OPTIONS_RSA_MIN_SIZE:
  ------------------
  |  Branch (4025:5): [True: 10, False: 306]
  ------------------
 4026|     10|        if (value == NULL) {
  ------------------
  |  Branch (4026:13): [True: 0, False: 10]
  ------------------
 4027|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 4028|      0|            return -1;
 4029|     10|        } else {
 4030|     10|            int *x = (int *)value;
 4031|       |
 4032|     10|            if (*x < 0) {
  ------------------
  |  Branch (4032:17): [True: 0, False: 10]
  ------------------
 4033|      0|                ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 4034|      0|                return -1;
 4035|      0|            }
 4036|       |
 4037|       |            /* (*x == 0) is allowed as it is used to revert to default */
 4038|       |
 4039|     10|            if (*x > 0 && *x < RSA_MIN_KEY_SIZE) {
  ------------------
  |  |   49|     10|#define RSA_MIN_KEY_SIZE      1024
  ------------------
  |  Branch (4039:17): [True: 10, False: 0]
  |  Branch (4039:27): [True: 2, False: 8]
  ------------------
 4040|      2|                ssh_set_error(sshbind,
  ------------------
  |  |  313|      2|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 4041|      2|                              SSH_REQUEST_DENIED,
 4042|      2|                              "The provided value (%d) for minimal RSA key "
 4043|      2|                              "size is too small. Use at least %d bits.",
 4044|      2|                              *x,
 4045|      2|                              RSA_MIN_KEY_SIZE);
 4046|      2|                return -1;
 4047|      2|            }
 4048|      8|            sshbind->rsa_min_size = *x;
 4049|      8|        }
 4050|      8|        break;
 4051|       |#ifdef WITH_GSSAPI
 4052|       |    case SSH_BIND_OPTIONS_GSSAPI_KEY_EXCHANGE:
 4053|       |        if (value == NULL) {
 4054|       |            ssh_set_error_invalid(sshbind);
 4055|       |            return -1;
 4056|       |        } else {
 4057|       |            bool *x = (bool *)value;
 4058|       |            sshbind->gssapi_key_exchange = *x;
 4059|       |        }
 4060|       |        break;
 4061|       |    case SSH_BIND_OPTIONS_GSSAPI_KEY_EXCHANGE_ALGS:
 4062|       |        if (value == NULL) {
 4063|       |            ssh_set_error_invalid(sshbind);
 4064|       |            return -1;
 4065|       |        } else {
 4066|       |            char *ret = NULL;
 4067|       |            SAFE_FREE(sshbind->gssapi_key_exchange_algs);
 4068|       |            ret = ssh_find_all_matching(GSSAPI_KEY_EXCHANGE_SUPPORTED, value);
 4069|       |            if (ret == NULL) {
 4070|       |                ssh_set_error(
 4071|       |                    sshbind,
 4072|       |                    SSH_REQUEST_DENIED,
 4073|       |                    "GSSAPI key exchange algorithms not supported or invalid");
 4074|       |                return -1;
 4075|       |            }
 4076|       |            sshbind->gssapi_key_exchange_algs = ret;
 4077|       |        }
 4078|       |        break;
 4079|       |#endif /* WITH_GSSAPI */
 4080|      8|    default:
  ------------------
  |  Branch (4080:5): [True: 0, False: 316]
  ------------------
 4081|      0|        ssh_set_error(sshbind,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 4082|      0|                      SSH_REQUEST_DENIED,
 4083|      0|                      "Unknown ssh option %d",
 4084|      0|                      type);
 4085|      0|        return -1;
 4086|      0|        break;
 4087|    316|    }
 4088|       |
 4089|    302|    return 0;
 4090|    316|}
options.c:ssh_bind_set_algo:
 3500|    292|{
 3501|       |    /* sshbind is needed only for ssh_set_error which takes void*
 3502|       |     * the typecast is only to satisfy function parameter type */
 3503|    292|    return ssh_options_set_algo((ssh_session)sshbind, algo, list, place);
 3504|    292|}

ssh_key_free:
  261|    807|{
  262|    807|    if (key) {
  ------------------
  |  Branch (262:9): [True: 0, False: 807]
  ------------------
  263|      0|        ssh_key_clean(key);
  264|       |        SAFE_FREE(key);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  265|      0|    }
  266|    807|}

ssh_poll_init:
   91|      2|{
   92|      2|    return;
   93|      2|}

ssh_socket_init:
  132|      2|{
  133|      2|    if (sockets_initialized == 0) {
  ------------------
  |  Branch (133:9): [True: 2, False: 0]
  ------------------
  134|       |#ifdef _WIN32
  135|       |        struct WSAData wsaData;
  136|       |
  137|       |        /* Initiates use of the Winsock DLL by a process. */
  138|       |        if (WSAStartup(MAKEWORD(2, 0), &wsaData) != 0) {
  139|       |            return -1;
  140|       |        }
  141|       |#endif
  142|      2|        ssh_poll_init();
  143|       |
  144|      2|        sockets_initialized = 1;
  145|      2|    }
  146|       |
  147|      2|    return 0;
  148|      2|}

ssh_threads_init:
   42|      2|{
   43|      2|    static int threads_initialized = 0;
   44|      2|    int rc;
   45|       |
   46|      2|    if (threads_initialized) {
  ------------------
  |  Branch (46:9): [True: 0, False: 2]
  ------------------
   47|      0|        return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
   48|      0|    }
   49|       |
   50|       |    /* first initialize the user_callbacks with our default handlers if not
   51|       |     * already the case
   52|       |     */
   53|      2|    if (user_callbacks == NULL){
  ------------------
  |  Branch (53:9): [True: 2, False: 0]
  ------------------
   54|      2|        user_callbacks = ssh_threads_get_default();
   55|      2|    }
   56|       |
   57|       |    /* Then initialize the crypto libraries threading callbacks */
   58|      2|    rc = crypto_thread_init(user_callbacks);
   59|      2|    if (rc == SSH_OK) {
  ------------------
  |  |  315|      2|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (59:9): [True: 2, False: 0]
  ------------------
   60|      2|        threads_initialized = 1;
   61|      2|    }
   62|      2|    return rc;
   63|      2|}

crypto_thread_init:
   28|      2|{
   29|      2|    (void) cb;
   30|      2|    return SSH_OK;
  ------------------
  |  |  315|      2|#define SSH_OK 0     /* No error */
  ------------------
   31|      2|}

ssh_mutex_lock:
  102|      4|{
  103|      4|    int rc;
  104|       |
  105|      4|    if (mutex == NULL) {
  ------------------
  |  Branch (105:9): [True: 0, False: 4]
  ------------------
  106|      0|        exit(EINVAL);
  107|      0|    }
  108|       |
  109|      4|    rc = pthread_mutex_lock(mutex);
  110|       |
  111|      4|    if (rc) {
  ------------------
  |  Branch (111:9): [True: 0, False: 4]
  ------------------
  112|      0|        exit(rc);
  113|      0|    }
  114|      4|}
ssh_mutex_unlock:
  117|      4|{
  118|      4|    int rc;
  119|       |
  120|      4|    if (mutex == NULL) {
  ------------------
  |  Branch (120:9): [True: 0, False: 4]
  ------------------
  121|      0|        exit(EINVAL);
  122|      0|    }
  123|       |
  124|      4|    rc = pthread_mutex_unlock(mutex);
  125|       |
  126|      4|    if (rc) {
  ------------------
  |  Branch (126:9): [True: 0, False: 4]
  ------------------
  127|      0|        exit(rc);
  128|      0|    }
  129|      4|}
ssh_threads_get_default:
  132|      2|{
  133|      2|    return &ssh_threads_pthread;
  134|      2|}

ssh_tokens_free:
   43|    791|{
   44|    791|    int i;
   45|    791|    if (tokens == NULL) {
  ------------------
  |  Branch (45:9): [True: 0, False: 791]
  ------------------
   46|      0|        return;
   47|      0|    }
   48|       |
   49|    791|    if (tokens->tokens != NULL) {
  ------------------
  |  Branch (49:9): [True: 791, False: 0]
  ------------------
   50|  23.2k|        for (i = 0; tokens->tokens[i] != NULL; i++) {
  ------------------
  |  Branch (50:21): [True: 22.4k, False: 791]
  ------------------
   51|  22.4k|            ssh_burn(tokens->tokens[i], strlen(tokens->tokens[i]));
  ------------------
  |  |  390|  22.4k|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
   52|  22.4k|        }
   53|    791|    }
   54|       |
   55|    791|    SAFE_FREE(tokens->buffer);
  ------------------
  |  |  375|    791|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 791, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 791]
  |  |  ------------------
  ------------------
   56|    791|    SAFE_FREE(tokens->tokens);
  ------------------
  |  |  375|    791|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 791, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 791]
  |  |  ------------------
  ------------------
   57|       |    SAFE_FREE(tokens);
  ------------------
  |  |  375|    791|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 791, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 791]
  |  |  ------------------
  ------------------
   58|    791|}
ssh_tokenize:
   74|    791|{
   75|       |
   76|    791|    struct ssh_tokens_st *tokens = NULL;
   77|    791|    size_t num_tokens = 1, i = 1;
   78|       |
   79|    791|    char *found, *c;
   80|       |
   81|    791|    if (chain == NULL) {
  ------------------
  |  Branch (81:9): [True: 0, False: 791]
  ------------------
   82|      0|        return NULL;
   83|      0|    }
   84|       |
   85|    791|    tokens = calloc(1, sizeof(struct ssh_tokens_st));
   86|    791|    if (tokens == NULL) {
  ------------------
  |  Branch (86:9): [True: 0, False: 791]
  ------------------
   87|      0|        return NULL;
   88|      0|    }
   89|       |
   90|    791|    tokens->buffer = strdup(chain);
   91|    791|    if (tokens->buffer == NULL) {
  ------------------
  |  Branch (91:9): [True: 0, False: 791]
  ------------------
   92|      0|        goto error;
   93|      0|    }
   94|       |
   95|    791|    c = tokens->buffer;
   96|  22.5k|    do {
   97|  22.5k|        found = strchr(c, separator);
   98|  22.5k|        if (found != NULL) {
  ------------------
  |  Branch (98:13): [True: 21.7k, False: 791]
  ------------------
   99|  21.7k|            c = found + 1;
  100|  21.7k|            num_tokens++;
  101|  21.7k|        }
  102|  22.5k|    } while(found != NULL);
  ------------------
  |  Branch (102:13): [True: 21.7k, False: 791]
  ------------------
  103|       |
  104|       |    /* Allocate tokens list */
  105|    791|    tokens->tokens = calloc(num_tokens + 1, sizeof(char *));
  106|    791|    if (tokens->tokens == NULL) {
  ------------------
  |  Branch (106:9): [True: 0, False: 791]
  ------------------
  107|      0|        goto error;
  108|      0|    }
  109|       |
  110|       |    /* First token starts in the beginning of the chain */
  111|    791|    tokens->tokens[0] = tokens->buffer;
  112|    791|    c = tokens->buffer;
  113|       |
  114|  22.4k|    for (i = 1; i < num_tokens; i++) {
  ------------------
  |  Branch (114:17): [True: 21.7k, False: 757]
  ------------------
  115|       |        /* Find next separator */
  116|  21.7k|        found = strchr(c, separator);
  117|  21.7k|        if (found == NULL) {
  ------------------
  |  Branch (117:13): [True: 0, False: 21.7k]
  ------------------
  118|      0|            break;
  119|      0|        }
  120|       |
  121|       |        /* Replace it with a string terminator */
  122|  21.7k|        *found = '\0';
  123|       |
  124|       |        /* The next token starts in the next byte */
  125|  21.7k|        c = found + 1;
  126|       |
  127|       |        /* If we did not reach the end of the chain yet, set the next token */
  128|  21.7k|        if (*c != '\0') {
  ------------------
  |  Branch (128:13): [True: 21.6k, False: 34]
  ------------------
  129|  21.6k|            tokens->tokens[i] = c;
  130|  21.6k|        } else {
  131|     34|            break;
  132|     34|        }
  133|  21.7k|    }
  134|       |
  135|    791|    return tokens;
  136|       |
  137|      0|error:
  138|      0|    ssh_tokens_free(tokens);
  139|       |    return NULL;
  140|    791|}
ssh_find_all_matching:
  208|    228|{
  209|    228|    struct ssh_tokens_st *a_tok = NULL, *p_tok = NULL;
  210|    228|    int i, j;
  211|    228|    char *ret = NULL;
  212|    228|    size_t max, len, pos = 0;
  213|    228|    int match;
  214|       |
  215|    228|    if ((available_list == NULL) || (preferred_list == NULL)) {
  ------------------
  |  Branch (215:9): [True: 0, False: 228]
  |  Branch (215:37): [True: 0, False: 228]
  ------------------
  216|      0|        return NULL;
  217|      0|    }
  218|       |
  219|    228|    max = MAX(strlen(available_list), strlen(preferred_list));
  ------------------
  |  |  371|    228|#define MAX(a,b) ((a) > (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (371:19): [True: 142, False: 86]
  |  |  ------------------
  ------------------
  220|       |
  221|    228|    ret = calloc(1, max + 1);
  222|    228|    if (ret == NULL) {
  ------------------
  |  Branch (222:9): [True: 0, False: 228]
  ------------------
  223|      0|        return NULL;
  224|      0|    }
  225|       |
  226|    228|    a_tok = ssh_tokenize(available_list, ',');
  227|    228|    if (a_tok == NULL) {
  ------------------
  |  Branch (227:9): [True: 0, False: 228]
  ------------------
  228|      0|        SAFE_FREE(ret);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  229|      0|        goto out;
  230|      0|    }
  231|       |
  232|    228|    p_tok = ssh_tokenize(preferred_list, ',');
  233|    228|    if (p_tok == NULL) {
  ------------------
  |  Branch (233:9): [True: 0, False: 228]
  ------------------
  234|      0|        SAFE_FREE(ret);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  235|      0|        goto out;
  236|      0|    }
  237|       |
  238|  4.78k|    for (i = 0; p_tok->tokens[i] ; i++) {
  ------------------
  |  Branch (238:17): [True: 4.55k, False: 228]
  ------------------
  239|  46.9k|        for (j = 0; a_tok->tokens[j]; j++) {
  ------------------
  |  Branch (239:21): [True: 42.4k, False: 4.55k]
  ------------------
  240|  42.4k|            match = !strcmp(a_tok->tokens[j], p_tok->tokens[i]);
  241|  42.4k|            if (match) {
  ------------------
  |  Branch (241:17): [True: 1.37k, False: 41.0k]
  ------------------
  242|  1.37k|                if (pos != 0) {
  ------------------
  |  Branch (242:21): [True: 1.15k, False: 220]
  ------------------
  243|  1.15k|                    ret[pos] = ',';
  244|  1.15k|                    pos++;
  245|  1.15k|                }
  246|       |
  247|  1.37k|                len = strlen(a_tok->tokens[j]);
  248|  1.37k|                memcpy(&ret[pos], a_tok->tokens[j], len);
  249|  1.37k|                pos += len;
  250|  1.37k|                ret[pos] = '\0';
  251|  1.37k|            }
  252|  42.4k|        }
  253|  4.55k|    }
  254|       |
  255|    228|    if (ret[0] == '\0') {
  ------------------
  |  Branch (255:9): [True: 8, False: 220]
  ------------------
  256|      8|        SAFE_FREE(ret);
  ------------------
  |  |  375|      8|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 8, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 8]
  |  |  ------------------
  ------------------
  257|      8|    }
  258|       |
  259|    228|out:
  260|    228|    ssh_tokens_free(a_tok);
  261|    228|    ssh_tokens_free(p_tok);
  262|    228|    return ret;
  263|    228|}
ssh_remove_duplicates:
  277|    207|{
  278|    207|    struct ssh_tokens_st *tok = NULL;
  279|       |
  280|    207|    size_t i, j, num_tokens, max_len;
  281|    207|    char *ret = NULL;
  282|    207|    bool *should_copy = NULL, need_comma = false;
  283|       |
  284|    207|    if (list == NULL) {
  ------------------
  |  Branch (284:9): [True: 0, False: 207]
  ------------------
  285|      0|        return NULL;
  286|      0|    }
  287|       |
  288|       |    /* The maximum number of tokens is the size of the list */
  289|    207|    max_len = strlen(list);
  290|    207|    if (max_len == 0) {
  ------------------
  |  Branch (290:9): [True: 0, False: 207]
  ------------------
  291|      0|        return NULL;
  292|      0|    }
  293|       |
  294|       |    /* Add space for ending '\0' */
  295|    207|    max_len++;
  296|       |
  297|    207|    tok = ssh_tokenize(list, ',');
  298|    207|    if ((tok == NULL) || (tok->tokens == NULL) || (tok->tokens[0] == NULL)) {
  ------------------
  |  Branch (298:9): [True: 0, False: 207]
  |  Branch (298:26): [True: 0, False: 207]
  |  Branch (298:51): [True: 0, False: 207]
  ------------------
  299|      0|        goto out;
  300|      0|    }
  301|       |
  302|    207|    should_copy = calloc(1, max_len);
  303|    207|    if (should_copy == NULL) {
  ------------------
  |  Branch (303:9): [True: 0, False: 207]
  ------------------
  304|      0|        goto out;
  305|      0|    }
  306|       |
  307|    207|    if (strlen(tok->tokens[0]) > 0) {
  ------------------
  |  Branch (307:9): [True: 183, False: 24]
  ------------------
  308|    183|        should_copy[0] = true;
  309|    183|    }
  310|       |
  311|  14.7k|    for (i = 1; tok->tokens[i]; i++) {
  ------------------
  |  Branch (311:17): [True: 14.5k, False: 207]
  ------------------
  312|   337k|        for (j = 0; j < i; j++) {
  ------------------
  |  Branch (312:21): [True: 333k, False: 4.17k]
  ------------------
  313|   333k|            if (strcmp(tok->tokens[i], tok->tokens[j]) == 0) {
  ------------------
  |  Branch (313:17): [True: 10.3k, False: 323k]
  ------------------
  314|       |                /* Found a duplicate; do not copy */
  315|  10.3k|                should_copy[i] = false;
  316|  10.3k|                break;
  317|  10.3k|            }
  318|   333k|        }
  319|       |
  320|       |        /* No matching token before */
  321|  14.5k|        if (j == i) {
  ------------------
  |  Branch (321:13): [True: 4.17k, False: 10.3k]
  ------------------
  322|       |            /* Only copy if it is not an empty string */
  323|  4.17k|            if (strlen(tok->tokens[i]) > 0) {
  ------------------
  |  Branch (323:17): [True: 4.04k, False: 133]
  ------------------
  324|  4.04k|                should_copy[i] = true;
  325|  4.04k|            } else {
  326|    133|                should_copy[i] = false;
  327|    133|            }
  328|  4.17k|        }
  329|  14.5k|    }
  330|       |
  331|    207|    num_tokens = i;
  332|       |
  333|    207|    ret = calloc(1, max_len);
  334|    207|    if (ret == NULL) {
  ------------------
  |  Branch (334:9): [True: 0, False: 207]
  ------------------
  335|      0|        goto out;
  336|      0|    }
  337|       |
  338|  14.9k|    for (i = 0; i < num_tokens; i++) {
  ------------------
  |  Branch (338:17): [True: 14.7k, False: 207]
  ------------------
  339|  14.7k|        if (should_copy[i]) {
  ------------------
  |  Branch (339:13): [True: 4.22k, False: 10.5k]
  ------------------
  340|  4.22k|            if (need_comma) {
  ------------------
  |  Branch (340:17): [True: 4.02k, False: 207]
  ------------------
  341|  4.02k|                strlcat(ret, ",", max_len);
  342|  4.02k|            }
  343|  4.22k|            strlcat(ret, tok->tokens[i], max_len);
  344|  4.22k|            need_comma = true;
  345|  4.22k|        }
  346|  14.7k|    }
  347|       |
  348|       |    /* If no comma is needed, nothing was copied */
  349|    207|    if (!need_comma) {
  ------------------
  |  Branch (349:9): [True: 0, False: 207]
  ------------------
  350|      0|        SAFE_FREE(ret);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  351|      0|    }
  352|       |
  353|    207|out:
  354|       |    SAFE_FREE(should_copy);
  ------------------
  |  |  375|    207|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 207, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 207]
  |  |  ------------------
  ------------------
  355|    207|    ssh_tokens_free(tok);
  356|    207|    return ret;
  357|    207|}
ssh_append_without_duplicates:
  376|     90|{
  377|     90|    size_t concat_len = 0;
  378|     90|    char *ret = NULL, *concat = NULL;
  379|     90|    int rc = 0;
  380|       |
  381|     90|    if (list != NULL) {
  ------------------
  |  Branch (381:9): [True: 90, False: 0]
  ------------------
  382|     90|        concat_len = strlen(list);
  383|     90|    }
  384|       |
  385|     90|    if (appended_list != NULL) {
  ------------------
  |  Branch (385:9): [True: 90, False: 0]
  ------------------
  386|     90|        concat_len += strlen(appended_list);
  387|     90|    }
  388|       |
  389|     90|    if (concat_len == 0) {
  ------------------
  |  Branch (389:9): [True: 0, False: 90]
  ------------------
  390|      0|        return NULL;
  391|      0|    }
  392|       |
  393|       |    /* Add room for ending '\0' and for middle ',' */
  394|     90|    concat_len += 2;
  395|     90|    concat = calloc(1, concat_len);
  396|     90|    if (concat == NULL) {
  ------------------
  |  Branch (396:9): [True: 0, False: 90]
  ------------------
  397|      0|        return NULL;
  398|      0|    }
  399|       |
  400|     90|    rc = snprintf(concat, concat_len, "%s%s%s",
  401|     90|                  list == NULL ? "" : list,
  ------------------
  |  Branch (401:19): [True: 0, False: 90]
  ------------------
  402|     90|                  list == NULL ? "" : ",",
  ------------------
  |  Branch (402:19): [True: 0, False: 90]
  ------------------
  403|     90|                  appended_list == NULL ? "" : appended_list);
  ------------------
  |  Branch (403:19): [True: 0, False: 90]
  ------------------
  404|     90|    if (rc < 0) {
  ------------------
  |  Branch (404:9): [True: 0, False: 90]
  ------------------
  405|      0|        SAFE_FREE(concat);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  406|      0|        return NULL;
  407|      0|    }
  408|       |
  409|     90|    ret = ssh_remove_duplicates(concat);
  410|       |
  411|     90|    SAFE_FREE(concat);
  ------------------
  |  |  375|     90|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 90, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 90]
  |  |  ------------------
  ------------------
  412|       |
  413|     90|    return ret;
  414|     90|}
ssh_remove_all_matching:
  431|     64|{
  432|     64|    struct ssh_tokens_st *l_tok = NULL, *r_tok = NULL;
  433|     64|    int i, j, cmp;
  434|     64|    char *ret = NULL;
  435|     64|    size_t len, pos = 0;
  436|     64|    bool exclude;
  437|       |
  438|     64|    if (list == NULL) {
  ------------------
  |  Branch (438:9): [True: 0, False: 64]
  ------------------
  439|      0|        return NULL;
  440|      0|    }
  441|     64|    if (remove_list == NULL) {
  ------------------
  |  Branch (441:9): [True: 0, False: 64]
  ------------------
  442|      0|        return strdup (list);
  443|      0|    }
  444|       |
  445|     64|    l_tok = ssh_tokenize(list, ',');
  446|     64|    if (l_tok == NULL) {
  ------------------
  |  Branch (446:9): [True: 0, False: 64]
  ------------------
  447|      0|        goto out;
  448|      0|    }
  449|       |
  450|     64|    r_tok = ssh_tokenize(remove_list, ',');
  451|     64|    if (r_tok == NULL) {
  ------------------
  |  Branch (451:9): [True: 0, False: 64]
  ------------------
  452|      0|        goto out;
  453|      0|    }
  454|       |
  455|     64|    ret = calloc(1, strlen(list) + 1);
  456|     64|    if (ret == NULL) {
  ------------------
  |  Branch (456:9): [True: 0, False: 64]
  ------------------
  457|      0|        goto out;
  458|      0|    }
  459|       |
  460|    462|    for (i = 0; l_tok->tokens[i]; i++) {
  ------------------
  |  Branch (460:17): [True: 398, False: 64]
  ------------------
  461|    398|        exclude = false;
  462|  2.91k|        for (j = 0; r_tok->tokens[j]; j++) {
  ------------------
  |  Branch (462:21): [True: 2.54k, False: 372]
  ------------------
  463|  2.54k|            cmp = strcmp(l_tok->tokens[i], r_tok->tokens[j]);
  464|  2.54k|            if (cmp == 0) {
  ------------------
  |  Branch (464:17): [True: 26, False: 2.51k]
  ------------------
  465|     26|                exclude = true;
  466|     26|                break;
  467|     26|            }
  468|  2.54k|        }
  469|    398|        if (exclude == false) {
  ------------------
  |  Branch (469:13): [True: 372, False: 26]
  ------------------
  470|    372|            if (pos != 0) {
  ------------------
  |  Branch (470:17): [True: 308, False: 64]
  ------------------
  471|    308|                ret[pos] = ',';
  472|    308|                pos++;
  473|    308|            }
  474|       |
  475|    372|            len = strlen(l_tok->tokens[i]);
  476|    372|            memcpy(&ret[pos], l_tok->tokens[i], len);
  477|    372|            pos += len;
  478|    372|        }
  479|    398|    }
  480|       |
  481|     64|    if (ret[0] == '\0') {
  ------------------
  |  Branch (481:9): [True: 0, False: 64]
  ------------------
  482|      0|        SAFE_FREE(ret);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  483|      0|    }
  484|       |
  485|     64|out:
  486|     64|    ssh_tokens_free(l_tok);
  487|     64|    ssh_tokens_free(r_tok);
  488|     64|    return ret;
  489|     64|}
ssh_prefix_without_duplicates:
  507|    117|{
  508|    117|    size_t concat_len = 0;
  509|    117|    char *ret = NULL, *concat = NULL;
  510|    117|    int rc = 0;
  511|       |
  512|    117|    if (list != NULL) {
  ------------------
  |  Branch (512:9): [True: 117, False: 0]
  ------------------
  513|    117|        concat_len = strlen(list);
  514|    117|    }
  515|       |
  516|    117|    if (prefixed_list != NULL) {
  ------------------
  |  Branch (516:9): [True: 117, False: 0]
  ------------------
  517|    117|        concat_len += strlen(prefixed_list);
  518|    117|    }
  519|       |
  520|    117|    if (concat_len == 0) {
  ------------------
  |  Branch (520:9): [True: 0, False: 117]
  ------------------
  521|      0|        return NULL;
  522|      0|    }
  523|       |
  524|       |    /* Add room for ending '\0' and for middle ',' */
  525|    117|    concat_len += 2;
  526|    117|    concat = calloc(concat_len, 1);
  527|    117|    if (concat == NULL) {
  ------------------
  |  Branch (527:9): [True: 0, False: 117]
  ------------------
  528|      0|        return NULL;
  529|      0|    }
  530|       |
  531|    117|    rc = snprintf(concat, concat_len, "%s%s%s",
  532|    117|                  prefixed_list == NULL ? "" : prefixed_list,
  ------------------
  |  Branch (532:19): [True: 0, False: 117]
  ------------------
  533|    117|                  prefixed_list == NULL ? "" : ",",
  ------------------
  |  Branch (533:19): [True: 0, False: 117]
  ------------------
  534|    117|                  list == NULL ? "" : list);
  ------------------
  |  Branch (534:19): [True: 0, False: 117]
  ------------------
  535|    117|    if (rc < 0) {
  ------------------
  |  Branch (535:9): [True: 0, False: 117]
  ------------------
  536|      0|        SAFE_FREE(concat);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  537|      0|        return NULL;
  538|      0|    }
  539|       |
  540|    117|    ret = ssh_remove_duplicates(concat);
  541|       |
  542|    117|    SAFE_FREE(concat);
  ------------------
  |  |  375|    117|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 117, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 117]
  |  |  ------------------
  ------------------
  543|       |
  544|    117|    return ret;
  545|    117|}

nalloc_init:
  114|      2|{
  115|      2|    if (nalloc_initialized) {
  ------------------
  |  Branch (115:9): [True: 0, False: 2]
  ------------------
  116|      0|        return;
  117|      0|    }
  118|      2|    nalloc_initialized = true;
  119|      2|    char *bitmask = getenv("NALLOC_FREQ");
  120|      2|    if (bitmask) {
  ------------------
  |  Branch (120:9): [True: 0, False: 2]
  ------------------
  121|      0|        int shift = atoi(bitmask);
  122|      0|        if (shift > 0 && shift < 31) {
  ------------------
  |  Branch (122:13): [True: 0, False: 0]
  |  Branch (122:26): [True: 0, False: 0]
  ------------------
  123|      0|            nalloc_bitmask = 1 << shift;
  124|      0|            nalloc_random_bitmask = false;
  125|      0|        } else if (shift == 0) {
  ------------------
  |  Branch (125:20): [True: 0, False: 0]
  ------------------
  126|      0|            nalloc_random_bitmask = false;
  127|      0|            nalloc_bitmask = 0;
  128|      0|        }
  129|      2|    } else if (prog == NULL || strstr(prog, "nalloc") == NULL) {
  ------------------
  |  Branch (129:16): [True: 0, False: 2]
  |  Branch (129:32): [True: 2, False: 0]
  ------------------
  130|      2|        nalloc_random_bitmask = false;
  131|      2|        nalloc_bitmask = 0;
  132|      2|        return;
  133|      2|    }
  134|       |
  135|      0|    char *verbose = getenv("NALLOC_VERBOSE");
  136|      0|    if (verbose) {
  ------------------
  |  Branch (136:9): [True: 0, False: 0]
  ------------------
  137|       |        nalloc_verbose = true;
  138|      0|    }
  139|      0|}
calloc:
  307|  2.77k|{
  308|  2.77k|    if (nalloc_fail(size, "calloc")) {
  ------------------
  |  Branch (308:9): [True: 0, False: 2.77k]
  ------------------
  309|      0|        errno = ENOMEM;
  310|      0|        return NULL;
  311|      0|    }
  312|  2.77k|    return nalloc_calloc(nmemb, size);
  ------------------
  |  |  259|  2.77k|#define nalloc_calloc(s, n)          __libc_calloc(s, n)
  ------------------
  313|  2.77k|}
malloc:
  316|  1.72M|{
  317|  1.72M|    if (nalloc_fail(size, "malloc")) {
  ------------------
  |  Branch (317:9): [True: 0, False: 1.72M]
  ------------------
  318|      0|        errno = ENOMEM;
  319|      0|        return NULL;
  320|      0|    }
  321|  1.72M|    return nalloc_malloc(size);
  ------------------
  |  |  258|  1.72M|#define nalloc_malloc(s)             __libc_malloc(s)
  ------------------
  322|  1.72M|}
realloc:
  325|  38.5k|{
  326|  38.5k|    if (nalloc_fail(size, "realloc")) {
  ------------------
  |  Branch (326:9): [True: 0, False: 38.5k]
  ------------------
  327|      0|        errno = ENOMEM;
  328|      0|        return NULL;
  329|      0|    }
  330|  38.5k|    return nalloc_realloc(ptr, size);
  ------------------
  |  |  260|  38.5k|#define nalloc_realloc(p, s)         __libc_realloc(p, s)
  ------------------
  331|  38.5k|}
ssh_bind_config_fuzzer.c:nalloc_fail:
  194|  1.76M|{
  195|       |    // do not fail before thread init
  196|  1.76M|    if (nalloc_runs == 0) {
  ------------------
  |  Branch (196:9): [True: 1.76M, False: 0]
  ------------------
  197|  1.76M|        return false;
  198|  1.76M|    }
  199|      0|    if (__sync_fetch_and_add(&nalloc_running, 1) != 1) {
  ------------------
  |  Branch (199:9): [True: 0, False: 0]
  ------------------
  200|       |        // do not fail allocations outside of fuzzer input
  201|       |        // and do not fail inside of this function
  202|      0|        __sync_fetch_and_sub(&nalloc_running, 1);
  203|      0|        return false;
  204|      0|    }
  205|      0|    nalloc_random_update((uint8_t)size);
  206|      0|    if (size >= 0x100) {
  ------------------
  |  Branch (206:9): [True: 0, False: 0]
  ------------------
  207|      0|        nalloc_random_update((uint8_t)(size >> 8));
  208|      0|        if (size >= 0x10000) {
  ------------------
  |  Branch (208:13): [True: 0, False: 0]
  ------------------
  209|      0|            nalloc_random_update((uint8_t)(size >> 16));
  210|       |            // bigger may already fail or oom
  211|      0|        }
  212|      0|    }
  213|      0|    if (((nalloc_random_state ^ nalloc_magic) & nalloc_bitmask) == 0) {
  ------------------
  |  Branch (213:9): [True: 0, False: 0]
  ------------------
  214|      0|        if (nalloc_backtrace_exclude(size, op)) {
  ------------------
  |  Branch (214:13): [True: 0, False: 0]
  ------------------
  215|      0|            __sync_fetch_and_sub(&nalloc_running, 1);
  216|      0|            return false;
  217|      0|        }
  218|      0|        __sync_fetch_and_sub(&nalloc_running, 1);
  219|      0|        return true;
  220|      0|    }
  221|      0|    __sync_fetch_and_sub(&nalloc_running, 1);
  222|       |    return false;
  223|      0|}
ssh_bind_config_fuzzer.c:nalloc_start:
  151|    269|{
  152|    269|    if (nalloc_random_bitmask) {
  ------------------
  |  Branch (152:9): [True: 0, False: 269]
  ------------------
  153|      0|        if (nalloc_random_state & 0x10) {
  ------------------
  |  Branch (153:13): [True: 0, False: 0]
  ------------------
  154|      0|            nalloc_bitmask = 0xFFFFFFFF;
  155|      0|        } else {
  156|      0|            nalloc_bitmask = 1 << (5 + (nalloc_random_state & 0xF));
  157|      0|        }
  158|    269|    } else if (nalloc_bitmask == 0) {
  ------------------
  |  Branch (158:16): [True: 269, False: 0]
  ------------------
  159|       |        // nalloc disabled
  160|    269|        return 2;
  161|    269|    }
  162|      0|    nalloc_random_state = 0;
  163|      0|    for (size_t i = 0; i < size; i++) {
  ------------------
  |  Branch (163:24): [True: 0, False: 0]
  ------------------
  164|      0|        nalloc_random_update(data[i]);
  165|      0|    }
  166|      0|    if (__sync_fetch_and_add(&nalloc_running, 1)) {
  ------------------
  |  Branch (166:9): [True: 0, False: 0]
  ------------------
  167|      0|        __sync_fetch_and_sub(&nalloc_running, 1);
  168|      0|        return 0;
  169|      0|    }
  170|      0|    nalloc_runs++;
  171|      0|    return 1;
  172|      0|}
ssh_bind_config_fuzzer.c:nalloc_end:
  176|    269|{
  177|    269|    __sync_fetch_and_sub(&nalloc_running, 1);
  178|    269|}

LLVMFuzzerInitialize:
   35|      2|{
   36|      2|    (void)argc;
   37|       |
   38|      2|    nalloc_init(*argv[0]);
   39|       |
   40|      2|    ssh_init();
   41|       |
   42|      2|    atexit(_fuzz_finalize);
   43|       |
   44|      2|    return 0;
   45|      2|}
LLVMFuzzerTestOneInput:
   48|    269|{
   49|    269|    ssh_bind bind = NULL;
   50|    269|    char *input = NULL;
   51|    269|    const char *env = NULL;
   52|       |
   53|    269|    input = (char *)malloc(size + 1);
   54|    269|    if (!input) {
  ------------------
  |  Branch (54:9): [True: 0, False: 269]
  ------------------
   55|      0|        return 1;
   56|      0|    }
   57|    269|    memcpy(input, data, size);
   58|    269|    input[size] = '\0';
   59|       |
   60|    269|    assert(nalloc_start(data, size) > 0);
  ------------------
  |  Branch (60:5): [True: 0, False: 269]
  |  Branch (60:5): [True: 269, False: 0]
  ------------------
   61|       |
   62|    269|    bind = ssh_bind_new();
   63|    269|    if (bind == NULL) {
  ------------------
  |  Branch (63:9): [True: 0, False: 269]
  ------------------
   64|      0|        goto out;
   65|      0|    }
   66|       |
   67|    269|    env = getenv("LIBSSH_VERBOSITY");
   68|    269|    if (env != NULL && strlen(env) > 0) {
  ------------------
  |  Branch (68:9): [True: 0, False: 269]
  |  Branch (68:24): [True: 0, False: 0]
  ------------------
   69|      0|        ssh_bind_options_set(bind, SSH_BIND_OPTIONS_LOG_VERBOSITY_STR, env);
   70|      0|    }
   71|    269|    ssh_bind_config_parse_string(bind, input);
   72|       |
   73|    269|    ssh_bind_free(bind);
   74|       |
   75|    269|out:
   76|    269|    free(input);
   77|       |
   78|    269|    nalloc_end();
   79|    269|    return 0;
   80|    269|}
ssh_bind_config_fuzzer.c:_fuzz_finalize:
   30|      2|{
   31|      2|    ssh_finalize();
   32|      2|}

