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

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

ssh_config_get_token_info:
   69|  1.63M|{
   70|  1.63M|    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.63M|    char *dst = NULL;
   76|  1.63M|    bool had_equal = false;
   77|  1.63M|    bool found = false;
   78|  1.63M|    bool invalid = false;
   79|  1.63M|    char *r = NULL;
   80|  1.63M|    char inquote = '\0';
   81|       |
   82|  1.63M|    if (info != NULL) {
  ------------------
  |  Branch (82:9): [True: 0, False: 1.63M]
  ------------------
   83|      0|        info->found = false;
   84|      0|        info->had_equal = false;
   85|      0|        info->invalid = false;
   86|      0|    }
   87|       |
   88|       |    /* Ignore leading spaces */
   89|  3.35M|    for (c = *str; *c; c++) {
  ------------------
  |  Branch (89:20): [True: 3.21M, False: 141k]
  ------------------
   90|  3.21M|        if (!isspace((unsigned char)*c)) {
  ------------------
  |  Branch (90:13): [True: 1.49M, False: 1.72M]
  ------------------
   91|  1.49M|            break;
   92|  1.49M|        }
   93|  3.21M|    }
   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.63M|    if (*c == '\0') {
  ------------------
  |  Branch (99:9): [True: 141k, False: 1.49M]
  ------------------
  100|   141k|        r = c;
  101|   141k|        goto out;
  102|   141k|    }
  103|  1.49M|    if (*c == '\n') {
  ------------------
  |  Branch (103:9): [True: 0, False: 1.49M]
  ------------------
  104|      0|        r = c;
  105|      0|        *c = '\0';
  106|      0|        c++;
  107|      0|        goto out;
  108|      0|    }
  109|       |
  110|  1.49M|    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.49M|    r = dst = c;
  117|  22.5M|    for (; *c; c++) {
  ------------------
  |  Branch (117:12): [True: 21.7M, False: 815k]
  ------------------
  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|  21.7M|        if (*c == '\\' &&
  ------------------
  |  Branch (123:13): [True: 29.6k, False: 21.6M]
  ------------------
  124|  29.6k|            (c[1] == '\\' || c[1] == '\'' || c[1] == '\"' ||
  ------------------
  |  Branch (124:14): [True: 1.28k, False: 28.3k]
  |  Branch (124:30): [True: 395, False: 27.9k]
  |  Branch (124:46): [True: 1.04k, False: 26.8k]
  ------------------
  125|  29.6k|             isspace((unsigned char)c[1]))) {
  ------------------
  |  Branch (125:14): [True: 150, False: 26.7k]
  ------------------
  126|  2.87k|            c++;
  127|  2.87k|            *dst++ = *c;
  128|  21.7M|        } else if (*c == '\n' || (!inquote && (isspace((unsigned char)*c) || *c == '='))) {
  ------------------
  |  Branch (128:20): [True: 0, False: 21.7M]
  |  Branch (128:35): [True: 20.4M, False: 1.28M]
  |  Branch (128:48): [True: 656k, False: 19.7M]
  |  Branch (128:78): [True: 24.9k, False: 19.7M]
  ------------------
  129|   681k|            had_equal = (*c == '=');
  130|   681k|            *dst = '\0';
  131|   681k|            c++;
  132|   681k|            break;
  133|  21.0M|        } else if (inquote) {
  ------------------
  |  Branch (133:20): [True: 1.28M, False: 19.7M]
  ------------------
  134|  1.28M|            if (*c == inquote) {
  ------------------
  |  Branch (134:17): [True: 33.0k, False: 1.25M]
  ------------------
  135|  33.0k|                inquote = '\0';
  136|  1.25M|            } else {
  137|  1.25M|                *dst++ = *c;
  138|  1.25M|            }
  139|  19.7M|        } else if (*c == '\'' || *c == '\"') {
  ------------------
  |  Branch (139:20): [True: 22.3k, False: 19.7M]
  |  Branch (139:34): [True: 40.5k, False: 19.6M]
  ------------------
  140|  62.9k|            inquote = *c;
  141|  19.6M|        } else {
  142|  19.6M|            *dst++ = *c;
  143|  19.6M|        }
  144|  21.7M|    }
  145|  1.49M|    if (inquote) {
  ------------------
  |  Branch (145:9): [True: 29.9k, False: 1.46M]
  ------------------
  146|  29.9k|        invalid = true;
  147|  29.9k|    }
  148|  1.49M|    if (*c == '\0') {
  ------------------
  |  Branch (148:9): [True: 819k, False: 677k]
  ------------------
  149|   819k|        *dst = '\0';
  150|   819k|    }
  151|       |
  152|       |    /* Skip any other remaining whitespace */
  153|  1.60M|    while (isspace((unsigned char)*c) || *c == '\n' ||
  ------------------
  |  Branch (153:12): [True: 78.9k, False: 1.52M]
  |  Branch (153:42): [True: 0, False: 1.52M]
  ------------------
  154|  1.52M|           (!had_equal && *c == '=')) {
  ------------------
  |  Branch (154:13): [True: 1.47M, False: 54.7k]
  |  Branch (154:27): [True: 29.8k, False: 1.44M]
  ------------------
  155|   108k|        if (*c == '=') {
  ------------------
  |  Branch (155:13): [True: 29.8k, False: 78.9k]
  ------------------
  156|  29.8k|            had_equal = true;
  157|  29.8k|        }
  158|   108k|        c++;
  159|   108k|    }
  160|  1.63M|out:
  161|  1.63M|    *str = c;
  162|  1.63M|    if (info != NULL) {
  ------------------
  |  Branch (162:9): [True: 0, False: 1.63M]
  ------------------
  163|      0|        info->found = found;
  164|      0|        info->had_equal = had_equal;
  165|      0|        info->invalid = invalid;
  166|      0|    }
  167|  1.63M|    return r;
  168|  1.49M|}
ssh_config_get_token:
  171|  1.63M|{
  172|       |    return ssh_config_get_token_info(str, NULL);
  173|  1.63M|}
ssh_config_get_long:
  176|  7.84k|{
  177|  7.84k|    char *p = NULL, *endp = NULL;
  178|  7.84k|    long i;
  179|       |
  180|  7.84k|    p = ssh_config_get_token(str);
  181|  7.84k|    if (p && *p) {
  ------------------
  |  Branch (181:9): [True: 7.84k, False: 0]
  |  Branch (181:14): [True: 7.80k, False: 42]
  ------------------
  182|  7.80k|        i = strtol(p, &endp, 10);
  183|  7.80k|        if (p == endp || *endp != '\0') {
  ------------------
  |  Branch (183:13): [True: 4.92k, False: 2.87k]
  |  Branch (183:26): [True: 982, False: 1.89k]
  ------------------
  184|  5.90k|            return notfound;
  185|  5.90k|        }
  186|  1.89k|        return i;
  187|  7.80k|    }
  188|       |
  189|     42|    return notfound;
  190|  7.84k|}
ssh_config_get_str_tok:
  193|  11.8k|{
  194|  11.8k|    char *p = NULL;
  195|       |
  196|  11.8k|    p = ssh_config_get_token(str);
  197|  11.8k|    if (p && *p) {
  ------------------
  |  Branch (197:9): [True: 11.8k, False: 0]
  |  Branch (197:14): [True: 6.18k, False: 5.61k]
  ------------------
  198|  6.18k|        return p;
  199|  6.18k|    }
  200|       |
  201|  5.61k|    return def;
  202|  11.8k|}

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|     52|{
   56|     52|    struct ssh_common_struct *err = error;
   57|     52|    va_list va;
   58|       |
   59|     52|    va_start(va, descr);
   60|     52|    vsnprintf(err->error.error_buffer, ERROR_BUFFERLEN, descr, va);
  ------------------
  |  |  219|     52|#define ERROR_BUFFERLEN 1024
  ------------------
   61|     52|    va_end(va);
   62|       |
   63|     52|    err->error.error_code = code;
   64|     52|    if (ssh_get_log_level() == SSH_LOG_TRACE) {
  ------------------
  |  |  362|     52|#define SSH_LOG_TRACE 4
  ------------------
  |  Branch (64:9): [True: 0, False: 52]
  ------------------
   65|      0|        ssh_log_function(SSH_LOG_TRACE,
  ------------------
  |  |  362|      0|#define SSH_LOG_TRACE 4
  ------------------
   66|      0|                         function,
   67|      0|                         err->error.error_buffer);
   68|      0|    }
   69|     52|}
_ssh_set_error_oom:
   81|     20|{
   82|     20|    struct error_struct *err = error;
   83|       |
   84|     20|    snprintf(err->error_buffer, sizeof(err->error_buffer),
   85|     20|            "%s: Out of memory", function);
   86|     20|    err->error_code = SSH_FATAL;
   87|     20|}

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_add_to_default_algos:
 1368|      6|{
 1369|      6|    char *tmp = NULL, *ret = NULL;
 1370|       |
 1371|      6|    if (algo > SSH_LANG_S_C || list == NULL || list[0] == '\0') {
  ------------------
  |  Branch (1371:9): [True: 0, False: 6]
  |  Branch (1371:32): [True: 0, False: 6]
  |  Branch (1371:48): [True: 0, False: 6]
  ------------------
 1372|      0|        return NULL;
 1373|      0|    }
 1374|       |
 1375|      6|    if (ssh_fips_mode()) {
  ------------------
  |  |  117|      6|#define ssh_fips_mode() EVP_default_properties_is_fips_enabled(NULL)
  |  |  ------------------
  |  |  |  Branch (117:25): [True: 0, False: 6]
  |  |  ------------------
  ------------------
 1376|      0|        tmp = ssh_append_without_duplicates(fips_methods[algo], list);
 1377|      0|        ret = ssh_find_all_matching(fips_methods[algo], tmp);
 1378|      6|    } else {
 1379|      6|        tmp = ssh_append_without_duplicates(default_methods[algo], list);
 1380|      6|        ret = ssh_find_all_matching(supported_methods[algo], tmp);
 1381|      6|    }
 1382|       |
 1383|      6|    free(tmp);
 1384|      6|    return ret;
 1385|      6|}
ssh_remove_from_default_algos:
 1401|     14|{
 1402|     14|    if (algo > SSH_LANG_S_C) {
  ------------------
  |  Branch (1402:9): [True: 0, False: 14]
  ------------------
 1403|      0|        return NULL;
 1404|      0|    }
 1405|       |
 1406|     14|    if (list == NULL || list[0] == '\0') {
  ------------------
  |  Branch (1406:9): [True: 0, False: 14]
  |  Branch (1406:25): [True: 14, False: 0]
  ------------------
 1407|     14|        if (ssh_fips_mode()) {
  ------------------
  |  |  117|     14|#define ssh_fips_mode() EVP_default_properties_is_fips_enabled(NULL)
  |  |  ------------------
  |  |  |  Branch (117:25): [True: 0, False: 14]
  |  |  ------------------
  ------------------
 1408|      0|            return strdup(fips_methods[algo]);
 1409|     14|        } else {
 1410|     14|            return strdup(default_methods[algo]);
 1411|     14|        }
 1412|     14|    }
 1413|       |
 1414|      0|    if (ssh_fips_mode()) {
  ------------------
  |  |  117|      0|#define ssh_fips_mode() EVP_default_properties_is_fips_enabled(NULL)
  |  |  ------------------
  |  |  |  Branch (117:25): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1415|      0|        return ssh_remove_all_matching(fips_methods[algo], list);
 1416|      0|    } else {
 1417|      0|        return ssh_remove_all_matching(default_methods[algo], list);
 1418|      0|    }
 1419|      0|}
ssh_prefix_default_algos:
 1439|      8|{
 1440|      8|    char *ret = NULL, *tmp = NULL;
 1441|       |
 1442|      8|    if (algo > SSH_LANG_S_C || list == NULL || list[0] == '\0') {
  ------------------
  |  Branch (1442:9): [True: 0, False: 8]
  |  Branch (1442:32): [True: 0, False: 8]
  |  Branch (1442:48): [True: 0, False: 8]
  ------------------
 1443|      0|        return NULL;
 1444|      0|    }
 1445|       |
 1446|      8|    if (ssh_fips_mode()) {
  ------------------
  |  |  117|      8|#define ssh_fips_mode() EVP_default_properties_is_fips_enabled(NULL)
  |  |  ------------------
  |  |  |  Branch (117:25): [True: 0, False: 8]
  |  |  ------------------
  ------------------
 1447|      0|        tmp = ssh_prefix_without_duplicates(fips_methods[algo], list);
 1448|      0|        ret = ssh_find_all_matching(fips_methods[algo], tmp);
 1449|      8|    } else {
 1450|      8|        tmp = ssh_prefix_without_duplicates(default_methods[algo], list);
 1451|      8|        ret = ssh_find_all_matching(supported_methods[algo], tmp);
 1452|      8|    }
 1453|       |
 1454|      8|    free(tmp);
 1455|      8|    return ret;
 1456|      8|}

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

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

ssh_strerror:
 2428|  1.41k|{
 2429|       |#if ((defined(__linux__) && defined(__GLIBC__)) || defined(__CYGWIN__)) && defined(_GNU_SOURCE)
 2430|       |    /* GNU extension on Linux */
 2431|       |    return strerror_r(err_num, buf, buflen);
 2432|       |#else
 2433|  1.41k|    int rv;
 2434|       |
 2435|       |#if defined(_WIN32)
 2436|       |    rv = strerror_s(buf, buflen, err_num);
 2437|       |#else
 2438|       |    /* POSIX version available for example on FreeBSD or in musl libc */
 2439|  1.41k|    rv = strerror_r(err_num, buf, buflen);
 2440|  1.41k|#endif /* _WIN32 */
 2441|       |
 2442|       |    /* make sure the buffer is initialized and terminated with NULL */
 2443|  1.41k|    if (-rv == ERANGE) {
  ------------------
  |  Branch (2443:9): [True: 0, False: 1.41k]
  ------------------
 2444|      0|        buf[0] = '\0';
 2445|      0|    }
 2446|  1.41k|    return buf;
 2447|  1.41k|#endif /* ((defined(__linux__) && defined(__GLIBC__)) || defined(__CYGWIN__)) && defined(_GNU_SOURCE) */
 2448|  1.41k|}
ssh_strict_fopen:
 2729|  3.65k|{
 2730|  3.65k|    FILE *f = NULL;
 2731|  3.65k|    struct stat sb;
 2732|  3.65k|    int r, fd;
 2733|       |
 2734|       |    /* open first to avoid TOCTOU */
 2735|  3.65k|    fd = open(filename, O_RDONLY);
 2736|  3.65k|    if (fd == -1) {
  ------------------
  |  Branch (2736:9): [True: 1.41k, False: 2.23k]
  ------------------
 2737|  1.41k|        SSH_LOG_STRERROR(SSH_LOG_TRACE,
  ------------------
  |  |  285|  1.41k|    do {                                                            \
  |  |  286|  1.41k|        char err_msg[SSH_ERRNO_MSG_MAX] = {0};                      \
  |  |  287|  1.41k|        _ssh_log(priority,                                          \
  |  |  288|  1.41k|                 __func__,                                          \
  |  |  289|  1.41k|                 __VA_ARGS__,                                       \
  |  |  290|  1.41k|                 ssh_strerror(errnum, err_msg, SSH_ERRNO_MSG_MAX)); \
  |  |  ------------------
  |  |  |  |  522|  1.41k|#define SSH_ERRNO_MSG_MAX   1024
  |  |  ------------------
  |  |  291|  1.41k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (291:14): [Folded, False: 1.41k]
  |  |  ------------------
  ------------------
 2738|  1.41k|                         errno,
 2739|  1.41k|                         "Failed to open a file %s for reading: %s",
 2740|  1.41k|                         filename);
 2741|  1.41k|        return NULL;
 2742|  1.41k|    }
 2743|       |
 2744|       |    /* Check the file is sensible for a configuration file */
 2745|  2.23k|    r = fstat(fd, &sb);
 2746|  2.23k|    if (r != 0) {
  ------------------
  |  Branch (2746:9): [True: 0, False: 2.23k]
  ------------------
 2747|      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]
  |  |  ------------------
  ------------------
 2748|      0|                         errno,
 2749|      0|                         "Failed to stat %s: %s",
 2750|      0|                         filename);
 2751|      0|        close(fd);
 2752|      0|        return NULL;
 2753|      0|    }
 2754|  2.23k|    if ((sb.st_mode & S_IFMT) != S_IFREG) {
  ------------------
  |  Branch (2754:9): [True: 923, False: 1.31k]
  ------------------
 2755|    923|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|    923|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2756|    923|                "The file %s is not a regular file: skipping",
 2757|    923|                filename);
 2758|    923|        close(fd);
 2759|    923|        return NULL;
 2760|    923|    }
 2761|       |
 2762|  1.31k|    if ((size_t)sb.st_size > max_file_size) {
  ------------------
  |  Branch (2762:9): [True: 86, False: 1.22k]
  ------------------
 2763|     86|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|     86|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2764|     86|                "The file %s is too large (%jd MB > %zu MB): skipping",
 2765|     86|                filename,
 2766|     86|                (intmax_t)sb.st_size / 1024 / 1024,
 2767|     86|                max_file_size / 1024 / 1024);
 2768|     86|        close(fd);
 2769|     86|        return NULL;
 2770|     86|    }
 2771|       |
 2772|  1.22k|    f = fdopen(fd, "r");
 2773|  1.22k|    if (f == NULL) {
  ------------------
  |  Branch (2773:9): [True: 0, False: 1.22k]
  ------------------
 2774|      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]
  |  |  ------------------
  ------------------
 2775|      0|                         errno,
 2776|      0|                         "Failed to open a file %s for reading: %s",
 2777|      0|                         filename);
 2778|      0|        close(fd);
 2779|      0|        return NULL;
 2780|      0|    }
 2781|       |
 2782|       |    /* the flcose() will close also the underlying fd */
 2783|  1.22k|    return f;
 2784|  1.22k|}

ssh_options_set_algo:
  470|     28|{
  471|       |    /* When the list start with +,-,^ the filtration of unknown algorithms
  472|       |     * gets handled inside the helper functions, otherwise the list is taken
  473|       |     * as it is. */
  474|     28|    char *p = (char *)list;
  475|       |
  476|       |    /* Clear errno so ENOMEM means allocation failure (best-effort). */
  477|     28|    errno = 0;
  478|       |
  479|     28|    if (algo < SSH_COMP_C_S) {
  ------------------
  |  Branch (479:9): [True: 28, False: 0]
  ------------------
  480|     28|        if (list[0] == '+') {
  ------------------
  |  Branch (480:13): [True: 6, False: 22]
  ------------------
  481|      6|            p = ssh_add_to_default_algos(algo, list+1);
  482|     22|        } else if (list[0] == '-') {
  ------------------
  |  Branch (482:20): [True: 14, False: 8]
  ------------------
  483|     14|            p = ssh_remove_from_default_algos(algo, list+1);
  484|     14|        } else if (list[0] == '^') {
  ------------------
  |  Branch (484:20): [True: 8, False: 0]
  ------------------
  485|      8|            p = ssh_prefix_default_algos(algo, list+1);
  486|      8|        }
  487|     28|    }
  488|       |
  489|     28|    if (p == list) {
  ------------------
  |  Branch (489:9): [True: 0, False: 28]
  ------------------
  490|      0|        bool fips = ssh_fips_mode();
  ------------------
  |  |  117|      0|#define ssh_fips_mode() EVP_default_properties_is_fips_enabled(NULL)
  ------------------
  491|       |
  492|       |        /*
  493|       |         * ssh_fips_mode() can set errno itself (OpenSSL config probe).
  494|       |         * Clear it after the probe, before the allocating filter.
  495|       |         */
  496|      0|        errno = 0;
  497|       |
  498|      0|        if (fips) {
  ------------------
  |  Branch (498:13): [True: 0, False: 0]
  ------------------
  499|      0|            p = ssh_keep_fips_algos(algo, list);
  500|      0|        } else {
  501|      0|            p = ssh_keep_known_algos(algo, list);
  502|      0|        }
  503|      0|    }
  504|       |
  505|     28|    if (p == NULL) {
  ------------------
  |  Branch (505:9): [True: 0, False: 28]
  ------------------
  506|      0|        if (errno == ENOMEM) {
  ------------------
  |  Branch (506:13): [True: 0, False: 0]
  ------------------
  507|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  508|      0|            return -1;
  509|      0|        }
  510|       |
  511|      0|        ssh_set_error(session, SSH_REQUEST_DENIED,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  512|      0|                "Setting method: no allowed algorithm for method \"%s\" (%s)",
  513|      0|                ssh_kex_get_description(algo), list);
  514|      0|        return -1;
  515|      0|    }
  516|       |
  517|     28|    SAFE_FREE(*place);
  ------------------
  |  |  375|     28|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 11, False: 17]
  |  |  |  Branch (375:71): [Folded, False: 28]
  |  |  ------------------
  ------------------
  518|     28|    *place = p;
  519|       |
  520|     28|    return 0;
  521|     28|}
ssh_bind_options_set:
 3725|     37|{
 3726|     37|    bool allowed;
 3727|     37|    char *p = NULL, *q = NULL;
 3728|     37|    const char *v = NULL;
 3729|     37|    int i, rc;
 3730|     37|    char **wanted_methods = sshbind->wanted_methods;
 3731|       |
 3732|     37|    if (sshbind == NULL) {
  ------------------
  |  Branch (3732:9): [True: 0, False: 37]
  ------------------
 3733|      0|        return -1;
 3734|      0|    }
 3735|       |
 3736|     37|    switch (type) {
 3737|      0|    case SSH_BIND_OPTIONS_RSAKEY:
  ------------------
  |  Branch (3737:5): [True: 0, False: 37]
  ------------------
 3738|      0|    case SSH_BIND_OPTIONS_ECDSAKEY:
  ------------------
  |  Branch (3738:5): [True: 0, False: 37]
  ------------------
 3739|       |        /* deprecated */
 3740|      0|    case SSH_BIND_OPTIONS_HOSTKEY:
  ------------------
  |  Branch (3740:5): [True: 0, False: 37]
  ------------------
 3741|      0|    case SSH_BIND_OPTIONS_IMPORT_KEY:
  ------------------
  |  Branch (3741:5): [True: 0, False: 37]
  ------------------
 3742|      0|    case SSH_BIND_OPTIONS_IMPORT_KEY_STR:
  ------------------
  |  Branch (3742:5): [True: 0, False: 37]
  ------------------
 3743|      0|        if (value == NULL) {
  ------------------
  |  Branch (3743:13): [True: 0, False: 0]
  ------------------
 3744|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3745|      0|            return -1;
 3746|      0|        } else {
 3747|      0|            int key_type;
 3748|      0|            ssh_key *bind_key_loc = NULL;
 3749|      0|            ssh_key key = NULL;
 3750|      0|            char **bind_key_path_loc = NULL;
 3751|       |
 3752|      0|            if (type == SSH_BIND_OPTIONS_IMPORT_KEY_STR) {
  ------------------
  |  Branch (3752:17): [True: 0, False: 0]
  ------------------
 3753|      0|                const char *key_str = (const char *)value;
 3754|      0|                rc = ssh_pki_import_privkey_base64(key_str,
 3755|      0|                                                   NULL,
 3756|      0|                                                   NULL,
 3757|      0|                                                   NULL,
 3758|      0|                                                   &key);
 3759|      0|                if (rc == SSH_ERROR) {
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (3759:21): [True: 0, False: 0]
  ------------------
 3760|      0|                    ssh_set_error(sshbind,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 3761|      0|                                  SSH_FATAL,
 3762|      0|                                  "Failed to import key from buffer");
 3763|      0|                    return -1;
 3764|      0|                }
 3765|      0|            } else if (type == SSH_BIND_OPTIONS_IMPORT_KEY) {
  ------------------
  |  Branch (3765:24): [True: 0, False: 0]
  ------------------
 3766|      0|                key = (ssh_key)value;
 3767|      0|            } else {
 3768|      0|                rc = ssh_pki_import_privkey_file(value, NULL, NULL, NULL, &key);
 3769|      0|                if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (3769:21): [True: 0, False: 0]
  ------------------
 3770|      0|                    return -1;
 3771|      0|                }
 3772|      0|            }
 3773|      0|            allowed = ssh_bind_key_size_allowed(sshbind, key);
 3774|      0|            if (!allowed) {
  ------------------
  |  Branch (3774:17): [True: 0, False: 0]
  ------------------
 3775|      0|                ssh_set_error(sshbind,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 3776|      0|                              SSH_FATAL,
 3777|      0|                              "The host key size %d is too small.",
 3778|      0|                              ssh_key_size(key));
 3779|      0|                if (type != SSH_BIND_OPTIONS_IMPORT_KEY) {
  ------------------
  |  Branch (3779:21): [True: 0, False: 0]
  ------------------
 3780|      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]
  |  |  ------------------
  ------------------
 3781|      0|                }
 3782|      0|                return -1;
 3783|      0|            }
 3784|      0|            key_type = ssh_key_type(key);
 3785|      0|            switch (key_type) {
 3786|      0|            case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (3786:13): [True: 0, False: 0]
  ------------------
 3787|      0|            case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (3787:13): [True: 0, False: 0]
  ------------------
 3788|      0|            case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (3788:13): [True: 0, False: 0]
  ------------------
 3789|      0|#ifdef HAVE_ECC
 3790|      0|                bind_key_loc = &sshbind->ecdsa;
 3791|      0|                bind_key_path_loc = &sshbind->ecdsakey;
 3792|       |#else
 3793|       |                ssh_set_error(sshbind,
 3794|       |                              SSH_FATAL,
 3795|       |                              "ECDSA key used and libssh compiled "
 3796|       |                              "without ECDSA support");
 3797|       |#endif
 3798|      0|                break;
 3799|      0|            case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (3799:13): [True: 0, False: 0]
  ------------------
 3800|      0|                bind_key_loc = &sshbind->rsa;
 3801|      0|                bind_key_path_loc = &sshbind->rsakey;
 3802|      0|                break;
 3803|      0|            case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (3803:13): [True: 0, False: 0]
  ------------------
 3804|      0|                bind_key_loc = &sshbind->ed25519;
 3805|      0|                bind_key_path_loc = &sshbind->ed25519key;
 3806|      0|                break;
 3807|      0|            default:
  ------------------
  |  Branch (3807:13): [True: 0, False: 0]
  ------------------
 3808|      0|                ssh_set_error(sshbind,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 3809|      0|                              SSH_FATAL,
 3810|      0|                              "Unsupported key type %d",
 3811|      0|                              key_type);
 3812|      0|            }
 3813|      0|            if (type == SSH_BIND_OPTIONS_RSAKEY ||
  ------------------
  |  Branch (3813:17): [True: 0, False: 0]
  ------------------
 3814|      0|                type == SSH_BIND_OPTIONS_ECDSAKEY ||
  ------------------
  |  Branch (3814:17): [True: 0, False: 0]
  ------------------
 3815|      0|                type == SSH_BIND_OPTIONS_HOSTKEY) {
  ------------------
  |  Branch (3815:17): [True: 0, False: 0]
  ------------------
 3816|      0|                if (bind_key_loc == NULL) {
  ------------------
  |  Branch (3816:21): [True: 0, False: 0]
  ------------------
 3817|      0|                    ssh_key_free(key);
 3818|      0|                    return -1;
 3819|      0|                }
 3820|       |                /* Set the location of the key on disk even though we don't
 3821|       |                   need it in case some other function wants it */
 3822|      0|                rc = ssh_bind_set_key(sshbind, bind_key_path_loc, value);
 3823|      0|                if (rc < 0) {
  ------------------
  |  Branch (3823:21): [True: 0, False: 0]
  ------------------
 3824|      0|                    ssh_key_free(key);
 3825|      0|                    return -1;
 3826|      0|                }
 3827|      0|            } else if (type == SSH_BIND_OPTIONS_IMPORT_KEY_STR) {
  ------------------
  |  Branch (3827:24): [True: 0, False: 0]
  ------------------
 3828|      0|                if (bind_key_loc == NULL) {
  ------------------
  |  Branch (3828:21): [True: 0, False: 0]
  ------------------
 3829|      0|                    ssh_key_free(key);
 3830|      0|                    return -1;
 3831|      0|                }
 3832|      0|            } else {
 3833|      0|                if (bind_key_loc == NULL) {
  ------------------
  |  Branch (3833:21): [True: 0, False: 0]
  ------------------
 3834|      0|                    return -1;
 3835|      0|                }
 3836|      0|            }
 3837|      0|            ssh_key_free(*bind_key_loc);
 3838|      0|            *bind_key_loc = key;
 3839|      0|        }
 3840|      0|        break;
 3841|      0|    case SSH_BIND_OPTIONS_BINDADDR:
  ------------------
  |  Branch (3841:5): [True: 0, False: 37]
  ------------------
 3842|      0|        if (value == NULL) {
  ------------------
  |  Branch (3842:13): [True: 0, False: 0]
  ------------------
 3843|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3844|      0|            return -1;
 3845|      0|        } else {
 3846|      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]
  |  |  ------------------
  ------------------
 3847|      0|            sshbind->bindaddr = strdup(value);
 3848|      0|            if (sshbind->bindaddr == NULL) {
  ------------------
  |  Branch (3848:17): [True: 0, False: 0]
  ------------------
 3849|      0|                ssh_set_error_oom(sshbind);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 3850|      0|                return -1;
 3851|      0|            }
 3852|      0|        }
 3853|      0|        break;
 3854|      0|    case SSH_BIND_OPTIONS_BINDPORT:
  ------------------
  |  Branch (3854:5): [True: 0, False: 37]
  ------------------
 3855|      0|        if (value == NULL) {
  ------------------
  |  Branch (3855:13): [True: 0, False: 0]
  ------------------
 3856|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3857|      0|            return -1;
 3858|      0|        } else {
 3859|      0|            int *x = (int *)value;
 3860|      0|            sshbind->bindport = *x & 0xffffU;
 3861|      0|        }
 3862|      0|        break;
 3863|      0|    case SSH_BIND_OPTIONS_BINDPORT_STR:
  ------------------
  |  Branch (3863:5): [True: 0, False: 37]
  ------------------
 3864|      0|        if (value == NULL) {
  ------------------
  |  Branch (3864:13): [True: 0, False: 0]
  ------------------
 3865|      0|            sshbind->bindport = 22 & 0xffffU;
 3866|      0|        } else {
 3867|      0|            q = strdup(value);
 3868|      0|            if (q == NULL) {
  ------------------
  |  Branch (3868:17): [True: 0, False: 0]
  ------------------
 3869|      0|                ssh_set_error_oom(sshbind);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 3870|      0|                return -1;
 3871|      0|            }
 3872|      0|            i = strtol(q, &p, 10);
 3873|      0|            if (q == p) {
  ------------------
  |  Branch (3873:17): [True: 0, False: 0]
  ------------------
 3874|      0|                SSH_LOG(SSH_LOG_DEBUG, "No bind port was parsed");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3875|      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]
  |  |  ------------------
  ------------------
 3876|      0|                return -1;
 3877|      0|            }
 3878|      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]
  |  |  ------------------
  ------------------
 3879|       |
 3880|      0|            sshbind->bindport = i & 0xffffU;
 3881|      0|        }
 3882|      0|        break;
 3883|      8|    case SSH_BIND_OPTIONS_LOG_VERBOSITY:
  ------------------
  |  Branch (3883:5): [True: 8, False: 29]
  ------------------
 3884|      8|        if (value == NULL) {
  ------------------
  |  Branch (3884:13): [True: 0, False: 8]
  ------------------
 3885|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3886|      0|            return -1;
 3887|      8|        } else {
 3888|      8|            int *x = (int *)value;
 3889|      8|            ssh_set_log_level(*x & 0xffffU);
 3890|      8|        }
 3891|      8|        break;
 3892|      8|    case SSH_BIND_OPTIONS_LOG_VERBOSITY_STR:
  ------------------
  |  Branch (3892:5): [True: 0, False: 37]
  ------------------
 3893|      0|        if (value == NULL) {
  ------------------
  |  Branch (3893:13): [True: 0, False: 0]
  ------------------
 3894|      0|            ssh_set_log_level(0);
 3895|      0|        } else {
 3896|      0|            q = strdup(value);
 3897|      0|            if (q == NULL) {
  ------------------
  |  Branch (3897:17): [True: 0, False: 0]
  ------------------
 3898|      0|                ssh_set_error_oom(sshbind);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 3899|      0|                return -1;
 3900|      0|            }
 3901|      0|            i = strtol(q, &p, 10);
 3902|      0|            if (q == p) {
  ------------------
  |  Branch (3902:17): [True: 0, False: 0]
  ------------------
 3903|      0|                SSH_LOG(SSH_LOG_DEBUG, "No log verbositiy was parsed");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3904|      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]
  |  |  ------------------
  ------------------
 3905|      0|                return -1;
 3906|      0|            }
 3907|      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]
  |  |  ------------------
  ------------------
 3908|       |
 3909|      0|            ssh_set_log_level(i & 0xffffU);
 3910|      0|        }
 3911|      0|        break;
 3912|      0|    case SSH_BIND_OPTIONS_BANNER:
  ------------------
  |  Branch (3912:5): [True: 0, False: 37]
  ------------------
 3913|      0|        if (value == NULL) {
  ------------------
  |  Branch (3913:13): [True: 0, False: 0]
  ------------------
 3914|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3915|      0|            return -1;
 3916|      0|        } else {
 3917|      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]
  |  |  ------------------
  ------------------
 3918|      0|            sshbind->banner = strdup(value);
 3919|      0|            if (sshbind->banner == NULL) {
  ------------------
  |  Branch (3919:17): [True: 0, False: 0]
  ------------------
 3920|      0|                ssh_set_error_oom(sshbind);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 3921|      0|                return -1;
 3922|      0|            }
 3923|      0|        }
 3924|      0|        break;
 3925|      0|    case SSH_BIND_OPTIONS_CIPHERS_C_S:
  ------------------
  |  Branch (3925:5): [True: 0, False: 37]
  ------------------
 3926|      0|        v = value;
 3927|      0|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (3927:13): [True: 0, False: 0]
  |  Branch (3927:26): [True: 0, False: 0]
  ------------------
 3928|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3929|      0|            return -1;
 3930|      0|        } else {
 3931|      0|            rc = ssh_bind_set_algo(sshbind,
 3932|      0|                                   SSH_CRYPT_C_S,
 3933|      0|                                   v,
 3934|      0|                                   &wanted_methods[SSH_CRYPT_C_S]);
 3935|      0|            if (rc < 0) {
  ------------------
  |  Branch (3935:17): [True: 0, False: 0]
  ------------------
 3936|      0|                return -1;
 3937|      0|            }
 3938|      0|        }
 3939|      0|        break;
 3940|      0|    case SSH_BIND_OPTIONS_CIPHERS_S_C:
  ------------------
  |  Branch (3940:5): [True: 0, False: 37]
  ------------------
 3941|      0|        v = value;
 3942|      0|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (3942:13): [True: 0, False: 0]
  |  Branch (3942:26): [True: 0, False: 0]
  ------------------
 3943|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3944|      0|            return -1;
 3945|      0|        } else {
 3946|      0|            rc = ssh_bind_set_algo(sshbind,
 3947|      0|                                   SSH_CRYPT_S_C,
 3948|      0|                                   v,
 3949|      0|                                   &wanted_methods[SSH_CRYPT_S_C]);
 3950|      0|            if (rc < 0) {
  ------------------
  |  Branch (3950:17): [True: 0, False: 0]
  ------------------
 3951|      0|                return -1;
 3952|      0|            }
 3953|      0|        }
 3954|      0|        break;
 3955|      0|    case SSH_BIND_OPTIONS_KEY_EXCHANGE:
  ------------------
  |  Branch (3955:5): [True: 0, False: 37]
  ------------------
 3956|      0|        v = value;
 3957|      0|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (3957:13): [True: 0, False: 0]
  |  Branch (3957:26): [True: 0, False: 0]
  ------------------
 3958|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3959|      0|            return -1;
 3960|      0|        } else {
 3961|      0|            rc = ssh_bind_set_algo(sshbind,
 3962|      0|                                   SSH_KEX,
 3963|      0|                                   v,
 3964|      0|                                   &wanted_methods[SSH_KEX]);
 3965|      0|            if (rc < 0) {
  ------------------
  |  Branch (3965:17): [True: 0, False: 0]
  ------------------
 3966|      0|                return -1;
 3967|      0|            }
 3968|      0|        }
 3969|      0|        break;
 3970|     11|    case SSH_BIND_OPTIONS_HMAC_C_S:
  ------------------
  |  Branch (3970:5): [True: 11, False: 26]
  ------------------
 3971|     11|        v = value;
 3972|     11|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (3972:13): [True: 0, False: 11]
  |  Branch (3972:26): [True: 0, False: 11]
  ------------------
 3973|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3974|      0|            return -1;
 3975|     11|        } else {
 3976|     11|            rc = ssh_bind_set_algo(sshbind,
 3977|     11|                                   SSH_MAC_C_S,
 3978|     11|                                   v,
 3979|     11|                                   &wanted_methods[SSH_MAC_C_S]);
 3980|     11|            if (rc < 0) {
  ------------------
  |  Branch (3980:17): [True: 0, False: 11]
  ------------------
 3981|      0|                return -1;
 3982|      0|            }
 3983|     11|        }
 3984|     11|        break;
 3985|     11|    case SSH_BIND_OPTIONS_HMAC_S_C:
  ------------------
  |  Branch (3985:5): [True: 11, False: 26]
  ------------------
 3986|     11|        v = value;
 3987|     11|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (3987:13): [True: 0, False: 11]
  |  Branch (3987:26): [True: 0, False: 11]
  ------------------
 3988|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3989|      0|            return -1;
 3990|     11|        } else {
 3991|     11|            rc = ssh_bind_set_algo(sshbind,
 3992|     11|                                   SSH_MAC_S_C,
 3993|     11|                                   v,
 3994|     11|                                   &wanted_methods[SSH_MAC_S_C]);
 3995|     11|            if (rc < 0) {
  ------------------
  |  Branch (3995:17): [True: 0, False: 11]
  ------------------
 3996|      0|                return -1;
 3997|      0|            }
 3998|     11|        }
 3999|     11|        break;
 4000|     11|    case SSH_BIND_OPTIONS_CONFIG_DIR:
  ------------------
  |  Branch (4000:5): [True: 0, False: 37]
  ------------------
 4001|      0|        v = value;
 4002|      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]
  |  |  ------------------
  ------------------
 4003|      0|        if (v == NULL) {
  ------------------
  |  Branch (4003:13): [True: 0, False: 0]
  ------------------
 4004|      0|            break;
 4005|      0|        } else if (v[0] == '\0') {
  ------------------
  |  Branch (4005:20): [True: 0, False: 0]
  ------------------
 4006|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 4007|      0|            return -1;
 4008|      0|        } else {
 4009|      0|            sshbind->config_dir = ssh_path_expand_tilde(v);
 4010|      0|            if (sshbind->config_dir == NULL) {
  ------------------
  |  Branch (4010:17): [True: 0, False: 0]
  ------------------
 4011|      0|                ssh_set_error_oom(sshbind);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 4012|      0|                return -1;
 4013|      0|            }
 4014|      0|        }
 4015|      0|        break;
 4016|      0|    case SSH_BIND_OPTIONS_PUBKEY_ACCEPTED_KEY_TYPES:
  ------------------
  |  Branch (4016:5): [True: 0, False: 37]
  ------------------
 4017|      0|        v = value;
 4018|      0|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (4018:13): [True: 0, False: 0]
  |  Branch (4018:26): [True: 0, False: 0]
  ------------------
 4019|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 4020|      0|            return -1;
 4021|      0|        } else {
 4022|      0|            rc = ssh_bind_set_algo(sshbind,
 4023|      0|                                   SSH_HOSTKEYS,
 4024|      0|                                   v,
 4025|      0|                                   &sshbind->pubkey_accepted_key_types);
 4026|      0|            if (rc < 0) {
  ------------------
  |  Branch (4026:17): [True: 0, False: 0]
  ------------------
 4027|      0|                return -1;
 4028|      0|            }
 4029|      0|        }
 4030|      0|        break;
 4031|      6|    case SSH_BIND_OPTIONS_HOSTKEY_ALGORITHMS:
  ------------------
  |  Branch (4031:5): [True: 6, False: 31]
  ------------------
 4032|      6|        v = value;
 4033|      6|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (4033:13): [True: 0, False: 6]
  |  Branch (4033:26): [True: 0, False: 6]
  ------------------
 4034|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 4035|      0|            return -1;
 4036|      6|        } else {
 4037|      6|            rc = ssh_bind_set_algo(sshbind,
 4038|      6|                                   SSH_HOSTKEYS,
 4039|      6|                                   v,
 4040|      6|                                   &wanted_methods[SSH_HOSTKEYS]);
 4041|      6|            if (rc < 0) {
  ------------------
  |  Branch (4041:17): [True: 0, False: 6]
  ------------------
 4042|      0|                return -1;
 4043|      0|            }
 4044|      6|        }
 4045|      6|        break;
 4046|      6|    case SSH_BIND_OPTIONS_PROCESS_CONFIG:
  ------------------
  |  Branch (4046:5): [True: 0, False: 37]
  ------------------
 4047|      0|        if (value == NULL) {
  ------------------
  |  Branch (4047:13): [True: 0, False: 0]
  ------------------
 4048|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 4049|      0|            return -1;
 4050|      0|        } else {
 4051|      0|            bool *x = (bool *)value;
 4052|      0|            sshbind->config_processed = !(*x);
 4053|      0|        }
 4054|      0|        break;
 4055|      0|    case SSH_BIND_OPTIONS_MODULI:
  ------------------
  |  Branch (4055:5): [True: 0, False: 37]
  ------------------
 4056|      0|        if (value == NULL) {
  ------------------
  |  Branch (4056:13): [True: 0, False: 0]
  ------------------
 4057|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 4058|      0|            return -1;
 4059|      0|        } else {
 4060|      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]
  |  |  ------------------
  ------------------
 4061|      0|            sshbind->moduli_file = strdup(value);
 4062|      0|            if (sshbind->moduli_file == NULL) {
  ------------------
  |  Branch (4062:17): [True: 0, False: 0]
  ------------------
 4063|      0|                ssh_set_error_oom(sshbind);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 4064|      0|                return -1;
 4065|      0|            }
 4066|      0|        }
 4067|      0|        break;
 4068|      1|    case SSH_BIND_OPTIONS_RSA_MIN_SIZE:
  ------------------
  |  Branch (4068:5): [True: 1, False: 36]
  ------------------
 4069|      1|        if (value == NULL) {
  ------------------
  |  Branch (4069:13): [True: 0, False: 1]
  ------------------
 4070|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 4071|      0|            return -1;
 4072|      1|        } else {
 4073|      1|            int *x = (int *)value;
 4074|       |
 4075|      1|            if (*x < 0) {
  ------------------
  |  Branch (4075:17): [True: 0, False: 1]
  ------------------
 4076|      0|                ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 4077|      0|                return -1;
 4078|      0|            }
 4079|       |
 4080|       |            /* (*x == 0) is allowed as it is used to revert to default */
 4081|       |
 4082|      1|            if (*x > 0 && *x < RSA_MIN_KEY_SIZE) {
  ------------------
  |  |   49|      0|#define RSA_MIN_KEY_SIZE      1024
  ------------------
  |  Branch (4082:17): [True: 0, False: 1]
  |  Branch (4082:27): [True: 0, False: 0]
  ------------------
 4083|      0|                ssh_set_error(sshbind,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 4084|      0|                              SSH_REQUEST_DENIED,
 4085|      0|                              "The provided value (%d) for minimal RSA key "
 4086|      0|                              "size is too small. Use at least %d bits.",
 4087|      0|                              *x,
 4088|      0|                              RSA_MIN_KEY_SIZE);
 4089|      0|                return -1;
 4090|      0|            }
 4091|      1|            sshbind->rsa_min_size = *x;
 4092|      1|        }
 4093|      1|        break;
 4094|       |#ifdef WITH_GSSAPI
 4095|       |    case SSH_BIND_OPTIONS_GSSAPI_KEY_EXCHANGE:
 4096|       |        if (value == NULL) {
 4097|       |            ssh_set_error_invalid(sshbind);
 4098|       |            return -1;
 4099|       |        } else {
 4100|       |            bool *x = (bool *)value;
 4101|       |            sshbind->gssapi_key_exchange = *x;
 4102|       |        }
 4103|       |        break;
 4104|       |    case SSH_BIND_OPTIONS_GSSAPI_KEY_EXCHANGE_ALGS:
 4105|       |        if (value == NULL) {
 4106|       |            ssh_set_error_invalid(sshbind);
 4107|       |            return -1;
 4108|       |        } else {
 4109|       |            char *ret = NULL;
 4110|       |            SAFE_FREE(sshbind->gssapi_key_exchange_algs);
 4111|       |            ret = ssh_find_all_matching(GSSAPI_KEY_EXCHANGE_SUPPORTED, value);
 4112|       |            if (ret == NULL) {
 4113|       |                ssh_set_error(
 4114|       |                    sshbind,
 4115|       |                    SSH_REQUEST_DENIED,
 4116|       |                    "GSSAPI key exchange algorithms not supported or invalid");
 4117|       |                return -1;
 4118|       |            }
 4119|       |            sshbind->gssapi_key_exchange_algs = ret;
 4120|       |        }
 4121|       |        break;
 4122|       |#endif /* WITH_GSSAPI */
 4123|      1|    default:
  ------------------
  |  Branch (4123:5): [True: 0, False: 37]
  ------------------
 4124|      0|        ssh_set_error(sshbind,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 4125|      0|                      SSH_REQUEST_DENIED,
 4126|      0|                      "Unknown ssh option %d",
 4127|      0|                      type);
 4128|      0|        return -1;
 4129|      0|        break;
 4130|     37|    }
 4131|       |
 4132|     37|    return 0;
 4133|     37|}
options.c:ssh_bind_set_algo:
 3543|     28|{
 3544|       |    /* sshbind is needed only for ssh_set_error which takes void*
 3545|       |     * the typecast is only to satisfy function parameter type */
 3546|     28|    return ssh_options_set_algo((ssh_session)sshbind, algo, list, place);
 3547|     28|}

ssh_key_free:
  261|    162|{
  262|    162|    if (key) {
  ------------------
  |  Branch (262:9): [True: 0, False: 162]
  ------------------
  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|    162|}

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|     42|{
   44|     42|    int i;
   45|     42|    if (tokens == NULL) {
  ------------------
  |  Branch (45:9): [True: 0, False: 42]
  ------------------
   46|      0|        return;
   47|      0|    }
   48|       |
   49|     42|    if (tokens->tokens != NULL) {
  ------------------
  |  Branch (49:9): [True: 42, False: 0]
  ------------------
   50|    527|        for (i = 0; tokens->tokens[i] != NULL; i++) {
  ------------------
  |  Branch (50:21): [True: 485, False: 42]
  ------------------
   51|    485|            ssh_burn(tokens->tokens[i], strlen(tokens->tokens[i]));
  ------------------
  |  |  390|    485|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
   52|    485|        }
   53|     42|    }
   54|       |
   55|     42|    SAFE_FREE(tokens->buffer);
  ------------------
  |  |  375|     42|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 42, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 42]
  |  |  ------------------
  ------------------
   56|     42|    SAFE_FREE(tokens->tokens);
  ------------------
  |  |  375|     42|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 42, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 42]
  |  |  ------------------
  ------------------
   57|       |    SAFE_FREE(tokens);
  ------------------
  |  |  375|     42|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 42, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 42]
  |  |  ------------------
  ------------------
   58|     42|}
ssh_tokenize:
   74|     42|{
   75|       |
   76|     42|    struct ssh_tokens_st *tokens = NULL;
   77|     42|    size_t num_tokens = 1, i = 1;
   78|       |
   79|     42|    char *found, *c;
   80|       |
   81|     42|    if (chain == NULL) {
  ------------------
  |  Branch (81:9): [True: 0, False: 42]
  ------------------
   82|      0|        return NULL;
   83|      0|    }
   84|       |
   85|     42|    tokens = calloc(1, sizeof(struct ssh_tokens_st));
   86|     42|    if (tokens == NULL) {
  ------------------
  |  Branch (86:9): [True: 0, False: 42]
  ------------------
   87|      0|        return NULL;
   88|      0|    }
   89|       |
   90|     42|    tokens->buffer = strdup(chain);
   91|     42|    if (tokens->buffer == NULL) {
  ------------------
  |  Branch (91:9): [True: 0, False: 42]
  ------------------
   92|      0|        goto error;
   93|      0|    }
   94|       |
   95|     42|    c = tokens->buffer;
   96|    489|    do {
   97|    489|        found = strchr(c, separator);
   98|    489|        if (found != NULL) {
  ------------------
  |  Branch (98:13): [True: 447, False: 42]
  ------------------
   99|    447|            c = found + 1;
  100|    447|            num_tokens++;
  101|    447|        }
  102|    489|    } while(found != NULL);
  ------------------
  |  Branch (102:13): [True: 447, False: 42]
  ------------------
  103|       |
  104|       |    /* Allocate tokens list */
  105|     42|    tokens->tokens = calloc(num_tokens + 1, sizeof(char *));
  106|     42|    if (tokens->tokens == NULL) {
  ------------------
  |  Branch (106:9): [True: 0, False: 42]
  ------------------
  107|      0|        goto error;
  108|      0|    }
  109|       |
  110|       |    /* First token starts in the beginning of the chain */
  111|     42|    tokens->tokens[0] = tokens->buffer;
  112|     42|    c = tokens->buffer;
  113|       |
  114|    485|    for (i = 1; i < num_tokens; i++) {
  ------------------
  |  Branch (114:17): [True: 447, False: 38]
  ------------------
  115|       |        /* Find next separator */
  116|    447|        found = strchr(c, separator);
  117|    447|        if (found == NULL) {
  ------------------
  |  Branch (117:13): [True: 0, False: 447]
  ------------------
  118|      0|            break;
  119|      0|        }
  120|       |
  121|       |        /* Replace it with a string terminator */
  122|    447|        *found = '\0';
  123|       |
  124|       |        /* The next token starts in the next byte */
  125|    447|        c = found + 1;
  126|       |
  127|       |        /* If we did not reach the end of the chain yet, set the next token */
  128|    447|        if (*c != '\0') {
  ------------------
  |  Branch (128:13): [True: 443, False: 4]
  ------------------
  129|    443|            tokens->tokens[i] = c;
  130|    443|        } else {
  131|      4|            break;
  132|      4|        }
  133|    447|    }
  134|       |
  135|     42|    return tokens;
  136|       |
  137|      0|error:
  138|      0|    ssh_tokens_free(tokens);
  139|       |    return NULL;
  140|     42|}
ssh_find_all_matching:
  208|     14|{
  209|     14|    struct ssh_tokens_st *a_tok = NULL, *p_tok = NULL;
  210|     14|    int i, j;
  211|     14|    char *ret = NULL;
  212|     14|    size_t max, len, pos = 0;
  213|     14|    int match;
  214|       |
  215|     14|    if ((available_list == NULL) || (preferred_list == NULL)) {
  ------------------
  |  Branch (215:9): [True: 0, False: 14]
  |  Branch (215:37): [True: 0, False: 14]
  ------------------
  216|      0|        return NULL;
  217|      0|    }
  218|       |
  219|     14|    max = MAX(strlen(available_list), strlen(preferred_list));
  ------------------
  |  |  371|     14|#define MAX(a,b) ((a) > (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (371:19): [True: 12, False: 2]
  |  |  ------------------
  ------------------
  220|       |
  221|     14|    ret = calloc(1, max + 1);
  222|     14|    if (ret == NULL) {
  ------------------
  |  Branch (222:9): [True: 0, False: 14]
  ------------------
  223|      0|        return NULL;
  224|      0|    }
  225|       |
  226|     14|    a_tok = ssh_tokenize(available_list, ',');
  227|     14|    if (a_tok == NULL) {
  ------------------
  |  Branch (227:9): [True: 0, False: 14]
  ------------------
  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|     14|    p_tok = ssh_tokenize(preferred_list, ',');
  233|     14|    if (p_tok == NULL) {
  ------------------
  |  Branch (233:9): [True: 0, False: 14]
  ------------------
  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|    162|    for (i = 0; p_tok->tokens[i] ; i++) {
  ------------------
  |  Branch (238:17): [True: 148, False: 14]
  ------------------
  239|  2.37k|        for (j = 0; a_tok->tokens[j]; j++) {
  ------------------
  |  Branch (239:21): [True: 2.22k, False: 148]
  ------------------
  240|  2.22k|            match = !strcmp(a_tok->tokens[j], p_tok->tokens[i]);
  241|  2.22k|            if (match) {
  ------------------
  |  Branch (241:17): [True: 122, False: 2.10k]
  ------------------
  242|    122|                if (pos != 0) {
  ------------------
  |  Branch (242:21): [True: 108, False: 14]
  ------------------
  243|    108|                    ret[pos] = ',';
  244|    108|                    pos++;
  245|    108|                }
  246|       |
  247|    122|                len = strlen(a_tok->tokens[j]);
  248|    122|                memcpy(&ret[pos], a_tok->tokens[j], len);
  249|    122|                pos += len;
  250|    122|                ret[pos] = '\0';
  251|    122|            }
  252|  2.22k|        }
  253|    148|    }
  254|       |
  255|     14|    if (ret[0] == '\0') {
  ------------------
  |  Branch (255:9): [True: 0, False: 14]
  ------------------
  256|      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]
  |  |  ------------------
  ------------------
  257|      0|    }
  258|       |
  259|     14|out:
  260|     14|    ssh_tokens_free(a_tok);
  261|     14|    ssh_tokens_free(p_tok);
  262|     14|    return ret;
  263|     14|}
ssh_remove_duplicates:
  277|     14|{
  278|     14|    struct ssh_tokens_st *tok = NULL;
  279|       |
  280|     14|    size_t i, j, num_tokens, max_len;
  281|     14|    char *ret = NULL;
  282|     14|    bool *should_copy = NULL, need_comma = false;
  283|       |
  284|     14|    if (list == NULL) {
  ------------------
  |  Branch (284:9): [True: 0, False: 14]
  ------------------
  285|      0|        return NULL;
  286|      0|    }
  287|       |
  288|       |    /* The maximum number of tokens is the size of the list */
  289|     14|    max_len = strlen(list);
  290|     14|    if (max_len == 0) {
  ------------------
  |  Branch (290:9): [True: 0, False: 14]
  ------------------
  291|      0|        return NULL;
  292|      0|    }
  293|       |
  294|       |    /* Add space for ending '\0' */
  295|     14|    max_len++;
  296|       |
  297|     14|    tok = ssh_tokenize(list, ',');
  298|     14|    if ((tok == NULL) || (tok->tokens == NULL) || (tok->tokens[0] == NULL)) {
  ------------------
  |  Branch (298:9): [True: 0, False: 14]
  |  Branch (298:26): [True: 0, False: 14]
  |  Branch (298:51): [True: 0, False: 14]
  ------------------
  299|      0|        goto out;
  300|      0|    }
  301|       |
  302|     14|    should_copy = calloc(1, max_len);
  303|     14|    if (should_copy == NULL) {
  ------------------
  |  Branch (303:9): [True: 0, False: 14]
  ------------------
  304|      0|        goto out;
  305|      0|    }
  306|       |
  307|     14|    if (strlen(tok->tokens[0]) > 0) {
  ------------------
  |  Branch (307:9): [True: 14, False: 0]
  ------------------
  308|     14|        should_copy[0] = true;
  309|     14|    }
  310|       |
  311|    173|    for (i = 1; tok->tokens[i]; i++) {
  ------------------
  |  Branch (311:17): [True: 159, False: 14]
  ------------------
  312|  1.65k|        for (j = 0; j < i; j++) {
  ------------------
  |  Branch (312:21): [True: 1.51k, False: 139]
  ------------------
  313|  1.51k|            if (strcmp(tok->tokens[i], tok->tokens[j]) == 0) {
  ------------------
  |  Branch (313:17): [True: 20, False: 1.49k]
  ------------------
  314|       |                /* Found a duplicate; do not copy */
  315|     20|                should_copy[i] = false;
  316|     20|                break;
  317|     20|            }
  318|  1.51k|        }
  319|       |
  320|       |        /* No matching token before */
  321|    159|        if (j == i) {
  ------------------
  |  Branch (321:13): [True: 139, False: 20]
  ------------------
  322|       |            /* Only copy if it is not an empty string */
  323|    139|            if (strlen(tok->tokens[i]) > 0) {
  ------------------
  |  Branch (323:17): [True: 134, False: 5]
  ------------------
  324|    134|                should_copy[i] = true;
  325|    134|            } else {
  326|      5|                should_copy[i] = false;
  327|      5|            }
  328|    139|        }
  329|    159|    }
  330|       |
  331|     14|    num_tokens = i;
  332|       |
  333|     14|    ret = calloc(1, max_len);
  334|     14|    if (ret == NULL) {
  ------------------
  |  Branch (334:9): [True: 0, False: 14]
  ------------------
  335|      0|        goto out;
  336|      0|    }
  337|       |
  338|    187|    for (i = 0; i < num_tokens; i++) {
  ------------------
  |  Branch (338:17): [True: 173, False: 14]
  ------------------
  339|    173|        if (should_copy[i]) {
  ------------------
  |  Branch (339:13): [True: 148, False: 25]
  ------------------
  340|    148|            if (need_comma) {
  ------------------
  |  Branch (340:17): [True: 134, False: 14]
  ------------------
  341|    134|                strlcat(ret, ",", max_len);
  342|    134|            }
  343|    148|            strlcat(ret, tok->tokens[i], max_len);
  344|    148|            need_comma = true;
  345|    148|        }
  346|    173|    }
  347|       |
  348|       |    /* If no comma is needed, nothing was copied */
  349|     14|    if (!need_comma) {
  ------------------
  |  Branch (349:9): [True: 0, False: 14]
  ------------------
  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|     14|out:
  354|       |    SAFE_FREE(should_copy);
  ------------------
  |  |  375|     14|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 14, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 14]
  |  |  ------------------
  ------------------
  355|     14|    ssh_tokens_free(tok);
  356|     14|    return ret;
  357|     14|}
ssh_append_without_duplicates:
  376|      6|{
  377|      6|    size_t concat_len = 0;
  378|      6|    char *ret = NULL, *concat = NULL;
  379|      6|    int rc = 0;
  380|       |
  381|      6|    if (list != NULL) {
  ------------------
  |  Branch (381:9): [True: 6, False: 0]
  ------------------
  382|      6|        concat_len = strlen(list);
  383|      6|    }
  384|       |
  385|      6|    if (appended_list != NULL) {
  ------------------
  |  Branch (385:9): [True: 6, False: 0]
  ------------------
  386|      6|        concat_len += strlen(appended_list);
  387|      6|    }
  388|       |
  389|      6|    if (concat_len == 0) {
  ------------------
  |  Branch (389:9): [True: 0, False: 6]
  ------------------
  390|      0|        return NULL;
  391|      0|    }
  392|       |
  393|       |    /* Add room for ending '\0' and for middle ',' */
  394|      6|    concat_len += 2;
  395|      6|    concat = calloc(1, concat_len);
  396|      6|    if (concat == NULL) {
  ------------------
  |  Branch (396:9): [True: 0, False: 6]
  ------------------
  397|      0|        return NULL;
  398|      0|    }
  399|       |
  400|      6|    rc = snprintf(concat, concat_len, "%s%s%s",
  401|      6|                  list == NULL ? "" : list,
  ------------------
  |  Branch (401:19): [True: 0, False: 6]
  ------------------
  402|      6|                  list == NULL ? "" : ",",
  ------------------
  |  Branch (402:19): [True: 0, False: 6]
  ------------------
  403|      6|                  appended_list == NULL ? "" : appended_list);
  ------------------
  |  Branch (403:19): [True: 0, False: 6]
  ------------------
  404|      6|    if (rc < 0) {
  ------------------
  |  Branch (404:9): [True: 0, False: 6]
  ------------------
  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|      6|    ret = ssh_remove_duplicates(concat);
  410|       |
  411|      6|    SAFE_FREE(concat);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  412|       |
  413|      6|    return ret;
  414|      6|}
ssh_prefix_without_duplicates:
  507|      8|{
  508|      8|    size_t concat_len = 0;
  509|      8|    char *ret = NULL, *concat = NULL;
  510|      8|    int rc = 0;
  511|       |
  512|      8|    if (list != NULL) {
  ------------------
  |  Branch (512:9): [True: 8, False: 0]
  ------------------
  513|      8|        concat_len = strlen(list);
  514|      8|    }
  515|       |
  516|      8|    if (prefixed_list != NULL) {
  ------------------
  |  Branch (516:9): [True: 8, False: 0]
  ------------------
  517|      8|        concat_len += strlen(prefixed_list);
  518|      8|    }
  519|       |
  520|      8|    if (concat_len == 0) {
  ------------------
  |  Branch (520:9): [True: 0, False: 8]
  ------------------
  521|      0|        return NULL;
  522|      0|    }
  523|       |
  524|       |    /* Add room for ending '\0' and for middle ',' */
  525|      8|    concat_len += 2;
  526|      8|    concat = calloc(concat_len, 1);
  527|      8|    if (concat == NULL) {
  ------------------
  |  Branch (527:9): [True: 0, False: 8]
  ------------------
  528|      0|        return NULL;
  529|      0|    }
  530|       |
  531|      8|    rc = snprintf(concat, concat_len, "%s%s%s",
  532|      8|                  prefixed_list == NULL ? "" : prefixed_list,
  ------------------
  |  Branch (532:19): [True: 0, False: 8]
  ------------------
  533|      8|                  prefixed_list == NULL ? "" : ",",
  ------------------
  |  Branch (533:19): [True: 0, False: 8]
  ------------------
  534|      8|                  list == NULL ? "" : list);
  ------------------
  |  Branch (534:19): [True: 0, False: 8]
  ------------------
  535|      8|    if (rc < 0) {
  ------------------
  |  Branch (535:9): [True: 0, False: 8]
  ------------------
  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|      8|    ret = ssh_remove_duplicates(concat);
  541|       |
  542|      8|    SAFE_FREE(concat);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  543|       |
  544|      8|    return ret;
  545|      8|}

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: 0, False: 2]
  ------------------
  130|      0|        nalloc_random_bitmask = false;
  131|      0|        nalloc_bitmask = 0;
  132|      0|        return;
  133|      0|    }
  134|       |
  135|      2|    char *verbose = getenv("NALLOC_VERBOSE");
  136|      2|    if (verbose) {
  ------------------
  |  Branch (136:9): [True: 0, False: 2]
  ------------------
  137|       |        nalloc_verbose = true;
  138|      0|    }
  139|      2|}
read:
  271|      1|{
  272|      1|    if (nalloc_fail(count, "read")) {
  ------------------
  |  Branch (272:9): [True: 0, False: 1]
  ------------------
  273|      0|        errno = EIO;
  274|      0|        return -1;
  275|      0|    }
  276|      1|    return nalloc_read(fd, buf, count);
  ------------------
  |  |  263|      1|#define nalloc_read(f, b, s)    __read(f, b, s)
  ------------------
  277|      1|}
calloc:
  307|    212|{
  308|    212|    if (nalloc_fail(size, "calloc")) {
  ------------------
  |  Branch (308:9): [True: 16, False: 196]
  ------------------
  309|     16|        errno = ENOMEM;
  310|     16|        return NULL;
  311|     16|    }
  312|    196|    return nalloc_calloc(nmemb, size);
  ------------------
  |  |  259|    196|#define nalloc_calloc(s, n)          __libc_calloc(s, n)
  ------------------
  313|    212|}
malloc:
  316|  1.64M|{
  317|  1.64M|    if (nalloc_fail(size, "malloc")) {
  ------------------
  |  Branch (317:9): [True: 24, False: 1.64M]
  ------------------
  318|     24|        errno = ENOMEM;
  319|     24|        return NULL;
  320|     24|    }
  321|  1.64M|    return nalloc_malloc(size);
  ------------------
  |  |  258|  1.64M|#define nalloc_malloc(s)             __libc_malloc(s)
  ------------------
  322|  1.64M|}
realloc:
  325|  1.94k|{
  326|  1.94k|    if (nalloc_fail(size, "realloc")) {
  ------------------
  |  Branch (326:9): [True: 0, False: 1.94k]
  ------------------
  327|      0|        errno = ENOMEM;
  328|      0|        return NULL;
  329|      0|    }
  330|  1.94k|    return nalloc_realloc(ptr, size);
  ------------------
  |  |  260|  1.94k|#define nalloc_realloc(p, s)         __libc_realloc(p, s)
  ------------------
  331|  1.94k|}
ssh_bind_config_fuzzer.c:nalloc_fail:
  194|  1.65M|{
  195|       |    // do not fail before thread init
  196|  1.65M|    if (nalloc_runs == 0) {
  ------------------
  |  Branch (196:9): [True: 10.2k, False: 1.64M]
  ------------------
  197|  10.2k|        return false;
  198|  10.2k|    }
  199|  1.64M|    if (__sync_fetch_and_add(&nalloc_running, 1) != 1) {
  ------------------
  |  Branch (199:9): [True: 418, False: 1.64M]
  ------------------
  200|       |        // do not fail allocations outside of fuzzer input
  201|       |        // and do not fail inside of this function
  202|    418|        __sync_fetch_and_sub(&nalloc_running, 1);
  203|    418|        return false;
  204|    418|    }
  205|  1.64M|    nalloc_random_update((uint8_t)size);
  206|  1.64M|    if (size >= 0x100) {
  ------------------
  |  Branch (206:9): [True: 29.4k, False: 1.61M]
  ------------------
  207|  29.4k|        nalloc_random_update((uint8_t)(size >> 8));
  208|  29.4k|        if (size >= 0x10000) {
  ------------------
  |  Branch (208:13): [True: 0, False: 29.4k]
  ------------------
  209|      0|            nalloc_random_update((uint8_t)(size >> 16));
  210|       |            // bigger may already fail or oom
  211|      0|        }
  212|  29.4k|    }
  213|  1.64M|    if (((nalloc_random_state ^ nalloc_magic) & nalloc_bitmask) == 0) {
  ------------------
  |  Branch (213:9): [True: 40, False: 1.64M]
  ------------------
  214|     40|        if (nalloc_backtrace_exclude(size, op)) {
  ------------------
  |  Branch (214:13): [True: 0, False: 40]
  ------------------
  215|      0|            __sync_fetch_and_sub(&nalloc_running, 1);
  216|      0|            return false;
  217|      0|        }
  218|     40|        __sync_fetch_and_sub(&nalloc_running, 1);
  219|     40|        return true;
  220|     40|    }
  221|  1.64M|    __sync_fetch_and_sub(&nalloc_running, 1);
  222|       |    return false;
  223|  1.64M|}
ssh_bind_config_fuzzer.c:nalloc_random_update:
  143|  14.1M|{
  144|  14.1M|    nalloc_random_state =
  145|  14.1M|        ((uint32_t)((uint32_t)nalloc_random_state << 8)) ^
  146|  14.1M|        nalloc_crc32_table[((nalloc_random_state >> 24) ^ b) & 0xFF];
  147|  14.1M|}
ssh_bind_config_fuzzer.c:nalloc_backtrace_exclude:
  181|     40|{
  182|     40|    if (nalloc_verbose) {
  ------------------
  |  Branch (182:9): [True: 0, False: 40]
  ------------------
  183|      0|        fprintf(stderr, "failed %s(%zu) \n", op, size);
  184|       |#ifdef NALLOC_ASAN
  185|       |        __sanitizer_print_stack_trace();
  186|       |#endif
  187|      0|    }
  188|       |
  189|       |    return false;
  190|     40|}
ssh_bind_config_fuzzer.c:nalloc_start:
  151|     70|{
  152|     70|    if (nalloc_random_bitmask) {
  ------------------
  |  Branch (152:9): [True: 70, False: 0]
  ------------------
  153|     70|        if (nalloc_random_state & 0x10) {
  ------------------
  |  Branch (153:13): [True: 31, False: 39]
  ------------------
  154|     31|            nalloc_bitmask = 0xFFFFFFFF;
  155|     39|        } else {
  156|     39|            nalloc_bitmask = 1 << (5 + (nalloc_random_state & 0xF));
  157|     39|        }
  158|     70|    } else if (nalloc_bitmask == 0) {
  ------------------
  |  Branch (158:16): [True: 0, False: 0]
  ------------------
  159|       |        // nalloc disabled
  160|      0|        return 2;
  161|      0|    }
  162|     70|    nalloc_random_state = 0;
  163|  12.5M|    for (size_t i = 0; i < size; i++) {
  ------------------
  |  Branch (163:24): [True: 12.5M, False: 70]
  ------------------
  164|  12.5M|        nalloc_random_update(data[i]);
  165|  12.5M|    }
  166|     70|    if (__sync_fetch_and_add(&nalloc_running, 1)) {
  ------------------
  |  Branch (166:9): [True: 0, False: 70]
  ------------------
  167|      0|        __sync_fetch_and_sub(&nalloc_running, 1);
  168|      0|        return 0;
  169|      0|    }
  170|     70|    nalloc_runs++;
  171|     70|    return 1;
  172|     70|}
ssh_bind_config_fuzzer.c:nalloc_end:
  176|     70|{
  177|     70|    __sync_fetch_and_sub(&nalloc_running, 1);
  178|     70|}

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|     70|{
   49|     70|    ssh_bind bind = NULL;
   50|     70|    char *input = NULL;
   51|     70|    const char *env = NULL;
   52|       |
   53|     70|    input = (char *)malloc(size + 1);
   54|     70|    if (!input) {
  ------------------
  |  Branch (54:9): [True: 0, False: 70]
  ------------------
   55|      0|        return 1;
   56|      0|    }
   57|     70|    memcpy(input, data, size);
   58|     70|    input[size] = '\0';
   59|       |
   60|     70|    assert(nalloc_start(data, size) > 0);
  ------------------
  |  Branch (60:5): [True: 0, False: 70]
  |  Branch (60:5): [True: 70, False: 0]
  ------------------
   61|       |
   62|     70|    bind = ssh_bind_new();
   63|     70|    if (bind == NULL) {
  ------------------
  |  Branch (63:9): [True: 16, False: 54]
  ------------------
   64|     16|        goto out;
   65|     16|    }
   66|       |
   67|     54|    env = getenv("LIBSSH_VERBOSITY");
   68|     54|    if (env != NULL && strlen(env) > 0) {
  ------------------
  |  Branch (68:9): [True: 0, False: 54]
  |  Branch (68:24): [True: 0, False: 0]
  ------------------
   69|      0|        ssh_bind_options_set(bind, SSH_BIND_OPTIONS_LOG_VERBOSITY_STR, env);
   70|      0|    }
   71|     54|    ssh_bind_config_parse_string(bind, input);
   72|       |
   73|     54|    ssh_bind_free(bind);
   74|       |
   75|     70|out:
   76|     70|    free(input);
   77|       |
   78|     70|    nalloc_end();
   79|     70|    return 0;
   80|     54|}
ssh_bind_config_fuzzer.c:_fuzz_finalize:
   30|      2|{
   31|      2|    ssh_finalize();
   32|      2|}

