ssh_agent_new:
  170|    661|{
  171|    661|    ssh_agent agent = NULL;
  172|       |
  173|    661|    agent = calloc(1, sizeof(struct ssh_agent_struct));
  174|    661|    if (agent == NULL) {
  ------------------
  |  Branch (174:9): [True: 0, False: 661]
  ------------------
  175|      0|        return NULL;
  176|      0|    }
  177|       |
  178|    661|    agent->count = 0;
  179|    661|    agent->sock = ssh_socket_new(session);
  180|    661|    if (agent->sock == NULL) {
  ------------------
  |  Branch (180:9): [True: 1, False: 660]
  ------------------
  181|      1|        SAFE_FREE(agent);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  182|      1|        return NULL;
  183|      1|    }
  184|    660|    agent->channel = NULL;
  185|       |#ifdef _WIN32
  186|       |    agent->pipe_handle = NULL;
  187|       |#endif
  188|    660|    return agent;
  189|    661|}
ssh_agent_close:
  258|    660|{
  259|    660|    if (agent == NULL) {
  ------------------
  |  Branch (259:9): [True: 0, False: 660]
  ------------------
  260|      0|        return;
  261|      0|    }
  262|       |
  263|       |#ifdef _WIN32
  264|       |    if (agent_pipe_is_open(agent)) {
  265|       |        CloseHandle((HANDLE)agent->pipe_handle);
  266|       |        agent->pipe_handle = NULL;
  267|       |    }
  268|       |#endif
  269|       |
  270|    660|    ssh_socket_close(agent->sock);
  271|    660|}
ssh_agent_free:
  274|    831|{
  275|    831|    if (agent) {
  ------------------
  |  Branch (275:9): [True: 660, False: 171]
  ------------------
  276|    660|        if (agent->ident) {
  ------------------
  |  Branch (276:13): [True: 0, False: 660]
  ------------------
  277|      0|            SSH_BUFFER_FREE(agent->ident);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  278|      0|        }
  279|    660|        if (agent->sock) {
  ------------------
  |  Branch (279:13): [True: 660, False: 0]
  ------------------
  280|    660|            ssh_agent_close(agent);
  281|    660|            ssh_socket_free(agent->sock);
  282|    660|        }
  283|       |        SAFE_FREE(agent);
  ------------------
  |  |  375|    660|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 660, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 660]
  |  |  ------------------
  ------------------
  284|    660|    }
  285|    831|}

ssh_packet_userauth_banner:
  206|    560|{
  207|    560|    ssh_string banner = NULL;
  208|    560|    (void)type;
  209|    560|    (void)user;
  210|       |
  211|    560|    banner = ssh_buffer_get_ssh_string(packet);
  212|    560|    if (banner == NULL) {
  ------------------
  |  Branch (212:9): [True: 391, False: 169]
  ------------------
  213|    391|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|    391|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  214|    391|                "Invalid SSH_USERAUTH_BANNER packet");
  215|    391|    } else {
  216|    169|        SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  283|    169|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  217|    169|                "Received SSH_USERAUTH_BANNER packet");
  218|    169|        if (session->banner != NULL)
  ------------------
  |  Branch (218:13): [True: 151, False: 18]
  ------------------
  219|    151|            SSH_STRING_FREE(session->banner);
  ------------------
  |  |  882|    151|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 151, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 151]
  |  |  ------------------
  ------------------
  220|    169|        session->banner = banner;
  221|    169|    }
  222|       |
  223|    560|    return SSH_PACKET_USED;
  ------------------
  |  |  638|    560|#define SSH_PACKET_USED 1
  ------------------
  224|    560|}
ssh_agent_state_free:
 1148|    831|{
 1149|    831|    struct ssh_agent_state_struct *state = data;
 1150|       |
 1151|    831|    if (state) {
  ------------------
  |  Branch (1151:9): [True: 0, False: 831]
  ------------------
 1152|       |        SSH_STRING_FREE_CHAR(state->comment);
  ------------------
  |  |  891|      0|    do { if ((x) != NULL) { ssh_string_free_char(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (891:14): [True: 0, False: 0]
  |  |  |  Branch (891:74): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1153|      0|        ssh_key_free(state->pubkey);
 1154|      0|        free(state);
 1155|      0|    }
 1156|    831|}

ssh_make_bignum_string:
   69|  1.49k|{
   70|  1.49k|    return make_bignum_string(num, 0);
   71|  1.49k|}
ssh_make_string_bn:
   79|  2.72k|{
   80|  2.72k|    bignum bn = NULL;
   81|  2.72k|    size_t len = ssh_string_len(string);
   82|       |
   83|       |#ifdef DEBUG_CRYPTO
   84|       |    SSH_LOG(SSH_LOG_TRACE,
   85|       |            "Importing a %zu bits, %zu bytes object ...",
   86|       |            len * 8,
   87|       |            len);
   88|       |#endif /* DEBUG_CRYPTO */
   89|       |
   90|  2.72k|    bignum_bin2bn(string->data, (int)len, &bn);
  ------------------
  |  |   79|  2.72k|    do {                                     \
  |  |   80|  2.72k|        (*dest) = BN_new();                  \
  |  |   81|  2.72k|        if ((*dest) != NULL) {               \
  |  |  ------------------
  |  |  |  Branch (81:13): [True: 2.72k, False: 0]
  |  |  ------------------
  |  |   82|  2.72k|            BN_bin2bn(data,datalen,(*dest)); \
  |  |   83|  2.72k|        }                                    \
  |  |   84|  2.72k|    } while(0)
  |  |  ------------------
  |  |  |  Branch (84:13): [Folded, False: 2.72k]
  |  |  ------------------
  ------------------
   91|       |
   92|  2.72k|    return bn;
   93|  2.72k|}
bignum.c:make_bignum_string:
   31|  1.49k|{
   32|  1.49k|    ssh_string ptr = NULL;
   33|  1.49k|    size_t pad = 0;
   34|  1.49k|    size_t len = bignum_num_bytes(num);
  ------------------
  |  |   98|  1.49k|#define bignum_num_bytes(num) (size_t)BN_num_bytes(num)
  ------------------
   35|  1.49k|    size_t bits = bignum_num_bits(num);
  ------------------
  |  |   99|  1.49k|#define bignum_num_bits(num) (size_t)BN_num_bits(num)
  ------------------
   36|       |
   37|  1.49k|    if (pad_to_len == 0) {
  ------------------
  |  Branch (37:9): [True: 1.49k, False: 0]
  ------------------
   38|       |        /* If the first bit is set we have a negative number */
   39|  1.49k|        if (!(bits % 8) && bignum_is_bit_set(num, bits - 1)) {
  ------------------
  |  |  100|    743|#define bignum_is_bit_set(num,bit) BN_is_bit_set(num, (int)bit)
  |  |  ------------------
  |  |  |  Branch (100:36): [True: 743, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (39:13): [True: 743, False: 751]
  ------------------
   40|    743|            pad++;
   41|    743|        }
   42|  1.49k|    } else {
   43|      0|        if (len > pad_to_len) {
  ------------------
  |  Branch (43:13): [True: 0, False: 0]
  ------------------
   44|      0|            return NULL;
   45|      0|        }
   46|      0|        pad = pad_to_len - len;
   47|      0|    }
   48|       |
   49|       |#ifdef DEBUG_CRYPTO
   50|       |    SSH_LOG(SSH_LOG_TRACE, "%zu bits, %zu bytes, %zu padding", bits, len, pad);
   51|       |#endif /* DEBUG_CRYPTO */
   52|       |
   53|  1.49k|    ptr = ssh_string_new(len + pad);
   54|  1.49k|    if (ptr == NULL) {
  ------------------
  |  Branch (54:9): [True: 0, False: 1.49k]
  ------------------
   55|      0|        return NULL;
   56|      0|    }
   57|       |
   58|       |    /* We have a negative number so we need a leading zero */
   59|  1.49k|    if (pad) {
  ------------------
  |  Branch (59:9): [True: 743, False: 751]
  ------------------
   60|    743|        memset(ptr->data, 0, pad);
   61|    743|    }
   62|       |
   63|  1.49k|    bignum_bn2bin(num, len, ptr->data + pad);
  ------------------
  |  |  101|  1.49k|#define bignum_bn2bin(num,len, ptr) BN_bn2bin(num, ptr)
  ------------------
   64|       |
   65|  1.49k|    return ptr;
   66|  1.49k|}

ssh_bind_new:
  136|  1.29k|{
  137|  1.29k|    ssh_bind ptr = NULL;
  138|       |
  139|  1.29k|    ptr = calloc(1, sizeof(struct ssh_bind_struct));
  140|  1.29k|    if (ptr == NULL) {
  ------------------
  |  Branch (140:9): [True: 303, False: 996]
  ------------------
  141|    303|        return NULL;
  142|    303|    }
  143|    996|    ptr->bindfd = SSH_INVALID_SOCKET;
  ------------------
  |  |  123|    996|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  144|    996|    ptr->bindport = 22;
  145|    996|    ptr->common.log_verbosity = 0;
  146|       |
  147|    996|    return ptr;
  148|  1.29k|}
ssh_bind_free:
  372|  1.29k|void ssh_bind_free(ssh_bind sshbind){
  373|  1.29k|  int i;
  374|       |
  375|  1.29k|  if (sshbind == NULL) {
  ------------------
  |  Branch (375:7): [True: 303, False: 996]
  ------------------
  376|    303|    return;
  377|    303|  }
  378|       |
  379|    996|  if (sshbind->bindfd >= 0) {
  ------------------
  |  Branch (379:7): [True: 0, False: 996]
  ------------------
  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|    996|  sshbind->bindfd = SSH_INVALID_SOCKET;
  ------------------
  |  |  123|    996|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  383|       |
  384|       |  /* options */
  385|    996|  SAFE_FREE(sshbind->banner);
  ------------------
  |  |  375|    996|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 996]
  |  |  |  Branch (375:71): [Folded, False: 996]
  |  |  ------------------
  ------------------
  386|    996|  SAFE_FREE(sshbind->moduli_file);
  ------------------
  |  |  375|    996|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 996]
  |  |  |  Branch (375:71): [Folded, False: 996]
  |  |  ------------------
  ------------------
  387|    996|  SAFE_FREE(sshbind->bindaddr);
  ------------------
  |  |  375|    996|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 996]
  |  |  |  Branch (375:71): [Folded, False: 996]
  |  |  ------------------
  ------------------
  388|    996|  SAFE_FREE(sshbind->config_dir);
  ------------------
  |  |  375|    996|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 996]
  |  |  |  Branch (375:71): [Folded, False: 996]
  |  |  ------------------
  ------------------
  389|    996|  SAFE_FREE(sshbind->pubkey_accepted_key_types);
  ------------------
  |  |  375|    996|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 996]
  |  |  |  Branch (375:71): [Folded, False: 996]
  |  |  ------------------
  ------------------
  390|       |
  391|    996|  SAFE_FREE(sshbind->rsakey);
  ------------------
  |  |  375|    996|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 319, False: 677]
  |  |  |  Branch (375:71): [Folded, False: 996]
  |  |  ------------------
  ------------------
  392|    996|  SAFE_FREE(sshbind->ecdsakey);
  ------------------
  |  |  375|    996|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 996]
  |  |  |  Branch (375:71): [Folded, False: 996]
  |  |  ------------------
  ------------------
  393|    996|  SAFE_FREE(sshbind->ed25519key);
  ------------------
  |  |  375|    996|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 996]
  |  |  |  Branch (375:71): [Folded, False: 996]
  |  |  ------------------
  ------------------
  394|    996|  SAFE_FREE(sshbind->gssapi_key_exchange_algs);
  ------------------
  |  |  375|    996|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 996]
  |  |  |  Branch (375:71): [Folded, False: 996]
  |  |  ------------------
  ------------------
  395|       |
  396|    996|  ssh_key_free(sshbind->rsa);
  397|    996|  sshbind->rsa = NULL;
  398|    996|  ssh_key_free(sshbind->ecdsa);
  399|    996|  sshbind->ecdsa = NULL;
  400|    996|  ssh_key_free(sshbind->ed25519);
  401|    996|  sshbind->ed25519 = NULL;
  402|       |
  403|  10.9k|  for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  10.9k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (403:15): [True: 9.96k, False: 996]
  ------------------
  404|  9.96k|    if (sshbind->wanted_methods[i]) {
  ------------------
  |  Branch (404:9): [True: 1.27k, False: 8.68k]
  ------------------
  405|  1.27k|      SAFE_FREE(sshbind->wanted_methods[i]);
  ------------------
  |  |  375|  1.27k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 1.27k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 1.27k]
  |  |  ------------------
  ------------------
  406|  1.27k|    }
  407|  9.96k|  }
  408|       |
  409|       |  SAFE_FREE(sshbind);
  ------------------
  |  |  375|    996|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 996, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 996]
  |  |  ------------------
  ------------------
  410|    996|}
ssh_bind_accept_fd:
  413|    319|{
  414|    319|    ssh_poll_handle handle = NULL;
  415|    319|    int i, rc;
  416|       |
  417|    319|    if (sshbind == NULL) {
  ------------------
  |  Branch (417:9): [True: 0, False: 319]
  ------------------
  418|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  419|      0|    }
  420|       |
  421|    319|    if (session == NULL){
  ------------------
  |  Branch (421:9): [True: 0, False: 319]
  ------------------
  422|      0|        ssh_set_error(sshbind, SSH_FATAL,"session is null");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  423|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  424|      0|    }
  425|       |
  426|    319|    session->server = 1;
  427|       |
  428|       |    /* Copy options from bind to session */
  429|  3.50k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  3.50k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (429:17): [True: 3.19k, False: 319]
  ------------------
  430|  3.19k|      if (sshbind->wanted_methods[i]) {
  ------------------
  |  Branch (430:11): [True: 1.27k, False: 1.91k]
  ------------------
  431|  1.27k|        session->opts.wanted_methods[i] = strdup(sshbind->wanted_methods[i]);
  432|  1.27k|        if (session->opts.wanted_methods[i] == NULL) {
  ------------------
  |  Branch (432:13): [True: 0, False: 1.27k]
  ------------------
  433|      0|          return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  434|      0|        }
  435|  1.27k|      }
  436|  3.19k|    }
  437|       |
  438|    319|    if (sshbind->bindaddr == NULL)
  ------------------
  |  Branch (438:9): [True: 319, False: 0]
  ------------------
  439|    319|      session->opts.bindaddr = NULL;
  440|      0|    else {
  441|      0|      SAFE_FREE(session->opts.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]
  |  |  ------------------
  ------------------
  442|      0|      session->opts.bindaddr = strdup(sshbind->bindaddr);
  443|      0|      if (session->opts.bindaddr == NULL) {
  ------------------
  |  Branch (443:11): [True: 0, False: 0]
  ------------------
  444|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  445|      0|      }
  446|      0|    }
  447|       |
  448|    319|    if (sshbind->pubkey_accepted_key_types != NULL) {
  ------------------
  |  Branch (448:9): [True: 0, False: 319]
  ------------------
  449|      0|        if (session->opts.pubkey_accepted_types == NULL) {
  ------------------
  |  Branch (449:13): [True: 0, False: 0]
  ------------------
  450|      0|            session->opts.pubkey_accepted_types = strdup(sshbind->pubkey_accepted_key_types);
  451|      0|            if (session->opts.pubkey_accepted_types == NULL) {
  ------------------
  |  Branch (451:17): [True: 0, False: 0]
  ------------------
  452|      0|                ssh_set_error_oom(sshbind);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  453|      0|                return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  454|      0|            }
  455|      0|        } else {
  456|      0|            char *p = NULL;
  457|       |            /* If something was set to the session prior to calling this
  458|       |             * function, keep only what is allowed by the options set in
  459|       |             * sshbind */
  460|      0|            p = ssh_find_all_matching(sshbind->pubkey_accepted_key_types,
  461|      0|                                      session->opts.pubkey_accepted_types);
  462|      0|            if (p == NULL) {
  ------------------
  |  Branch (462:17): [True: 0, False: 0]
  ------------------
  463|      0|                return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  464|      0|            }
  465|       |
  466|      0|            SAFE_FREE(session->opts.pubkey_accepted_types);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  467|      0|            session->opts.pubkey_accepted_types = p;
  468|      0|        }
  469|      0|    }
  470|       |
  471|    319|    session->common.log_verbosity = sshbind->common.log_verbosity;
  472|    319|    session->opts.gssapi_key_exchange = sshbind->gssapi_key_exchange;
  473|       |
  474|    319|    if (sshbind->gssapi_key_exchange_algs != NULL) {
  ------------------
  |  Branch (474:9): [True: 0, False: 319]
  ------------------
  475|      0|        SAFE_FREE(session->opts.gssapi_key_exchange_algs);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  476|      0|        session->opts.gssapi_key_exchange_algs =
  477|      0|            strdup(sshbind->gssapi_key_exchange_algs);
  478|      0|        if (session->opts.gssapi_key_exchange_algs == NULL) {
  ------------------
  |  Branch (478:13): [True: 0, False: 0]
  ------------------
  479|      0|            ssh_set_error_oom(sshbind);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  480|      0|            return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  481|      0|        }
  482|      0|    }
  483|       |
  484|    319|    if (sshbind->banner != NULL) {
  ------------------
  |  Branch (484:9): [True: 0, False: 319]
  ------------------
  485|      0|        session->server_opts.custombanner = strdup(sshbind->banner);
  486|      0|        if (session->server_opts.custombanner == NULL) {
  ------------------
  |  Branch (486:13): [True: 0, False: 0]
  ------------------
  487|      0|            ssh_set_error_oom(sshbind);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  488|      0|            return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  489|      0|        }
  490|      0|    }
  491|       |
  492|    319|    if (sshbind->moduli_file != NULL) {
  ------------------
  |  Branch (492:9): [True: 0, False: 319]
  ------------------
  493|      0|        session->server_opts.moduli_file = strdup(sshbind->moduli_file);
  494|      0|        if (session->server_opts.moduli_file == NULL) {
  ------------------
  |  Branch (494:13): [True: 0, False: 0]
  ------------------
  495|      0|            ssh_set_error_oom(sshbind);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  496|      0|            return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  497|      0|        }
  498|      0|    }
  499|       |
  500|    319|    session->opts.rsa_min_size = sshbind->rsa_min_size;
  501|       |
  502|    319|    ssh_socket_free(session->socket);
  503|    319|    session->socket = ssh_socket_new(session);
  504|    319|    if (session->socket == NULL) {
  ------------------
  |  Branch (504:9): [True: 0, False: 319]
  ------------------
  505|       |      /* perhaps it may be better to copy the error from session to sshbind */
  506|      0|      ssh_set_error_oom(sshbind);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  507|      0|      return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  508|      0|    }
  509|    319|    rc = ssh_socket_set_fd(session->socket, fd);
  510|    319|    if (rc != SSH_OK) {
  ------------------
  |  |  315|    319|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (510:9): [True: 0, False: 319]
  ------------------
  511|      0|        return rc;
  512|      0|    }
  513|    319|    handle = ssh_socket_get_poll_handle(session->socket);
  514|    319|    if (handle == NULL) {
  ------------------
  |  Branch (514:9): [True: 0, False: 319]
  ------------------
  515|      0|        ssh_set_error_oom(sshbind);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  516|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  517|      0|    }
  518|    319|    ssh_socket_set_connected(session->socket, handle);
  519|       |
  520|       |    /* We must try to import any keys that could be imported in case
  521|       |     * we are not using ssh_bind_listen (which is the other place
  522|       |     * where keys can be imported) on this ssh_bind and are instead
  523|       |     * only using ssh_bind_accept_fd to manage sockets ourselves.
  524|       |     */
  525|    319|    if (sshbind->rsa == NULL &&
  ------------------
  |  Branch (525:9): [True: 0, False: 319]
  ------------------
  526|      0|        sshbind->ecdsa == NULL &&
  ------------------
  |  Branch (526:9): [True: 0, False: 0]
  ------------------
  527|      0|        sshbind->ed25519 == NULL) {
  ------------------
  |  Branch (527:9): [True: 0, False: 0]
  ------------------
  528|      0|        rc = ssh_bind_import_keys(sshbind);
  529|      0|        if (rc == SSH_ERROR) {
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (529:13): [True: 0, False: 0]
  ------------------
  530|      0|            if (!sshbind->gssapi_key_exchange) {
  ------------------
  |  Branch (530:17): [True: 0, False: 0]
  ------------------
  531|      0|                ssh_set_error(sshbind, SSH_FATAL, "No usable hostkeys found");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  532|      0|                return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  533|      0|            }
  534|      0|            SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  535|      0|                    "No usable hostkeys found: Using \"null\" hostkey algorithm");
  536|      0|        }
  537|      0|    }
  538|       |
  539|    319|#ifdef HAVE_ECC
  540|    319|    if (sshbind->ecdsa) {
  ------------------
  |  Branch (540:9): [True: 0, False: 319]
  ------------------
  541|      0|        session->srv.ecdsa_key = ssh_key_dup(sshbind->ecdsa);
  542|      0|        if (session->srv.ecdsa_key == NULL) {
  ------------------
  |  Branch (542:13): [True: 0, False: 0]
  ------------------
  543|      0|          ssh_set_error_oom(sshbind);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  544|      0|          return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  545|      0|        }
  546|      0|    }
  547|    319|#endif
  548|    319|    if (sshbind->rsa) {
  ------------------
  |  Branch (548:9): [True: 319, False: 0]
  ------------------
  549|    319|        session->srv.rsa_key = ssh_key_dup(sshbind->rsa);
  550|    319|        if (session->srv.rsa_key == NULL) {
  ------------------
  |  Branch (550:13): [True: 0, False: 319]
  ------------------
  551|      0|          ssh_set_error_oom(sshbind);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  552|      0|          return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  553|      0|        }
  554|    319|    }
  555|    319|    if (sshbind->ed25519 != NULL) {
  ------------------
  |  Branch (555:9): [True: 0, False: 319]
  ------------------
  556|      0|        session->srv.ed25519_key = ssh_key_dup(sshbind->ed25519);
  557|      0|        if (session->srv.ed25519_key == NULL){
  ------------------
  |  Branch (557:13): [True: 0, False: 0]
  ------------------
  558|      0|            ssh_set_error_oom(sshbind);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  559|      0|            return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  560|      0|        }
  561|      0|    }
  562|       |
  563|       |    /* force PRNG to change state in case we fork after ssh_bind_accept */
  564|    319|    ssh_reseed();
  565|    319|    return SSH_OK;
  ------------------
  |  |  315|    319|#define SSH_OK 0     /* No error */
  ------------------
  566|    319|}

ssh_buffer_new:
  126|  9.55k|{
  127|  9.55k|    struct ssh_buffer_struct *buf = NULL;
  128|  9.55k|    int rc;
  129|       |
  130|  9.55k|    buf = calloc(1, sizeof(struct ssh_buffer_struct));
  131|  9.55k|    if (buf == NULL) {
  ------------------
  |  Branch (131:9): [True: 30, False: 9.52k]
  ------------------
  132|     30|        return NULL;
  133|     30|    }
  134|       |
  135|       |    /*
  136|       |     * Always preallocate 64 bytes.
  137|       |     *
  138|       |     * -1 for realloc_buffer magic.
  139|       |     */
  140|  9.52k|    rc = ssh_buffer_allocate_size(buf, 64 - 1);
  141|  9.52k|    if (rc != 0) {
  ------------------
  |  Branch (141:9): [True: 15, False: 9.51k]
  ------------------
  142|     15|        SAFE_FREE(buf);
  ------------------
  |  |  375|     15|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 15, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 15]
  |  |  ------------------
  ------------------
  143|     15|        return NULL;
  144|     15|    }
  145|  9.51k|    buffer_verify(buf);
  146|       |
  147|  9.51k|    return buf;
  148|  9.52k|}
ssh_buffer_free:
  156|  9.51k|{
  157|  9.51k|    if (buffer == NULL) {
  ------------------
  |  Branch (157:9): [True: 0, False: 9.51k]
  ------------------
  158|      0|        return;
  159|      0|    }
  160|  9.51k|    buffer_verify(buffer);
  161|       |
  162|  9.51k|    if (buffer->secure && buffer->allocated > 0) {
  ------------------
  |  Branch (162:9): [True: 740, False: 8.77k]
  |  Branch (162:27): [True: 740, False: 0]
  ------------------
  163|       |        /* burn the data */
  164|    740|        ssh_burn(buffer->data, buffer->allocated);
  ------------------
  |  |  390|    740|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  165|    740|        SAFE_FREE(buffer->data);
  ------------------
  |  |  375|    740|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 740, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 740]
  |  |  ------------------
  ------------------
  166|       |
  167|    740|        ssh_burn(buffer, sizeof(struct ssh_buffer_struct));
  ------------------
  |  |  390|    740|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  168|  8.77k|    } else {
  169|  8.77k|        SAFE_FREE(buffer->data);
  ------------------
  |  |  375|  8.77k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 8.77k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 8.77k]
  |  |  ------------------
  ------------------
  170|  8.77k|    }
  171|       |    SAFE_FREE(buffer);
  ------------------
  |  |  375|  9.51k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 9.51k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 9.51k]
  |  |  ------------------
  ------------------
  172|  9.51k|}
ssh_buffer_set_secure:
  183|    740|{
  184|       |    buffer->secure = true;
  185|    740|}
ssh_buffer_reinit:
  266|  67.6k|{
  267|  67.6k|    if (buffer == NULL) {
  ------------------
  |  Branch (267:9): [True: 0, False: 67.6k]
  ------------------
  268|      0|        return -1;
  269|      0|    }
  270|       |
  271|  67.6k|    buffer_verify(buffer);
  272|       |
  273|  67.6k|    if (buffer->secure && buffer->allocated > 0) {
  ------------------
  |  Branch (273:9): [True: 0, False: 67.6k]
  |  Branch (273:27): [True: 0, False: 0]
  ------------------
  274|      0|        ssh_burn(buffer->data, buffer->allocated);
  ------------------
  |  |  390|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  275|      0|    }
  276|  67.6k|    buffer->used = 0;
  277|  67.6k|    buffer->pos = 0;
  278|       |
  279|       |    /* If the buffer is bigger then 64K, reset it to 64K */
  280|  67.6k|    if (buffer->allocated > 65536) {
  ------------------
  |  Branch (280:9): [True: 33, False: 67.5k]
  ------------------
  281|     33|        int rc;
  282|       |
  283|       |        /* -1 for realloc_buffer magic */
  284|     33|        rc = realloc_buffer(buffer, 65536 - 1);
  285|     33|        if (rc != 0) {
  ------------------
  |  Branch (285:13): [True: 0, False: 33]
  ------------------
  286|      0|            return -1;
  287|      0|        }
  288|     33|    }
  289|       |
  290|  67.6k|    buffer_verify(buffer);
  291|       |
  292|  67.6k|    return 0;
  293|  67.6k|}
ssh_buffer_add_data:
  307|  87.7k|{
  308|  87.7k|    if (buffer == NULL) {
  ------------------
  |  Branch (308:9): [True: 0, False: 87.7k]
  ------------------
  309|      0|        return -1;
  310|      0|    }
  311|       |
  312|  87.7k|    buffer_verify(buffer);
  313|       |
  314|  87.7k|    if (data == NULL) {
  ------------------
  |  Branch (314:9): [True: 0, False: 87.7k]
  ------------------
  315|      0|        return -1;
  316|      0|    }
  317|       |
  318|  87.7k|    if (buffer->used + len < len) {
  ------------------
  |  Branch (318:9): [True: 0, False: 87.7k]
  ------------------
  319|      0|        return -1;
  320|      0|    }
  321|       |
  322|  87.7k|    if (buffer->allocated < (buffer->used + len)) {
  ------------------
  |  Branch (322:9): [True: 2.67k, False: 85.0k]
  ------------------
  323|  2.67k|        if (buffer->pos > 0) {
  ------------------
  |  Branch (323:13): [True: 0, False: 2.67k]
  ------------------
  324|      0|            buffer_shift(buffer);
  325|      0|        }
  326|  2.67k|        if (realloc_buffer(buffer, buffer->used + len) < 0) {
  ------------------
  |  Branch (326:13): [True: 0, False: 2.67k]
  ------------------
  327|      0|            return -1;
  328|      0|        }
  329|  2.67k|    }
  330|       |
  331|  87.7k|    memcpy(buffer->data + buffer->used, data, len);
  332|  87.7k|    buffer->used += len;
  333|  87.7k|    buffer_verify(buffer);
  334|  87.7k|    return 0;
  335|  87.7k|}
ssh_buffer_allocate_size:
  348|  26.0k|{
  349|  26.0k|    buffer_verify(buffer);
  350|       |
  351|  26.0k|    if (buffer->allocated < len) {
  ------------------
  |  Branch (351:9): [True: 9.72k, False: 16.3k]
  ------------------
  352|  9.72k|        if (buffer->pos > 0) {
  ------------------
  |  Branch (352:13): [True: 0, False: 9.72k]
  ------------------
  353|      0|            buffer_shift(buffer);
  354|      0|        }
  355|  9.72k|        if (realloc_buffer(buffer, len) < 0) {
  ------------------
  |  Branch (355:13): [True: 15, False: 9.71k]
  ------------------
  356|     15|            return -1;
  357|     15|        }
  358|  9.72k|    }
  359|       |
  360|  26.0k|    buffer_verify(buffer);
  361|       |
  362|  26.0k|    return 0;
  363|  26.0k|}
ssh_buffer_allocate:
  378|   100k|{
  379|   100k|    void *ptr = NULL;
  380|       |
  381|   100k|    buffer_verify(buffer);
  382|       |
  383|   100k|    if (buffer->used + len < len) {
  ------------------
  |  Branch (383:9): [True: 0, False: 100k]
  ------------------
  384|      0|        return NULL;
  385|      0|    }
  386|       |
  387|   100k|    if (buffer->allocated < (buffer->used + len)) {
  ------------------
  |  Branch (387:9): [True: 1.39k, False: 99.3k]
  ------------------
  388|  1.39k|        if (buffer->pos > 0) {
  ------------------
  |  Branch (388:13): [True: 449, False: 946]
  ------------------
  389|    449|            buffer_shift(buffer);
  390|    449|        }
  391|       |
  392|  1.39k|        if (realloc_buffer(buffer, buffer->used + len) < 0) {
  ------------------
  |  Branch (392:13): [True: 0, False: 1.39k]
  ------------------
  393|      0|            return NULL;
  394|      0|        }
  395|  1.39k|    }
  396|       |
  397|   100k|    ptr = buffer->data + buffer->used;
  398|   100k|    buffer->used+=len;
  399|   100k|    buffer_verify(buffer);
  400|       |
  401|   100k|    return ptr;
  402|   100k|}
ssh_buffer_add_ssh_string:
  418|  12.7k|{
  419|  12.7k|    size_t len;
  420|  12.7k|    int rc;
  421|       |
  422|  12.7k|    if (string == NULL) {
  ------------------
  |  Branch (422:9): [True: 0, False: 12.7k]
  ------------------
  423|      0|        return -1;
  424|      0|    }
  425|       |
  426|  12.7k|    len = ssh_string_len(string) + sizeof(uint32_t);
  427|       |    /* this can't overflow the uint32_t as the
  428|       |     * STRING_SIZE_MAX is (UINT32_MAX >> 8) + 1 */
  429|  12.7k|    rc = ssh_buffer_add_data(buffer, string, (uint32_t)len);
  430|  12.7k|    if (rc < 0) {
  ------------------
  |  Branch (430:9): [True: 0, False: 12.7k]
  ------------------
  431|      0|        return -1;
  432|      0|    }
  433|       |
  434|  12.7k|    return 0;
  435|  12.7k|}
ssh_buffer_add_u32:
  449|  16.8k|{
  450|  16.8k|    int rc;
  451|       |
  452|  16.8k|    rc = ssh_buffer_add_data(buffer, &data, sizeof(data));
  453|  16.8k|    if (rc < 0) {
  ------------------
  |  Branch (453:9): [True: 0, False: 16.8k]
  ------------------
  454|      0|        return -1;
  455|      0|    }
  456|       |
  457|  16.8k|    return 0;
  458|  16.8k|}
ssh_buffer_add_u8:
  518|  16.5k|{
  519|  16.5k|    int rc;
  520|       |
  521|  16.5k|    rc = ssh_buffer_add_data(buffer, &data, sizeof(uint8_t));
  522|  16.5k|    if (rc < 0) {
  ------------------
  |  Branch (522:9): [True: 0, False: 16.5k]
  ------------------
  523|      0|        return -1;
  524|      0|    }
  525|       |
  526|  16.5k|    return 0;
  527|  16.5k|}
ssh_buffer_prepend_data:
  543|  15.1k|    uint32_t len) {
  544|  15.1k|  buffer_verify(buffer);
  545|       |
  546|  15.1k|  if(len <= buffer->pos){
  ------------------
  |  Branch (546:6): [True: 0, False: 15.1k]
  ------------------
  547|       |    /* It's possible to insert data between begin and pos */
  548|      0|    memcpy(buffer->data + (buffer->pos - len), data, len);
  549|      0|    buffer->pos -= len;
  550|      0|    buffer_verify(buffer);
  551|      0|    return 0;
  552|      0|  }
  553|       |  /* pos isn't high enough */
  554|  15.1k|  if (buffer->used - buffer->pos + len < len) {
  ------------------
  |  Branch (554:7): [True: 0, False: 15.1k]
  ------------------
  555|      0|    return -1;
  556|      0|  }
  557|       |
  558|  15.1k|  if (buffer->allocated < (buffer->used - buffer->pos + len)) {
  ------------------
  |  Branch (558:7): [True: 294, False: 14.8k]
  ------------------
  559|    294|    if (realloc_buffer(buffer, buffer->used - buffer->pos + len) < 0) {
  ------------------
  |  Branch (559:9): [True: 0, False: 294]
  ------------------
  560|      0|      return -1;
  561|      0|    }
  562|    294|  }
  563|  15.1k|  memmove(buffer->data + len, buffer->data + buffer->pos, buffer->used - buffer->pos);
  564|  15.1k|  memcpy(buffer->data, data, len);
  565|  15.1k|  buffer->used += len - buffer->pos;
  566|  15.1k|  buffer->pos = 0;
  567|  15.1k|  buffer_verify(buffer);
  568|  15.1k|  return 0;
  569|  15.1k|}
ssh_buffer_add_buffer:
  585|  1.26k|{
  586|  1.26k|    int rc;
  587|       |
  588|  1.26k|    rc = ssh_buffer_add_data(buffer,
  589|  1.26k|                             ssh_buffer_get(source),
  590|  1.26k|                             ssh_buffer_get_len(source));
  591|  1.26k|    if (rc < 0) {
  ------------------
  |  Branch (591:9): [True: 0, False: 1.26k]
  ------------------
  592|      0|        return -1;
  593|      0|    }
  594|       |
  595|  1.26k|    return 0;
  596|  1.26k|}
ssh_buffer_get:
  607|   115k|void *ssh_buffer_get(struct ssh_buffer_struct *buffer){
  608|   115k|    return buffer->data + buffer->pos;
  609|   115k|}
ssh_buffer_get_len:
  620|   321k|uint32_t ssh_buffer_get_len(struct ssh_buffer_struct *buffer){
  621|   321k|  buffer_verify(buffer);
  622|   321k|  return buffer->used - buffer->pos;
  623|   321k|}
ssh_buffer_pass_bytes:
  685|   101k|uint32_t ssh_buffer_pass_bytes(struct ssh_buffer_struct *buffer, uint32_t len){
  686|   101k|    buffer_verify(buffer);
  687|       |
  688|   101k|    if (buffer->pos + len < len || buffer->used < buffer->pos + len) {
  ------------------
  |  Branch (688:9): [True: 0, False: 101k]
  |  Branch (688:36): [True: 0, False: 101k]
  ------------------
  689|      0|        return 0;
  690|      0|    }
  691|       |
  692|   101k|    buffer->pos+=len;
  693|       |    /* if the buffer is empty after having passed the whole bytes into it, we can clean it */
  694|   101k|    if(buffer->pos==buffer->used){
  ------------------
  |  Branch (694:8): [True: 750, False: 100k]
  ------------------
  695|    750|        buffer->pos=0;
  696|    750|        buffer->used=0;
  697|    750|    }
  698|   101k|    buffer_verify(buffer);
  699|   101k|    return len;
  700|   101k|}
ssh_buffer_pass_bytes_end:
  713|  51.0k|uint32_t ssh_buffer_pass_bytes_end(struct ssh_buffer_struct *buffer, uint32_t len){
  714|  51.0k|  buffer_verify(buffer);
  715|       |
  716|  51.0k|  if (buffer->used < len) {
  ------------------
  |  Branch (716:7): [True: 0, False: 51.0k]
  ------------------
  717|      0|      return 0;
  718|      0|  }
  719|       |
  720|  51.0k|  buffer->used-=len;
  721|  51.0k|  buffer_verify(buffer);
  722|  51.0k|  return len;
  723|  51.0k|}
ssh_buffer_get_data:
  737|   193k|{
  738|   193k|    int rc;
  739|       |
  740|       |    /*
  741|       |     * Check for a integer overflow first, then check if not enough data is in
  742|       |     * the buffer.
  743|       |     */
  744|   193k|    rc = ssh_buffer_validate_length(buffer, len);
  745|   193k|    if (rc != SSH_OK) {
  ------------------
  |  |  315|   193k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (745:9): [True: 21.2k, False: 172k]
  ------------------
  746|  21.2k|        return 0;
  747|  21.2k|    }
  748|   172k|    memcpy(data,buffer->data+buffer->pos,len);
  749|   172k|    buffer->pos+=len;
  750|   172k|    return len;   /* no yet support for partial reads (is it really needed ?? ) */
  751|   193k|}
ssh_buffer_get_u8:
  765|   115k|uint32_t ssh_buffer_get_u8(struct ssh_buffer_struct *buffer, uint8_t *data){
  766|   115k|    return ssh_buffer_get_data(buffer,data,sizeof(uint8_t));
  767|   115k|}
ssh_buffer_get_u32:
  780|  54.0k|uint32_t ssh_buffer_get_u32(struct ssh_buffer_struct *buffer, uint32_t *data){
  781|  54.0k|    return ssh_buffer_get_data(buffer,data,sizeof(uint32_t));
  782|  54.0k|}
ssh_buffer_validate_length:
  809|   219k|{
  810|   219k|    if (buffer == NULL || buffer->pos + len < len ||
  ------------------
  |  Branch (810:9): [True: 0, False: 219k]
  |  Branch (810:27): [True: 0, False: 219k]
  ------------------
  811|   219k|        buffer->pos + len > buffer->used) {
  ------------------
  |  Branch (811:9): [True: 23.0k, False: 196k]
  ------------------
  812|  23.0k|        return SSH_ERROR;
  ------------------
  |  |  316|  23.0k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  813|  23.0k|    }
  814|       |
  815|   196k|    return SSH_OK;
  ------------------
  |  |  315|   196k|#define SSH_OK 0     /* No error */
  ------------------
  816|   219k|}
ssh_buffer_get_ssh_string:
  829|  14.2k|{
  830|  14.2k|    uint32_t stringlen;
  831|  14.2k|    uint32_t hostlen;
  832|  14.2k|    struct ssh_string_struct *str = NULL;
  833|  14.2k|    int rc;
  834|       |
  835|  14.2k|    rc = ssh_buffer_get_u32(buffer, &stringlen);
  836|  14.2k|    if (rc == 0) {
  ------------------
  |  Branch (836:9): [True: 144, False: 14.1k]
  ------------------
  837|    144|        return NULL;
  838|    144|    }
  839|  14.1k|    hostlen = ntohl(stringlen);
  840|       |    /* verify if there is enough space in buffer to get it */
  841|  14.1k|    rc = ssh_buffer_validate_length(buffer, hostlen);
  842|  14.1k|    if (rc != SSH_OK) {
  ------------------
  |  |  315|  14.1k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (842:9): [True: 1.78k, False: 12.3k]
  ------------------
  843|  1.78k|      return NULL; /* it is indeed */
  844|  1.78k|    }
  845|  12.3k|    str = ssh_string_new(hostlen);
  846|  12.3k|    if (str == NULL) {
  ------------------
  |  Branch (846:9): [True: 0, False: 12.3k]
  ------------------
  847|      0|        return NULL;
  848|      0|    }
  849|       |
  850|  12.3k|    stringlen = ssh_buffer_get_data(buffer, ssh_string_data(str), hostlen);
  851|  12.3k|    if (stringlen != hostlen) {
  ------------------
  |  Branch (851:9): [True: 0, False: 12.3k]
  ------------------
  852|       |        /* should never happen */
  853|      0|        SAFE_FREE(str);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  854|      0|        return NULL;
  855|      0|    }
  856|       |
  857|  12.3k|    return str;
  858|  12.3k|}
_ssh_buffer_pack:
 1135|  15.9k|{
 1136|  15.9k|    va_list ap;
 1137|  15.9k|    int rc;
 1138|       |
 1139|  15.9k|    if (argc > 256) {
  ------------------
  |  Branch (1139:9): [True: 0, False: 15.9k]
  ------------------
 1140|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1141|      0|    }
 1142|       |
 1143|  15.9k|    va_start(ap, argc);
 1144|  15.9k|    rc = ssh_buffer_pack_allocate_va(buffer, format, argc, ap);
 1145|  15.9k|    va_end(ap);
 1146|       |
 1147|  15.9k|    if (rc != SSH_OK) {
  ------------------
  |  |  315|  15.9k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1147:9): [True: 0, False: 15.9k]
  ------------------
 1148|      0|        return rc;
 1149|      0|    }
 1150|       |
 1151|  15.9k|    va_start(ap, argc);
 1152|  15.9k|    rc = ssh_buffer_pack_va(buffer, format, argc, ap);
 1153|  15.9k|    va_end(ap);
 1154|       |
 1155|  15.9k|    return rc;
 1156|  15.9k|}
ssh_buffer_unpack_va:
 1173|  37.6k|{
 1174|  37.6k|    int rc = SSH_ERROR;
  ------------------
  |  |  316|  37.6k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1175|  37.6k|    const char *p = format, *last = NULL;
 1176|  37.6k|    union {
 1177|  37.6k|        uint8_t *byte;
 1178|  37.6k|        uint16_t *word;
 1179|  37.6k|        uint32_t *dword;
 1180|  37.6k|        uint64_t *qword;
 1181|  37.6k|        ssh_string *string;
 1182|  37.6k|        char **cstring;
 1183|  37.6k|        bignum *bignum;
 1184|  37.6k|        void **data;
 1185|  37.6k|    } o;
 1186|  37.6k|    size_t len;
 1187|  37.6k|    uint32_t rlen, max_len;
 1188|  37.6k|    ssh_string tmp_string = NULL;
 1189|  37.6k|    va_list ap_copy;
 1190|  37.6k|    size_t count;
 1191|       |
 1192|  37.6k|    max_len = ssh_buffer_get_len(buffer);
 1193|       |
 1194|       |    /* copy the argument list in case a rollback is needed */
 1195|  37.6k|    va_copy(ap_copy, ap);
 1196|       |
 1197|  37.6k|    if (argc > 256) {
  ------------------
  |  Branch (1197:9): [True: 0, False: 37.6k]
  ------------------
 1198|      0|        rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1199|      0|        goto cleanup;
 1200|      0|    }
 1201|       |
 1202|  77.0k|    for (count = 0; *p != '\0'; p++, count++) {
  ------------------
  |  Branch (1202:21): [True: 62.4k, False: 14.6k]
  ------------------
 1203|       |        /* Invalid number of arguments passed */
 1204|  62.4k|        if (count > argc) {
  ------------------
  |  Branch (1204:13): [True: 0, False: 62.4k]
  ------------------
 1205|      0|            rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1206|      0|            goto cleanup;
 1207|      0|        }
 1208|       |
 1209|  62.4k|        rc = SSH_ERROR;
  ------------------
  |  |  316|  62.4k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1210|  62.4k|        switch (*p) {
 1211|  16.2k|        case 'b':
  ------------------
  |  Branch (1211:9): [True: 16.2k, False: 46.1k]
  ------------------
 1212|  16.2k|            o.byte = va_arg(ap, uint8_t *);
 1213|  16.2k|            rlen = ssh_buffer_get_u8(buffer, o.byte);
 1214|  16.2k|            rc = rlen==1 ? SSH_OK : SSH_ERROR;
  ------------------
  |  |  315|  12.2k|#define SSH_OK 0     /* No error */
  ------------------
                          rc = rlen==1 ? SSH_OK : SSH_ERROR;
  ------------------
  |  |  316|  20.1k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1214:18): [True: 12.2k, False: 3.95k]
  ------------------
 1215|  16.2k|            break;
 1216|      0|        case 'w':
  ------------------
  |  Branch (1216:9): [True: 0, False: 62.4k]
  ------------------
 1217|      0|            o.word = va_arg(ap,  uint16_t *);
 1218|      0|            rlen = ssh_buffer_get_data(buffer, o.word, sizeof(uint16_t));
 1219|      0|            if (rlen == 2) {
  ------------------
  |  Branch (1219:17): [True: 0, False: 0]
  ------------------
 1220|      0|                *o.word = ntohs(*o.word);
 1221|      0|                rc = SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
 1222|      0|            }
 1223|      0|            break;
 1224|  14.6k|        case 'd':
  ------------------
  |  Branch (1224:9): [True: 14.6k, False: 47.7k]
  ------------------
 1225|  14.6k|            o.dword = va_arg(ap, uint32_t *);
 1226|  14.6k|            rlen = ssh_buffer_get_u32(buffer, o.dword);
 1227|  14.6k|            if (rlen == 4) {
  ------------------
  |  Branch (1227:17): [True: 9.26k, False: 5.38k]
  ------------------
 1228|  9.26k|                *o.dword = ntohl(*o.dword);
 1229|  9.26k|                rc = SSH_OK;
  ------------------
  |  |  315|  9.26k|#define SSH_OK 0     /* No error */
  ------------------
 1230|  9.26k|            }
 1231|  14.6k|            break;
 1232|      0|        case 'q':
  ------------------
  |  Branch (1232:9): [True: 0, False: 62.4k]
  ------------------
 1233|      0|            o.qword = va_arg(ap, uint64_t*);
 1234|      0|            rlen = ssh_buffer_get_u64(buffer, o.qword);
 1235|      0|            if (rlen == 8) {
  ------------------
  |  Branch (1235:17): [True: 0, False: 0]
  ------------------
 1236|      0|                *o.qword = ntohll(*o.qword);
  ------------------
  |  |  490|      0|    (((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32))
  ------------------
 1237|      0|                rc = SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
 1238|      0|            }
 1239|      0|            break;
 1240|      2|        case 'B':
  ------------------
  |  Branch (1240:9): [True: 2, False: 62.4k]
  ------------------
 1241|      2|            o.bignum = va_arg(ap, bignum *);
 1242|      2|            *o.bignum = NULL;
 1243|      2|            tmp_string = ssh_buffer_get_ssh_string(buffer);
 1244|      2|            if (tmp_string == NULL) {
  ------------------
  |  Branch (1244:17): [True: 0, False: 2]
  ------------------
 1245|      0|                break;
 1246|      0|            }
 1247|      2|            *o.bignum = ssh_make_string_bn(tmp_string);
 1248|      2|            ssh_string_burn(tmp_string);
 1249|      2|            SSH_STRING_FREE(tmp_string);
  ------------------
  |  |  882|      2|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 2, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 2]
  |  |  ------------------
  ------------------
 1250|      2|            rc = (*o.bignum != NULL) ? SSH_OK : SSH_ERROR;
  ------------------
  |  |  315|      2|#define SSH_OK 0     /* No error */
  ------------------
                          rc = (*o.bignum != NULL) ? SSH_OK : SSH_ERROR;
  ------------------
  |  |  316|      2|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1250:18): [True: 2, False: 0]
  ------------------
 1251|      2|            break;
 1252|  6.56k|        case 'S':
  ------------------
  |  Branch (1252:9): [True: 6.56k, False: 55.8k]
  ------------------
 1253|  6.56k|            o.string = va_arg(ap, ssh_string *);
 1254|  6.56k|            *o.string = ssh_buffer_get_ssh_string(buffer);
 1255|  6.56k|            rc = *o.string != NULL ? SSH_OK : SSH_ERROR;
  ------------------
  |  |  315|  6.33k|#define SSH_OK 0     /* No error */
  ------------------
                          rc = *o.string != NULL ? SSH_OK : SSH_ERROR;
  ------------------
  |  |  316|  6.79k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1255:18): [True: 6.33k, False: 228]
  ------------------
 1256|  6.56k|            o.string = NULL;
 1257|  6.56k|            break;
 1258|  24.9k|        case 's': {
  ------------------
  |  Branch (1258:9): [True: 24.9k, False: 37.4k]
  ------------------
 1259|  24.9k|            uint32_t u32len = 0;
 1260|       |
 1261|  24.9k|            o.cstring = va_arg(ap, char **);
 1262|  24.9k|            *o.cstring = NULL;
 1263|  24.9k|            rlen = ssh_buffer_get_u32(buffer, &u32len);
 1264|  24.9k|            if (rlen != 4){
  ------------------
  |  Branch (1264:17): [True: 11.0k, False: 13.9k]
  ------------------
 1265|  11.0k|                break;
 1266|  11.0k|            }
 1267|  13.9k|            u32len = ntohl(u32len);
 1268|  13.9k|            if (u32len > max_len - 1) {
  ------------------
  |  Branch (1268:17): [True: 2.33k, False: 11.5k]
  ------------------
 1269|  2.33k|                break;
 1270|  2.33k|            }
 1271|       |
 1272|  11.5k|            rc = ssh_buffer_validate_length(buffer, u32len);
 1273|  11.5k|            if (rc != SSH_OK) {
  ------------------
  |  |  315|  11.5k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1273:17): [True: 11, False: 11.5k]
  ------------------
 1274|     11|                break;
 1275|     11|            }
 1276|       |
 1277|  11.5k|            *o.cstring = malloc(u32len + 1);
 1278|  11.5k|            if (*o.cstring == NULL){
  ------------------
  |  Branch (1278:17): [True: 0, False: 11.5k]
  ------------------
 1279|      0|                rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1280|      0|                break;
 1281|      0|            }
 1282|  11.5k|            rlen = ssh_buffer_get_data(buffer, *o.cstring, u32len);
 1283|  11.5k|            if (rlen != u32len) {
  ------------------
  |  Branch (1283:17): [True: 0, False: 11.5k]
  ------------------
 1284|      0|                SAFE_FREE(*o.cstring);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1285|      0|                rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1286|      0|                break;
 1287|      0|            }
 1288|  11.5k|            (*o.cstring)[u32len] = '\0';
 1289|  11.5k|            o.cstring = NULL;
 1290|  11.5k|            rc = SSH_OK;
  ------------------
  |  |  315|  11.5k|#define SSH_OK 0     /* No error */
  ------------------
 1291|  11.5k|            break;
 1292|  11.5k|        }
 1293|      0|        case 'P':
  ------------------
  |  Branch (1293:9): [True: 0, False: 62.4k]
  ------------------
 1294|      0|            len = va_arg(ap, size_t);
 1295|      0|            if (len > max_len - 1) {
  ------------------
  |  Branch (1295:17): [True: 0, False: 0]
  ------------------
 1296|      0|                rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1297|      0|                break;
 1298|      0|            }
 1299|       |
 1300|      0|            rc = ssh_buffer_validate_length(buffer, len);
 1301|      0|            if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1301:17): [True: 0, False: 0]
  ------------------
 1302|      0|                break;
 1303|      0|            }
 1304|       |
 1305|      0|            o.data = va_arg(ap, void **);
 1306|      0|            count++;
 1307|       |
 1308|      0|            *o.data = malloc(len);
 1309|      0|            if(*o.data == NULL){
  ------------------
  |  Branch (1309:16): [True: 0, False: 0]
  ------------------
 1310|      0|                rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1311|      0|                break;
 1312|      0|            }
 1313|      0|            rlen = ssh_buffer_get_data(buffer, *o.data, (uint32_t)len);
 1314|      0|            if (rlen != len){
  ------------------
  |  Branch (1314:17): [True: 0, False: 0]
  ------------------
 1315|      0|                SAFE_FREE(*o.data);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1316|      0|                rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1317|      0|                break;
 1318|      0|            }
 1319|      0|            o.data = NULL;
 1320|      0|            rc = SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
 1321|      0|            break;
 1322|      0|        default:
  ------------------
  |  Branch (1322:9): [True: 0, False: 62.4k]
  ------------------
 1323|      0|            SSH_LOG(SSH_LOG_TRACE, "Invalid buffer format %c", *p);
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1324|  62.4k|        }
 1325|  62.4k|        if (rc != SSH_OK) {
  ------------------
  |  |  315|  62.4k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1325:13): [True: 22.9k, False: 39.4k]
  ------------------
 1326|  22.9k|            break;
 1327|  22.9k|        }
 1328|  62.4k|    }
 1329|       |
 1330|  37.6k|    if (argc != count) {
  ------------------
  |  Branch (1330:9): [True: 22.9k, False: 14.6k]
  ------------------
 1331|  22.9k|        rc = SSH_ERROR;
  ------------------
  |  |  316|  22.9k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1332|  22.9k|    }
 1333|       |
 1334|  37.6k|cleanup:
 1335|  37.6k|    if (rc != SSH_ERROR){
  ------------------
  |  |  316|  37.6k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1335:9): [True: 14.6k, False: 22.9k]
  ------------------
 1336|       |        /* Check if our canary is intact, if not something really bad happened */
 1337|  14.6k|        uint32_t canary = va_arg(ap, uint32_t);
 1338|  14.6k|        if (canary != SSH_BUFFER_PACK_END){
  ------------------
  |  |   28|  14.6k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  ------------------
  |  Branch (1338:13): [True: 0, False: 14.6k]
  ------------------
 1339|      0|            abort();
 1340|      0|        }
 1341|  14.6k|    }
 1342|       |
 1343|  37.6k|    if (rc != SSH_OK){
  ------------------
  |  |  315|  37.6k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1343:9): [True: 22.9k, False: 14.6k]
  ------------------
 1344|       |        /* Reset the format string and erase everything that was allocated */
 1345|  22.9k|        last = p;
 1346|  37.5k|        for(p=format;p<last;++p){
  ------------------
  |  Branch (1346:22): [True: 14.6k, False: 22.9k]
  ------------------
 1347|  14.6k|            switch(*p){
 1348|  10.5k|            case 'b':
  ------------------
  |  Branch (1348:13): [True: 10.5k, False: 4.11k]
  ------------------
 1349|  10.5k|                o.byte = va_arg(ap_copy, uint8_t *);
 1350|  10.5k|                if (buffer->secure) {
  ------------------
  |  Branch (1350:21): [True: 0, False: 10.5k]
  ------------------
 1351|      0|                    ssh_burn(o.byte, sizeof(uint8_t));
  ------------------
  |  |  390|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
 1352|      0|                    break;
 1353|      0|                }
 1354|  10.5k|                break;
 1355|  10.5k|            case 'w':
  ------------------
  |  Branch (1355:13): [True: 0, False: 14.6k]
  ------------------
 1356|      0|                o.word = va_arg(ap_copy, uint16_t *);
 1357|      0|                if (buffer->secure) {
  ------------------
  |  Branch (1357:21): [True: 0, False: 0]
  ------------------
 1358|      0|                    ssh_burn(o.word, sizeof(uint16_t));
  ------------------
  |  |  390|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
 1359|      0|                    break;
 1360|      0|                }
 1361|      0|                break;
 1362|      1|            case 'd':
  ------------------
  |  Branch (1362:13): [True: 1, False: 14.6k]
  ------------------
 1363|      1|                o.dword = va_arg(ap_copy, uint32_t *);
 1364|      1|                if (buffer->secure) {
  ------------------
  |  Branch (1364:21): [True: 0, False: 1]
  ------------------
 1365|      0|                    ssh_burn(o.dword, sizeof(uint32_t));
  ------------------
  |  |  390|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
 1366|      0|                    break;
 1367|      0|                }
 1368|      1|                break;
 1369|      1|            case 'q':
  ------------------
  |  Branch (1369:13): [True: 0, False: 14.6k]
  ------------------
 1370|      0|                o.qword = va_arg(ap_copy, uint64_t *);
 1371|      0|                if (buffer->secure) {
  ------------------
  |  Branch (1371:21): [True: 0, False: 0]
  ------------------
 1372|      0|                    ssh_burn(o.qword, sizeof(uint64_t));
  ------------------
  |  |  390|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
 1373|      0|                    break;
 1374|      0|                }
 1375|      0|                break;
 1376|      0|            case 'B':
  ------------------
  |  Branch (1376:13): [True: 0, False: 14.6k]
  ------------------
 1377|      0|                o.bignum = va_arg(ap_copy, bignum *);
 1378|      0|                bignum_safe_free(*o.bignum);
  ------------------
  |  |   71|      0|#define bignum_safe_free(num) do { \
  |  |   72|      0|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 0]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1379|      0|                break;
 1380|    116|            case 'S':
  ------------------
  |  Branch (1380:13): [True: 116, False: 14.5k]
  ------------------
 1381|    116|                o.string = va_arg(ap_copy, ssh_string *);
 1382|    116|                if (buffer->secure) {
  ------------------
  |  Branch (1382:21): [True: 0, False: 116]
  ------------------
 1383|      0|                    ssh_string_burn(*o.string);
 1384|      0|                }
 1385|    116|                SAFE_FREE(*o.string);
  ------------------
  |  |  375|    116|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 116, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 116]
  |  |  ------------------
  ------------------
 1386|    116|                break;
 1387|  3.99k|            case 's':
  ------------------
  |  Branch (1387:13): [True: 3.99k, False: 10.6k]
  ------------------
 1388|  3.99k|                o.cstring = va_arg(ap_copy, char **);
 1389|  3.99k|                if (buffer->secure) {
  ------------------
  |  Branch (1389:21): [True: 0, False: 3.99k]
  ------------------
 1390|      0|                    ssh_burn(*o.cstring, strlen(*o.cstring));
  ------------------
  |  |  390|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
 1391|      0|                }
 1392|  3.99k|                SAFE_FREE(*o.cstring);
  ------------------
  |  |  375|  3.99k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 3.99k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 3.99k]
  |  |  ------------------
  ------------------
 1393|  3.99k|                break;
 1394|      0|            case 'P':
  ------------------
  |  Branch (1394:13): [True: 0, False: 14.6k]
  ------------------
 1395|      0|                len = va_arg(ap_copy, size_t);
 1396|      0|                o.data = va_arg(ap_copy, void **);
 1397|      0|                if (buffer->secure) {
  ------------------
  |  Branch (1397:21): [True: 0, False: 0]
  ------------------
 1398|      0|                    ssh_burn(*o.data, len);
  ------------------
  |  |  390|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
 1399|      0|                }
 1400|      0|                SAFE_FREE(*o.data);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1401|      0|                break;
 1402|      0|            default:
  ------------------
  |  Branch (1402:13): [True: 0, False: 14.6k]
  ------------------
 1403|      0|                (void)va_arg(ap_copy, void *);
 1404|      0|                break;
 1405|  14.6k|            }
 1406|  14.6k|        }
 1407|  22.9k|    }
 1408|  37.6k|    va_end(ap_copy);
 1409|       |
 1410|  37.6k|    return rc;
 1411|  37.6k|}
_ssh_buffer_unpack:
 1439|  37.6k|{
 1440|  37.6k|    va_list ap;
 1441|  37.6k|    int rc;
 1442|       |
 1443|  37.6k|    va_start(ap, argc);
 1444|  37.6k|    rc = ssh_buffer_unpack_va(buffer, format, argc, ap);
 1445|       |    va_end(ap);
 1446|  37.6k|    return rc;
 1447|  37.6k|}
buffer.c:realloc_buffer:
  188|  14.1k|{
  189|  14.1k|    uint32_t smallest = 1;
  190|  14.1k|    uint8_t *new = NULL;
  191|       |
  192|  14.1k|    buffer_verify(buffer);
  193|       |
  194|       |    /* Find the smallest power of two which is greater or equal to needed */
  195|   117k|    while(smallest <= needed) {
  ------------------
  |  Branch (195:11): [True: 103k, False: 14.1k]
  ------------------
  196|   103k|        if (smallest == 0) {
  ------------------
  |  Branch (196:13): [True: 0, False: 103k]
  ------------------
  197|      0|            return -1;
  198|      0|        }
  199|   103k|        smallest <<= 1;
  200|   103k|    }
  201|  14.1k|    needed = smallest;
  202|       |
  203|  14.1k|    if (needed > BUFFER_SIZE_MAX) {
  ------------------
  |  |   57|  14.1k|#define BUFFER_SIZE_MAX 0x10000000
  ------------------
  |  Branch (203:9): [True: 0, False: 14.1k]
  ------------------
  204|      0|        return -1;
  205|      0|    }
  206|       |
  207|  14.1k|    if (buffer->secure) {
  ------------------
  |  Branch (207:9): [True: 555, False: 13.5k]
  ------------------
  208|    555|        new = malloc(needed);
  209|    555|        if (new == NULL) {
  ------------------
  |  Branch (209:13): [True: 0, False: 555]
  ------------------
  210|      0|            return -1;
  211|      0|        }
  212|    555|        memcpy(new, buffer->data, buffer->used);
  213|    555|        ssh_burn(buffer->data, buffer->used);
  ------------------
  |  |  390|    555|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  214|    555|        SAFE_FREE(buffer->data);
  ------------------
  |  |  375|    555|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 555, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 555]
  |  |  ------------------
  ------------------
  215|  13.5k|    } else {
  216|  13.5k|        new = realloc(buffer->data, needed);
  217|  13.5k|        if (new == NULL) {
  ------------------
  |  Branch (217:13): [True: 15, False: 13.5k]
  ------------------
  218|     15|            return -1;
  219|     15|        }
  220|  13.5k|    }
  221|  14.1k|    buffer->data = new;
  222|  14.1k|    buffer->allocated = needed;
  223|       |
  224|  14.1k|    buffer_verify(buffer);
  225|  14.1k|    return 0;
  226|  14.1k|}
buffer.c:buffer_shift:
  233|    449|{
  234|    449|    size_t burn_pos = buffer->pos;
  235|       |
  236|    449|    buffer_verify(buffer);
  237|       |
  238|    449|    if (buffer->pos == 0) {
  ------------------
  |  Branch (238:9): [True: 0, False: 449]
  ------------------
  239|      0|        return;
  240|      0|    }
  241|    449|    memmove(buffer->data,
  242|    449|            buffer->data + buffer->pos,
  243|    449|            buffer->used - buffer->pos);
  244|    449|    buffer->used -= buffer->pos;
  245|    449|    buffer->pos = 0;
  246|       |
  247|    449|    if (buffer->secure) {
  ------------------
  |  Branch (247:9): [True: 0, False: 449]
  ------------------
  248|      0|        void *ptr = buffer->data + buffer->used;
  249|      0|        ssh_burn(ptr, burn_pos);
  ------------------
  |  |  390|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  250|      0|    }
  251|       |
  252|    449|    buffer_verify(buffer);
  253|    449|}
buffer.c:ssh_buffer_pack_allocate_va:
  880|  15.9k|{
  881|  15.9k|    const char *p = NULL;
  882|  15.9k|    ssh_string string = NULL;
  883|  15.9k|    char *cstring = NULL;
  884|  15.9k|    bignum b = NULL;
  885|  15.9k|    size_t needed_size = 0;
  886|  15.9k|    size_t len;
  887|  15.9k|    size_t count;
  888|  15.9k|    int rc = SSH_OK;
  ------------------
  |  |  315|  15.9k|#define SSH_OK 0     /* No error */
  ------------------
  889|       |
  890|  48.9k|    for (p = format, count = 0; *p != '\0'; p++, count++) {
  ------------------
  |  Branch (890:33): [True: 32.9k, False: 15.9k]
  ------------------
  891|       |        /* Invalid number of arguments passed */
  892|  32.9k|        if (count > argc) {
  ------------------
  |  Branch (892:13): [True: 0, False: 32.9k]
  ------------------
  893|      0|            return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  894|      0|        }
  895|       |
  896|  32.9k|        switch(*p) {
  897|  15.0k|        case 'b':
  ------------------
  |  Branch (897:9): [True: 15.0k, False: 17.9k]
  ------------------
  898|  15.0k|            va_arg(ap, unsigned int);
  899|  15.0k|            needed_size += sizeof(uint8_t);
  900|  15.0k|            break;
  901|      0|        case 'w':
  ------------------
  |  Branch (901:9): [True: 0, False: 32.9k]
  ------------------
  902|      0|            va_arg(ap, unsigned int);
  903|      0|            needed_size += sizeof(uint16_t);
  904|      0|            break;
  905|  15.6k|        case 'd':
  ------------------
  |  Branch (905:9): [True: 15.6k, False: 17.3k]
  ------------------
  906|  15.6k|            va_arg(ap, uint32_t);
  907|  15.6k|            needed_size += sizeof(uint32_t);
  908|  15.6k|            break;
  909|      0|        case 'q':
  ------------------
  |  Branch (909:9): [True: 0, False: 32.9k]
  ------------------
  910|      0|            va_arg(ap, uint64_t);
  911|      0|            needed_size += sizeof(uint64_t);
  912|      0|            break;
  913|    189|        case 'S':
  ------------------
  |  Branch (913:9): [True: 189, False: 32.7k]
  ------------------
  914|    189|            string = va_arg(ap, ssh_string);
  915|    189|            needed_size += sizeof(uint32_t) + ssh_string_len(string);
  916|    189|            string = NULL;
  917|    189|            break;
  918|    693|        case 's':
  ------------------
  |  Branch (918:9): [True: 693, False: 32.2k]
  ------------------
  919|    693|            cstring = va_arg(ap, char *);
  920|    693|            needed_size += sizeof(uint32_t) + strlen(cstring);
  921|    693|            cstring = NULL;
  922|    693|            break;
  923|  1.21k|        case 'P':
  ------------------
  |  Branch (923:9): [True: 1.21k, False: 31.7k]
  ------------------
  924|  1.21k|            len = va_arg(ap, size_t);
  925|  1.21k|            needed_size += len;
  926|  1.21k|            va_arg(ap, void *);
  927|  1.21k|            count++; /* increase argument count */
  928|  1.21k|            break;
  929|    199|        case 'B':
  ------------------
  |  Branch (929:9): [True: 199, False: 32.7k]
  ------------------
  930|    199|            b = va_arg(ap, bignum);
  931|       |            /* The bignum bytes + 1 for possible padding */
  932|    199|            needed_size += sizeof(uint32_t) + bignum_num_bytes(b) + 1;
  ------------------
  |  |   98|    199|#define bignum_num_bytes(num) (size_t)BN_num_bytes(num)
  ------------------
  933|    199|            break;
  934|      0|        case 't':
  ------------------
  |  Branch (934:9): [True: 0, False: 32.9k]
  ------------------
  935|      0|            cstring = va_arg(ap, char *);
  936|      0|            needed_size += strlen(cstring);
  937|      0|            cstring = NULL;
  938|      0|            break;
  939|      0|        default:
  ------------------
  |  Branch (939:9): [True: 0, False: 32.9k]
  ------------------
  940|      0|            SSH_LOG(SSH_LOG_TRACE, "Invalid buffer format %c", *p);
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  941|      0|            rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  942|  32.9k|        }
  943|  32.9k|        if (rc != SSH_OK){
  ------------------
  |  |  315|  32.9k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (943:13): [True: 0, False: 32.9k]
  ------------------
  944|      0|            break;
  945|      0|        }
  946|  32.9k|    }
  947|       |
  948|  15.9k|    if (argc != count) {
  ------------------
  |  Branch (948:9): [True: 0, False: 15.9k]
  ------------------
  949|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  950|      0|    }
  951|       |
  952|  15.9k|    if (rc != SSH_ERROR){
  ------------------
  |  |  316|  15.9k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (952:9): [True: 15.9k, False: 0]
  ------------------
  953|       |        /*
  954|       |         * Check if our canary is intact, if not, something really bad happened.
  955|       |         */
  956|  15.9k|        uint32_t canary = va_arg(ap, uint32_t);
  957|  15.9k|        if (canary != SSH_BUFFER_PACK_END) {
  ------------------
  |  |   28|  15.9k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  ------------------
  |  Branch (957:13): [True: 0, False: 15.9k]
  ------------------
  958|      0|            abort();
  959|      0|        }
  960|  15.9k|    }
  961|       |
  962|  15.9k|    rc = ssh_buffer_allocate_size(buffer, (uint32_t)needed_size);
  963|  15.9k|    if (rc != 0) {
  ------------------
  |  Branch (963:9): [True: 0, False: 15.9k]
  ------------------
  964|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  965|      0|    }
  966|       |
  967|  15.9k|    return SSH_OK;
  ------------------
  |  |  315|  15.9k|#define SSH_OK 0     /* No error */
  ------------------
  968|  15.9k|}
buffer.c:ssh_buffer_pack_va:
  987|  15.9k|{
  988|  15.9k|    int rc = SSH_ERROR;
  ------------------
  |  |  316|  15.9k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  989|  15.9k|    const char *p = NULL;
  990|  15.9k|    union {
  991|  15.9k|        uint8_t byte;
  992|  15.9k|        uint16_t word;
  993|  15.9k|        uint32_t dword;
  994|  15.9k|        uint64_t qword;
  995|  15.9k|        ssh_string string;
  996|  15.9k|        void *data;
  997|  15.9k|    } o;
  998|  15.9k|    char *cstring = NULL;
  999|  15.9k|    bignum b;
 1000|  15.9k|    size_t len;
 1001|  15.9k|    size_t count;
 1002|       |
 1003|  15.9k|    if (argc > 256) {
  ------------------
  |  Branch (1003:9): [True: 0, False: 15.9k]
  ------------------
 1004|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1005|      0|    }
 1006|       |
 1007|  48.9k|    for (p = format, count = 0; *p != '\0'; p++, count++) {
  ------------------
  |  Branch (1007:33): [True: 32.9k, False: 15.9k]
  ------------------
 1008|       |        /* Invalid number of arguments passed */
 1009|  32.9k|        if (count > argc) {
  ------------------
  |  Branch (1009:13): [True: 0, False: 32.9k]
  ------------------
 1010|      0|            return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1011|      0|        }
 1012|       |
 1013|  32.9k|        switch(*p) {
 1014|  15.0k|        case 'b':
  ------------------
  |  Branch (1014:9): [True: 15.0k, False: 17.9k]
  ------------------
 1015|  15.0k|            o.byte = (uint8_t)va_arg(ap, unsigned int);
 1016|  15.0k|            rc = ssh_buffer_add_u8(buffer, o.byte);
 1017|  15.0k|            break;
 1018|      0|        case 'w':
  ------------------
  |  Branch (1018:9): [True: 0, False: 32.9k]
  ------------------
 1019|      0|            o.word = (uint16_t)va_arg(ap, unsigned int);
 1020|      0|            o.word = htons(o.word);
 1021|      0|            rc = ssh_buffer_add_u16(buffer, o.word);
 1022|      0|            break;
 1023|  15.6k|        case 'd':
  ------------------
  |  Branch (1023:9): [True: 15.6k, False: 17.3k]
  ------------------
 1024|  15.6k|            o.dword = va_arg(ap, uint32_t);
 1025|  15.6k|            o.dword = htonl(o.dword);
 1026|  15.6k|            rc = ssh_buffer_add_u32(buffer, o.dword);
 1027|  15.6k|            break;
 1028|      0|        case 'q':
  ------------------
  |  Branch (1028:9): [True: 0, False: 32.9k]
  ------------------
 1029|      0|            o.qword = va_arg(ap, uint64_t);
 1030|      0|            o.qword = htonll(o.qword);
  ------------------
  |  |  481|      0|    (((uint64_t)htonl((x) & 0xFFFFFFFF) << 32) | htonl((x) >> 32))
  ------------------
 1031|      0|            rc = ssh_buffer_add_u64(buffer, o.qword);
 1032|      0|            break;
 1033|    189|        case 'S':
  ------------------
  |  Branch (1033:9): [True: 189, False: 32.7k]
  ------------------
 1034|    189|            o.string = va_arg(ap, ssh_string);
 1035|    189|            rc = ssh_buffer_add_ssh_string(buffer, o.string);
 1036|    189|            o.string = NULL;
 1037|    189|            break;
 1038|    693|        case 's':
  ------------------
  |  Branch (1038:9): [True: 693, False: 32.2k]
  ------------------
 1039|    693|            cstring = va_arg(ap, char *);
 1040|    693|            len = strlen(cstring);
 1041|    693|            if (len > UINT32_MAX) {
  ------------------
  |  Branch (1041:17): [True: 0, False: 693]
  ------------------
 1042|      0|                rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1043|      0|                break;
 1044|      0|            }
 1045|    693|            o.dword = (uint32_t)len;
 1046|    693|            rc = ssh_buffer_add_u32(buffer, htonl(o.dword));
 1047|    693|            if (rc == SSH_OK){
  ------------------
  |  |  315|    693|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1047:17): [True: 693, False: 0]
  ------------------
 1048|    693|                rc = ssh_buffer_add_data(buffer, cstring, o.dword);
 1049|    693|            }
 1050|    693|            cstring = NULL;
 1051|    693|            break;
 1052|  1.21k|        case 'P':
  ------------------
  |  Branch (1052:9): [True: 1.21k, False: 31.7k]
  ------------------
 1053|  1.21k|            len = va_arg(ap, size_t);
 1054|  1.21k|            if (len > UINT32_MAX) {
  ------------------
  |  Branch (1054:17): [True: 0, False: 1.21k]
  ------------------
 1055|      0|                rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1056|      0|                break;
 1057|      0|            }
 1058|       |
 1059|  1.21k|            o.data = va_arg(ap, void *);
 1060|  1.21k|            count++; /* increase argument count */
 1061|       |
 1062|  1.21k|            rc = ssh_buffer_add_data(buffer, o.data, (uint32_t)len);
 1063|  1.21k|            o.data = NULL;
 1064|  1.21k|            break;
 1065|    199|        case 'B':
  ------------------
  |  Branch (1065:9): [True: 199, False: 32.7k]
  ------------------
 1066|    199|            b = va_arg(ap, bignum);
 1067|    199|            o.string = ssh_make_bignum_string(b);
 1068|    199|            if(o.string == NULL){
  ------------------
  |  Branch (1068:16): [True: 0, False: 199]
  ------------------
 1069|      0|                rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1070|      0|                break;
 1071|      0|            }
 1072|    199|            rc = ssh_buffer_add_ssh_string(buffer, o.string);
 1073|    199|            SAFE_FREE(o.string);
  ------------------
  |  |  375|    199|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 199, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 199]
  |  |  ------------------
  ------------------
 1074|    199|            break;
 1075|      0|        case 't':
  ------------------
  |  Branch (1075:9): [True: 0, False: 32.9k]
  ------------------
 1076|      0|            cstring = va_arg(ap, char *);
 1077|      0|            len = strlen(cstring);
 1078|      0|            if (len > UINT32_MAX) {
  ------------------
  |  Branch (1078:17): [True: 0, False: 0]
  ------------------
 1079|      0|                rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1080|      0|                break;
 1081|      0|            }
 1082|      0|            rc = ssh_buffer_add_data(buffer, cstring, (uint32_t)len);
 1083|      0|            cstring = NULL;
 1084|      0|            break;
 1085|      0|        default:
  ------------------
  |  Branch (1085:9): [True: 0, False: 32.9k]
  ------------------
 1086|      0|            SSH_LOG(SSH_LOG_TRACE, "Invalid buffer format %c", *p);
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1087|      0|            rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1088|  32.9k|        }
 1089|  32.9k|        if (rc != SSH_OK){
  ------------------
  |  |  315|  32.9k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1089:13): [True: 0, False: 32.9k]
  ------------------
 1090|      0|            break;
 1091|      0|        }
 1092|  32.9k|    }
 1093|       |
 1094|  15.9k|    if (argc != count) {
  ------------------
  |  Branch (1094:9): [True: 0, False: 15.9k]
  ------------------
 1095|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1096|      0|    }
 1097|       |
 1098|  15.9k|    if (rc != SSH_ERROR){
  ------------------
  |  |  316|  15.9k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1098:9): [True: 15.9k, False: 0]
  ------------------
 1099|       |        /* Check if our canary is intact, if not something really bad happened */
 1100|  15.9k|        uint32_t canary = va_arg(ap, uint32_t);
 1101|  15.9k|        if (canary != SSH_BUFFER_PACK_END) {
  ------------------
  |  |   28|  15.9k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  ------------------
  |  Branch (1101:13): [True: 0, False: 15.9k]
  ------------------
 1102|      0|            abort();
 1103|      0|        }
 1104|  15.9k|    }
 1105|  15.9k|    return rc;
 1106|  15.9k|}

_ssh_remove_legacy_log_cb:
   49|    831|{
   50|    831|    if (ssh_get_log_callback() == ssh_legacy_log_callback) {
  ------------------
  |  Branch (50:9): [True: 0, False: 831]
  ------------------
   51|      0|        _ssh_reset_log_cb();
   52|       |        ssh_set_log_userdata(NULL);
   53|      0|    }
   54|    831|}
ssh_set_server_callbacks:
  142|    319|{
  143|    319|    if (session == NULL || cb == NULL) {
  ------------------
  |  Branch (143:9): [True: 0, False: 319]
  |  Branch (143:28): [True: 0, False: 319]
  ------------------
  144|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  145|      0|    }
  146|       |
  147|    319|    if (!is_callback_valid(session, cb)) {
  ------------------
  |  |   31|    319|    (cb->size > 0 || cb->size <= 1024 * sizeof(void *))
  |  |  ------------------
  |  |  |  Branch (31:6): [True: 319, False: 0]
  |  |  |  Branch (31:22): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  148|      0|        ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  149|      0|                      SSH_FATAL,
  150|      0|                      "Invalid callback passed in (badly initialized)");
  151|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  152|    319|    };
  153|    319|    session->server_callbacks = cb;
  154|       |
  155|    319|    return 0;
  156|    319|}

ssh_channel_new:
   91|     17|{
   92|     17|    ssh_channel channel = NULL;
   93|       |
   94|     17|    if (session == NULL) {
  ------------------
  |  Branch (94:9): [True: 0, False: 17]
  ------------------
   95|      0|        return NULL;
   96|      0|    }
   97|       |
   98|       |    /* Check if we have an authenticated session */
   99|     17|    if (!(session->flags & SSH_SESSION_FLAG_AUTHENTICATED)) {
  ------------------
  |  |   78|     17|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (99:9): [True: 0, False: 17]
  ------------------
  100|      0|        return NULL;
  101|      0|    }
  102|       |
  103|     17|    channel = calloc(1, sizeof(struct ssh_channel_struct));
  104|     17|    if (channel == NULL) {
  ------------------
  |  Branch (104:9): [True: 0, False: 17]
  ------------------
  105|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  106|      0|        return NULL;
  107|      0|    }
  108|       |
  109|     17|    channel->stdout_buffer = ssh_buffer_new();
  110|     17|    if (channel->stdout_buffer == NULL) {
  ------------------
  |  Branch (110:9): [True: 0, False: 17]
  ------------------
  111|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  112|      0|        SAFE_FREE(channel);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  113|      0|        return NULL;
  114|      0|    }
  115|       |
  116|     17|    channel->stderr_buffer = ssh_buffer_new();
  117|     17|    if (channel->stderr_buffer == NULL) {
  ------------------
  |  Branch (117:9): [True: 0, False: 17]
  ------------------
  118|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  119|      0|        SSH_BUFFER_FREE(channel->stdout_buffer);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  120|      0|        SAFE_FREE(channel);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  121|      0|        return NULL;
  122|      0|    }
  123|       |
  124|     17|    channel->session = session;
  125|     17|    channel->exit.code = (uint32_t)-1;
  126|     17|    channel->flags = SSH_CHANNEL_FLAG_NOT_BOUND;
  ------------------
  |  |   64|     17|#define SSH_CHANNEL_FLAG_NOT_BOUND 0x0008
  ------------------
  127|       |
  128|     17|    if (session->channels == NULL) {
  ------------------
  |  Branch (128:9): [True: 12, False: 5]
  ------------------
  129|     12|        session->channels = ssh_list_new();
  130|     12|        if (session->channels == NULL) {
  ------------------
  |  Branch (130:13): [True: 0, False: 12]
  ------------------
  131|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  132|      0|            SSH_BUFFER_FREE(channel->stdout_buffer);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  133|      0|            SSH_BUFFER_FREE(channel->stderr_buffer);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  134|      0|            SAFE_FREE(channel);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  135|      0|            return NULL;
  136|      0|        }
  137|     12|    }
  138|       |
  139|     17|    ssh_list_prepend(session->channels, channel);
  140|       |
  141|       |    /* Set states explicitly */
  142|     17|    channel->state = SSH_CHANNEL_STATE_NOT_OPEN;
  143|     17|    channel->request_state = SSH_CHANNEL_REQ_STATE_NONE;
  144|       |
  145|     17|    return channel;
  146|     17|}
ssh_channel_new_id:
  158|     17|{
  159|     17|    return ++(session->maxchannel);
  160|     17|}
ssh_packet_channel_open_fail:
  250|     14|{
  251|     14|    ssh_channel channel = NULL;
  252|     14|    char *error = NULL;
  253|     14|    uint32_t code;
  254|     14|    int rc;
  255|     14|    (void)user;
  256|     14|    (void)type;
  257|       |
  258|     14|    channel = channel_from_msg(session, packet);
  259|     14|    if (channel == NULL) {
  ------------------
  |  Branch (259:9): [True: 14, False: 0]
  ------------------
  260|     14|        SSH_LOG(SSH_LOG_RARE, "Invalid channel in packet");
  ------------------
  |  |  283|     14|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  261|     14|        return SSH_PACKET_USED;
  ------------------
  |  |  638|     14|#define SSH_PACKET_USED 1
  ------------------
  262|     14|    }
  263|       |
  264|      0|    rc = ssh_buffer_unpack(packet, "ds", &code, &error);
  ------------------
  |  |   60|      0|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  265|      0|    if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (265:9): [True: 0, False: 0]
  ------------------
  266|      0|        ssh_set_error(session, SSH_FATAL, "Invalid packet");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  267|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  268|      0|    }
  269|       |
  270|      0|    if (channel->state != SSH_CHANNEL_STATE_OPENING) {
  ------------------
  |  Branch (270:9): [True: 0, False: 0]
  ------------------
  271|      0|        SSH_LOG(SSH_LOG_RARE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  272|      0|                "SSH2_MSG_CHANNEL_OPEN_FAILURE received in incorrect channel "
  273|      0|                "state %d",
  274|      0|                channel->state);
  275|      0|        SAFE_FREE(error);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  276|      0|        goto error;
  277|      0|    }
  278|       |
  279|      0|    ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  280|      0|                  SSH_REQUEST_DENIED,
  281|      0|                  "Channel opening failure: channel %" PRIu32 " error (%" PRIu32
  282|      0|                  ") %s",
  283|      0|                  channel->local_channel,
  284|      0|                  code,
  285|      0|                  error);
  286|      0|    SAFE_FREE(error);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  287|      0|    channel->state = SSH_CHANNEL_STATE_OPEN_DENIED;
  288|       |
  289|      0|    ssh_callbacks_execute_list(channel->callbacks,
  ------------------
  |  |  567|      0|    do {                                                      \
  |  |  568|      0|        struct ssh_iterator *i = ssh_list_get_iterator(list); \
  |  |  569|      0|        cbtype cb;                                            \
  |  |  570|      0|        while (i != NULL){                                    \
  |  |  ------------------
  |  |  |  Branch (570:16): [True: 0, False: 0]
  |  |  ------------------
  |  |  571|      0|            cb = ssh_iterator_value(cbtype, i);               \
  |  |  ------------------
  |  |  |  |  122|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  572|      0|            if (ssh_callbacks_exists(cb, c))                  \
  |  |  ------------------
  |  |  |  |  548|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  549|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (549:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (550:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  551|      0|  )
  |  |  ------------------
  |  |  573|      0|                cb-> c (__VA_ARGS__, cb->userdata);           \
  |  |  574|      0|            i = i->next;                                      \
  |  |  575|      0|        }                                                     \
  |  |  576|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (576:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  290|      0|                               ssh_channel_callbacks,
  291|      0|                               channel_open_response_function,
  292|      0|                               channel->session,
  293|      0|                               channel,
  294|      0|                               false /* is_success */);
  295|       |
  296|      0|    return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  297|       |
  298|      0|error:
  299|      0|  ssh_set_error(session, SSH_FATAL, "Invalid packet");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  300|      0|  return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  301|      0|}
ssh_channel_from_local:
  420|     79|{
  421|     79|    struct ssh_iterator *it = NULL;
  422|     79|    ssh_channel channel = NULL;
  423|       |
  424|    206|    for (it = ssh_list_get_iterator(session->channels); it != NULL;
  ------------------
  |  Branch (424:57): [True: 136, False: 70]
  ------------------
  425|    136|         it = it->next) {
  426|    136|        channel = ssh_iterator_value(ssh_channel, it);
  ------------------
  |  |  122|    136|  ((type)((iterator)->data))
  ------------------
  427|    136|        if (channel == NULL) {
  ------------------
  |  Branch (427:13): [True: 0, False: 136]
  ------------------
  428|      0|            continue;
  429|      0|        }
  430|    136|        if (channel->local_channel == id) {
  ------------------
  |  Branch (430:13): [True: 9, False: 127]
  ------------------
  431|      9|            return channel;
  432|      9|        }
  433|    136|    }
  434|       |
  435|     70|    return NULL;
  436|     79|}
channel_rcv_change_window:
  543|    117|{
  544|    117|    ssh_channel channel = NULL;
  545|    117|    uint32_t bytes;
  546|    117|    int rc;
  547|    117|    bool was_empty;
  548|       |
  549|    117|    (void)user;
  550|    117|    (void)type;
  551|       |
  552|    117|    channel = channel_from_msg(session, packet);
  553|    117|    if (channel == NULL) {
  ------------------
  |  Branch (553:9): [True: 116, False: 1]
  ------------------
  554|    116|        SSH_LOG(SSH_LOG_FUNCTIONS, "%s", ssh_get_error(session));
  ------------------
  |  |  283|    116|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  555|    116|    }
  556|       |
  557|    117|    rc = ssh_buffer_unpack(packet, "d", &bytes);
  ------------------
  |  |   60|    117|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|    117|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|    117|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|    117|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|    117|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|    117|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    117|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  558|    117|    if (channel == NULL || rc != SSH_OK) {
  ------------------
  |  |  315|      1|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (558:9): [True: 116, False: 1]
  |  Branch (558:28): [True: 0, False: 1]
  ------------------
  559|    116|        SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|    116|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  560|    116|                "Error getting a window adjust message: invalid packet");
  561|       |
  562|    116|        return SSH_PACKET_USED;
  ------------------
  |  |  638|    116|#define SSH_PACKET_USED 1
  ------------------
  563|    116|    }
  564|       |
  565|      1|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  283|      1|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  566|      1|            "Adding %" PRIu32 " bytes to channel (%" PRIu32 ":%" PRIu32
  567|      1|            ") (from %" PRIu32 " bytes)",
  568|      1|            bytes,
  569|      1|            channel->local_channel,
  570|      1|            channel->remote_channel,
  571|      1|            channel->remote_window);
  572|       |
  573|      1|    was_empty = channel->remote_window == 0;
  574|       |
  575|      1|    if (UINT32_MAX - channel->remote_window < bytes) {
  ------------------
  |  Branch (575:9): [True: 0, False: 1]
  ------------------
  576|      0|        ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  577|      0|                      SSH_FATAL,
  578|      0|                      "Window adjust %" PRIu32 " overflows remote window.",
  579|      0|                      bytes);
  580|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  581|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  582|      0|    }
  583|       |
  584|      1|    channel->remote_window += bytes;
  585|       |
  586|       |    /* Writing to the channel is non-blocking until the receive window is empty.
  587|       |     * When the receive window becomes non-zero again, call
  588|       |     * channel_write_wontblock_function. */
  589|      1|    if (was_empty && bytes > 0) {
  ------------------
  |  Branch (589:9): [True: 0, False: 1]
  |  Branch (589:22): [True: 0, False: 0]
  ------------------
  590|      0|        ssh_callbacks_execute_list(channel->callbacks,
  ------------------
  |  |  567|      0|    do {                                                      \
  |  |  568|      0|        struct ssh_iterator *i = ssh_list_get_iterator(list); \
  |  |  569|      0|        cbtype cb;                                            \
  |  |  570|      0|        while (i != NULL){                                    \
  |  |  ------------------
  |  |  |  Branch (570:16): [True: 0, False: 0]
  |  |  ------------------
  |  |  571|      0|            cb = ssh_iterator_value(cbtype, i);               \
  |  |  ------------------
  |  |  |  |  122|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  572|      0|            if (ssh_callbacks_exists(cb, c))                  \
  |  |  ------------------
  |  |  |  |  548|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  549|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (549:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (550:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  551|      0|  )
  |  |  ------------------
  |  |  573|      0|                cb-> c (__VA_ARGS__, cb->userdata);           \
  |  |  574|      0|            i = i->next;                                      \
  |  |  575|      0|        }                                                     \
  |  |  576|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (576:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  591|      0|                                   ssh_channel_callbacks,
  592|      0|                                   channel_write_wontblock_function,
  593|      0|                                   session,
  594|      0|                                   channel,
  595|      0|                                   channel->remote_window);
  596|      0|    }
  597|       |
  598|      1|    return SSH_PACKET_USED;
  ------------------
  |  |  638|      1|#define SSH_PACKET_USED 1
  ------------------
  599|      1|}
channel_rcv_data:
  603|     77|{
  604|     77|    ssh_channel channel = NULL;
  605|     77|    ssh_string str = NULL;
  606|     77|    ssh_buffer buf = NULL;
  607|     77|    void *data = NULL;
  608|     77|    uint32_t len;
  609|     77|    int extended, is_stderr = 0;
  610|     77|    int rest;
  611|       |
  612|     77|    (void)user;
  613|       |
  614|     77|    if (type == SSH2_MSG_CHANNEL_DATA) {
  ------------------
  |  |   58|     77|#define SSH2_MSG_CHANNEL_DATA 94
  ------------------
  |  Branch (614:9): [True: 64, False: 13]
  ------------------
  615|     64|        extended = 0;
  616|     64|    } else { /* SSH_MSG_CHANNEL_EXTENDED_DATA */
  617|     13|        extended = 1;
  618|     13|    }
  619|       |
  620|     77|    channel = channel_from_msg(session, packet);
  621|     77|    if (channel == NULL) {
  ------------------
  |  Branch (621:9): [True: 69, False: 8]
  ------------------
  622|     69|        SSH_LOG(SSH_LOG_FUNCTIONS, "%s", ssh_get_error(session));
  ------------------
  |  |  283|     69|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  623|       |
  624|     69|        return SSH_PACKET_USED;
  ------------------
  |  |  638|     69|#define SSH_PACKET_USED 1
  ------------------
  625|     69|    }
  626|       |
  627|      8|    if (extended) {
  ------------------
  |  Branch (627:9): [True: 0, False: 8]
  ------------------
  628|      0|        uint32_t data_type_code, rc;
  629|      0|        rc = ssh_buffer_get_u32(packet, &data_type_code);
  630|      0|        if (rc != sizeof(uint32_t)) {
  ------------------
  |  Branch (630:13): [True: 0, False: 0]
  ------------------
  631|      0|            SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  632|      0|                    "Failed to read data type code: rc = %" PRIu32, rc);
  633|       |
  634|      0|            return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  635|      0|        }
  636|      0|        is_stderr = 1;
  637|      0|        data_type_code = ntohl(data_type_code);
  638|      0|        if (data_type_code != SSH2_EXTENDED_DATA_STDERR) {
  ------------------
  |  |   94|      0|#define SSH2_EXTENDED_DATA_STDERR			1
  ------------------
  |  Branch (638:13): [True: 0, False: 0]
  ------------------
  639|      0|            SSH_LOG(SSH_LOG_PACKET, "Invalid data type code %" PRIu32 "!",
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  640|      0|                    data_type_code);
  641|      0|        }
  642|      0|    }
  643|       |
  644|      8|    str = ssh_buffer_get_ssh_string(packet);
  645|      8|    if (str == NULL) {
  ------------------
  |  Branch (645:9): [True: 6, False: 2]
  ------------------
  646|      6|        SSH_LOG(SSH_LOG_PACKET, "Invalid data packet!");
  ------------------
  |  |  283|      6|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  647|       |
  648|      6|        return SSH_PACKET_USED;
  ------------------
  |  |  638|      6|#define SSH_PACKET_USED 1
  ------------------
  649|      6|    }
  650|       |    /* STRING_SIZE_MAX < UINT32_MAX */
  651|      2|    len = (uint32_t)ssh_string_len(str);
  652|       |
  653|      2|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|      4|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (283:34): [True: 0, False: 2]
  |  |  ------------------
  ------------------
  654|      2|            "Channel receiving %" PRIu32 " bytes data%s (local win=%" PRIu32
  655|      2|            " remote win=%" PRIu32 ") on channel %" PRIu32 ":%" PRIu32,
  656|      2|            len,
  657|      2|            is_stderr ? " in stderr" : "",
  658|      2|            channel->local_window,
  659|      2|            channel->remote_window,
  660|      2|            channel->local_channel,
  661|      2|            channel->remote_channel);
  662|       |
  663|      2|    if (channel->flags & SSH_CHANNEL_FLAG_CLOSED_REMOTE) {
  ------------------
  |  |   55|      2|#define SSH_CHANNEL_FLAG_CLOSED_REMOTE 0x0001
  ------------------
  |  Branch (663:9): [True: 0, False: 2]
  ------------------
  664|      0|        SSH_LOG(SSH_LOG_WARNING, "Received data on (remotely) closed channel");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  665|      0|        ssh_set_error(session, SSH_FATAL, "Received data on (remotely) closed channel");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  666|      0|        SSH_STRING_FREE(str);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  667|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  668|      0|    }
  669|       |
  670|      2|    if (len > channel->local_window) {
  ------------------
  |  Branch (670:9): [True: 0, False: 2]
  ------------------
  671|      0|        SSH_LOG(SSH_LOG_RARE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  672|      0|                "Data packet too big for our window(%" PRIu32 " vs %" PRIu32 ")",
  673|      0|                len,
  674|      0|                channel->local_window);
  675|       |
  676|      0|        SSH_STRING_FREE(str);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  677|       |
  678|      0|        ssh_set_error(session, SSH_FATAL, "Window exceeded");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  679|       |
  680|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  681|      0|    }
  682|       |
  683|      2|    data = ssh_string_data(str);
  684|      2|    if (channel_default_bufferize(channel, data, len, is_stderr) < 0) {
  ------------------
  |  Branch (684:9): [True: 0, False: 2]
  ------------------
  685|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  686|       |
  687|      0|        SSH_STRING_FREE(str);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  688|       |
  689|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  690|      0|    }
  691|       |
  692|      2|    channel->local_window -= len;
  693|       |
  694|      2|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|      2|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  695|      2|            "Channel windows are now (local win=%" PRIu32 " remote win=%" PRIu32 ")",
  696|      2|            channel->local_window,
  697|      2|            channel->remote_window);
  698|       |
  699|      2|    SSH_STRING_FREE(str);
  ------------------
  |  |  882|      2|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 2, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 2]
  |  |  ------------------
  ------------------
  700|       |
  701|      2|    if (is_stderr) {
  ------------------
  |  Branch (701:9): [True: 0, False: 2]
  ------------------
  702|      0|        buf = channel->stderr_buffer;
  703|      2|    } else {
  704|      2|        buf = channel->stdout_buffer;
  705|      2|    }
  706|       |
  707|      2|    ssh_callbacks_iterate(channel->callbacks,
  ------------------
  |  |  599|      2|    do {                                                              \
  |  |  600|      2|        struct ssh_iterator *_cb_i = ssh_list_get_iterator(_cb_list); \
  |  |  601|      2|        _cb_type _cb;                                                 \
  |  |  602|      2|        for (; _cb_i != NULL; _cb_i = _cb_i->next) {                  \
  |  |  ------------------
  |  |  |  Branch (602:16): [True: 0, False: 2]
  |  |  ------------------
  |  |  603|      0|            _cb = ssh_iterator_value(_cb_type, _cb_i);                \
  |  |  ------------------
  |  |  |  |  122|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  604|      0|            if (ssh_callbacks_exists(_cb, _cb_name))
  |  |  ------------------
  |  |  |  |  548|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  549|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (549:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (550:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  551|      0|  )
  |  |  ------------------
  ------------------
  708|      2|                          ssh_channel_callbacks,
  709|      2|                          channel_data_function) {
  710|      0|        if (ssh_buffer_get(buf) == NULL) {
  ------------------
  |  Branch (710:13): [True: 0, False: 0]
  ------------------
  711|      0|            break;
  712|      0|        }
  713|      0|        rest = ssh_callbacks_iterate_exec(channel_data_function,
  ------------------
  |  |  613|      0|                _cb->_cb_name(__VA_ARGS__, _cb->userdata)
  ------------------
  714|      0|                                          channel->session,
  715|      0|                                          channel,
  716|      0|                                          ssh_buffer_get(buf),
  717|      0|                                          ssh_buffer_get_len(buf),
  718|      0|                                          is_stderr);
  719|      0|        if (rest > 0) {
  ------------------
  |  Branch (719:13): [True: 0, False: 0]
  ------------------
  720|      0|            int rc;
  721|      0|            if (channel->counter != NULL) {
  ------------------
  |  Branch (721:17): [True: 0, False: 0]
  ------------------
  722|      0|                channel->counter->in_bytes += rest;
  723|      0|            }
  724|      0|            ssh_buffer_pass_bytes(buf, rest);
  725|       |
  726|      0|            rc = grow_window(session, channel);
  727|      0|            if (rc == SSH_ERROR) {
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (727:17): [True: 0, False: 0]
  ------------------
  728|      0|              return -1;
  729|      0|            }
  730|      0|        }
  731|      0|    }
  732|      2|    ssh_callbacks_iterate_end();
  ------------------
  |  |  619|      0|        }                           \
  |  |  620|      2|    } while(0)
  |  |  ------------------
  |  |  |  Branch (620:13): [Folded, False: 2]
  |  |  ------------------
  ------------------
  733|       |
  734|      2|    return SSH_PACKET_USED;
  ------------------
  |  |  638|      2|#define SSH_PACKET_USED 1
  ------------------
  735|      2|}
channel_rcv_eof:
  738|     41|{
  739|     41|    ssh_channel channel = NULL;
  740|     41|    (void)user;
  741|     41|    (void)type;
  742|       |
  743|     41|    channel = channel_from_msg(session, packet);
  744|     41|    if (channel == NULL) {
  ------------------
  |  Branch (744:9): [True: 41, False: 0]
  ------------------
  745|     41|        SSH_LOG(SSH_LOG_FUNCTIONS, "%s", ssh_get_error(session));
  ------------------
  |  |  283|     41|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  746|       |
  747|     41|        return SSH_PACKET_USED;
  ------------------
  |  |  638|     41|#define SSH_PACKET_USED 1
  ------------------
  748|     41|    }
  749|       |
  750|      0|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  751|      0|            "Received eof on channel (%" PRIu32 ":%" PRIu32 ")",
  752|      0|            channel->local_channel,
  753|      0|            channel->remote_channel);
  754|       |    /* channel->remote_window = 0; */
  755|      0|    channel->remote_eof = 1;
  756|       |
  757|      0|    ssh_callbacks_execute_list(channel->callbacks,
  ------------------
  |  |  567|      0|    do {                                                      \
  |  |  568|      0|        struct ssh_iterator *i = ssh_list_get_iterator(list); \
  |  |  569|      0|        cbtype cb;                                            \
  |  |  570|      0|        while (i != NULL){                                    \
  |  |  ------------------
  |  |  |  Branch (570:16): [True: 0, False: 0]
  |  |  ------------------
  |  |  571|      0|            cb = ssh_iterator_value(cbtype, i);               \
  |  |  ------------------
  |  |  |  |  122|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  572|      0|            if (ssh_callbacks_exists(cb, c))                  \
  |  |  ------------------
  |  |  |  |  548|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  549|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (549:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (550:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  551|      0|  )
  |  |  ------------------
  |  |  573|      0|                cb-> c (__VA_ARGS__, cb->userdata);           \
  |  |  574|      0|            i = i->next;                                      \
  |  |  575|      0|        }                                                     \
  |  |  576|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (576:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  758|      0|                               ssh_channel_callbacks,
  759|      0|                               channel_eof_function,
  760|      0|                               channel->session,
  761|      0|                               channel);
  762|       |
  763|      0|    return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  764|     41|}
channel_rcv_request:
  831|      1|{
  832|      1|    ssh_channel channel = NULL;
  833|      1|    char *request = NULL;
  834|      1|    uint8_t want_reply;
  835|      1|    int rc;
  836|      1|    (void)user;
  837|      1|    (void)type;
  838|       |
  839|      1|    channel = channel_from_msg(session, packet);
  840|      1|    if (channel == NULL) {
  ------------------
  |  Branch (840:9): [True: 1, False: 0]
  ------------------
  841|      1|        SSH_LOG(SSH_LOG_FUNCTIONS, "%s", ssh_get_error(session));
  ------------------
  |  |  283|      1|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  842|      1|        return SSH_PACKET_USED;
  ------------------
  |  |  638|      1|#define SSH_PACKET_USED 1
  ------------------
  843|      1|    }
  844|       |
  845|      0|    rc = ssh_buffer_unpack(packet, "sb", &request, &want_reply);
  ------------------
  |  |   60|      0|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  846|      0|    if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (846:9): [True: 0, False: 0]
  ------------------
  847|      0|        SSH_LOG(SSH_LOG_PACKET, "Invalid MSG_CHANNEL_REQUEST");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  848|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  849|      0|    }
  850|       |
  851|      0|    if (strcmp(request, "exit-status") == 0) {
  ------------------
  |  Branch (851:9): [True: 0, False: 0]
  ------------------
  852|      0|        SAFE_FREE(request);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  853|      0|        rc = ssh_buffer_unpack(packet, "d", &channel->exit.code);
  ------------------
  |  |   60|      0|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  854|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (854:13): [True: 0, False: 0]
  ------------------
  855|      0|            SSH_LOG(SSH_LOG_PACKET, "Invalid exit-status packet");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  856|      0|            return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  857|      0|        }
  858|      0|        channel->exit.status = true;
  859|       |
  860|      0|        SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  861|      0|                "received exit-status %u on channel %" PRIu32 ":%" PRIu32,
  862|      0|                channel->exit.code,
  863|      0|                channel->local_channel,
  864|      0|                channel->remote_channel);
  865|       |
  866|      0|        ssh_callbacks_execute_list(channel->callbacks,
  ------------------
  |  |  567|      0|    do {                                                      \
  |  |  568|      0|        struct ssh_iterator *i = ssh_list_get_iterator(list); \
  |  |  569|      0|        cbtype cb;                                            \
  |  |  570|      0|        while (i != NULL){                                    \
  |  |  ------------------
  |  |  |  Branch (570:16): [True: 0, False: 0]
  |  |  ------------------
  |  |  571|      0|            cb = ssh_iterator_value(cbtype, i);               \
  |  |  ------------------
  |  |  |  |  122|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  572|      0|            if (ssh_callbacks_exists(cb, c))                  \
  |  |  ------------------
  |  |  |  |  548|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  549|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (549:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (550:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  551|      0|  )
  |  |  ------------------
  |  |  573|      0|                cb-> c (__VA_ARGS__, cb->userdata);           \
  |  |  574|      0|            i = i->next;                                      \
  |  |  575|      0|        }                                                     \
  |  |  576|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (576:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  867|      0|                                   ssh_channel_callbacks,
  868|      0|                                   channel_exit_status_function,
  869|      0|                                   channel->session,
  870|      0|                                   channel,
  871|      0|                                   channel->exit.code);
  872|       |
  873|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  874|      0|    }
  875|       |
  876|      0|    if (strcmp(request, "signal") == 0) {
  ------------------
  |  Branch (876:9): [True: 0, False: 0]
  ------------------
  877|      0|        char *sig = NULL;
  878|       |
  879|      0|        SAFE_FREE(request);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  880|      0|        SSH_LOG(SSH_LOG_PACKET, "received signal");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  881|       |
  882|      0|        rc = ssh_buffer_unpack(packet, "s", &sig);
  ------------------
  |  |   60|      0|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  883|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (883:13): [True: 0, False: 0]
  ------------------
  884|      0|            SSH_LOG(SSH_LOG_PACKET, "Invalid MSG_CHANNEL_REQUEST");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  885|      0|            return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  886|      0|        }
  887|       |
  888|      0|        SSH_LOG(SSH_LOG_PACKET, "Remote connection sent a signal SIG %s", sig);
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  889|      0|        ssh_callbacks_execute_list(channel->callbacks,
  ------------------
  |  |  567|      0|    do {                                                      \
  |  |  568|      0|        struct ssh_iterator *i = ssh_list_get_iterator(list); \
  |  |  569|      0|        cbtype cb;                                            \
  |  |  570|      0|        while (i != NULL){                                    \
  |  |  ------------------
  |  |  |  Branch (570:16): [True: 0, False: 0]
  |  |  ------------------
  |  |  571|      0|            cb = ssh_iterator_value(cbtype, i);               \
  |  |  ------------------
  |  |  |  |  122|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  572|      0|            if (ssh_callbacks_exists(cb, c))                  \
  |  |  ------------------
  |  |  |  |  548|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  549|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (549:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (550:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  551|      0|  )
  |  |  ------------------
  |  |  573|      0|                cb-> c (__VA_ARGS__, cb->userdata);           \
  |  |  574|      0|            i = i->next;                                      \
  |  |  575|      0|        }                                                     \
  |  |  576|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (576:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  890|      0|                                   ssh_channel_callbacks,
  891|      0|                                   channel_signal_function,
  892|      0|                                   channel->session,
  893|      0|                                   channel,
  894|      0|                                   sig);
  895|      0|        SAFE_FREE(sig);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  896|       |
  897|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  898|      0|    }
  899|       |
  900|      0|    if (strcmp(request, "exit-signal") == 0) {
  ------------------
  |  Branch (900:9): [True: 0, False: 0]
  ------------------
  901|      0|        const char *core = "(core dumped)";
  902|      0|        char *sig = NULL;
  903|      0|        char *errmsg = NULL;
  904|      0|        char *lang = NULL;
  905|      0|        uint8_t core_dumped;
  906|       |
  907|      0|        SAFE_FREE(request);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  908|       |
  909|      0|        rc = ssh_buffer_unpack(packet,
  ------------------
  |  |   60|      0|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  910|      0|                               "sbss",
  911|      0|                               &sig,         /* signal name */
  912|      0|                               &core_dumped, /* core dumped */
  913|      0|                               &errmsg,      /* error message */
  914|      0|                               &lang);
  915|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (915:13): [True: 0, False: 0]
  ------------------
  916|      0|            SSH_LOG(SSH_LOG_PACKET, "Invalid MSG_CHANNEL_REQUEST");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  917|      0|            return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  918|      0|        }
  919|       |
  920|      0|        if (core_dumped == 0) {
  ------------------
  |  Branch (920:13): [True: 0, False: 0]
  ------------------
  921|      0|            core = "";
  922|      0|        }
  923|       |
  924|      0|        SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  925|      0|                "Remote connection closed by signal SIG %s %s",
  926|      0|                sig,
  927|      0|                core);
  928|      0|        ssh_callbacks_execute_list(channel->callbacks,
  ------------------
  |  |  567|      0|    do {                                                      \
  |  |  568|      0|        struct ssh_iterator *i = ssh_list_get_iterator(list); \
  |  |  569|      0|        cbtype cb;                                            \
  |  |  570|      0|        while (i != NULL){                                    \
  |  |  ------------------
  |  |  |  Branch (570:16): [True: 0, False: 0]
  |  |  ------------------
  |  |  571|      0|            cb = ssh_iterator_value(cbtype, i);               \
  |  |  ------------------
  |  |  |  |  122|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  572|      0|            if (ssh_callbacks_exists(cb, c))                  \
  |  |  ------------------
  |  |  |  |  548|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  549|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (549:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (550:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  551|      0|  )
  |  |  ------------------
  |  |  573|      0|                cb-> c (__VA_ARGS__, cb->userdata);           \
  |  |  574|      0|            i = i->next;                                      \
  |  |  575|      0|        }                                                     \
  |  |  576|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (576:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  929|      0|                                   ssh_channel_callbacks,
  930|      0|                                   channel_exit_signal_function,
  931|      0|                                   channel->session,
  932|      0|                                   channel,
  933|      0|                                   sig,
  934|      0|                                   core_dumped,
  935|      0|                                   errmsg,
  936|      0|                                   lang);
  937|       |
  938|      0|        channel->exit.core_dumped = core_dumped;
  939|      0|        if (sig != NULL) {
  ------------------
  |  Branch (939:13): [True: 0, False: 0]
  ------------------
  940|      0|            SAFE_FREE(channel->exit.signal);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  941|      0|            channel->exit.signal = sig;
  942|      0|        }
  943|      0|        channel->exit.status = true;
  944|       |
  945|      0|        SAFE_FREE(lang);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  946|      0|        SAFE_FREE(errmsg);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  947|       |
  948|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  949|      0|    }
  950|      0|    if (strcmp(request, "keepalive@openssh.com") == 0) {
  ------------------
  |  Branch (950:9): [True: 0, False: 0]
  ------------------
  951|      0|        SAFE_FREE(request);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  952|      0|        SSH_LOG(SSH_LOG_DEBUG, "Responding to Openssh's keepalive");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  953|       |
  954|      0|        rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  955|      0|                             "bd",
  956|      0|                             SSH2_MSG_CHANNEL_FAILURE,
  957|      0|                             channel->remote_channel);
  958|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (958:13): [True: 0, False: 0]
  ------------------
  959|      0|            return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  960|      0|        }
  961|      0|        ssh_packet_send(session);
  962|       |
  963|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  964|      0|    }
  965|       |
  966|      0|    if (strcmp(request, "auth-agent-req") == 0 ||
  ------------------
  |  Branch (966:9): [True: 0, False: 0]
  ------------------
  967|      0|        strcmp(request, "auth-agent-req@openssh.com") == 0) {
  ------------------
  |  Branch (967:9): [True: 0, False: 0]
  ------------------
  968|      0|        int status;
  969|       |
  970|      0|        SAFE_FREE(request);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  971|      0|        SSH_LOG(SSH_LOG_DEBUG, "Received an auth-agent-req request");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  972|       |
  973|      0|        status = SSH2_MSG_CHANNEL_FAILURE;
  ------------------
  |  |   64|      0|#define SSH2_MSG_CHANNEL_FAILURE 100
  ------------------
  974|      0|        ssh_callbacks_iterate (channel->callbacks,
  ------------------
  |  |  599|      0|    do {                                                              \
  |  |  600|      0|        struct ssh_iterator *_cb_i = ssh_list_get_iterator(_cb_list); \
  |  |  601|      0|        _cb_type _cb;                                                 \
  |  |  602|      0|        for (; _cb_i != NULL; _cb_i = _cb_i->next) {                  \
  |  |  ------------------
  |  |  |  Branch (602:16): [True: 0, False: 0]
  |  |  ------------------
  |  |  603|      0|            _cb = ssh_iterator_value(_cb_type, _cb_i);                \
  |  |  ------------------
  |  |  |  |  122|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  604|      0|            if (ssh_callbacks_exists(_cb, _cb_name))
  |  |  ------------------
  |  |  |  |  548|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  549|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (549:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (550:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  551|      0|  )
  |  |  ------------------
  ------------------
  975|      0|                               ssh_channel_callbacks,
  976|      0|                               channel_auth_agent_req_function) {
  977|      0|            ssh_callbacks_iterate_exec(channel_auth_agent_req_function,
  ------------------
  |  |  613|      0|                _cb->_cb_name(__VA_ARGS__, _cb->userdata)
  ------------------
  978|      0|                                       channel->session,
  979|      0|                                       channel);
  980|       |            /* in lieu of a return value, if the callback exists it's supported
  981|       |             */
  982|      0|            status = SSH2_MSG_CHANNEL_SUCCESS;
  ------------------
  |  |   63|      0|#define SSH2_MSG_CHANNEL_SUCCESS 99
  ------------------
  983|      0|            break;
  984|      0|        }
  985|      0|        ssh_callbacks_iterate_end();
  ------------------
  |  |  619|      0|        }                           \
  |  |  620|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (620:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  986|       |
  987|      0|        if (want_reply) {
  ------------------
  |  Branch (987:13): [True: 0, False: 0]
  ------------------
  988|      0|            rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  989|      0|                                 "bd",
  990|      0|                                 status,
  991|      0|                                 channel->remote_channel);
  992|      0|            if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (992:17): [True: 0, False: 0]
  ------------------
  993|      0|                return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  994|      0|            }
  995|      0|            ssh_packet_send(session);
  996|      0|        }
  997|       |
  998|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  999|      0|    }
 1000|      0|#ifdef WITH_SERVER
 1001|       |    /* If we are here, that means we have a request that is not in the
 1002|       |     * understood client requests. That means we need to create a ssh message to
 1003|       |     * be passed to the user code handling ssh messages
 1004|       |     */
 1005|      0|    ssh_message_handle_channel_request(session,
 1006|      0|                                       channel,
 1007|      0|                                       packet,
 1008|      0|                                       request,
 1009|      0|                                       want_reply);
 1010|       |#else
 1011|       |    SSH_LOG(SSH_LOG_DEBUG, "Unhandled channel request %s", request);
 1012|       |#endif
 1013|       |
 1014|      0|    SAFE_FREE(request);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1015|       |
 1016|      0|    return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
 1017|      0|}
channel_default_bufferize:
 1028|      2|{
 1029|      2|    ssh_session session = NULL;
 1030|       |
 1031|      2|    if (channel == NULL) {
  ------------------
  |  Branch (1031:9): [True: 0, False: 2]
  ------------------
 1032|      0|        return -1;
 1033|      0|    }
 1034|       |
 1035|      2|    session = channel->session;
 1036|       |
 1037|      2|    if (data == NULL) {
  ------------------
  |  Branch (1037:9): [True: 0, False: 2]
  ------------------
 1038|      0|        ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1039|      0|        return -1;
 1040|      0|    }
 1041|       |
 1042|      2|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|      4|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (283:34): [True: 0, False: 2]
  |  |  ------------------
  ------------------
 1043|      2|            "placing %" PRIu32 " bytes into channel buffer (%s)",
 1044|      2|            len,
 1045|      2|            is_stderr ? "stderr" : "stdout");
 1046|      2|    if (!is_stderr) {
  ------------------
  |  Branch (1046:9): [True: 2, False: 0]
  ------------------
 1047|       |        /* stdout */
 1048|      2|        if (channel->stdout_buffer == NULL) {
  ------------------
  |  Branch (1048:13): [True: 0, False: 2]
  ------------------
 1049|      0|            channel->stdout_buffer = ssh_buffer_new();
 1050|      0|            if (channel->stdout_buffer == NULL) {
  ------------------
  |  Branch (1050:17): [True: 0, False: 0]
  ------------------
 1051|      0|                ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1052|      0|                return -1;
 1053|      0|            }
 1054|      0|        }
 1055|       |
 1056|       |        /* On failure the buffer is unchanged. Keep it: the data already
 1057|       |         * buffered is still valid and the readers expect the buffer */
 1058|      2|        if (ssh_buffer_add_data(channel->stdout_buffer, data, len) < 0) {
  ------------------
  |  Branch (1058:13): [True: 0, False: 2]
  ------------------
 1059|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1060|      0|            return -1;
 1061|      0|        }
 1062|      2|    } else {
 1063|       |        /* stderr */
 1064|      0|        if (channel->stderr_buffer == NULL) {
  ------------------
  |  Branch (1064:13): [True: 0, False: 0]
  ------------------
 1065|      0|            channel->stderr_buffer = ssh_buffer_new();
 1066|      0|            if (channel->stderr_buffer == NULL) {
  ------------------
  |  Branch (1066:17): [True: 0, False: 0]
  ------------------
 1067|      0|                ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1068|      0|                return -1;
 1069|      0|            }
 1070|      0|        }
 1071|       |
 1072|       |        /* On failure the buffer is unchanged. Keep it: the data already
 1073|       |         * buffered is still valid and the readers expect the buffer */
 1074|      0|        if (ssh_buffer_add_data(channel->stderr_buffer, data, len) < 0) {
  ------------------
  |  Branch (1074:13): [True: 0, False: 0]
  ------------------
 1075|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1076|      0|            return -1;
 1077|      0|        }
 1078|      0|    }
 1079|       |
 1080|      2|    return 0;
 1081|      2|}
ssh_channel_do_free:
 1359|     17|{
 1360|     17|    struct ssh_iterator *it = NULL;
 1361|     17|    ssh_session session = channel->session;
 1362|       |
 1363|     17|    it = ssh_list_find(session->channels, channel);
 1364|     17|    if (it != NULL) {
  ------------------
  |  Branch (1364:9): [True: 17, False: 0]
  ------------------
 1365|     17|        ssh_list_remove(session->channels, it);
 1366|     17|    }
 1367|       |
 1368|       |    /* Drop queued requests that still point to this channel */
 1369|     17|    it = ssh_list_get_iterator(session->ssh_message_list);
 1370|     17|    while (it != NULL) {
  ------------------
  |  Branch (1370:12): [True: 0, False: 17]
  ------------------
 1371|      0|        struct ssh_iterator *next = it->next;
 1372|      0|        ssh_message msg = ssh_iterator_value(ssh_message, it);
  ------------------
  |  |  122|      0|  ((type)((iterator)->data))
  ------------------
 1373|       |
 1374|      0|        if (msg->type == SSH_REQUEST_CHANNEL &&
  ------------------
  |  Branch (1374:13): [True: 0, False: 0]
  ------------------
 1375|      0|            msg->channel_request.channel == channel) {
  ------------------
  |  Branch (1375:13): [True: 0, False: 0]
  ------------------
 1376|      0|            ssh_list_remove(session->ssh_message_list, it);
 1377|      0|            SSH_MESSAGE_FREE(msg);
  ------------------
  |  |  685|      0|    do { if ((x) != NULL) { ssh_message_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (685:14): [True: 0, False: 0]
  |  |  |  Branch (685:72): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1378|      0|        }
 1379|      0|        it = next;
 1380|      0|    }
 1381|       |
 1382|     17|    SSH_BUFFER_FREE(channel->stdout_buffer);
  ------------------
  |  |  924|     17|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 17, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 17]
  |  |  ------------------
  ------------------
 1383|     17|    SSH_BUFFER_FREE(channel->stderr_buffer);
  ------------------
  |  |  924|     17|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 17, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 17]
  |  |  ------------------
  ------------------
 1384|       |
 1385|     17|    if (channel->callbacks != NULL) {
  ------------------
  |  Branch (1385:9): [True: 0, False: 17]
  ------------------
 1386|      0|        ssh_list_free(channel->callbacks);
 1387|      0|        channel->callbacks = NULL;
 1388|      0|    }
 1389|     17|    SAFE_FREE(channel->exit.signal);
  ------------------
  |  |  375|     17|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 17]
  |  |  |  Branch (375:71): [Folded, False: 17]
  |  |  ------------------
  ------------------
 1390|       |
 1391|     17|    channel->session = NULL;
 1392|       |    SAFE_FREE(channel);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1393|     17|}
ssh_packet_channel_success:
 1849|      1|{
 1850|      1|    ssh_channel channel = NULL;
 1851|      1|    (void)type;
 1852|      1|    (void)user;
 1853|       |
 1854|      1|    channel = channel_from_msg(session, packet);
 1855|      1|    if (channel == NULL) {
  ------------------
  |  Branch (1855:9): [True: 1, False: 0]
  ------------------
 1856|      1|        SSH_LOG(SSH_LOG_FUNCTIONS, "%s", ssh_get_error(session));
  ------------------
  |  |  283|      1|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1857|      1|        return SSH_PACKET_USED;
  ------------------
  |  |  638|      1|#define SSH_PACKET_USED 1
  ------------------
 1858|      1|    }
 1859|       |
 1860|      0|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1861|      0|            "Received SSH_CHANNEL_SUCCESS on channel (%" PRIu32 ":%" PRIu32 ")",
 1862|      0|            channel->local_channel,
 1863|      0|            channel->remote_channel);
 1864|      0|    if (channel->request_state != SSH_CHANNEL_REQ_STATE_PENDING) {
  ------------------
  |  Branch (1864:9): [True: 0, False: 0]
  ------------------
 1865|      0|        SSH_LOG(SSH_LOG_RARE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1866|      0|                "SSH_CHANNEL_SUCCESS received in incorrect state %d",
 1867|      0|                channel->request_state);
 1868|      0|    } else {
 1869|      0|        channel->request_state = SSH_CHANNEL_REQ_STATE_ACCEPTED;
 1870|       |
 1871|      0|        ssh_callbacks_execute_list(channel->callbacks,
  ------------------
  |  |  567|      0|    do {                                                      \
  |  |  568|      0|        struct ssh_iterator *i = ssh_list_get_iterator(list); \
  |  |  569|      0|        cbtype cb;                                            \
  |  |  570|      0|        while (i != NULL){                                    \
  |  |  ------------------
  |  |  |  Branch (570:16): [True: 0, False: 0]
  |  |  ------------------
  |  |  571|      0|            cb = ssh_iterator_value(cbtype, i);               \
  |  |  ------------------
  |  |  |  |  122|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  572|      0|            if (ssh_callbacks_exists(cb, c))                  \
  |  |  ------------------
  |  |  |  |  548|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  549|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (549:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (550:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  551|      0|  )
  |  |  ------------------
  |  |  573|      0|                cb-> c (__VA_ARGS__, cb->userdata);           \
  |  |  574|      0|            i = i->next;                                      \
  |  |  575|      0|        }                                                     \
  |  |  576|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (576:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1872|      0|                                   ssh_channel_callbacks,
 1873|      0|                                   channel_request_response_function,
 1874|      0|                                   channel->session,
 1875|      0|                                   channel);
 1876|      0|    }
 1877|       |
 1878|      0|    return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
 1879|      1|}
ssh_request_success:
 2482|      1|SSH_PACKET_CALLBACK(ssh_request_success){
 2483|      1|  (void)type;
 2484|      1|  (void)user;
 2485|      1|  (void)packet;
 2486|       |
 2487|      1|  SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|      1|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2488|      1|      "Received SSH_REQUEST_SUCCESS");
 2489|      1|  if(session->global_req_state != SSH_CHANNEL_REQ_STATE_PENDING){
  ------------------
  |  Branch (2489:6): [True: 1, False: 0]
  ------------------
 2490|      1|    SSH_LOG(SSH_LOG_RARE, "SSH_REQUEST_SUCCESS received in incorrect state %d",
  ------------------
  |  |  283|      1|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2491|      1|        session->global_req_state);
 2492|      1|  } else {
 2493|      0|    session->global_req_state=SSH_CHANNEL_REQ_STATE_ACCEPTED;
 2494|      0|  }
 2495|       |
 2496|      1|  return SSH_PACKET_USED;
  ------------------
  |  |  638|      1|#define SSH_PACKET_USED 1
  ------------------
 2497|      1|}
ssh_request_denied:
 2505|      1|SSH_PACKET_CALLBACK(ssh_request_denied){
 2506|      1|  (void)type;
 2507|      1|  (void)user;
 2508|      1|  (void)packet;
 2509|       |
 2510|      1|  SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|      1|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2511|      1|      "Received SSH_REQUEST_FAILURE");
 2512|      1|  if(session->global_req_state != SSH_CHANNEL_REQ_STATE_PENDING){
  ------------------
  |  Branch (2512:6): [True: 1, False: 0]
  ------------------
 2513|      1|    SSH_LOG(SSH_LOG_RARE, "SSH_REQUEST_DENIED received in incorrect state %d",
  ------------------
  |  |  283|      1|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2514|      1|        session->global_req_state);
 2515|      1|  } else {
 2516|      0|    session->global_req_state=SSH_CHANNEL_REQ_STATE_DENIED;
 2517|      0|  }
 2518|       |
 2519|      1|  return SSH_PACKET_USED;
  ------------------
  |  |  638|      1|#define SSH_PACKET_USED 1
  ------------------
 2520|       |
 2521|      1|}
channels.c:channel_from_msg:
  518|    251|{
  519|    251|    ssh_channel channel = NULL;
  520|    251|    uint32_t chan;
  521|    251|    int rc;
  522|       |
  523|    251|    rc = ssh_buffer_unpack(packet, "d", &chan);
  ------------------
  |  |   60|    251|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|    251|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|    251|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|    251|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|    251|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|    251|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    251|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  524|    251|    if (rc != SSH_OK) {
  ------------------
  |  |  315|    251|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (524:9): [True: 172, False: 79]
  ------------------
  525|    172|        ssh_set_error(session,
  ------------------
  |  |  313|    172|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  526|    172|                      SSH_FATAL,
  527|    172|                      "Getting channel from message: short read");
  528|    172|        return NULL;
  529|    172|    }
  530|       |
  531|     79|    channel = ssh_channel_from_local(session, chan);
  532|     79|    if (channel == NULL) {
  ------------------
  |  Branch (532:9): [True: 70, False: 9]
  ------------------
  533|     70|        ssh_set_error(session,
  ------------------
  |  |  313|     70|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  534|     70|                      SSH_FATAL,
  535|     70|                      "Server specified invalid channel %" PRIu32,
  536|     70|                      (uint32_t)chan);
  537|     70|    }
  538|       |
  539|     79|    return channel;
  540|    251|}

ssh_send_banner:
  187|    319|{
  188|    319|    const char *banner = CLIENT_BANNER_SSH2;
  ------------------
  |  |  223|    319|#define CLIENT_BANNER_SSH2 "SSH-2.0-libssh_" SSH_STRINGIFY(LIBSSH_VERSION)
  |  |  ------------------
  |  |  |  |   71|    319|#define SSH_STRINGIFY(s) SSH_TOSTRING(s)
  |  |  |  |  ------------------
  |  |  |  |  |  |   72|    319|#define SSH_TOSTRING(s) #s
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  189|    319|    const char *terminator = "\r\n";
  190|       |    /* The maximum banner length is 255 for SSH2 */
  191|    319|    char buffer[256] = {0};
  192|    319|    size_t len;
  193|    319|    int rc = SSH_ERROR;
  ------------------
  |  |  316|    319|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  194|       |
  195|    319|    if (server == 1) {
  ------------------
  |  Branch (195:9): [True: 319, False: 0]
  ------------------
  196|    319|        if (session->server_opts.custombanner == NULL) {
  ------------------
  |  Branch (196:13): [True: 319, False: 0]
  ------------------
  197|    319|            session->serverbanner = strdup(banner);
  198|    319|            if (session->serverbanner == NULL) {
  ------------------
  |  Branch (198:17): [True: 0, False: 319]
  ------------------
  199|      0|                goto end;
  200|      0|            }
  201|    319|        } else {
  202|      0|            len = strlen(session->server_opts.custombanner);
  203|      0|            session->serverbanner = malloc(len + 8 + 1);
  204|      0|            if(session->serverbanner == NULL) {
  ------------------
  |  Branch (204:16): [True: 0, False: 0]
  ------------------
  205|      0|                goto end;
  206|      0|            }
  207|      0|            snprintf(session->serverbanner,
  208|      0|                     len + 8 + 1,
  209|      0|                     "SSH-2.0-%s",
  210|      0|                     session->server_opts.custombanner);
  211|      0|        }
  212|       |
  213|    319|        snprintf(buffer,
  214|    319|                 sizeof(buffer),
  215|    319|                 "%s%s",
  216|    319|                 session->serverbanner,
  217|    319|                 terminator);
  218|    319|    } else {
  219|      0|        session->clientbanner = strdup(banner);
  220|      0|        if (session->clientbanner == NULL) {
  ------------------
  |  Branch (220:13): [True: 0, False: 0]
  ------------------
  221|      0|            goto end;
  222|      0|        }
  223|       |
  224|      0|        snprintf(buffer,
  225|      0|                 sizeof(buffer),
  226|      0|                 "%s%s",
  227|      0|                 session->clientbanner,
  228|      0|                 terminator);
  229|      0|    }
  230|       |
  231|    319|    rc = ssh_socket_write(session->socket, buffer, (uint32_t)strlen(buffer));
  232|    319|    if (rc == SSH_ERROR) {
  ------------------
  |  |  316|    319|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (232:9): [True: 0, False: 319]
  ------------------
  233|      0|        goto end;
  234|      0|    }
  235|    319|#ifdef WITH_PCAP
  236|    319|    if (session->pcap_ctx != NULL) {
  ------------------
  |  Branch (236:9): [True: 0, False: 319]
  ------------------
  237|      0|        ssh_pcap_context_write(session->pcap_ctx,
  238|      0|                               SSH_PCAP_DIR_OUT,
  239|      0|                               buffer,
  240|      0|                               (uint32_t)strlen(buffer),
  241|      0|                               (uint32_t)strlen(buffer));
  242|      0|    }
  243|    319|#endif
  244|       |
  245|    319|    rc = SSH_OK;
  ------------------
  |  |  315|    319|#define SSH_OK 0     /* No error */
  ------------------
  246|    319|end:
  247|    319|    return rc;
  248|    319|}
ssh_disconnect:
  809|  1.29k|{
  810|  1.29k|    struct ssh_iterator *it = NULL;
  811|  1.29k|    int rc;
  812|       |
  813|  1.29k|    if (session == NULL) {
  ------------------
  |  Branch (813:9): [True: 639, False: 660]
  ------------------
  814|    639|        return;
  815|    639|    }
  816|       |
  817|    660|#ifndef _WIN32
  818|    660|#ifdef HAVE_PTHREAD
  819|       |    /* Only send the disconnect to all other threads when the root session calls
  820|       |     * ssh_disconnect() */
  821|    660|    if (session->proxy_root) {
  ------------------
  |  Branch (821:9): [True: 660, False: 0]
  ------------------
  822|    660|        proxy_disconnect = 1;
  823|    660|    }
  824|    660|#endif /* HAVE_PTHREAD */
  825|    660|#endif /* _WIN32 */
  826|       |
  827|    660|    if (session->disconnect_message == NULL) {
  ------------------
  |  Branch (827:9): [True: 660, False: 0]
  ------------------
  828|    660|        session->disconnect_message = strdup("Bye Bye") ;
  829|    660|        if (session->disconnect_message == NULL) {
  ------------------
  |  Branch (829:13): [True: 0, False: 660]
  ------------------
  830|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  831|      0|            goto error;
  832|      0|        }
  833|    660|    }
  834|       |
  835|    660|    if (session->socket != NULL && ssh_socket_is_open(session->socket)) {
  ------------------
  |  Branch (835:9): [True: 660, False: 0]
  |  Branch (835:36): [True: 161, False: 499]
  ------------------
  836|    161|        rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    161|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|    161|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|    161|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|    161|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|    161|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|    161|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    161|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  837|    161|                             "bdss",
  838|    161|                             SSH2_MSG_DISCONNECT,
  839|    161|                             SSH2_DISCONNECT_BY_APPLICATION,
  840|    161|                             session->disconnect_message,
  841|    161|                             ""); /* language tag */
  842|    161|        if (rc != SSH_OK) {
  ------------------
  |  |  315|    161|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (842:13): [True: 0, False: 161]
  ------------------
  843|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  844|      0|            goto error;
  845|      0|        }
  846|       |
  847|    161|        ssh_packet_send(session);
  848|    161|        ssh_session_socket_close(session);
  849|    161|    }
  850|       |
  851|    660|error:
  852|    660|    session->recv_seq = 0;
  853|    660|    session->send_seq = 0;
  854|    660|    session->alive = 0;
  855|    660|    if (session->socket != NULL){
  ------------------
  |  Branch (855:9): [True: 660, False: 0]
  ------------------
  856|    660|        ssh_socket_reset(session->socket);
  857|    660|    }
  858|    660|    session->opts.fd = SSH_INVALID_SOCKET;
  ------------------
  |  |  123|    660|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  859|    660|    session->session_state = SSH_SESSION_STATE_DISCONNECTED;
  860|    660|    session->pending_call_state = SSH_PENDING_CALL_NONE;
  861|    660|    session->packet_state = PACKET_STATE_INIT;
  862|       |
  863|    677|    while ((it = ssh_list_get_iterator(session->channels)) != NULL) {
  ------------------
  |  Branch (863:12): [True: 17, False: 660]
  ------------------
  864|     17|        ssh_channel_do_free(ssh_iterator_value(ssh_channel, it));
  ------------------
  |  |  122|     17|  ((type)((iterator)->data))
  ------------------
  865|     17|        ssh_list_remove(session->channels, it);
  866|     17|    }
  867|    660|    if (session->current_crypto) {
  ------------------
  |  Branch (867:9): [True: 180, False: 480]
  ------------------
  868|    180|      crypto_free(session->current_crypto);
  869|    180|      session->current_crypto = NULL;
  870|    180|    }
  871|    660|    if (session->next_crypto) {
  ------------------
  |  Branch (871:9): [True: 660, False: 0]
  ------------------
  872|    660|        crypto_free(session->next_crypto);
  873|    660|        session->next_crypto = crypto_new();
  874|    660|        if (session->next_crypto == NULL) {
  ------------------
  |  Branch (874:13): [True: 0, False: 660]
  ------------------
  875|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  876|      0|        }
  877|    660|    }
  878|    660|    if (session->in_buffer) {
  ------------------
  |  Branch (878:9): [True: 660, False: 0]
  ------------------
  879|    660|        ssh_buffer_reinit(session->in_buffer);
  880|    660|    }
  881|    660|    if (session->out_buffer) {
  ------------------
  |  Branch (881:9): [True: 660, False: 0]
  ------------------
  882|    660|        ssh_buffer_reinit(session->out_buffer);
  883|    660|    }
  884|    660|    if (session->in_hashbuf) {
  ------------------
  |  Branch (884:9): [True: 75, False: 585]
  ------------------
  885|     75|        ssh_buffer_reinit(session->in_hashbuf);
  886|     75|    }
  887|    660|    if (session->out_hashbuf) {
  ------------------
  |  Branch (887:9): [True: 113, False: 547]
  ------------------
  888|    113|        ssh_buffer_reinit(session->out_hashbuf);
  889|    113|    }
  890|    660|    session->auth.supported_methods = 0;
  891|    660|    SAFE_FREE(session->serverbanner);
  ------------------
  |  |  375|    660|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 319, False: 341]
  |  |  |  Branch (375:71): [Folded, False: 660]
  |  |  ------------------
  ------------------
  892|    660|    SAFE_FREE(session->clientbanner);
  ------------------
  |  |  375|    660|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 307, False: 353]
  |  |  |  Branch (375:71): [Folded, False: 660]
  |  |  ------------------
  ------------------
  893|    660|    SAFE_FREE(session->disconnect_message);
  ------------------
  |  |  375|    660|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 660, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 660]
  |  |  ------------------
  ------------------
  894|       |
  895|    660|    if (session->ssh_message_list) {
  ------------------
  |  Branch (895:9): [True: 0, False: 660]
  ------------------
  896|      0|        ssh_message msg = NULL;
  897|       |
  898|      0|        while ((msg = ssh_list_pop_head(ssh_message,
  ------------------
  |  |  130|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  |  Branch (898:16): [True: 0, False: 0]
  ------------------
  899|      0|                                        session->ssh_message_list)) != NULL) {
  900|      0|              ssh_message_free(msg);
  901|      0|        }
  902|      0|        ssh_list_free(session->ssh_message_list);
  903|      0|        session->ssh_message_list = NULL;
  904|      0|    }
  905|       |
  906|    660|    if (session->packet_callbacks) {
  ------------------
  |  Branch (906:9): [True: 294, False: 366]
  ------------------
  907|    294|        ssh_list_free(session->packet_callbacks);
  908|       |        session->packet_callbacks = NULL;
  909|    294|    }
  910|    660|}

ssh_curve25519_create_k:
   52|    183|{
   53|    183|    int rc;
   54|       |
   55|       |#ifdef DEBUG_CRYPTO
   56|       |    ssh_log_hexdump("Session server cookie",
   57|       |                    session->next_crypto->server_kex.cookie,
   58|       |                    16);
   59|       |    ssh_log_hexdump("Session client cookie",
   60|       |                    session->next_crypto->client_kex.cookie,
   61|       |                    16);
   62|       |#endif
   63|       |
   64|    183|    rc = curve25519_do_create_k(session, k);
   65|    183|    return rc;
   66|    183|}
ssh_curve25519_build_k:
  105|    183|{
  106|    183|    ssh_curve25519_secret k;
  107|    183|    int rc;
  108|       |
  109|    183|    rc = ssh_curve25519_create_k(session, k);
  110|    183|    if (rc != SSH_OK) {
  ------------------
  |  |  315|    183|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (110:9): [True: 0, False: 183]
  ------------------
  111|      0|        return rc;
  112|      0|    }
  113|       |
  114|    183|    bignum_bin2bn(k,
  ------------------
  |  |   79|    183|    do {                                     \
  |  |   80|    183|        (*dest) = BN_new();                  \
  |  |   81|    183|        if ((*dest) != NULL) {               \
  |  |  ------------------
  |  |  |  Branch (81:13): [True: 183, False: 0]
  |  |  ------------------
  |  |   82|    183|            BN_bin2bn(data,datalen,(*dest)); \
  |  |   83|    183|        }                                    \
  |  |   84|    183|    } while(0)
  |  |  ------------------
  |  |  |  Branch (84:13): [Folded, False: 183]
  |  |  ------------------
  ------------------
  115|    183|                  CURVE25519_SECRET_SIZE,
  116|    183|                  &session->next_crypto->shared_secret);
  117|    183|    ssh_burn(k, sizeof(ssh_curve25519_secret));
  ------------------
  |  |  390|    183|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  118|    183|    if (session->next_crypto->shared_secret == NULL) {
  ------------------
  |  Branch (118:9): [True: 0, False: 183]
  ------------------
  119|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  120|      0|    }
  121|       |
  122|       |#ifdef DEBUG_CRYPTO
  123|       |    ssh_print_bignum("Shared secret key", session->next_crypto->shared_secret);
  124|       |#endif
  125|       |
  126|    183|    return SSH_OK;
  ------------------
  |  |  315|    183|#define SSH_OK 0     /* No error */
  ------------------
  127|    183|}
ssh_server_curve25519_init:
  221|    192|{
  222|       |    /* register the packet callbacks */
  223|    192|    ssh_packet_set_callbacks(session, &ssh_curve25519_server_callbacks);
  224|    192|}
curve25519.c:ssh_packet_server_curve25519_init:
  230|    184|{
  231|       |    /* ECDH keys */
  232|    184|    ssh_string q_c_string = NULL;
  233|    184|    ssh_string q_s_string = NULL;
  234|    184|    ssh_string server_pubkey_blob = NULL;
  235|       |
  236|       |    /* SSH host keys (rsa, ed25519 and ecdsa) */
  237|    184|    ssh_key privkey = NULL;
  238|    184|    enum ssh_digest_e digest = SSH_DIGEST_AUTO;
  239|    184|    ssh_string sig_blob = NULL;
  240|    184|    int rc;
  241|    184|    (void)type;
  242|    184|    (void)user;
  243|       |
  244|    184|    ssh_packet_remove_callbacks(session, &ssh_curve25519_server_callbacks);
  245|       |
  246|       |    /* Extract the client pubkey from the init packet */
  247|    184|    q_c_string = ssh_buffer_get_ssh_string(packet);
  248|    184|    if (q_c_string == NULL) {
  ------------------
  |  Branch (248:9): [True: 1, False: 183]
  ------------------
  249|      1|        ssh_set_error(session, SSH_FATAL, "No Q_C ECC point in packet");
  ------------------
  |  |  313|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  250|      1|        goto error;
  251|      1|    }
  252|    183|    if (ssh_string_len(q_c_string) != CURVE25519_PUBKEY_SIZE) {
  ------------------
  |  |   41|    183|#define CURVE25519_PUBKEY_SIZE 32
  ------------------
  |  Branch (252:9): [True: 0, False: 183]
  ------------------
  253|      0|        ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  254|      0|                      SSH_FATAL,
  255|      0|                      "Incorrect size for server Curve25519 public key: %zu",
  256|      0|                      ssh_string_len(q_c_string));
  257|      0|        goto error;
  258|      0|    }
  259|       |
  260|    183|    memcpy(session->next_crypto->curve25519_client_pubkey,
  261|    183|           ssh_string_data(q_c_string),
  262|    183|           CURVE25519_PUBKEY_SIZE);
  ------------------
  |  |   41|    183|#define CURVE25519_PUBKEY_SIZE 32
  ------------------
  263|    183|    SSH_STRING_FREE(q_c_string);
  ------------------
  |  |  882|    183|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 183, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 183]
  |  |  ------------------
  ------------------
  264|       |
  265|       |    /* Build server's key pair */
  266|    183|    rc = ssh_curve25519_init(session);
  267|    183|    if (rc != SSH_OK) {
  ------------------
  |  |  315|    183|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (267:9): [True: 0, False: 183]
  ------------------
  268|      0|        ssh_set_error(session, SSH_FATAL, "Failed to generate curve25519 keys");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  269|      0|        goto error;
  270|      0|    }
  271|       |
  272|    183|    rc = ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_KEX_ECDH_REPLY);
  ------------------
  |  |   18|    183|#define SSH2_MSG_KEX_ECDH_REPLY 31
  ------------------
  273|    183|    if (rc < 0) {
  ------------------
  |  Branch (273:9): [True: 0, False: 183]
  ------------------
  274|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  275|      0|        goto error;
  276|      0|    }
  277|       |
  278|       |    /* build k and session_id */
  279|    183|    rc = ssh_curve25519_build_k(session);
  280|    183|    if (rc < 0) {
  ------------------
  |  Branch (280:9): [True: 0, False: 183]
  ------------------
  281|      0|        ssh_set_error(session, SSH_FATAL, "Cannot build k number");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  282|      0|        goto error;
  283|      0|    }
  284|       |
  285|       |    /* privkey is not allocated */
  286|    183|    rc = ssh_get_key_params(session, &privkey, &digest);
  287|    183|    if (rc == SSH_ERROR) {
  ------------------
  |  |  316|    183|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (287:9): [True: 0, False: 183]
  ------------------
  288|      0|        goto error;
  289|      0|    }
  290|       |
  291|    183|    rc = ssh_make_sessionid(session);
  292|    183|    if (rc != SSH_OK) {
  ------------------
  |  |  315|    183|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (292:9): [True: 0, False: 183]
  ------------------
  293|      0|        ssh_set_error(session, SSH_FATAL, "Could not create a session id");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  294|      0|        goto error;
  295|      0|    }
  296|       |
  297|    183|    rc = ssh_dh_get_next_server_publickey_blob(session, &server_pubkey_blob);
  298|    183|    if (rc != 0) {
  ------------------
  |  Branch (298:9): [True: 0, False: 183]
  ------------------
  299|      0|        ssh_set_error(session, SSH_FATAL, "Could not export server public key");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  300|      0|        goto error;
  301|      0|    }
  302|       |
  303|       |    /* add host's public key */
  304|    183|    rc = ssh_buffer_add_ssh_string(session->out_buffer, server_pubkey_blob);
  305|    183|    SSH_STRING_FREE(server_pubkey_blob);
  ------------------
  |  |  882|    183|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 183, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 183]
  |  |  ------------------
  ------------------
  306|    183|    if (rc < 0) {
  ------------------
  |  Branch (306:9): [True: 0, False: 183]
  ------------------
  307|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  308|      0|        goto error;
  309|      0|    }
  310|       |
  311|       |    /* add ecdh public key */
  312|    183|    q_s_string = ssh_string_new(CURVE25519_PUBKEY_SIZE);
  ------------------
  |  |   41|    183|#define CURVE25519_PUBKEY_SIZE 32
  ------------------
  313|    183|    if (q_s_string == NULL) {
  ------------------
  |  Branch (313:9): [True: 0, False: 183]
  ------------------
  314|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  315|      0|        goto error;
  316|      0|    }
  317|       |
  318|    183|    rc = ssh_string_fill(q_s_string,
  319|    183|                         session->next_crypto->curve25519_server_pubkey,
  320|    183|                         CURVE25519_PUBKEY_SIZE);
  ------------------
  |  |   41|    183|#define CURVE25519_PUBKEY_SIZE 32
  ------------------
  321|    183|    if (rc < 0) {
  ------------------
  |  Branch (321:9): [True: 0, False: 183]
  ------------------
  322|      0|        ssh_set_error(session, SSH_FATAL, "Could not copy public key");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  323|      0|        goto error;
  324|      0|    }
  325|       |
  326|    183|    rc = ssh_buffer_add_ssh_string(session->out_buffer, q_s_string);
  327|    183|    SSH_STRING_FREE(q_s_string);
  ------------------
  |  |  882|    183|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 183, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 183]
  |  |  ------------------
  ------------------
  328|    183|    if (rc < 0) {
  ------------------
  |  Branch (328:9): [True: 0, False: 183]
  ------------------
  329|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  330|      0|        goto error;
  331|      0|    }
  332|       |    /* add signature blob */
  333|    183|    sig_blob = ssh_srv_pki_do_sign_sessionid(session, privkey, digest);
  334|    183|    if (sig_blob == NULL) {
  ------------------
  |  Branch (334:9): [True: 0, False: 183]
  ------------------
  335|      0|        ssh_set_error(session, SSH_FATAL, "Could not sign the session id");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  336|      0|        goto error;
  337|      0|    }
  338|       |
  339|    183|    rc = ssh_buffer_add_ssh_string(session->out_buffer, sig_blob);
  340|    183|    SSH_STRING_FREE(sig_blob);
  ------------------
  |  |  882|    183|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 183, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 183]
  |  |  ------------------
  ------------------
  341|    183|    if (rc < 0) {
  ------------------
  |  Branch (341:9): [True: 0, False: 183]
  ------------------
  342|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  343|      0|        goto error;
  344|      0|    }
  345|       |
  346|    183|    SSH_LOG(SSH_LOG_DEBUG, "SSH_MSG_KEX_ECDH_REPLY sent");
  ------------------
  |  |  283|    183|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  347|    183|    rc = ssh_packet_send(session);
  348|    183|    if (rc == SSH_ERROR) {
  ------------------
  |  |  316|    183|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (348:9): [True: 0, False: 183]
  ------------------
  349|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  350|      0|    }
  351|       |
  352|    183|    session->dh_handshake_state = DH_STATE_NEWKEYS_SENT;
  353|       |
  354|       |    /* Send the MSG_NEWKEYS */
  355|    183|    rc = ssh_packet_send_newkeys(session);
  356|    183|    if (rc == SSH_ERROR) {
  ------------------
  |  |  316|    183|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (356:9): [True: 0, False: 183]
  ------------------
  357|      0|        goto error;
  358|      0|    }
  359|       |
  360|    183|    return SSH_PACKET_USED;
  ------------------
  |  |  638|    183|#define SSH_PACKET_USED 1
  ------------------
  361|      1|error:
  362|      1|    SSH_STRING_FREE(q_c_string);
  ------------------
  |  |  882|      1|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 1]
  |  |  |  Branch (882:69): [Folded, False: 1]
  |  |  ------------------
  ------------------
  363|      1|    SSH_STRING_FREE(q_s_string);
  ------------------
  |  |  882|      1|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 1]
  |  |  |  Branch (882:69): [Folded, False: 1]
  |  |  ------------------
  ------------------
  364|      1|    ssh_buffer_reinit(session->out_buffer);
  365|      1|    session->session_state = SSH_SESSION_STATE_ERROR;
  366|      1|    return SSH_PACKET_USED;
  ------------------
  |  |  638|      1|#define SSH_PACKET_USED 1
  ------------------
  367|    183|}

ssh_curve25519_init:
   34|    183|{
   35|    183|    ssh_curve25519_pubkey *pubkey_loc = NULL;
   36|    183|    EVP_PKEY_CTX *pctx = NULL;
   37|    183|    EVP_PKEY *pkey = NULL;
   38|    183|    size_t pubkey_len = CURVE25519_PUBKEY_SIZE;
  ------------------
  |  |   41|    183|#define CURVE25519_PUBKEY_SIZE 32
  ------------------
   39|    183|    int rc;
   40|       |
   41|    183|    if (session->server) {
  ------------------
  |  Branch (41:9): [True: 183, False: 0]
  ------------------
   42|    183|        pubkey_loc = &session->next_crypto->curve25519_server_pubkey;
   43|    183|    } else {
   44|      0|        pubkey_loc = &session->next_crypto->curve25519_client_pubkey;
   45|      0|    }
   46|       |
   47|    183|    pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_X25519, NULL);
   48|    183|    if (pctx == NULL) {
  ------------------
  |  Branch (48:9): [True: 0, False: 183]
  ------------------
   49|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
   50|      0|                "Failed to initialize X25519 context: %s",
   51|      0|                ERR_error_string(ERR_get_error(), NULL));
   52|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   53|      0|    }
   54|       |
   55|    183|    rc = EVP_PKEY_keygen_init(pctx);
   56|    183|    if (rc != 1) {
  ------------------
  |  Branch (56:9): [True: 0, False: 183]
  ------------------
   57|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
   58|      0|                "Failed to initialize X25519 keygen: %s",
   59|      0|                ERR_error_string(ERR_get_error(), NULL));
   60|      0|        EVP_PKEY_CTX_free(pctx);
   61|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   62|      0|    }
   63|       |
   64|    183|    rc = EVP_PKEY_keygen(pctx, &pkey);
   65|    183|    EVP_PKEY_CTX_free(pctx);
   66|    183|    if (rc != 1) {
  ------------------
  |  Branch (66:9): [True: 0, False: 183]
  ------------------
   67|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
   68|      0|                "Failed to generate X25519 keys: %s",
   69|      0|                ERR_error_string(ERR_get_error(), NULL));
   70|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   71|      0|    }
   72|       |
   73|    183|    rc = EVP_PKEY_get_raw_public_key(pkey, *pubkey_loc, &pubkey_len);
   74|    183|    if (rc != 1) {
  ------------------
  |  Branch (74:9): [True: 0, False: 183]
  ------------------
   75|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
   76|      0|                "Failed to get X25519 raw public key: %s",
   77|      0|                ERR_error_string(ERR_get_error(), NULL));
   78|      0|        EVP_PKEY_free(pkey);
   79|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   80|      0|    }
   81|       |
   82|       |    /* Free any previously allocated privkey */
   83|    183|    if (session->next_crypto->curve25519_privkey != NULL) {
  ------------------
  |  Branch (83:9): [True: 0, False: 183]
  ------------------
   84|      0|        EVP_PKEY_free(session->next_crypto->curve25519_privkey);
   85|      0|        session->next_crypto->curve25519_privkey = NULL;
   86|      0|    }
   87|       |
   88|    183|    session->next_crypto->curve25519_privkey = pkey;
   89|    183|    pkey = NULL;
   90|       |
   91|    183|    return SSH_OK;
  ------------------
  |  |  315|    183|#define SSH_OK 0     /* No error */
  ------------------
   92|    183|}
curve25519_do_create_k:
   95|    183|{
   96|    183|    ssh_curve25519_pubkey *peer_pubkey_loc = NULL;
   97|    183|    int rc, ret = SSH_ERROR;
  ------------------
  |  |  316|    183|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   98|    183|    EVP_PKEY_CTX *pctx = NULL;
   99|    183|    EVP_PKEY *pkey = NULL, *pubkey = NULL;
  100|    183|    size_t shared_key_len = CURVE25519_SECRET_SIZE;
  ------------------
  |  |   43|    183|#define CURVE25519_SECRET_SIZE  32
  ------------------
  101|       |
  102|    183|    if (session->server) {
  ------------------
  |  Branch (102:9): [True: 183, False: 0]
  ------------------
  103|    183|        peer_pubkey_loc = &session->next_crypto->curve25519_client_pubkey;
  104|    183|    } else {
  105|      0|        peer_pubkey_loc = &session->next_crypto->curve25519_server_pubkey;
  106|      0|    }
  107|       |
  108|    183|    pkey = session->next_crypto->curve25519_privkey;
  109|    183|    if (pkey == NULL) {
  ------------------
  |  Branch (109:9): [True: 0, False: 183]
  ------------------
  110|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  111|      0|                "Failed to create X25519 EVP_PKEY: %s",
  112|      0|                ERR_error_string(ERR_get_error(), NULL));
  113|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  114|      0|    }
  115|       |
  116|    183|    pctx = EVP_PKEY_CTX_new(pkey, NULL);
  117|    183|    if (pctx == NULL) {
  ------------------
  |  Branch (117:9): [True: 0, False: 183]
  ------------------
  118|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  119|      0|                "Failed to initialize X25519 context: %s",
  120|      0|                ERR_error_string(ERR_get_error(), NULL));
  121|      0|        goto out;
  122|      0|    }
  123|       |
  124|    183|    rc = EVP_PKEY_derive_init(pctx);
  125|    183|    if (rc != 1) {
  ------------------
  |  Branch (125:9): [True: 0, False: 183]
  ------------------
  126|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  127|      0|                "Failed to initialize X25519 key derivation: %s",
  128|      0|                ERR_error_string(ERR_get_error(), NULL));
  129|      0|        goto out;
  130|      0|    }
  131|       |
  132|    183|    pubkey = EVP_PKEY_new_raw_public_key(EVP_PKEY_X25519,
  133|    183|                                         NULL,
  134|    183|                                         *peer_pubkey_loc,
  135|    183|                                         CURVE25519_PUBKEY_SIZE);
  ------------------
  |  |   41|    183|#define CURVE25519_PUBKEY_SIZE 32
  ------------------
  136|    183|    if (pubkey == NULL) {
  ------------------
  |  Branch (136:9): [True: 0, False: 183]
  ------------------
  137|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  138|      0|                "Failed to create X25519 public key EVP_PKEY: %s",
  139|      0|                ERR_error_string(ERR_get_error(), NULL));
  140|      0|        goto out;
  141|      0|    }
  142|       |
  143|    183|    rc = EVP_PKEY_derive_set_peer(pctx, pubkey);
  144|    183|    if (rc != 1) {
  ------------------
  |  Branch (144:9): [True: 0, False: 183]
  ------------------
  145|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  146|      0|                "Failed to set peer X25519 public key: %s",
  147|      0|                ERR_error_string(ERR_get_error(), NULL));
  148|      0|        goto out;
  149|      0|    }
  150|       |
  151|    183|    rc = EVP_PKEY_derive(pctx, k, &shared_key_len);
  152|    183|    if (rc != 1) {
  ------------------
  |  Branch (152:9): [True: 0, False: 183]
  ------------------
  153|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  154|      0|                "Failed to derive X25519 shared secret: %s",
  155|      0|                ERR_error_string(ERR_get_error(), NULL));
  156|      0|        goto out;
  157|      0|    }
  158|    183|    ret = SSH_OK;
  ------------------
  |  |  315|    183|#define SSH_OK 0     /* No error */
  ------------------
  159|       |
  160|    183|out:
  161|    183|    EVP_PKEY_free(pubkey);
  162|    183|    EVP_PKEY_CTX_free(pctx);
  163|    183|    return ret;
  164|    183|}

ssh_server_dhgex_init:
  590|     23|void ssh_server_dhgex_init(ssh_session session){
  591|       |    /* register the packet callbacks */
  592|     23|    ssh_packet_set_callbacks(session, &ssh_dhgex_server_callbacks);
  593|     23|    ssh_dh_init_common(session->next_crypto);
  594|     23|    session->dh_handshake_state = DH_STATE_INIT;
  595|     23|}
dh-gex.c:ssh_packet_server_dhgex_request:
  598|    950|{
  599|    950|    bignum modulus = NULL, generator = NULL;
  600|    950|    uint32_t pmin, pn, pmax;
  601|    950|    size_t size = 0;
  602|    950|    int rc;
  603|       |
  604|    950|    (void) type;
  605|    950|    (void) user;
  606|       |
  607|    950|    if (session->dh_handshake_state != DH_STATE_INIT) {
  ------------------
  |  Branch (607:9): [True: 0, False: 950]
  ------------------
  608|      0|        ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  609|      0|                      SSH_FATAL,
  610|      0|                      "Received DH_GEX_REQUEST in invalid state");
  611|      0|        goto error;
  612|      0|    }
  613|       |
  614|       |    /* Minimum group size, preferred group size, maximum group size */
  615|    950|    rc = ssh_buffer_unpack(packet, "ddd", &pmin, &pn, &pmax);
  ------------------
  |  |   60|    950|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|    950|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|    950|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|    950|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|    950|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|    950|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    950|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  616|    950|    if (rc != SSH_OK){
  ------------------
  |  |  315|    950|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (616:9): [True: 806, False: 144]
  ------------------
  617|    806|        ssh_set_error_invalid(session);
  ------------------
  |  |  324|    806|    _ssh_set_error_invalid(error, __func__)
  ------------------
  618|    806|        goto error;
  619|    806|    }
  620|    144|    SSH_LOG(SSH_LOG_DEBUG, "dh-gex: DHGEX_REQUEST[%" PRIu32 ":%" PRIu32 ":%" PRIu32 "]", pmin, pn, pmax);
  ------------------
  |  |  283|    144|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  621|       |
  622|    144|    if (pmin > pn || pn > pmax || pn > DH_PMAX || pmax < DH_PMIN) {
  ------------------
  |  |   43|    152|#define DH_PMAX 8192
  ------------------
                  if (pmin > pn || pn > pmax || pn > DH_PMAX || pmax < DH_PMIN) {
  ------------------
  |  |   41|      5|#define DH_PMIN 2048
  ------------------
  |  Branch (622:9): [True: 0, False: 144]
  |  Branch (622:22): [True: 136, False: 8]
  |  Branch (622:35): [True: 3, False: 5]
  |  Branch (622:51): [True: 1, False: 4]
  ------------------
  623|    140|        ssh_set_error(session,
  ------------------
  |  |  313|    140|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  624|    140|                      SSH_FATAL,
  625|    140|                      "Invalid dh-gex arguments [%" PRIu32 ":%" PRIu32 ":%" PRIu32 "]",
  626|    140|                      pmin,
  627|    140|                      pn,
  628|    140|                      pmax);
  629|    140|        goto error;
  630|    140|    }
  631|      4|    session->next_crypto->dh_pmin = pmin;
  632|      4|    session->next_crypto->dh_pn = pn;
  633|      4|    session->next_crypto->dh_pmax = pmax;
  634|       |
  635|       |    /* ensure safe parameters */
  636|      4|    if (pmin < DH_PMIN) {
  ------------------
  |  |   41|      4|#define DH_PMIN 2048
  ------------------
  |  Branch (636:9): [True: 4, False: 0]
  ------------------
  637|      4|        pmin = DH_PMIN;
  ------------------
  |  |   41|      4|#define DH_PMIN 2048
  ------------------
  638|      4|        if (pn < pmin) {
  ------------------
  |  Branch (638:13): [True: 4, False: 0]
  ------------------
  639|      4|            pn = pmin;
  640|      4|        }
  641|      4|    }
  642|      4|    rc = ssh_retrieve_dhgroup(session->server_opts.moduli_file,
  643|      4|                              pmin,
  644|      4|                              pn,
  645|      4|                              pmax,
  646|      4|                              &size,
  647|      4|                              &modulus,
  648|      4|                              &generator);
  649|      4|    if (rc == SSH_ERROR) {
  ------------------
  |  |  316|      4|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (649:9): [True: 0, False: 4]
  ------------------
  650|      0|        ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  651|      0|                      SSH_FATAL,
  652|      0|                      "Couldn't find DH group for [%" PRIu32 ":%" PRIu32 ":%" PRIu32 "]",
  653|      0|                      pmin,
  654|      0|                      pn,
  655|      0|                      pmax);
  656|      0|        goto error;
  657|      0|    }
  658|      4|    rc = ssh_dh_set_parameters(session->next_crypto->dh_ctx,
  659|      4|                               modulus, generator);
  660|      4|    if (rc != SSH_OK) {
  ------------------
  |  |  315|      4|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (660:9): [True: 0, False: 4]
  ------------------
  661|      0|        bignum_safe_free(generator);
  ------------------
  |  |   71|      0|#define bignum_safe_free(num) do { \
  |  |   72|      0|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 0]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  662|      0|        bignum_safe_free(modulus);
  ------------------
  |  |   71|      0|#define bignum_safe_free(num) do { \
  |  |   72|      0|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 0]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  663|      0|        goto error;
  664|      0|    }
  665|      4|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|      4|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      4|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      4|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      4|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      4|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      4|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      4|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  666|      4|                         "bBB",
  667|      4|                         SSH2_MSG_KEX_DH_GEX_GROUP,
  668|      4|                         modulus,
  669|      4|                         generator);
  670|       |
  671|      4|#ifdef HAVE_LIBCRYPTO
  672|      4|    bignum_safe_free(generator);
  ------------------
  |  |   71|      4|#define bignum_safe_free(num) do { \
  |  |   72|      4|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 4, False: 0]
  |  |  ------------------
  |  |   73|      4|        BN_clear_free((num)); \
  |  |   74|      4|        (num)=NULL; \
  |  |   75|      4|    } \
  |  |   76|      4|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 4]
  |  |  ------------------
  ------------------
  673|      4|    bignum_safe_free(modulus);
  ------------------
  |  |   71|      4|#define bignum_safe_free(num) do { \
  |  |   72|      4|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 4, False: 0]
  |  |  ------------------
  |  |   73|      4|        BN_clear_free((num)); \
  |  |   74|      4|        (num)=NULL; \
  |  |   75|      4|    } \
  |  |   76|      4|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 4]
  |  |  ------------------
  ------------------
  674|      4|#endif
  675|       |
  676|      4|    if (rc != SSH_OK) {
  ------------------
  |  |  315|      4|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (676:9): [True: 0, False: 4]
  ------------------
  677|      0|        ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  678|      0|        goto error;
  679|      0|    }
  680|       |
  681|      4|    session->dh_handshake_state = DH_STATE_GROUP_SENT;
  682|       |
  683|      4|    rc = ssh_packet_send(session);
  684|      4|    if (rc == SSH_ERROR) {
  ------------------
  |  |  316|      4|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (684:9): [True: 0, False: 4]
  ------------------
  685|      0|        goto error;
  686|      0|    }
  687|       |
  688|    950|error:
  689|    950|    return SSH_PACKET_USED;
  ------------------
  |  |  638|    950|#define SSH_PACKET_USED 1
  ------------------
  690|      4|}
dh-gex.c:ssh_retrieve_dhgroup:
  506|      4|{
  507|      4|    FILE *moduli = NULL;
  508|      4|    char *generator = NULL;
  509|      4|    char *modulus = NULL;
  510|      4|    int rc;
  511|       |
  512|       |    /* In FIPS mode, we can not negotiate arbitrary primes,
  513|       |     * but just the approved ones */
  514|      4|    if (ssh_fips_mode()) {
  ------------------
  |  |  117|      4|#define ssh_fips_mode() EVP_default_properties_is_fips_enabled(NULL)
  |  |  ------------------
  |  |  |  Branch (117:25): [True: 0, False: 4]
  |  |  ------------------
  ------------------
  515|      0|        SSH_LOG(SSH_LOG_TRACE, "In FIPS mode, using built-in primes");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  516|      0|        return ssh_fallback_group(pmax, p, g);
  517|      0|    }
  518|       |
  519|      4|    if (moduli_file != NULL)
  ------------------
  |  Branch (519:9): [True: 0, False: 4]
  ------------------
  520|      0|        moduli = ssh_strict_fopen(moduli_file, SSH_MAX_CONFIG_FILE_SIZE);
  ------------------
  |  |  530|      0|#define SSH_MAX_CONFIG_FILE_SIZE 16 * 1024 * 1024
  ------------------
  521|      4|    else
  522|      4|        moduli = ssh_strict_fopen(MODULI_FILE, SSH_MAX_CONFIG_FILE_SIZE);
  ------------------
  |  |  308|      4|#define MODULI_FILE "/etc/ssh/moduli"
  ------------------
                      moduli = ssh_strict_fopen(MODULI_FILE, SSH_MAX_CONFIG_FILE_SIZE);
  ------------------
  |  |  530|      4|#define SSH_MAX_CONFIG_FILE_SIZE 16 * 1024 * 1024
  ------------------
  523|       |
  524|      4|    if (moduli == NULL) {
  ------------------
  |  Branch (524:9): [True: 4, False: 0]
  ------------------
  525|      4|        SSH_LOG_STRERROR(SSH_LOG_DEBUG,
  ------------------
  |  |  285|      4|    do {                                                            \
  |  |  286|      4|        char err_msg[SSH_ERRNO_MSG_MAX] = {0};                      \
  |  |  287|      4|        _ssh_log(priority,                                          \
  |  |  288|      4|                 __func__,                                          \
  |  |  289|      4|                 __VA_ARGS__,                                       \
  |  |  290|      4|                 ssh_strerror(errnum, err_msg, SSH_ERRNO_MSG_MAX)); \
  |  |  ------------------
  |  |  |  |  522|      4|#define SSH_ERRNO_MSG_MAX   1024
  |  |  ------------------
  |  |  291|      4|    } while (0)
  |  |  ------------------
  |  |  |  Branch (291:14): [Folded, False: 4]
  |  |  ------------------
  ------------------
  526|      4|                         errno,
  527|      4|                         "Unable to open moduli file: %s");
  528|      4|        return ssh_fallback_group(pmax, p, g);
  529|      4|    }
  530|       |
  531|      0|    *size = 0;
  532|      0|    *p = NULL;
  533|      0|    *g = NULL;
  534|       |
  535|      0|    rc = ssh_retrieve_dhgroup_file(moduli,
  536|      0|                                   pmin,
  537|      0|                                   pn,
  538|      0|                                   pmax,
  539|      0|                                   size,
  540|      0|                                   &generator,
  541|      0|                                   &modulus);
  542|      0|    fclose(moduli);
  543|      0|    if (rc == SSH_ERROR || *size == 0) {
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (543:9): [True: 0, False: 0]
  |  Branch (543:28): [True: 0, False: 0]
  ------------------
  544|      0|        goto error;
  545|      0|    }
  546|      0|    rc = bignum_hex2bn(generator, g);
  ------------------
  |  |   87|      0|#define bignum_hex2bn(data, bn) BN_hex2bn(bn, data)
  ------------------
  547|      0|    if (rc == 0) {
  ------------------
  |  Branch (547:9): [True: 0, False: 0]
  ------------------
  548|      0|        goto error;
  549|      0|    }
  550|      0|    rc = bignum_hex2bn(modulus, p);
  ------------------
  |  |   87|      0|#define bignum_hex2bn(data, bn) BN_hex2bn(bn, data)
  ------------------
  551|      0|    if (rc == 0) {
  ------------------
  |  Branch (551:9): [True: 0, False: 0]
  ------------------
  552|      0|        goto error;
  553|      0|    }
  554|      0|    SAFE_FREE(generator);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  555|      0|    SAFE_FREE(modulus);
  ------------------
  |  |  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|       |
  557|      0|    return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  558|       |
  559|      0|error:
  560|      0|    bignum_safe_free(*g);
  ------------------
  |  |   71|      0|#define bignum_safe_free(num) do { \
  |  |   72|      0|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 0]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  561|      0|    bignum_safe_free(*p);
  ------------------
  |  |   71|      0|#define bignum_safe_free(num) do { \
  |  |   72|      0|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 0]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  562|      0|    SAFE_FREE(generator);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  563|      0|    SAFE_FREE(modulus);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  564|       |
  565|      0|    return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  566|      0|}

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_dh_import_next_pubkey_blob:
  295|    185|{
  296|    185|    return ssh_pki_import_pubkey_blob(pubkey_blob,
  297|    185|                                      &session->next_crypto->server_pubkey);
  298|       |
  299|    185|}
ssh_server_dh_init:
  436|      3|void ssh_server_dh_init(ssh_session session){
  437|       |    /* register the packet callbacks */
  438|      3|    ssh_packet_set_callbacks(session, &ssh_dh_server_callbacks);
  439|       |
  440|      3|    ssh_dh_init_common(session->next_crypto);
  441|      3|}
ssh_server_dh_process_init:
  448|      2|{
  449|      2|    struct ssh_crypto_struct *crypto = session->next_crypto;
  450|      2|    ssh_key privkey = NULL;
  451|      2|    enum ssh_digest_e digest = SSH_DIGEST_AUTO;
  452|      2|    ssh_string sig_blob = NULL;
  453|      2|    ssh_string pubkey_blob = NULL;
  454|      2|    bignum client_pubkey;
  455|       |#if !defined(HAVE_LIBCRYPTO) || OPENSSL_VERSION_NUMBER < 0x30000000L
  456|       |    const_bignum server_pubkey;
  457|       |#else
  458|      2|    bignum server_pubkey = NULL;
  459|      2|#endif /* OPENSSL_VERSION_NUMBER */
  460|      2|    int packet_type;
  461|      2|    int rc;
  462|       |
  463|      2|    rc = ssh_buffer_unpack(packet, "B", &client_pubkey);
  ------------------
  |  |   60|      2|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      2|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      2|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      2|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      2|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      2|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      2|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  464|      2|    if (rc == SSH_ERROR) {
  ------------------
  |  |  316|      2|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (464:9): [True: 0, False: 2]
  ------------------
  465|      0|        ssh_set_error(session, SSH_FATAL, "No e number in client request");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  466|      0|        goto error;
  467|      0|    }
  468|       |
  469|      2|    rc = ssh_dh_keypair_set_keys(crypto->dh_ctx, DH_CLIENT_KEYPAIR,
  ------------------
  |  |   30|      2|#define DH_CLIENT_KEYPAIR 0
  ------------------
  470|      2|                                 NULL, client_pubkey);
  471|      2|    if (rc != SSH_OK) {
  ------------------
  |  |  315|      2|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (471:9): [True: 0, False: 2]
  ------------------
  472|      0|        bignum_safe_free(client_pubkey);
  ------------------
  |  |   71|      0|#define bignum_safe_free(num) do { \
  |  |   72|      0|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 0]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  473|      0|        goto error;
  474|      0|    }
  475|       |
  476|      2|    rc = ssh_dh_keypair_gen_keys(crypto->dh_ctx, DH_SERVER_KEYPAIR);
  ------------------
  |  |   31|      2|#define DH_SERVER_KEYPAIR 1
  ------------------
  477|      2|    if (rc == SSH_ERROR) {
  ------------------
  |  |  316|      2|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (477:9): [True: 0, False: 2]
  ------------------
  478|      0|        goto error;
  479|      0|    }
  480|       |
  481|      2|    rc = ssh_get_key_params(session, &privkey, &digest);
  482|      2|    if (rc != SSH_OK) {
  ------------------
  |  |  315|      2|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (482:9): [True: 0, False: 2]
  ------------------
  483|      0|        goto error;
  484|      0|    }
  485|      2|    rc = ssh_dh_compute_shared_secret(crypto->dh_ctx,
  486|      2|                                      DH_SERVER_KEYPAIR, DH_CLIENT_KEYPAIR,
  ------------------
  |  |   31|      2|#define DH_SERVER_KEYPAIR 1
  ------------------
                                                    DH_SERVER_KEYPAIR, DH_CLIENT_KEYPAIR,
  ------------------
  |  |   30|      2|#define DH_CLIENT_KEYPAIR 0
  ------------------
  487|      2|                                      &crypto->shared_secret);
  488|      2|    ssh_dh_debug_crypto(crypto);
  489|      2|    if (rc == SSH_ERROR) {
  ------------------
  |  |  316|      2|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (489:9): [True: 0, False: 2]
  ------------------
  490|      0|        ssh_set_error(session, SSH_FATAL, "Could not generate shared secret");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  491|      0|        goto error;
  492|      0|    }
  493|      2|    rc = ssh_make_sessionid(session);
  494|      2|    if (rc != SSH_OK) {
  ------------------
  |  |  315|      2|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (494:9): [True: 0, False: 2]
  ------------------
  495|      0|        ssh_set_error(session, SSH_FATAL, "Could not create a session id");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  496|      0|        goto error;
  497|      0|    }
  498|      2|    sig_blob = ssh_srv_pki_do_sign_sessionid(session, privkey, digest);
  499|      2|    if (sig_blob == NULL) {
  ------------------
  |  Branch (499:9): [True: 0, False: 2]
  ------------------
  500|      0|        ssh_set_error(session, SSH_FATAL, "Could not sign the session id");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  501|      0|        goto error;
  502|      0|    }
  503|      2|    switch (crypto->kex_type){
  504|      0|    case SSH_KEX_DH_GROUP1_SHA1:
  ------------------
  |  Branch (504:5): [True: 0, False: 2]
  ------------------
  505|      0|    case SSH_KEX_DH_GROUP14_SHA1:
  ------------------
  |  Branch (505:5): [True: 0, False: 2]
  ------------------
  506|      2|    case SSH_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (506:5): [True: 2, False: 0]
  ------------------
  507|      2|    case SSH_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (507:5): [True: 0, False: 2]
  ------------------
  508|      2|    case SSH_KEX_DH_GROUP18_SHA512:
  ------------------
  |  Branch (508:5): [True: 0, False: 2]
  ------------------
  509|      2|        packet_type = SSH2_MSG_KEXDH_REPLY;
  ------------------
  |  |   16|      2|#define SSH2_MSG_KEXDH_REPLY 31
  ------------------
  510|      2|        break;
  511|      0|#ifdef WITH_GEX
  512|      0|    case SSH_KEX_DH_GEX_SHA1:
  ------------------
  |  Branch (512:5): [True: 0, False: 2]
  ------------------
  513|      0|    case SSH_KEX_DH_GEX_SHA256:
  ------------------
  |  Branch (513:5): [True: 0, False: 2]
  ------------------
  514|      0|        packet_type = SSH2_MSG_KEX_DH_GEX_REPLY;
  ------------------
  |  |   25|      0|#define SSH2_MSG_KEX_DH_GEX_REPLY 33
  ------------------
  515|      0|        break;
  516|      0|#endif /* WITH_GEX */
  517|      0|    default:
  ------------------
  |  Branch (517:5): [True: 0, False: 2]
  ------------------
  518|      0|        ssh_set_error(session, SSH_FATAL, "Invalid kex type");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  519|      0|        goto error;
  520|      2|    }
  521|      2|    rc = ssh_dh_keypair_get_keys(crypto->dh_ctx, DH_SERVER_KEYPAIR,
  ------------------
  |  |   31|      2|#define DH_SERVER_KEYPAIR 1
  ------------------
  522|      2|                                 NULL, &server_pubkey);
  523|      2|    if (rc != SSH_OK){
  ------------------
  |  |  315|      2|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (523:9): [True: 0, False: 2]
  ------------------
  524|      0|        goto error;
  525|      0|    }
  526|      2|    rc = ssh_dh_get_next_server_publickey_blob(session, &pubkey_blob);
  527|      2|    if (rc != SSH_OK){
  ------------------
  |  |  315|      2|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (527:9): [True: 0, False: 2]
  ------------------
  528|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  529|      0|        goto error;
  530|      0|    }
  531|      2|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|      2|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      2|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      2|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      2|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      2|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      2|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      2|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  532|      2|                         "bSBS",
  533|      2|                         packet_type,
  534|      2|                         pubkey_blob,
  535|      2|                         server_pubkey,
  536|      2|                         sig_blob);
  537|      2|    SSH_STRING_FREE(sig_blob);
  ------------------
  |  |  882|      2|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 2, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 2]
  |  |  ------------------
  ------------------
  538|      2|    SSH_STRING_FREE(pubkey_blob);
  ------------------
  |  |  882|      2|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 2, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 2]
  |  |  ------------------
  ------------------
  539|      2|#if defined(HAVE_LIBCRYPTO) && OPENSSL_VERSION_NUMBER >= 0x30000000L
  540|      2|    bignum_safe_free(server_pubkey);
  ------------------
  |  |   71|      2|#define bignum_safe_free(num) do { \
  |  |   72|      2|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 2, False: 0]
  |  |  ------------------
  |  |   73|      2|        BN_clear_free((num)); \
  |  |   74|      2|        (num)=NULL; \
  |  |   75|      2|    } \
  |  |   76|      2|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 2]
  |  |  ------------------
  ------------------
  541|      2|#endif
  542|      2|    if(rc != SSH_OK) {
  ------------------
  |  |  315|      2|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (542:8): [True: 0, False: 2]
  ------------------
  543|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  544|      0|        ssh_buffer_reinit(session->out_buffer);
  545|      0|        goto error;
  546|      0|    }
  547|      2|    rc = ssh_packet_send(session);
  548|      2|    if (rc == SSH_ERROR) {
  ------------------
  |  |  316|      2|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (548:9): [True: 0, False: 2]
  ------------------
  549|      0|        goto error;
  550|      0|    }
  551|      2|    SSH_LOG(SSH_LOG_DEBUG, "Sent KEX_DH_[GEX]_REPLY");
  ------------------
  |  |  283|      2|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  552|       |
  553|      2|    session->dh_handshake_state=DH_STATE_NEWKEYS_SENT;
  554|       |    /* Send the MSG_NEWKEYS */
  555|      2|    rc = ssh_packet_send_newkeys(session);
  556|      2|    if (rc == SSH_ERROR) {
  ------------------
  |  |  316|      2|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (556:9): [True: 0, False: 2]
  ------------------
  557|      0|        goto error;
  558|      0|    }
  559|       |
  560|      2|    return SSH_OK;
  ------------------
  |  |  315|      2|#define SSH_OK 0     /* No error */
  ------------------
  561|      0|error:
  562|      0|    SSH_STRING_FREE(sig_blob);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  563|      0|    SSH_STRING_FREE(pubkey_blob);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  564|      0|#if defined(HAVE_LIBCRYPTO) && OPENSSL_VERSION_NUMBER >= 0x30000000L
  565|      0|    bignum_safe_free(server_pubkey);
  ------------------
  |  |   71|      0|#define bignum_safe_free(num) do { \
  |  |   72|      0|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 0]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  566|      0|#endif
  567|       |
  568|      0|    session->session_state = SSH_SESSION_STATE_ERROR;
  569|      0|    ssh_dh_cleanup(session->next_crypto);
  570|      0|    return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  571|      2|}
ssh_fallback_group:
  597|      4|{
  598|      4|    *modulus = NULL;
  599|      4|    *generator = NULL;
  600|       |
  601|      4|    if (pmax < 3072) {
  ------------------
  |  Branch (601:9): [True: 0, False: 4]
  ------------------
  602|      0|        bignum_dup(ssh_dh_group14, modulus);
  ------------------
  |  |  104|      0|#define bignum_dup(orig, dest) do { \
  |  |  105|      0|        if (*(dest) == NULL) { \
  |  |  ------------------
  |  |  |  Branch (105:13): [True: 0, False: 0]
  |  |  ------------------
  |  |  106|      0|            *(dest) = BN_dup(orig); \
  |  |  107|      0|        } else { \
  |  |  108|      0|            BN_copy(*(dest), orig); \
  |  |  109|      0|        } \
  |  |  110|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (110:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  603|      4|    } else if (pmax < 6144) {
  ------------------
  |  Branch (603:16): [True: 0, False: 4]
  ------------------
  604|      0|        bignum_dup(ssh_dh_group16, modulus);
  ------------------
  |  |  104|      0|#define bignum_dup(orig, dest) do { \
  |  |  105|      0|        if (*(dest) == NULL) { \
  |  |  ------------------
  |  |  |  Branch (105:13): [True: 0, False: 0]
  |  |  ------------------
  |  |  106|      0|            *(dest) = BN_dup(orig); \
  |  |  107|      0|        } else { \
  |  |  108|      0|            BN_copy(*(dest), orig); \
  |  |  109|      0|        } \
  |  |  110|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (110:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  605|      4|    } else {
  606|      4|        bignum_dup(ssh_dh_group18, modulus);
  ------------------
  |  |  104|      4|#define bignum_dup(orig, dest) do { \
  |  |  105|      4|        if (*(dest) == NULL) { \
  |  |  ------------------
  |  |  |  Branch (105:13): [True: 4, False: 0]
  |  |  ------------------
  |  |  106|      4|            *(dest) = BN_dup(orig); \
  |  |  107|      4|        } else { \
  |  |  108|      0|            BN_copy(*(dest), orig); \
  |  |  109|      0|        } \
  |  |  110|      4|    } while(0)
  |  |  ------------------
  |  |  |  Branch (110:13): [Folded, False: 4]
  |  |  ------------------
  ------------------
  607|      4|    }
  608|      4|    if (*modulus == NULL) {
  ------------------
  |  Branch (608:9): [True: 0, False: 4]
  ------------------
  609|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  610|      0|    }
  611|       |
  612|      4|    bignum_dup(ssh_dh_generator, generator);
  ------------------
  |  |  104|      4|#define bignum_dup(orig, dest) do { \
  |  |  105|      4|        if (*(dest) == NULL) { \
  |  |  ------------------
  |  |  |  Branch (105:13): [True: 4, False: 0]
  |  |  ------------------
  |  |  106|      4|            *(dest) = BN_dup(orig); \
  |  |  107|      4|        } else { \
  |  |  108|      0|            BN_copy(*(dest), orig); \
  |  |  109|      0|        } \
  |  |  110|      4|    } while(0)
  |  |  ------------------
  |  |  |  Branch (110:13): [Folded, False: 4]
  |  |  ------------------
  ------------------
  613|      4|    if (*generator == NULL) {
  ------------------
  |  Branch (613:9): [True: 0, False: 4]
  ------------------
  614|      0|        bignum_safe_free((*modulus));
  ------------------
  |  |   71|      0|#define bignum_safe_free(num) do { \
  |  |   72|      0|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 0]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  615|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  616|      0|    }
  617|       |
  618|      4|    return SSH_OK;
  ------------------
  |  |  315|      4|#define SSH_OK 0     /* No error */
  ------------------
  619|      4|}
ssh_dh_get_next_server_publickey:
  676|    370|{
  677|    370|    return session->next_crypto->server_pubkey;
  678|    370|}
ssh_dh_get_next_server_publickey_blob:
  683|    370|{
  684|    370|    const ssh_key pubkey = ssh_dh_get_next_server_publickey(session);
  685|       |
  686|    370|    return ssh_pki_export_pubkey_blob(pubkey, pubkey_blob);
  687|    370|}
dh.c:ssh_packet_server_dh_init:
  577|      2|static SSH_PACKET_CALLBACK(ssh_packet_server_dh_init){
  578|      2|    (void)type;
  579|      2|    (void)user;
  580|      2|    SSH_LOG(SSH_LOG_DEBUG, "Received SSH_MSG_KEXDH_INIT");
  ------------------
  |  |  283|      2|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  581|      2|    ssh_packet_remove_callbacks(session, &ssh_dh_server_callbacks);
  582|      2|    ssh_server_dh_process_init(session, packet);
  583|      2|    return SSH_PACKET_USED;
  ------------------
  |  |  638|      2|#define SSH_PACKET_USED 1
  ------------------
  584|      2|}

ssh_dh_debug_crypto:
   56|      2|{
   57|       |#ifdef DEBUG_CRYPTO
   58|       |#if OPENSSL_VERSION_NUMBER < 0x30000000L
   59|       |    const_bignum x = NULL, y = NULL, e = NULL, f = NULL;
   60|       |#else
   61|       |    bignum x = NULL, y = NULL, e = NULL, f = NULL;
   62|       |#endif /* OPENSSL_VERSION_NUMBER */
   63|       |
   64|       |    ssh_dh_keypair_get_keys(c->dh_ctx, DH_CLIENT_KEYPAIR, &x, &e);
   65|       |    ssh_dh_keypair_get_keys(c->dh_ctx, DH_SERVER_KEYPAIR, &y, &f);
   66|       |    ssh_print_bignum("x", x);
   67|       |    ssh_print_bignum("y", y);
   68|       |    ssh_print_bignum("e", e);
   69|       |    ssh_print_bignum("f", f);
   70|       |#if OPENSSL_VERSION_NUMBER >= 0x30000000L
   71|       |    bignum_safe_free(x);
   72|       |    bignum_safe_free(y);
   73|       |    bignum_safe_free(e);
   74|       |    bignum_safe_free(f);
   75|       |#endif /* OPENSSL_VERSION_NUMBER */
   76|       |
   77|       |    ssh_log_hexdump("Session server cookie", c->server_kex.cookie, 16);
   78|       |    ssh_log_hexdump("Session client cookie", c->client_kex.cookie, 16);
   79|       |    ssh_print_bignum("k", c->shared_secret);
   80|       |
   81|       |#else
   82|      2|    (void)c; /* UNUSED_PARAM */
   83|      2|#endif /* DEBUG_CRYPTO */
   84|      2|}
ssh_dh_keypair_get_keys:
  113|      6|{
  114|      6|    int rc;
  115|      6|    if (((peer != DH_CLIENT_KEYPAIR) && (peer != DH_SERVER_KEYPAIR)) ||
  ------------------
  |  |   30|      6|#define DH_CLIENT_KEYPAIR 0
  ------------------
                  if (((peer != DH_CLIENT_KEYPAIR) && (peer != DH_SERVER_KEYPAIR)) ||
  ------------------
  |  |   31|      4|#define DH_SERVER_KEYPAIR 1
  ------------------
  |  Branch (115:10): [True: 4, False: 2]
  |  Branch (115:41): [True: 0, False: 4]
  ------------------
  116|      6|        ((priv == NULL) && (pub == NULL)) || (ctx == NULL) ||
  ------------------
  |  Branch (116:10): [True: 6, False: 0]
  |  Branch (116:28): [True: 0, False: 6]
  |  Branch (116:46): [True: 0, False: 6]
  ------------------
  117|      6|        (ctx->keypair[peer] == NULL)) {
  ------------------
  |  Branch (117:9): [True: 0, False: 6]
  ------------------
  118|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  119|      0|    }
  120|       |
  121|      6|    if (priv) {
  ------------------
  |  Branch (121:9): [True: 0, False: 6]
  ------------------
  122|      0|        rc = EVP_PKEY_get_bn_param(ctx->keypair[peer],
  123|      0|                                   OSSL_PKEY_PARAM_PRIV_KEY,
  124|      0|                                   priv);
  125|      0|        if (rc != 1) {
  ------------------
  |  Branch (125:13): [True: 0, False: 0]
  ------------------
  126|      0|            return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  127|      0|        }
  128|      0|    }
  129|      6|    if (pub) {
  ------------------
  |  Branch (129:9): [True: 6, False: 0]
  ------------------
  130|      6|        rc = EVP_PKEY_get_bn_param(ctx->keypair[peer],
  131|      6|                                   OSSL_PKEY_PARAM_PUB_KEY,
  132|      6|                                   pub);
  133|      6|        if (rc != 1) {
  ------------------
  |  Branch (133:13): [True: 0, False: 6]
  ------------------
  134|      0|            return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  135|      0|        }
  136|      6|    }
  137|      6|    if (priv && (*priv == NULL || bignum_num_bits(*priv) == 0)) {
  ------------------
  |  |   99|      0|#define bignum_num_bits(num) (size_t)BN_num_bits(num)
  ------------------
  |  Branch (137:9): [True: 0, False: 6]
  |  Branch (137:18): [True: 0, False: 0]
  |  Branch (137:35): [True: 0, False: 0]
  ------------------
  138|      0|        if (pub && (*pub != NULL && bignum_num_bits(*pub) != 0)) {
  ------------------
  |  |   99|      0|#define bignum_num_bits(num) (size_t)BN_num_bits(num)
  ------------------
  |  Branch (138:13): [True: 0, False: 0]
  |  Branch (138:21): [True: 0, False: 0]
  |  Branch (138:37): [True: 0, False: 0]
  ------------------
  139|      0|            bignum_safe_free(*pub);
  ------------------
  |  |   71|      0|#define bignum_safe_free(num) do { \
  |  |   72|      0|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 0]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  140|      0|            *pub = NULL;
  141|      0|        }
  142|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  143|      0|    }
  144|      6|    if (pub && (*pub == NULL || bignum_num_bits(*pub) == 0)) {
  ------------------
  |  |   99|      6|#define bignum_num_bits(num) (size_t)BN_num_bits(num)
  ------------------
  |  Branch (144:9): [True: 6, False: 0]
  |  Branch (144:17): [True: 0, False: 6]
  |  Branch (144:33): [True: 0, False: 6]
  ------------------
  145|      0|        if (priv) {
  ------------------
  |  Branch (145:13): [True: 0, False: 0]
  ------------------
  146|      0|            bignum_safe_free(*priv);
  ------------------
  |  |   71|      0|#define bignum_safe_free(num) do { \
  |  |   72|      0|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 0]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  147|      0|            *priv = NULL;
  148|      0|        }
  149|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  150|      0|    }
  151|       |
  152|      6|    return SSH_OK;
  ------------------
  |  |  315|      6|#define SSH_OK 0     /* No error */
  ------------------
  153|      6|}
ssh_dh_keypair_set_keys:
  158|      2|{
  159|      2|#if OPENSSL_VERSION_NUMBER >= 0x30000000L
  160|      2|    int rc;
  161|      2|    OSSL_PARAM *params = NULL, *out_params = NULL, *merged_params = NULL;
  162|      2|    OSSL_PARAM_BLD *param_bld = NULL;
  163|      2|    EVP_PKEY_CTX *evp_ctx = NULL;
  164|      2|#endif /* OPENSSL_VERSION_NUMBER */
  165|       |
  166|      2|    if (((peer != DH_CLIENT_KEYPAIR) && (peer != DH_SERVER_KEYPAIR)) ||
  ------------------
  |  |   30|      2|#define DH_CLIENT_KEYPAIR 0
  ------------------
                  if (((peer != DH_CLIENT_KEYPAIR) && (peer != DH_SERVER_KEYPAIR)) ||
  ------------------
  |  |   31|      0|#define DH_SERVER_KEYPAIR 1
  ------------------
  |  Branch (166:10): [True: 0, False: 2]
  |  Branch (166:41): [True: 0, False: 0]
  ------------------
  167|      2|        ((priv == NULL) && (pub == NULL)) || (ctx == NULL) ||
  ------------------
  |  Branch (167:10): [True: 2, False: 0]
  |  Branch (167:28): [True: 0, False: 2]
  |  Branch (167:46): [True: 0, False: 2]
  ------------------
  168|      2|        (ctx->keypair[peer] == NULL)) {
  ------------------
  |  Branch (168:9): [True: 0, False: 2]
  ------------------
  169|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  170|      0|    }
  171|       |
  172|       |#if OPENSSL_VERSION_NUMBER < 0x30000000L
  173|       |    (void)DH_set0_key(ctx->keypair[peer], pub, priv);
  174|       |
  175|       |    return SSH_OK;
  176|       |#else
  177|      2|    rc = EVP_PKEY_todata(ctx->keypair[peer], EVP_PKEY_KEYPAIR, &out_params);
  178|      2|    if (rc != 1) {
  ------------------
  |  Branch (178:9): [True: 0, False: 2]
  ------------------
  179|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  180|      0|    }
  181|       |
  182|      2|    param_bld = OSSL_PARAM_BLD_new();
  183|      2|    if (param_bld == NULL) {
  ------------------
  |  Branch (183:9): [True: 0, False: 2]
  ------------------
  184|      0|        rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  185|      0|        goto out;
  186|      0|    }
  187|       |
  188|      2|    evp_ctx = EVP_PKEY_CTX_new_from_pkey(NULL, ctx->keypair[peer], NULL);
  189|      2|    if (evp_ctx == NULL) {
  ------------------
  |  Branch (189:9): [True: 0, False: 2]
  ------------------
  190|      0|        rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  191|      0|        goto out;
  192|      0|    }
  193|       |
  194|      2|    rc = EVP_PKEY_fromdata_init(evp_ctx);
  195|      2|    if (rc != 1) {
  ------------------
  |  Branch (195:9): [True: 0, False: 2]
  ------------------
  196|      0|        rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  197|      0|        goto out;
  198|      0|    }
  199|       |
  200|      2|    if (priv) {
  ------------------
  |  Branch (200:9): [True: 0, False: 2]
  ------------------
  201|      0|        rc = OSSL_PARAM_BLD_push_BN(param_bld, OSSL_PKEY_PARAM_PRIV_KEY, priv);
  202|      0|        if (rc != 1) {
  ------------------
  |  Branch (202:13): [True: 0, False: 0]
  ------------------
  203|      0|            rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  204|      0|            goto out;
  205|      0|        }
  206|      0|    }
  207|      2|    if (pub) {
  ------------------
  |  Branch (207:9): [True: 2, False: 0]
  ------------------
  208|      2|        rc = OSSL_PARAM_BLD_push_BN(param_bld, OSSL_PKEY_PARAM_PUB_KEY, pub);
  209|      2|        if (rc != 1) {
  ------------------
  |  Branch (209:13): [True: 0, False: 2]
  ------------------
  210|      0|            rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  211|      0|            goto out;
  212|      0|        }
  213|      2|    }
  214|       |
  215|      2|    params = OSSL_PARAM_BLD_to_param(param_bld);
  216|      2|    if (params == NULL) {
  ------------------
  |  Branch (216:9): [True: 0, False: 2]
  ------------------
  217|      0|        rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  218|      0|        goto out;
  219|      0|    }
  220|      2|    OSSL_PARAM_BLD_free(param_bld);
  221|       |
  222|      2|    merged_params = OSSL_PARAM_merge(out_params, params);
  223|      2|    if (merged_params == NULL) {
  ------------------
  |  Branch (223:9): [True: 0, False: 2]
  ------------------
  224|      0|        rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  225|      0|        goto out;
  226|      0|    }
  227|       |
  228|      2|    rc = EVP_PKEY_fromdata(evp_ctx,
  229|      2|                           &(ctx->keypair[peer]),
  230|      2|                           EVP_PKEY_PUBLIC_KEY,
  231|      2|                           merged_params);
  232|      2|    if (rc != 1) {
  ------------------
  |  Branch (232:9): [True: 0, False: 2]
  ------------------
  233|      0|        rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  234|      0|        goto out;
  235|      0|    }
  236|       |
  237|      2|    rc = SSH_OK;
  ------------------
  |  |  315|      2|#define SSH_OK 0     /* No error */
  ------------------
  238|      2|out:
  239|      2|    bignum_safe_free(priv);
  ------------------
  |  |   71|      2|#define bignum_safe_free(num) do { \
  |  |   72|      2|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 2]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|      2|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 2]
  |  |  ------------------
  ------------------
  240|      2|    bignum_safe_free(pub);
  ------------------
  |  |   71|      2|#define bignum_safe_free(num) do { \
  |  |   72|      2|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 2, False: 0]
  |  |  ------------------
  |  |   73|      2|        BN_clear_free((num)); \
  |  |   74|      2|        (num)=NULL; \
  |  |   75|      2|    } \
  |  |   76|      2|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 2]
  |  |  ------------------
  ------------------
  241|      2|    EVP_PKEY_CTX_free(evp_ctx);
  242|      2|    OSSL_PARAM_free(out_params);
  243|      2|    OSSL_PARAM_free(params);
  244|      2|    OSSL_PARAM_free(merged_params);
  245|       |
  246|      2|    return rc;
  247|      2|#endif /* OPENSSL_VERSION_NUMBER */
  248|      2|}
ssh_dh_set_parameters:
  286|      7|{
  287|      7|    size_t i;
  288|      7|    int rc;
  289|      7|#if OPENSSL_VERSION_NUMBER >= 0x30000000L
  290|      7|    OSSL_PARAM *params = NULL;
  291|      7|    OSSL_PARAM_BLD *param_bld = NULL;
  292|      7|    EVP_PKEY_CTX *evp_ctx = NULL;
  293|      7|#endif /* OPENSSL_VERSION_NUMBER */
  294|       |
  295|      7|    if ((ctx == NULL) || (modulus == NULL) || (generator == NULL)) {
  ------------------
  |  Branch (295:9): [True: 0, False: 7]
  |  Branch (295:26): [True: 0, False: 7]
  |  Branch (295:47): [True: 0, False: 7]
  ------------------
  296|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  297|      0|    }
  298|       |
  299|      7|#if OPENSSL_VERSION_NUMBER >= 0x30000000L
  300|      7|    evp_ctx = EVP_PKEY_CTX_new_from_name(NULL, "DHX", NULL);
  301|      7|#endif
  302|       |
  303|     21|    for (i = 0; i < 2; i++) {
  ------------------
  |  Branch (303:17): [True: 14, False: 7]
  ------------------
  304|       |#if OPENSSL_VERSION_NUMBER < 0x30000000L
  305|       |        bignum p = NULL;
  306|       |        bignum g = NULL;
  307|       |
  308|       |        /* when setting modulus or generator,
  309|       |         * make sure to invalidate existing keys */
  310|       |        DH_free(ctx->keypair[i]);
  311|       |        ctx->keypair[i] = DH_new();
  312|       |        if (ctx->keypair[i] == NULL) {
  313|       |            rc = SSH_ERROR;
  314|       |            goto done;
  315|       |        }
  316|       |
  317|       |        p = BN_dup(modulus);
  318|       |        g = BN_dup(generator);
  319|       |        rc = DH_set0_pqg(ctx->keypair[i], p, NULL, g);
  320|       |        if (rc != 1) {
  321|       |            BN_free(p);
  322|       |            BN_free(g);
  323|       |            rc = SSH_ERROR;
  324|       |            goto done;
  325|       |        }
  326|       |#else
  327|     14|        param_bld = OSSL_PARAM_BLD_new();
  328|       |
  329|     14|        if (param_bld == NULL) {
  ------------------
  |  Branch (329:13): [True: 0, False: 14]
  ------------------
  330|      0|            rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  331|      0|            goto done;
  332|      0|        }
  333|       |
  334|     14|        rc = OSSL_PARAM_BLD_push_BN(param_bld, OSSL_PKEY_PARAM_FFC_P, modulus);
  335|     14|        if (rc != 1) {
  ------------------
  |  Branch (335:13): [True: 0, False: 14]
  ------------------
  336|      0|            rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  337|      0|            goto done;
  338|      0|        }
  339|     14|        rc = OSSL_PARAM_BLD_push_BN(param_bld, OSSL_PKEY_PARAM_FFC_G, generator);
  340|     14|        if (rc != 1) {
  ------------------
  |  Branch (340:13): [True: 0, False: 14]
  ------------------
  341|      0|            rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  342|      0|            goto done;
  343|      0|        }
  344|     14|        params = OSSL_PARAM_BLD_to_param(param_bld);
  345|     14|        if (params == NULL) {
  ------------------
  |  Branch (345:13): [True: 0, False: 14]
  ------------------
  346|      0|            OSSL_PARAM_BLD_free(param_bld);
  347|      0|            rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  348|      0|            goto done;
  349|      0|        }
  350|     14|        OSSL_PARAM_BLD_free(param_bld);
  351|       |
  352|     14|        rc = EVP_PKEY_fromdata_init(evp_ctx);
  353|     14|        if (rc != 1) {
  ------------------
  |  Branch (353:13): [True: 0, False: 14]
  ------------------
  354|      0|            OSSL_PARAM_free(params);
  355|      0|            rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  356|      0|            goto done;
  357|      0|        }
  358|       |
  359|       |        /* make sure to invalidate existing keys */
  360|     14|        EVP_PKEY_free(ctx->keypair[i]);
  361|     14|        ctx->keypair[i] = NULL;
  362|       |
  363|     14|        rc = EVP_PKEY_fromdata(evp_ctx,
  364|     14|                               &(ctx->keypair[i]),
  365|     14|                               EVP_PKEY_KEY_PARAMETERS,
  366|     14|                               params);
  367|     14|        if (rc != 1) {
  ------------------
  |  Branch (367:13): [True: 0, False: 14]
  ------------------
  368|      0|            OSSL_PARAM_free(params);
  369|      0|            rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  370|      0|            goto done;
  371|      0|        }
  372|       |
  373|     14|        OSSL_PARAM_free(params);
  374|     14|#endif /* OPENSSL_VERSION_NUMBER */
  375|     14|    }
  376|       |
  377|      7|    rc = SSH_OK;
  ------------------
  |  |  315|      7|#define SSH_OK 0     /* No error */
  ------------------
  378|       |#if OPENSSL_VERSION_NUMBER < 0x30000000L
  379|       |done:
  380|       |    if (rc != SSH_OK) {
  381|       |        DH_free(ctx->keypair[0]);
  382|       |        DH_free(ctx->keypair[1]);
  383|       |    }
  384|       |#else
  385|      7|done:
  386|      7|    EVP_PKEY_CTX_free(evp_ctx);
  387|       |
  388|      7|    if (rc != SSH_OK) {
  ------------------
  |  |  315|      7|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (388:9): [True: 0, False: 7]
  ------------------
  389|      0|        EVP_PKEY_free(ctx->keypair[0]);
  390|      0|        EVP_PKEY_free(ctx->keypair[1]);
  391|      0|    }
  392|      7|#endif /* OPENSSL_VERSION_NUMBER */
  393|      7|    if (rc != SSH_OK) {
  ------------------
  |  |  315|      7|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (393:9): [True: 0, False: 7]
  ------------------
  394|      0|        ctx->keypair[0] = NULL;
  395|      0|        ctx->keypair[1] = NULL;
  396|      0|    }
  397|       |
  398|      7|    return rc;
  399|      7|}
ssh_dh_init_common:
  406|     26|{
  407|     26|    struct dh_ctx *ctx = NULL;
  408|     26|    int rc;
  409|       |
  410|       |    /* Cleanup any previously allocated dh_ctx */
  411|     26|    if (crypto->dh_ctx != NULL) {
  ------------------
  |  Branch (411:9): [True: 0, False: 26]
  ------------------
  412|      0|        ssh_dh_cleanup(crypto);
  413|      0|    }
  414|       |
  415|     26|    ctx = calloc(1, sizeof(*ctx));
  416|     26|    if (ctx == NULL) {
  ------------------
  |  Branch (416:9): [True: 0, False: 26]
  ------------------
  417|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  418|      0|    }
  419|     26|    crypto->dh_ctx = ctx;
  420|       |
  421|     26|    switch (crypto->kex_type) {
  422|      0|    case SSH_KEX_DH_GROUP1_SHA1:
  ------------------
  |  Branch (422:5): [True: 0, False: 26]
  ------------------
  423|      0|        rc = ssh_dh_set_parameters(ctx, ssh_dh_group1, ssh_dh_generator);
  424|      0|        break;
  425|      0|    case SSH_KEX_DH_GROUP14_SHA1:
  ------------------
  |  Branch (425:5): [True: 0, False: 26]
  ------------------
  426|      3|    case SSH_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (426:5): [True: 3, False: 23]
  ------------------
  427|      3|    case SSH_GSS_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (427:5): [True: 0, False: 26]
  ------------------
  428|      3|        rc = ssh_dh_set_parameters(ctx, ssh_dh_group14, ssh_dh_generator);
  429|      3|        break;
  430|      0|    case SSH_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (430:5): [True: 0, False: 26]
  ------------------
  431|      0|    case SSH_GSS_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (431:5): [True: 0, False: 26]
  ------------------
  432|      0|        rc = ssh_dh_set_parameters(ctx, ssh_dh_group16, ssh_dh_generator);
  433|      0|        break;
  434|      0|    case SSH_KEX_DH_GROUP18_SHA512:
  ------------------
  |  Branch (434:5): [True: 0, False: 26]
  ------------------
  435|      0|        rc = ssh_dh_set_parameters(ctx, ssh_dh_group18, ssh_dh_generator);
  436|      0|        break;
  437|     23|    default:
  ------------------
  |  Branch (437:5): [True: 23, False: 3]
  ------------------
  438|     23|        rc = SSH_OK;
  ------------------
  |  |  315|     23|#define SSH_OK 0     /* No error */
  ------------------
  439|     23|        break;
  440|     26|    }
  441|       |
  442|     26|    if (rc != SSH_OK) {
  ------------------
  |  |  315|     26|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (442:9): [True: 0, False: 26]
  ------------------
  443|      0|        ssh_dh_cleanup(crypto);
  444|      0|    }
  445|     26|    return rc;
  446|     26|}
ssh_dh_cleanup:
  449|  1.58k|{
  450|  1.58k|    if (crypto->dh_ctx != NULL) {
  ------------------
  |  Branch (450:9): [True: 26, False: 1.56k]
  ------------------
  451|       |#if OPENSSL_VERSION_NUMBER < 0x30000000L
  452|       |        DH_free(crypto->dh_ctx->keypair[0]);
  453|       |        DH_free(crypto->dh_ctx->keypair[1]);
  454|       |#else
  455|     26|        EVP_PKEY_free(crypto->dh_ctx->keypair[0]);
  456|     26|        EVP_PKEY_free(crypto->dh_ctx->keypair[1]);
  457|     26|#endif /* OPENSSL_VERSION_NUMBER */
  458|     26|        free(crypto->dh_ctx);
  459|       |        crypto->dh_ctx = NULL;
  460|     26|    }
  461|  1.58k|}
ssh_dh_keypair_gen_keys:
  474|      2|{
  475|      2|    int rc;
  476|      2|#if OPENSSL_VERSION_NUMBER >= 0x30000000L
  477|      2|    EVP_PKEY_CTX *evp_ctx = NULL;
  478|      2|#endif
  479|       |
  480|      2|    if ((dh_ctx == NULL) || (dh_ctx->keypair[peer] == NULL)) {
  ------------------
  |  Branch (480:9): [True: 0, False: 2]
  |  Branch (480:29): [True: 0, False: 2]
  ------------------
  481|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  482|      0|    }
  483|       |
  484|       |#if OPENSSL_VERSION_NUMBER < 0x30000000L
  485|       |    rc = DH_generate_key(dh_ctx->keypair[peer]);
  486|       |    if (rc != 1) {
  487|       |        return SSH_ERROR;
  488|       |    }
  489|       |#else
  490|      2|    evp_ctx = EVP_PKEY_CTX_new_from_pkey(NULL, dh_ctx->keypair[peer], NULL);
  491|      2|    if (evp_ctx == NULL) {
  ------------------
  |  Branch (491:9): [True: 0, False: 2]
  ------------------
  492|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  493|      0|    }
  494|       |
  495|      2|    rc = EVP_PKEY_keygen_init(evp_ctx);
  496|      2|    if (rc != 1) {
  ------------------
  |  Branch (496:9): [True: 0, False: 2]
  ------------------
  497|      0|        EVP_PKEY_CTX_free(evp_ctx);
  498|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  499|      0|    }
  500|       |
  501|      2|    rc = EVP_PKEY_generate(evp_ctx, &(dh_ctx->keypair[peer]));
  502|      2|    if (rc != 1) {
  ------------------
  |  Branch (502:9): [True: 0, False: 2]
  ------------------
  503|      0|        EVP_PKEY_CTX_free(evp_ctx);
  504|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  505|      0|                "Failed to generate DH: %s",
  506|      0|                ERR_error_string(ERR_get_error(), NULL));
  507|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  508|      0|    }
  509|       |
  510|      2|    EVP_PKEY_CTX_free(evp_ctx);
  511|      2|#endif /* OPENSSL_VERSION_NUMBER */
  512|       |
  513|      2|    return SSH_OK;
  ------------------
  |  |  315|      2|#define SSH_OK 0     /* No error */
  ------------------
  514|      2|}
ssh_dh_compute_shared_secret:
  529|      2|{
  530|      2|    unsigned char *kstring = NULL;
  531|      2|    size_t kstring_len = 0;
  532|      2|    int rc;
  533|       |#if OPENSSL_VERSION_NUMBER < 0x30000000L
  534|       |    const_bignum pub_key = NULL;
  535|       |    int klen;
  536|       |#else
  537|      2|    size_t klen;
  538|      2|    EVP_PKEY_CTX *evp_ctx = NULL;
  539|      2|#endif /* OPENSSL_VERSION_NUMBER */
  540|       |
  541|      2|    if ((dh_ctx == NULL) ||
  ------------------
  |  Branch (541:9): [True: 0, False: 2]
  ------------------
  542|      2|        (dh_ctx->keypair[local] == NULL) ||
  ------------------
  |  Branch (542:9): [True: 0, False: 2]
  ------------------
  543|      2|        (dh_ctx->keypair[remote] == NULL)) {
  ------------------
  |  Branch (543:9): [True: 0, False: 2]
  ------------------
  544|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  545|      0|    }
  546|       |
  547|       |#if OPENSSL_VERSION_NUMBER < 0x30000000L
  548|       |    kstring_len = DH_size(dh_ctx->keypair[local]);
  549|       |    kstring = malloc(kstring_len);
  550|       |    if (kstring == NULL) {
  551|       |        rc = SSH_ERROR;
  552|       |        goto done;
  553|       |    }
  554|       |
  555|       |    rc = ssh_dh_keypair_get_keys(dh_ctx, remote, NULL, &pub_key);
  556|       |    if (rc != SSH_OK) {
  557|       |        rc = SSH_ERROR;
  558|       |        goto done;
  559|       |    }
  560|       |
  561|       |    klen = DH_compute_key(kstring, pub_key, dh_ctx->keypair[local]);
  562|       |    if (klen == -1) {
  563|       |        rc = SSH_ERROR;
  564|       |        goto done;
  565|       |    }
  566|       |#else
  567|      2|    evp_ctx = EVP_PKEY_CTX_new_from_pkey(NULL, dh_ctx->keypair[local], NULL);
  568|       |
  569|      2|    rc = EVP_PKEY_derive_init(evp_ctx);
  570|      2|    if (rc != 1) {
  ------------------
  |  Branch (570:9): [True: 0, False: 2]
  ------------------
  571|      0|        rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  572|      0|        goto done;
  573|      0|    }
  574|       |
  575|      2|    rc = EVP_PKEY_derive_set_peer(evp_ctx, dh_ctx->keypair[remote]);
  576|      2|    if (rc != 1) {
  ------------------
  |  Branch (576:9): [True: 0, False: 2]
  ------------------
  577|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  578|      0|                "Failed to set peer key: %s",
  579|      0|                ERR_error_string(ERR_get_error(), NULL));
  580|      0|        rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  581|      0|        goto done;
  582|      0|    }
  583|       |
  584|       |    /* getting the size of the secret */
  585|      2|    rc = EVP_PKEY_derive(evp_ctx, kstring, &klen);
  586|      2|    if (rc != 1) {
  ------------------
  |  Branch (586:9): [True: 0, False: 2]
  ------------------
  587|      0|        rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  588|      0|        goto done;
  589|      0|    }
  590|       |
  591|      2|    kstring = malloc(klen);
  592|      2|    if (kstring == NULL) {
  ------------------
  |  Branch (592:9): [True: 0, False: 2]
  ------------------
  593|      0|        rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  594|      0|        goto done;
  595|      0|    }
  596|      2|    kstring_len = klen;
  597|       |
  598|      2|    rc = EVP_PKEY_derive(evp_ctx, kstring, &klen);
  599|      2|    if (rc != 1) {
  ------------------
  |  Branch (599:9): [True: 0, False: 2]
  ------------------
  600|      0|        rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  601|      0|        goto done;
  602|      0|    }
  603|      2|#endif /* OPENSSL_VERSION_NUMBER */
  604|       |
  605|      2|    *dest = BN_bin2bn(kstring, (int)klen, NULL);
  606|      2|    if (*dest == NULL) {
  ------------------
  |  Branch (606:9): [True: 0, False: 2]
  ------------------
  607|      0|        rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  608|      0|        goto done;
  609|      0|    }
  610|       |
  611|      2|    rc = SSH_OK;
  ------------------
  |  |  315|      2|#define SSH_OK 0     /* No error */
  ------------------
  612|      2|done:
  613|      2|#if OPENSSL_VERSION_NUMBER >= 0x30000000L
  614|      2|    EVP_PKEY_CTX_free(evp_ctx);
  615|      2|#endif
  616|       |    /* The raw shared secret */
  617|       |    BURN_FREE(kstring, kstring_len);
  ------------------
  |  |  414|      2|    do {                           \
  |  |  415|      2|        if ((x) != NULL) {         \
  |  |  ------------------
  |  |  |  Branch (415:13): [True: 2, False: 0]
  |  |  ------------------
  |  |  416|      2|            burn_free((x), (len)); \
  |  |  417|      2|            (x) = NULL;            \
  |  |  418|      2|        }                          \
  |  |  419|      2|    } while (0)
  |  |  ------------------
  |  |  |  Branch (419:14): [Folded, False: 2]
  |  |  ------------------
  ------------------
  618|      2|    return rc;
  619|      2|}

_ssh_set_error:
   55|  2.16k|{
   56|  2.16k|    struct ssh_common_struct *err = error;
   57|  2.16k|    va_list va;
   58|       |
   59|  2.16k|    va_start(va, descr);
   60|  2.16k|    vsnprintf(err->error.error_buffer, ERROR_BUFFERLEN, descr, va);
  ------------------
  |  |  219|  2.16k|#define ERROR_BUFFERLEN 1024
  ------------------
   61|  2.16k|    va_end(va);
   62|       |
   63|  2.16k|    err->error.error_code = code;
   64|  2.16k|    if (ssh_get_log_level() == SSH_LOG_TRACE) {
  ------------------
  |  |  362|  2.16k|#define SSH_LOG_TRACE 4
  ------------------
  |  Branch (64:9): [True: 0, False: 2.16k]
  ------------------
   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|  2.16k|}
_ssh_set_error_oom:
   81|     87|{
   82|     87|    struct error_struct *err = error;
   83|       |
   84|     87|    snprintf(err->error_buffer, sizeof(err->error_buffer),
   85|     87|            "%s: Out of memory", function);
   86|     87|    err->error_code = SSH_FATAL;
   87|     87|}
_ssh_set_error_invalid:
  100|    806|{
  101|    806|    _ssh_set_error(error, SSH_FATAL, function,
  102|    806|                   "Invalid argument in %s", function);
  103|    806|}
ssh_get_error:
  127|    228|const char *ssh_get_error(void *error) {
  128|    228|  struct error_struct *err = error;
  129|       |
  130|    228|  return err->error_buffer;
  131|    228|}

ssh_get_random:
   48|  5.60k|{
   49|       |#ifdef HAVE_OPENSSL_RAND_PRIV_BYTES
   50|       |    if (strong) {
   51|       |        /* Returns -1 when not supported, 0 on error, 1 on success */
   52|       |        return !!RAND_priv_bytes(where, len);
   53|       |    }
   54|       |#else
   55|  5.60k|    (void)strong;
   56|  5.60k|#endif /* HAVE_RAND_PRIV_BYTES */
   57|       |
   58|       |    /* Returns -1 when not supported, 0 on error, 1 on success */
   59|  5.60k|    return !!RAND_bytes(where, len);
   60|  5.60k|}

compress_cleanup:
  266|  1.58k|{
  267|  1.58k|    if (crypto->compress_out_ctx) {
  ------------------
  |  Branch (267:9): [True: 0, False: 1.58k]
  ------------------
  268|      0|        deflateEnd(crypto->compress_out_ctx);
  269|      0|    }
  270|  1.58k|    SAFE_FREE(crypto->compress_out_ctx);
  ------------------
  |  |  375|  1.58k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 1.58k]
  |  |  |  Branch (375:71): [Folded, False: 1.58k]
  |  |  ------------------
  ------------------
  271|       |
  272|  1.58k|    if (crypto->compress_in_ctx) {
  ------------------
  |  Branch (272:9): [True: 0, False: 1.58k]
  ------------------
  273|      0|        inflateEnd(crypto->compress_in_ctx);
  274|      0|    }
  275|       |    SAFE_FREE(crypto->compress_in_ctx);
  ------------------
  |  |  375|  1.58k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 1.58k]
  |  |  |  Branch (375:71): [Folded, False: 1.58k]
  |  |  ------------------
  ------------------
  276|  1.58k|}

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

ssh_kex_get_default_methods:
  300|  1.93k|{
  301|  1.93k|    if (type >= SSH_KEX_METHODS) {
  ------------------
  |  |   27|  1.93k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (301:9): [True: 0, False: 1.93k]
  ------------------
  302|      0|        return NULL;
  303|      0|    }
  304|       |
  305|  1.93k|    return default_methods[type];
  306|  1.93k|}
ssh_packet_kexinit:
  397|    260|{
  398|    260|    int i, ok;
  399|    260|    struct ssh_crypto_struct *crypto = session->next_crypto;
  400|    260|    int server_kex = session->server;
  401|    260|    ssh_string str = NULL;
  402|    260|    char *strings[SSH_KEX_METHODS] = {0};
  403|    260|    int rc = SSH_ERROR;
  ------------------
  |  |  316|    260|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  404|    260|    size_t len;
  405|       |
  406|    260|    uint8_t first_kex_packet_follows = 0;
  407|    260|    uint32_t kexinit_reserved = 0;
  408|       |
  409|    260|    (void)type;
  410|    260|    (void)user;
  411|       |
  412|    260|    SSH_LOG(SSH_LOG_TRACE, "KEXINIT received");
  ------------------
  |  |  283|    260|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  413|       |
  414|    260|    if (session->session_state == SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (414:9): [True: 4, False: 256]
  ------------------
  415|      4|        if (session->dh_handshake_state == DH_STATE_FINISHED) {
  ------------------
  |  Branch (415:13): [True: 4, False: 0]
  ------------------
  416|      4|            SSH_LOG(SSH_LOG_DEBUG, "Peer initiated key re-exchange");
  ------------------
  |  |  283|      4|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  417|       |            /* Reset the sent flag if the re-kex was initiated by the peer */
  418|      4|            session->flags &= ~SSH_SESSION_FLAG_KEXINIT_SENT;
  ------------------
  |  |   86|      4|#define SSH_SESSION_FLAG_KEXINIT_SENT 0x0008
  ------------------
  419|      4|        } else if (session->flags & SSH_SESSION_FLAG_KEXINIT_SENT &&
  ------------------
  |  |   86|      0|#define SSH_SESSION_FLAG_KEXINIT_SENT 0x0008
  ------------------
  |  Branch (419:20): [True: 0, False: 0]
  ------------------
  420|      0|                   session->dh_handshake_state == DH_STATE_INIT_SENT) {
  ------------------
  |  Branch (420:20): [True: 0, False: 0]
  ------------------
  421|       |            /* This happens only when we are sending our-guessed first kex
  422|       |             * packet right after our KEXINIT packet. */
  423|      0|            SSH_LOG(SSH_LOG_DEBUG, "Received peer kexinit answer.");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  424|      0|        } else if (session->session_state != SSH_SESSION_STATE_INITIAL_KEX) {
  ------------------
  |  Branch (424:20): [True: 0, False: 0]
  ------------------
  425|      0|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  426|      0|                          "SSH_KEXINIT received in wrong state");
  427|      0|            goto error;
  428|      0|        }
  429|    256|    } else if (session->session_state != SSH_SESSION_STATE_INITIAL_KEX) {
  ------------------
  |  Branch (429:16): [True: 0, False: 256]
  ------------------
  430|      0|        ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  431|      0|                      "SSH_KEXINIT received in wrong state");
  432|      0|        goto error;
  433|      0|    }
  434|       |
  435|    260|    if (server_kex) {
  ------------------
  |  Branch (435:9): [True: 260, False: 0]
  ------------------
  436|    260|#ifdef WITH_SERVER
  437|    260|        len = ssh_buffer_get_data(packet, crypto->client_kex.cookie, 16);
  438|    260|        if (len != 16) {
  ------------------
  |  Branch (438:13): [True: 0, False: 260]
  ------------------
  439|      0|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  440|      0|                          "ssh_packet_kexinit: no cookie in packet");
  441|      0|            goto error;
  442|      0|        }
  443|       |
  444|    260|        ok = ssh_hashbufin_add_cookie(session, crypto->client_kex.cookie);
  445|    260|        if (ok < 0) {
  ------------------
  |  Branch (445:13): [True: 0, False: 260]
  ------------------
  446|      0|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  447|      0|                          "ssh_packet_kexinit: adding cookie failed");
  448|      0|            goto error;
  449|      0|        }
  450|       |
  451|    260|        ok = server_set_kex(session);
  452|    260|        if (ok == SSH_ERROR) {
  ------------------
  |  |  316|    260|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (452:13): [True: 0, False: 260]
  ------------------
  453|      0|            goto error;
  454|      0|        }
  455|    260|#endif /* WITH_SERVER */
  456|    260|    } else {
  457|      0|        len = ssh_buffer_get_data(packet, crypto->server_kex.cookie, 16);
  458|      0|        if (len != 16) {
  ------------------
  |  Branch (458:13): [True: 0, False: 0]
  ------------------
  459|      0|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  460|      0|                          "ssh_packet_kexinit: no cookie in packet");
  461|      0|            goto error;
  462|      0|        }
  463|       |
  464|      0|        ok = ssh_hashbufin_add_cookie(session, crypto->server_kex.cookie);
  465|      0|        if (ok < 0) {
  ------------------
  |  Branch (465:13): [True: 0, False: 0]
  ------------------
  466|      0|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  467|      0|                          "ssh_packet_kexinit: adding cookie failed");
  468|      0|            goto error;
  469|      0|        }
  470|       |
  471|      0|        ok = ssh_set_client_kex(session);
  472|      0|        if (ok == SSH_ERROR) {
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (472:13): [True: 0, False: 0]
  ------------------
  473|      0|            goto error;
  474|      0|        }
  475|      0|    }
  476|       |
  477|  2.80k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  2.80k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (477:17): [True: 2.55k, False: 249]
  ------------------
  478|  2.55k|        str = ssh_buffer_get_ssh_string(packet);
  479|  2.55k|        if (str == NULL) {
  ------------------
  |  Branch (479:13): [True: 11, False: 2.54k]
  ------------------
  480|     11|          goto error;
  481|     11|        }
  482|       |
  483|  2.54k|        rc = ssh_buffer_add_ssh_string(session->in_hashbuf, str);
  484|  2.54k|        if (rc < 0) {
  ------------------
  |  Branch (484:13): [True: 0, False: 2.54k]
  ------------------
  485|      0|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  486|      0|                          "Error adding string in hash buffer");
  487|      0|            goto error;
  488|      0|        }
  489|       |
  490|  2.54k|        strings[i] = ssh_string_to_char(str);
  491|  2.54k|        if (strings[i] == NULL) {
  ------------------
  |  Branch (491:13): [True: 0, False: 2.54k]
  ------------------
  492|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  493|      0|            goto error;
  494|      0|        }
  495|  2.54k|        SSH_STRING_FREE(str);
  ------------------
  |  |  882|  2.54k|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 2.54k, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 2.54k]
  |  |  ------------------
  ------------------
  496|  2.54k|        str = NULL;
  497|  2.54k|    }
  498|       |
  499|       |    /* copy the peer kex info into an array of strings */
  500|    249|    if (server_kex) {
  ------------------
  |  Branch (500:9): [True: 249, False: 0]
  ------------------
  501|    249|#ifdef WITH_SERVER
  502|  2.73k|        for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  2.73k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (502:21): [True: 2.49k, False: 249]
  ------------------
  503|  2.49k|            crypto->client_kex.methods[i] = strings[i];
  504|  2.49k|        }
  505|    249|#endif /* WITH_SERVER */
  506|    249|    } else { /* client */
  507|      0|        for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|      0|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (507:21): [True: 0, False: 0]
  ------------------
  508|      0|            crypto->server_kex.methods[i] = strings[i];
  509|      0|        }
  510|      0|    }
  511|       |
  512|       |    /*
  513|       |     * Handle the two final fields for the KEXINIT message (RFC 4253 7.1):
  514|       |     *
  515|       |     *      boolean      first_kex_packet_follows
  516|       |     *      uint32       0 (reserved for future extension)
  517|       |     *
  518|       |     * Notably if clients set 'first_kex_packet_follows', it is expected
  519|       |     * that its value is included when computing the session ID (see
  520|       |     * 'make_sessionid').
  521|       |     */
  522|       |
  523|    249|    rc = ssh_buffer_get_u8(packet, &first_kex_packet_follows);
  524|    249|    if (rc != 1) {
  ------------------
  |  Branch (524:9): [True: 0, False: 249]
  ------------------
  525|      0|        goto error;
  526|      0|    }
  527|       |
  528|    249|    rc = ssh_buffer_add_u8(session->in_hashbuf, first_kex_packet_follows);
  529|    249|    if (rc < 0) {
  ------------------
  |  Branch (529:9): [True: 0, False: 249]
  ------------------
  530|      0|        goto error;
  531|      0|    }
  532|       |
  533|    249|    rc = ssh_buffer_add_u32(session->in_hashbuf, kexinit_reserved);
  534|    249|    if (rc < 0) {
  ------------------
  |  Branch (534:9): [True: 0, False: 249]
  ------------------
  535|      0|        goto error;
  536|      0|    }
  537|       |
  538|       |    /*
  539|       |     * Remember whether 'first_kex_packet_follows' was set and the client
  540|       |     * guess was wrong: in this case the next SSH_MSG_KEXDH_INIT message
  541|       |     * must be ignored on the server side.
  542|       |     * Client needs to start the Key exchange over with the correct method
  543|       |     */
  544|    249|    if (first_kex_packet_follows || session->send_first_kex_follows) {
  ------------------
  |  Branch (544:9): [True: 7, False: 242]
  |  Branch (544:37): [True: 0, False: 242]
  ------------------
  545|      7|        char **client_methods = crypto->client_kex.methods;
  546|      7|        char **server_methods = crypto->server_kex.methods;
  547|      7|        session->first_kex_follows_guess_wrong =
  548|      7|            cmp_first_kex_algo(client_methods[SSH_KEX],
  ------------------
  |  Branch (548:13): [True: 7, False: 0]
  ------------------
  549|      7|                               server_methods[SSH_KEX]) ||
  550|      0|            cmp_first_kex_algo(client_methods[SSH_HOSTKEYS],
  ------------------
  |  Branch (550:13): [True: 0, False: 0]
  ------------------
  551|      0|                               server_methods[SSH_HOSTKEYS]);
  552|      7|            SSH_LOG(SSH_LOG_DEBUG, "The initial guess was %s.",
  ------------------
  |  |  283|     14|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (283:34): [True: 7, False: 0]
  |  |  ------------------
  ------------------
  553|      7|                    session->first_kex_follows_guess_wrong ? "wrong" : "right");
  554|      7|    }
  555|       |
  556|       |    /*
  557|       |     * handle the "strict KEX" feature. If supported by peer, then set up the
  558|       |     * flag and verify packet sequence numbers.
  559|       |     */
  560|    249|    if (server_kex) {
  ------------------
  |  Branch (560:9): [True: 249, False: 0]
  ------------------
  561|    249|        ok = match_group(crypto->client_kex.methods[SSH_KEX],
  562|    249|                         KEX_STRICT_CLIENT);
  ------------------
  |  |  196|    249|#define KEX_STRICT_CLIENT "kex-strict-c-v00@openssh.com"
  ------------------
  563|    249|        if (ok) {
  ------------------
  |  Branch (563:13): [True: 2, False: 247]
  ------------------
  564|      2|            SSH_LOG(SSH_LOG_DEBUG, "Client supports strict kex, enabling.");
  ------------------
  |  |  283|      2|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  565|      2|            session->flags |= SSH_SESSION_FLAG_KEX_STRICT;
  ------------------
  |  |   90|      2|#define SSH_SESSION_FLAG_KEX_STRICT 0x0010
  ------------------
  566|      2|        }
  567|    249|    } else {
  568|       |        /* client kex */
  569|      0|        ok = match_group(crypto->server_kex.methods[SSH_KEX],
  570|      0|                         KEX_STRICT_SERVER);
  ------------------
  |  |  197|      0|#define KEX_STRICT_SERVER "kex-strict-s-v00@openssh.com"
  ------------------
  571|      0|        if (ok) {
  ------------------
  |  Branch (571:13): [True: 0, False: 0]
  ------------------
  572|      0|            SSH_LOG(SSH_LOG_DEBUG, "Server supports strict kex, enabling.");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  573|      0|            session->flags |= SSH_SESSION_FLAG_KEX_STRICT;
  ------------------
  |  |   90|      0|#define SSH_SESSION_FLAG_KEX_STRICT 0x0010
  ------------------
  574|      0|        }
  575|      0|    }
  576|    249|#ifdef WITH_SERVER
  577|    249|    if (server_kex) {
  ------------------
  |  Branch (577:9): [True: 249, False: 0]
  ------------------
  578|       |        /*
  579|       |         * If client sent a ext-info-c message in the kex list, it supports
  580|       |         * RFC 8308 extension negotiation.
  581|       |         */
  582|    249|        ok = match_group(crypto->client_kex.methods[SSH_KEX],
  583|    249|                         KEX_EXTENSION_CLIENT);
  ------------------
  |  |  194|    249|#define KEX_EXTENSION_CLIENT "ext-info-c"
  ------------------
  584|    249|        if (ok) {
  ------------------
  |  Branch (584:13): [True: 1, False: 248]
  ------------------
  585|      1|            const char *hostkeys = NULL, *wanted_hostkeys = NULL;
  586|       |
  587|       |            /* The client supports extension negotiation */
  588|      1|            session->extensions |= SSH_EXT_NEGOTIATION;
  ------------------
  |  |  124|      1|#define SSH_EXT_NEGOTIATION     0x01
  ------------------
  589|       |            /*
  590|       |             * RFC 8332 Section 3.1: Use for Server Authentication
  591|       |             * Check what algorithms were provided in the SSH_HOSTKEYS list
  592|       |             * by the client and enable the respective extensions to provide
  593|       |             * correct signature in the next packet if RSA is negotiated
  594|       |             */
  595|      1|            hostkeys = crypto->client_kex.methods[SSH_HOSTKEYS];
  596|      1|            wanted_hostkeys = session->opts.wanted_methods[SSH_HOSTKEYS];
  597|      1|            ok = match_group(hostkeys, "rsa-sha2-512");
  598|      1|            if (ok) {
  ------------------
  |  Branch (598:17): [True: 0, False: 1]
  ------------------
  599|       |                /* Check if rsa-sha2-512 is allowed by config */
  600|      0|                if (wanted_hostkeys != NULL) {
  ------------------
  |  Branch (600:21): [True: 0, False: 0]
  ------------------
  601|      0|                    char *is_allowed = ssh_find_matching(wanted_hostkeys,
  602|      0|                                                         "rsa-sha2-512");
  603|      0|                    if (is_allowed != NULL) {
  ------------------
  |  Branch (603:25): [True: 0, False: 0]
  ------------------
  604|      0|                        session->extensions |= SSH_EXT_SIG_RSA_SHA512;
  ------------------
  |  |  127|      0|#define SSH_EXT_SIG_RSA_SHA512  0x04
  ------------------
  605|      0|                    }
  606|      0|                    SAFE_FREE(is_allowed);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  607|      0|                }
  608|      0|            }
  609|      1|            ok = match_group(hostkeys, "rsa-sha2-256");
  610|      1|            if (ok) {
  ------------------
  |  Branch (610:17): [True: 0, False: 1]
  ------------------
  611|       |                /* Check if rsa-sha2-256 is allowed by config */
  612|      0|                if (wanted_hostkeys != NULL) {
  ------------------
  |  Branch (612:21): [True: 0, False: 0]
  ------------------
  613|      0|                    char *is_allowed = ssh_find_matching(wanted_hostkeys,
  614|      0|                                                         "rsa-sha2-256");
  615|      0|                    if (is_allowed != NULL) {
  ------------------
  |  Branch (615:25): [True: 0, False: 0]
  ------------------
  616|      0|                        session->extensions |= SSH_EXT_SIG_RSA_SHA256;
  ------------------
  |  |  126|      0|#define SSH_EXT_SIG_RSA_SHA256  0x02
  ------------------
  617|      0|                    }
  618|      0|                    SAFE_FREE(is_allowed);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  619|      0|                }
  620|      0|            }
  621|       |
  622|       |            /*
  623|       |             * Ensure that the client preference is honored for the case
  624|       |             * both signature types are enabled.
  625|       |             */
  626|      1|            if ((session->extensions & SSH_EXT_SIG_RSA_SHA256) &&
  ------------------
  |  |  126|      1|#define SSH_EXT_SIG_RSA_SHA256  0x02
  ------------------
  |  Branch (626:17): [True: 0, False: 1]
  ------------------
  627|      0|                (session->extensions & SSH_EXT_SIG_RSA_SHA512)) {
  ------------------
  |  |  127|      0|#define SSH_EXT_SIG_RSA_SHA512  0x04
  ------------------
  |  Branch (627:17): [True: 0, False: 0]
  ------------------
  628|      0|                char *rsa_sig_ext = NULL;
  629|      0|                session->extensions &= ~(SSH_EXT_SIG_RSA_SHA256 | SSH_EXT_SIG_RSA_SHA512);
  ------------------
  |  |  126|      0|#define SSH_EXT_SIG_RSA_SHA256  0x02
  ------------------
                              session->extensions &= ~(SSH_EXT_SIG_RSA_SHA256 | SSH_EXT_SIG_RSA_SHA512);
  ------------------
  |  |  127|      0|#define SSH_EXT_SIG_RSA_SHA512  0x04
  ------------------
  630|      0|                rsa_sig_ext = ssh_find_matching("rsa-sha2-512,rsa-sha2-256",
  631|      0|                                                hostkeys);
  632|      0|                if (rsa_sig_ext == NULL) {
  ------------------
  |  Branch (632:21): [True: 0, False: 0]
  ------------------
  633|      0|                    goto error; /* should never happen */
  634|      0|                } else if (strcmp(rsa_sig_ext, "rsa-sha2-512") == 0) {
  ------------------
  |  Branch (634:28): [True: 0, False: 0]
  ------------------
  635|      0|                    session->extensions |= SSH_EXT_SIG_RSA_SHA512;
  ------------------
  |  |  127|      0|#define SSH_EXT_SIG_RSA_SHA512  0x04
  ------------------
  636|      0|                } else if (strcmp(rsa_sig_ext, "rsa-sha2-256") == 0) {
  ------------------
  |  Branch (636:28): [True: 0, False: 0]
  ------------------
  637|      0|                    session->extensions |= SSH_EXT_SIG_RSA_SHA256;
  ------------------
  |  |  126|      0|#define SSH_EXT_SIG_RSA_SHA256  0x02
  ------------------
  638|      0|                } else {
  639|      0|                    SAFE_FREE(rsa_sig_ext);
  ------------------
  |  |  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|                    goto error; /* should never happen */
  641|      0|                }
  642|      0|                SAFE_FREE(rsa_sig_ext);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  643|      0|            }
  644|       |
  645|      1|            SSH_LOG(SSH_LOG_DEBUG, "The client supports extension "
  ------------------
  |  |  283|      4|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (283:34): [True: 0, False: 1]
  |  |  |  Branch (283:34): [True: 0, False: 1]
  |  |  ------------------
  ------------------
  646|      1|                    "negotiation. Enabled signature algorithms: %s%s",
  647|      1|                    session->extensions & SSH_EXT_SIG_RSA_SHA256 ? "SHA256" : "",
  648|      1|                    session->extensions & SSH_EXT_SIG_RSA_SHA512 ? " SHA512" : "");
  649|      1|        }
  650|    249|    }
  651|    249|#endif /* WITH_SERVER */
  652|       |
  653|       |    /* Note, that his overwrites authenticated state in case of rekeying */
  654|    249|    session->session_state = SSH_SESSION_STATE_KEXINIT_RECEIVED;
  655|       |    /* if we already sent our initial key exchange packet, do not reset the
  656|       |     * DH state. We will know if we were right with our guess only in
  657|       |     * dh_handshake_state() */
  658|    249|    if (session->send_first_kex_follows == false) {
  ------------------
  |  Branch (658:9): [True: 249, False: 0]
  ------------------
  659|    249|        session->dh_handshake_state = DH_STATE_INIT;
  660|    249|    }
  661|    249|    session->ssh_connection_callback(session);
  662|    249|    return SSH_PACKET_USED;
  ------------------
  |  |  638|    249|#define SSH_PACKET_USED 1
  ------------------
  663|       |
  664|     11|error:
  665|     11|    SSH_STRING_FREE(str);
  ------------------
  |  |  882|     11|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 11]
  |  |  |  Branch (882:69): [Folded, False: 11]
  |  |  ------------------
  ------------------
  666|    121|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|    121|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (666:17): [True: 110, False: 11]
  ------------------
  667|    110|        if (server_kex) {
  ------------------
  |  Branch (667:13): [True: 110, False: 0]
  ------------------
  668|    110|#ifdef WITH_SERVER
  669|    110|            session->next_crypto->client_kex.methods[i] = NULL;
  670|    110|#endif /* WITH_SERVER */
  671|    110|        } else { /* client */
  672|      0|            session->next_crypto->server_kex.methods[i] = NULL;
  673|      0|        }
  674|    110|        SAFE_FREE(strings[i]);
  ------------------
  |  |  375|    110|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 52, False: 58]
  |  |  |  Branch (375:71): [Folded, False: 110]
  |  |  ------------------
  ------------------
  675|    110|    }
  676|       |
  677|     11|    session->session_state = SSH_SESSION_STATE_ERROR;
  678|       |
  679|     11|    return SSH_PACKET_USED;
  ------------------
  |  |  638|     11|#define SSH_PACKET_USED 1
  ------------------
  680|    249|}
ssh_list_kex:
  682|    547|void ssh_list_kex(struct ssh_kex_struct *kex) {
  683|    547|  int i = 0;
  684|       |
  685|       |#ifdef DEBUG_CRYPTO
  686|       |  ssh_log_hexdump("session cookie", kex->cookie, 16);
  687|       |#endif
  688|       |
  689|  6.01k|  for(i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  6.01k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (689:14): [True: 5.47k, False: 547]
  ------------------
  690|  5.47k|    if (kex->methods[i] == NULL) {
  ------------------
  |  Branch (690:9): [True: 0, False: 5.47k]
  ------------------
  691|      0|      continue;
  692|      0|    }
  693|  5.47k|    SSH_LOG(SSH_LOG_FUNCTIONS, "%s: %s",
  ------------------
  |  |  283|  5.47k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  694|  5.47k|        ssh_kex_descriptions[i], kex->methods[i]);
  695|  5.47k|  }
  696|    547|}
ssh_kex_append_extensions:
  911|    319|{
  912|    319|    char *kex = NULL;
  913|    319|    char *kex_tmp = NULL;
  914|    319|    size_t kex_len, len;
  915|       |
  916|       |    /* Here we append ext-info-c and kex-strict-c-v00@openssh.com for client
  917|       |     * and kex-strict-s-v00@openssh.com for server to the list of kex algorithms
  918|       |     */
  919|    319|    kex = pkex->methods[SSH_KEX];
  920|    319|    len = strlen(kex);
  921|    319|    if (session->server) {
  ------------------
  |  Branch (921:9): [True: 319, False: 0]
  ------------------
  922|       |        /* Comma, nul byte */
  923|    319|        kex_len = len + 1 + strlen(KEX_STRICT_SERVER) + 1;
  ------------------
  |  |  197|    319|#define KEX_STRICT_SERVER "kex-strict-s-v00@openssh.com"
  ------------------
  924|    319|    } else {
  925|       |        /* Comma, comma, nul byte */
  926|      0|        kex_len = len + 1 + strlen(KEX_EXTENSION_CLIENT) + 1 +
  ------------------
  |  |  194|      0|#define KEX_EXTENSION_CLIENT "ext-info-c"
  ------------------
  927|      0|                  strlen(KEX_STRICT_CLIENT) + 1;
  ------------------
  |  |  196|      0|#define KEX_STRICT_CLIENT "kex-strict-c-v00@openssh.com"
  ------------------
  928|      0|    }
  929|    319|    if (kex_len >= MAX_PACKET_LEN) {
  ------------------
  |  |  216|    319|#define MAX_PACKET_LEN 262144
  ------------------
  |  Branch (929:9): [True: 0, False: 319]
  ------------------
  930|       |        /* Overflow */
  931|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  932|      0|    }
  933|    319|    kex_tmp = realloc(kex, kex_len);
  934|    319|    if (kex_tmp == NULL) {
  ------------------
  |  Branch (934:9): [True: 0, False: 319]
  ------------------
  935|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  936|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  937|      0|    }
  938|    319|    if (session->server){
  ------------------
  |  Branch (938:9): [True: 319, False: 0]
  ------------------
  939|    319|        snprintf(kex_tmp + len, kex_len - len, ",%s", KEX_STRICT_SERVER);
  ------------------
  |  |  197|    319|#define KEX_STRICT_SERVER "kex-strict-s-v00@openssh.com"
  ------------------
  940|    319|    } else {
  941|      0|        snprintf(kex_tmp + len,
  942|      0|                 kex_len - len,
  943|      0|                 ",%s,%s",
  944|      0|                 KEX_EXTENSION_CLIENT,
  ------------------
  |  |  194|      0|#define KEX_EXTENSION_CLIENT "ext-info-c"
  ------------------
  945|      0|                 KEX_STRICT_CLIENT);
  ------------------
  |  |  196|      0|#define KEX_STRICT_CLIENT "kex-strict-c-v00@openssh.com"
  ------------------
  946|      0|    }
  947|    319|    pkex->methods[SSH_KEX] = kex_tmp;
  948|    319|    return SSH_OK;
  ------------------
  |  |  315|    319|#define SSH_OK 0     /* No error */
  ------------------
  949|    319|}
ssh_kex_select_methods:
 1082|    249|{
 1083|    249|    struct ssh_crypto_struct *crypto = session->next_crypto;
 1084|    249|    struct ssh_kex_struct *server = &crypto->server_kex;
 1085|    249|    struct ssh_kex_struct *client = &crypto->client_kex;
 1086|    249|    char *ext_start = NULL;
 1087|    249|    const char *aead_hmac = NULL;
 1088|    249|    enum ssh_key_exchange_e kex_type;
 1089|    249|    int i;
 1090|       |
 1091|       |    /* Here we should drop the extensions from the list so we avoid matching.
 1092|       |     * it. We added it to the end, so we can just truncate the string here */
 1093|    249|    if (session->client) {
  ------------------
  |  Branch (1093:9): [True: 0, False: 249]
  ------------------
 1094|      0|        ext_start = strstr(client->methods[SSH_KEX], "," KEX_EXTENSION_CLIENT);
  ------------------
  |  |  194|      0|#define KEX_EXTENSION_CLIENT "ext-info-c"
  ------------------
 1095|      0|        if (ext_start != NULL) {
  ------------------
  |  Branch (1095:13): [True: 0, False: 0]
  ------------------
 1096|      0|            ext_start[0] = '\0';
 1097|      0|        }
 1098|      0|    }
 1099|    249|    if (session->server) {
  ------------------
  |  Branch (1099:9): [True: 249, False: 0]
  ------------------
 1100|    249|        ext_start = strstr(server->methods[SSH_KEX], "," KEX_STRICT_SERVER);
  ------------------
  |  |  197|    249|#define KEX_STRICT_SERVER "kex-strict-s-v00@openssh.com"
  ------------------
 1101|    249|        if (ext_start != NULL) {
  ------------------
  |  Branch (1101:13): [True: 245, False: 4]
  ------------------
 1102|    245|            ext_start[0] = '\0';
 1103|    245|        }
 1104|    249|    }
 1105|       |
 1106|  2.43k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  2.43k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (1106:17): [True: 2.21k, False: 218]
  ------------------
 1107|  2.21k|        crypto->kex_methods[i] = ssh_find_matching(server->methods[i],
 1108|  2.21k|                                                   client->methods[i]);
 1109|       |
 1110|  2.21k|        if (i == SSH_MAC_C_S || i == SSH_MAC_S_C) {
  ------------------
  |  Branch (1110:13): [True: 218, False: 2.00k]
  |  Branch (1110:33): [True: 218, False: 1.78k]
  ------------------
 1111|    436|            aead_hmac = ssh_find_aead_hmac(crypto->kex_methods[i - 2]);
 1112|    436|            if (aead_hmac) {
  ------------------
  |  Branch (1112:17): [True: 0, False: 436]
  ------------------
 1113|      0|                free(crypto->kex_methods[i]);
 1114|      0|                crypto->kex_methods[i] = strdup(aead_hmac);
 1115|      0|            }
 1116|    436|        }
 1117|  2.21k|        if (crypto->kex_methods[i] == NULL && i < SSH_LANG_C_S) {
  ------------------
  |  Branch (1117:13): [True: 223, False: 1.99k]
  |  Branch (1117:47): [True: 31, False: 192]
  ------------------
 1118|     31|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  313|     31|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1119|     31|                          "kex error : no match for method %s: server [%s], "
 1120|     31|                          "client [%s]", ssh_kex_descriptions[i],
 1121|     31|                          server->methods[i], client->methods[i]);
 1122|     31|            return SSH_ERROR;
  ------------------
  |  |  316|     31|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1123|  2.18k|        } else if ((i >= SSH_LANG_C_S) && (crypto->kex_methods[i] == NULL)) {
  ------------------
  |  Branch (1123:20): [True: 436, False: 1.75k]
  |  Branch (1123:43): [True: 192, False: 244]
  ------------------
 1124|       |            /* we can safely do that for languages */
 1125|    192|            crypto->kex_methods[i] = strdup("");
 1126|    192|        }
 1127|  2.21k|    }
 1128|       |
 1129|       |    /* We can not set this value directly as the old value is needed to revert
 1130|       |     * callbacks if we are client */
 1131|    218|    kex_type = kex_select_kex_type(crypto->kex_methods[SSH_KEX]);
 1132|    218|    if (session->client && session->first_kex_follows_guess_wrong) {
  ------------------
  |  Branch (1132:9): [True: 0, False: 218]
  |  Branch (1132:28): [True: 0, False: 0]
  ------------------
 1133|      0|        SSH_LOG(SSH_LOG_DEBUG, "Our guess was wrong. Restarting the KEX");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1134|       |        /* We need to remove the wrong callbacks and start kex again */
 1135|      0|        revert_kex_callbacks(session);
 1136|      0|        session->dh_handshake_state = DH_STATE_INIT;
 1137|      0|        session->first_kex_follows_guess_wrong = false;
 1138|      0|    }
 1139|    218|    crypto->kex_type = kex_type;
 1140|       |
 1141|    218|    SSH_LOG(SSH_LOG_DEBUG, "Negotiated %s,%s,%s,%s,%s,%s,%s,%s,%s,%s",
  ------------------
  |  |  283|    218|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1142|    218|            session->next_crypto->kex_methods[SSH_KEX],
 1143|    218|            session->next_crypto->kex_methods[SSH_HOSTKEYS],
 1144|    218|            session->next_crypto->kex_methods[SSH_CRYPT_C_S],
 1145|    218|            session->next_crypto->kex_methods[SSH_CRYPT_S_C],
 1146|    218|            session->next_crypto->kex_methods[SSH_MAC_C_S],
 1147|    218|            session->next_crypto->kex_methods[SSH_MAC_S_C],
 1148|    218|            session->next_crypto->kex_methods[SSH_COMP_C_S],
 1149|    218|            session->next_crypto->kex_methods[SSH_COMP_S_C],
 1150|    218|            session->next_crypto->kex_methods[SSH_LANG_C_S],
 1151|    218|            session->next_crypto->kex_methods[SSH_LANG_S_C]
 1152|    218|    );
 1153|    218|    return SSH_OK;
  ------------------
  |  |  315|    218|#define SSH_OK 0     /* No error */
  ------------------
 1154|    249|}
ssh_send_kex:
 1159|    298|{
 1160|    298|    struct ssh_kex_struct *kex = (session->server ?
  ------------------
  |  Branch (1160:35): [True: 298, False: 0]
  ------------------
 1161|    298|        &session->next_crypto->server_kex :
 1162|    298|        &session->next_crypto->client_kex);
 1163|    298|    ssh_string str = NULL;
 1164|    298|    int i;
 1165|    298|    int rc;
 1166|    298|    int first_kex_packet_follows = 0;
 1167|       |
 1168|       |    /* Only client can initiate the handshake methods we implement. If we
 1169|       |     * already received the peer mechanisms, there is no point in guessing */
 1170|    298|    if (session->client &&
  ------------------
  |  Branch (1170:9): [True: 0, False: 298]
  ------------------
 1171|      0|        session->session_state != SSH_SESSION_STATE_KEXINIT_RECEIVED &&
  ------------------
  |  Branch (1171:9): [True: 0, False: 0]
  ------------------
 1172|      0|        session->send_first_kex_follows) {
  ------------------
  |  Branch (1172:9): [True: 0, False: 0]
  ------------------
 1173|      0|        first_kex_packet_follows = 1;
 1174|      0|    }
 1175|       |
 1176|    298|    SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|    298|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1177|    298|            "Sending KEXINIT packet, first_kex_packet_follows = %d",
 1178|    298|            first_kex_packet_follows);
 1179|       |
 1180|    298|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    298|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|    298|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|    298|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|    298|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|    298|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|    298|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    298|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1181|    298|                         "bP",
 1182|    298|                         SSH2_MSG_KEXINIT,
 1183|    298|                         (size_t)16,
 1184|    298|                         kex->cookie); /* cookie */
 1185|    298|    if (rc != SSH_OK)
  ------------------
  |  |  315|    298|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1185:9): [True: 0, False: 298]
  ------------------
 1186|      0|        goto error;
 1187|    298|    if (ssh_hashbufout_add_cookie(session) < 0) {
  ------------------
  |  Branch (1187:9): [True: 0, False: 298]
  ------------------
 1188|      0|        goto error;
 1189|      0|    }
 1190|       |
 1191|    298|    ssh_list_kex(kex);
 1192|       |
 1193|  3.27k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  3.27k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (1193:17): [True: 2.98k, False: 298]
  ------------------
 1194|  2.98k|        str = ssh_string_from_char(kex->methods[i]);
 1195|  2.98k|        if (str == NULL) {
  ------------------
  |  Branch (1195:13): [True: 0, False: 2.98k]
  ------------------
 1196|      0|            goto error;
 1197|      0|        }
 1198|       |
 1199|  2.98k|        rc = ssh_buffer_add_ssh_string(session->out_hashbuf, str);
 1200|  2.98k|        if (rc < 0) {
  ------------------
  |  Branch (1200:13): [True: 0, False: 2.98k]
  ------------------
 1201|      0|            goto error;
 1202|      0|        }
 1203|  2.98k|        rc = ssh_buffer_add_ssh_string(session->out_buffer, str);
 1204|  2.98k|        if (rc < 0) {
  ------------------
  |  Branch (1204:13): [True: 0, False: 2.98k]
  ------------------
 1205|      0|            goto error;
 1206|      0|        }
 1207|  2.98k|        SSH_STRING_FREE(str);
  ------------------
  |  |  882|  2.98k|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 2.98k, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 2.98k]
  |  |  ------------------
  ------------------
 1208|  2.98k|        str = NULL;
 1209|  2.98k|    }
 1210|       |
 1211|    298|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    298|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|    298|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|    298|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|    298|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|    298|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|    298|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    298|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1212|    298|                         "bd",
 1213|    298|                         first_kex_packet_follows,
 1214|    298|                         0);
 1215|    298|    if (rc != SSH_OK) {
  ------------------
  |  |  315|    298|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1215:9): [True: 0, False: 298]
  ------------------
 1216|      0|        goto error;
 1217|      0|    }
 1218|       |
 1219|       |    /* Prepare also the first_kex_packet_follows and reserved to 0 */
 1220|    298|    rc = ssh_buffer_add_u8(session->out_hashbuf, first_kex_packet_follows);
 1221|    298|    if (rc < 0) {
  ------------------
  |  Branch (1221:9): [True: 0, False: 298]
  ------------------
 1222|      0|        goto error;
 1223|      0|    }
 1224|    298|    rc = ssh_buffer_add_u32(session->out_hashbuf, 0);
 1225|    298|    if (rc < 0) {
  ------------------
  |  Branch (1225:9): [True: 0, False: 298]
  ------------------
 1226|      0|        goto error;
 1227|      0|    }
 1228|       |
 1229|    298|    rc = ssh_packet_send(session);
 1230|    298|    if (rc == SSH_ERROR) {
  ------------------
  |  |  316|    298|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1230:9): [True: 0, False: 298]
  ------------------
 1231|      0|        return -1;
 1232|      0|    }
 1233|       |
 1234|    298|    session->flags |= SSH_SESSION_FLAG_KEXINIT_SENT;
  ------------------
  |  |   86|    298|#define SSH_SESSION_FLAG_KEXINIT_SENT 0x0008
  ------------------
 1235|    298|    SSH_LOG(SSH_LOG_PACKET, "SSH_MSG_KEXINIT sent");
  ------------------
  |  |  283|    298|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1236|       |
 1237|       |    /* If we indicated that we are sending the guessed key exchange packet,
 1238|       |     * do it now. The packet is simple, but we need to do some preparations */
 1239|    298|    if (first_kex_packet_follows == 1) {
  ------------------
  |  Branch (1239:9): [True: 0, False: 298]
  ------------------
 1240|      0|        char *list = kex->methods[SSH_KEX];
 1241|      0|        const char *colon = strchr(list, ',');
 1242|      0|        size_t kex_name_len = colon ? (size_t)(colon - list) : strlen(list);
  ------------------
  |  Branch (1242:31): [True: 0, False: 0]
  ------------------
 1243|      0|        char *kex_name = calloc(kex_name_len + 1, 1);
 1244|      0|        if (kex_name == NULL) {
  ------------------
  |  Branch (1244:13): [True: 0, False: 0]
  ------------------
 1245|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1246|      0|            goto error;
 1247|      0|        }
 1248|      0|        snprintf(kex_name, kex_name_len + 1, "%.*s", (int)kex_name_len, list);
 1249|      0|        SSH_LOG(SSH_LOG_TRACE, "Sending the first kex packet for %s", kex_name);
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1250|       |
 1251|      0|        session->next_crypto->kex_type = kex_select_kex_type(kex_name);
 1252|      0|        free(kex_name);
 1253|       |
 1254|       |        /* run the first step of the DH handshake */
 1255|      0|        session->dh_handshake_state = DH_STATE_INIT;
 1256|      0|        if (dh_handshake(session) == SSH_ERROR) {
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1256:13): [True: 0, False: 0]
  ------------------
 1257|      0|            goto error;
 1258|      0|        }
 1259|      0|    }
 1260|    298|    return 0;
 1261|       |
 1262|      0|error:
 1263|      0|    ssh_buffer_reinit(session->out_buffer);
 1264|      0|    ssh_buffer_reinit(session->out_hashbuf);
 1265|      0|    SSH_STRING_FREE(str);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1266|       |
 1267|      0|    return -1;
 1268|    298|}
ssh_keep_known_algos:
 1324|  1.59k|{
 1325|  1.59k|    if (algo > SSH_LANG_S_C) {
  ------------------
  |  Branch (1325:9): [True: 0, False: 1.59k]
  ------------------
 1326|      0|        return NULL;
 1327|      0|    }
 1328|       |
 1329|  1.59k|    return ssh_find_all_matching(supported_methods[algo], list);
 1330|  1.59k|}
ssh_make_sessionid:
 1459|    185|{
 1460|    185|    ssh_string num = NULL;
 1461|    185|    ssh_buffer server_hash = NULL;
 1462|    185|    ssh_buffer client_hash = NULL;
 1463|    185|    ssh_buffer buf = NULL;
 1464|    185|    ssh_string server_pubkey_blob = NULL;
 1465|       |#if !defined(HAVE_LIBCRYPTO) || OPENSSL_VERSION_NUMBER < 0x30000000L
 1466|       |    const_bignum client_pubkey, server_pubkey;
 1467|       |#else
 1468|    185|    bignum client_pubkey = NULL, server_pubkey = NULL;
 1469|    185|#endif /* OPENSSL_VERSION_NUMBER */
 1470|    185|#ifdef WITH_GEX
 1471|       |#if !defined(HAVE_LIBCRYPTO) || OPENSSL_VERSION_NUMBER < 0x30000000L
 1472|       |    const_bignum modulus, generator;
 1473|       |#else
 1474|    185|    bignum modulus = NULL, generator = NULL;
 1475|    185|#endif /* OPENSSL_VERSION_NUMBER */
 1476|    185|#endif /* WITH_GEX */
 1477|    185|    int rc = SSH_ERROR;
  ------------------
  |  |  316|    185|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1478|       |
 1479|    185|    buf = ssh_buffer_new();
 1480|    185|    if (buf == NULL) {
  ------------------
  |  Branch (1480:9): [True: 0, False: 185]
  ------------------
 1481|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1482|      0|        return rc;
 1483|      0|    }
 1484|       |
 1485|    185|    rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|    185|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|    185|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|    185|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|    185|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|    185|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|    185|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    185|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1486|    185|                         "ss",
 1487|    185|                         session->clientbanner,
 1488|    185|                         session->serverbanner);
 1489|    185|    if (rc == SSH_ERROR) {
  ------------------
  |  |  316|    185|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1489:9): [True: 0, False: 185]
  ------------------
 1490|      0|        ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1491|      0|                      SSH_FATAL,
 1492|      0|                      "Failed to pack client and server banner");
 1493|      0|        goto error;
 1494|      0|    }
 1495|       |
 1496|    185|    if (session->client) {
  ------------------
  |  Branch (1496:9): [True: 0, False: 185]
  ------------------
 1497|      0|        server_hash = session->in_hashbuf;
 1498|      0|        client_hash = session->out_hashbuf;
 1499|    185|    } else {
 1500|    185|        server_hash = session->out_hashbuf;
 1501|    185|        client_hash = session->in_hashbuf;
 1502|    185|    }
 1503|       |
 1504|    185|    rc = ssh_dh_get_next_server_publickey_blob(session, &server_pubkey_blob);
 1505|    185|    if (rc != SSH_OK) {
  ------------------
  |  |  315|    185|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1505:9): [True: 0, False: 185]
  ------------------
 1506|      0|        ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1507|      0|                      SSH_FATAL,
 1508|      0|                      "Failed to get next server pubkey blob");
 1509|      0|        goto error;
 1510|      0|    }
 1511|       |
 1512|    185|    if (server_pubkey_blob == NULL) {
  ------------------
  |  Branch (1512:9): [True: 0, False: 185]
  ------------------
 1513|      0|        if ((session->server && ssh_kex_is_gss(session->next_crypto)) ||
  ------------------
  |  Branch (1513:14): [True: 0, False: 0]
  |  Branch (1513:33): [True: 0, False: 0]
  ------------------
 1514|      0|            session->opts.gssapi_key_exchange) {
  ------------------
  |  Branch (1514:13): [True: 0, False: 0]
  ------------------
 1515|      0|            server_pubkey_blob = ssh_string_new(0);
 1516|      0|            if (server_pubkey_blob == NULL) {
  ------------------
  |  Branch (1516:17): [True: 0, False: 0]
  ------------------
 1517|      0|                ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1518|      0|                rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1519|      0|                goto error;
 1520|      0|            }
 1521|      0|        }
 1522|      0|    }
 1523|       |
 1524|    185|    rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|    185|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|    185|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|    185|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|    185|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|    185|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|    185|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    185|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1525|    185|                         "dPdPS",
 1526|    185|                         ssh_buffer_get_len(client_hash),
 1527|    185|                         (size_t)ssh_buffer_get_len(client_hash),
 1528|    185|                         ssh_buffer_get(client_hash),
 1529|    185|                         ssh_buffer_get_len(server_hash),
 1530|    185|                         (size_t)ssh_buffer_get_len(server_hash),
 1531|    185|                         ssh_buffer_get(server_hash),
 1532|    185|                         server_pubkey_blob);
 1533|    185|    SSH_STRING_FREE(server_pubkey_blob);
  ------------------
  |  |  882|    185|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 185, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 185]
  |  |  ------------------
  ------------------
 1534|    185|    if (rc != SSH_OK){
  ------------------
  |  |  315|    185|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1534:9): [True: 0, False: 185]
  ------------------
 1535|      0|        ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1536|      0|                      SSH_FATAL,
 1537|      0|                      "Failed to pack hashes and pubkey blob");
 1538|      0|        goto error;
 1539|      0|    }
 1540|       |
 1541|    185|    switch(session->next_crypto->kex_type) {
 1542|      0|    case SSH_KEX_DH_GROUP1_SHA1:
  ------------------
  |  Branch (1542:5): [True: 0, False: 185]
  ------------------
 1543|      0|    case SSH_KEX_DH_GROUP14_SHA1:
  ------------------
  |  Branch (1543:5): [True: 0, False: 185]
  ------------------
 1544|      2|    case SSH_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (1544:5): [True: 2, False: 183]
  ------------------
 1545|      2|    case SSH_GSS_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (1545:5): [True: 0, False: 185]
  ------------------
 1546|      2|    case SSH_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (1546:5): [True: 0, False: 185]
  ------------------
 1547|      2|    case SSH_GSS_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (1547:5): [True: 0, False: 185]
  ------------------
 1548|      2|    case SSH_KEX_DH_GROUP18_SHA512:
  ------------------
  |  Branch (1548:5): [True: 0, False: 185]
  ------------------
 1549|      2|        rc = ssh_dh_keypair_get_keys(session->next_crypto->dh_ctx,
 1550|      2|                                     DH_CLIENT_KEYPAIR, NULL, &client_pubkey);
  ------------------
  |  |   30|      2|#define DH_CLIENT_KEYPAIR 0
  ------------------
 1551|      2|        if (rc != SSH_OK) {
  ------------------
  |  |  315|      2|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1551:13): [True: 0, False: 2]
  ------------------
 1552|      0|            goto error;
 1553|      0|        }
 1554|      2|        rc = ssh_dh_keypair_get_keys(session->next_crypto->dh_ctx,
 1555|      2|                                     DH_SERVER_KEYPAIR, NULL, &server_pubkey);
  ------------------
  |  |   31|      2|#define DH_SERVER_KEYPAIR 1
  ------------------
 1556|      2|        if (rc != SSH_OK) {
  ------------------
  |  |  315|      2|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1556:13): [True: 0, False: 2]
  ------------------
 1557|      0|            goto error;
 1558|      0|        }
 1559|      2|        rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|      2|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      2|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      2|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      2|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      2|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      2|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      2|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1560|      2|                             "BB",
 1561|      2|                             client_pubkey,
 1562|      2|                             server_pubkey);
 1563|      2|        if (rc != SSH_OK) {
  ------------------
  |  |  315|      2|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1563:13): [True: 0, False: 2]
  ------------------
 1564|      0|            ssh_set_error(session, SSH_FATAL, "Failed to pack DH pubkeys");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1565|      0|            goto error;
 1566|      0|        }
 1567|      2|#if defined(HAVE_LIBCRYPTO) && OPENSSL_VERSION_NUMBER >= 0x30000000L
 1568|      2|        bignum_safe_free(client_pubkey);
  ------------------
  |  |   71|      2|#define bignum_safe_free(num) do { \
  |  |   72|      2|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 2, False: 0]
  |  |  ------------------
  |  |   73|      2|        BN_clear_free((num)); \
  |  |   74|      2|        (num)=NULL; \
  |  |   75|      2|    } \
  |  |   76|      2|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 2]
  |  |  ------------------
  ------------------
 1569|      2|        bignum_safe_free(server_pubkey);
  ------------------
  |  |   71|      2|#define bignum_safe_free(num) do { \
  |  |   72|      2|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 2, False: 0]
  |  |  ------------------
  |  |   73|      2|        BN_clear_free((num)); \
  |  |   74|      2|        (num)=NULL; \
  |  |   75|      2|    } \
  |  |   76|      2|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 2]
  |  |  ------------------
  ------------------
 1570|      2|#endif /* OPENSSL_VERSION_NUMBER */
 1571|      2|        break;
 1572|      0|#ifdef WITH_GEX
 1573|      0|    case SSH_KEX_DH_GEX_SHA1:
  ------------------
  |  Branch (1573:5): [True: 0, False: 185]
  ------------------
 1574|      0|    case SSH_KEX_DH_GEX_SHA256:
  ------------------
  |  Branch (1574:5): [True: 0, False: 185]
  ------------------
 1575|      0|        rc = ssh_dh_keypair_get_keys(session->next_crypto->dh_ctx,
 1576|      0|                                     DH_CLIENT_KEYPAIR, NULL, &client_pubkey);
  ------------------
  |  |   30|      0|#define DH_CLIENT_KEYPAIR 0
  ------------------
 1577|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1577:13): [True: 0, False: 0]
  ------------------
 1578|      0|            goto error;
 1579|      0|        }
 1580|      0|        rc = ssh_dh_keypair_get_keys(session->next_crypto->dh_ctx,
 1581|      0|                                     DH_SERVER_KEYPAIR, NULL, &server_pubkey);
  ------------------
  |  |   31|      0|#define DH_SERVER_KEYPAIR 1
  ------------------
 1582|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1582:13): [True: 0, False: 0]
  ------------------
 1583|      0|            goto error;
 1584|      0|        }
 1585|      0|        rc = ssh_dh_get_parameters(session->next_crypto->dh_ctx,
 1586|      0|                                   &modulus, &generator);
 1587|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1587:13): [True: 0, False: 0]
  ------------------
 1588|      0|            goto error;
 1589|      0|        }
 1590|      0|        rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1591|      0|                    "dddBBBB",
 1592|      0|                    session->next_crypto->dh_pmin,
 1593|      0|                    session->next_crypto->dh_pn,
 1594|      0|                    session->next_crypto->dh_pmax,
 1595|      0|                    modulus,
 1596|      0|                    generator,
 1597|      0|                    client_pubkey,
 1598|      0|                    server_pubkey);
 1599|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1599:13): [True: 0, False: 0]
  ------------------
 1600|      0|            ssh_set_error(session, SSH_FATAL, "Failed to pack DH GEX params");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1601|      0|            goto error;
 1602|      0|        }
 1603|      0|#if defined(HAVE_LIBCRYPTO) && OPENSSL_VERSION_NUMBER >= 0x30000000L
 1604|      0|        bignum_safe_free(modulus);
  ------------------
  |  |   71|      0|#define bignum_safe_free(num) do { \
  |  |   72|      0|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 0]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1605|      0|        bignum_safe_free(generator);
  ------------------
  |  |   71|      0|#define bignum_safe_free(num) do { \
  |  |   72|      0|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 0]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1606|      0|#endif /* OPENSSL_VERSION_NUMBER */
 1607|      0|        break;
 1608|      0|#endif /* WITH_GEX */
 1609|      0|#ifdef HAVE_ECDH
 1610|      0|    case SSH_KEX_ECDH_SHA2_NISTP256:
  ------------------
  |  Branch (1610:5): [True: 0, False: 185]
  ------------------
 1611|      0|    case SSH_KEX_ECDH_SHA2_NISTP384:
  ------------------
  |  Branch (1611:5): [True: 0, False: 185]
  ------------------
 1612|      0|    case SSH_KEX_ECDH_SHA2_NISTP521:
  ------------------
  |  Branch (1612:5): [True: 0, False: 185]
  ------------------
 1613|      0|    case SSH_GSS_KEX_ECDH_NISTP256_SHA256:
  ------------------
  |  Branch (1613:5): [True: 0, False: 185]
  ------------------
 1614|      0|        if (session->next_crypto->ecdh_client_pubkey == NULL ||
  ------------------
  |  Branch (1614:13): [True: 0, False: 0]
  ------------------
 1615|      0|            session->next_crypto->ecdh_server_pubkey == NULL) {
  ------------------
  |  Branch (1615:13): [True: 0, False: 0]
  ------------------
 1616|      0|            SSH_LOG(SSH_LOG_TRACE, "ECDH parameter missing");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1617|      0|            goto error;
 1618|      0|        }
 1619|      0|        rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1620|      0|                             "SS",
 1621|      0|                             session->next_crypto->ecdh_client_pubkey,
 1622|      0|                             session->next_crypto->ecdh_server_pubkey);
 1623|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1623:13): [True: 0, False: 0]
  ------------------
 1624|      0|            ssh_set_error(session, SSH_FATAL, "Failed to pack ECDH pubkeys");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1625|      0|            goto error;
 1626|      0|        }
 1627|      0|        break;
 1628|      0|#endif /* HAVE_ECDH */
 1629|      0|#ifdef HAVE_CURVE25519
 1630|    183|    case SSH_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (1630:5): [True: 183, False: 2]
  ------------------
 1631|    183|    case SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG:
  ------------------
  |  Branch (1631:5): [True: 0, False: 185]
  ------------------
 1632|    183|    case SSH_GSS_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (1632:5): [True: 0, False: 185]
  ------------------
 1633|    183|        rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|    183|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|    183|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|    183|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|    183|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|    183|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|    183|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    183|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1634|    183|                             "dPdP",
 1635|    183|                             CURVE25519_PUBKEY_SIZE,
 1636|    183|                             (size_t)CURVE25519_PUBKEY_SIZE,
 1637|    183|                             session->next_crypto->curve25519_client_pubkey,
 1638|    183|                             CURVE25519_PUBKEY_SIZE,
 1639|    183|                             (size_t)CURVE25519_PUBKEY_SIZE,
 1640|    183|                             session->next_crypto->curve25519_server_pubkey);
 1641|       |
 1642|    183|        if (rc != SSH_OK) {
  ------------------
  |  |  315|    183|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1642:13): [True: 0, False: 183]
  ------------------
 1643|      0|            ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1644|      0|                          SSH_FATAL,
 1645|      0|                          "Failed to pack Curve25519 pubkeys");
 1646|      0|            goto error;
 1647|      0|        }
 1648|    183|        break;
 1649|    183|#endif /* HAVE_CURVE25519 */
 1650|    183|#ifdef HAVE_SNTRUP761
 1651|    183|    case SSH_KEX_SNTRUP761X25519_SHA512:
  ------------------
  |  Branch (1651:5): [True: 0, False: 185]
  ------------------
 1652|      0|    case SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM:
  ------------------
  |  Branch (1652:5): [True: 0, False: 185]
  ------------------
 1653|      0|        rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1654|      0|                             "dPPdPP",
 1655|      0|                             SNTRUP761_PUBLICKEY_SIZE + CURVE25519_PUBKEY_SIZE,
 1656|      0|                             (size_t)SNTRUP761_PUBLICKEY_SIZE,
 1657|      0|                             session->next_crypto->sntrup761_client_pubkey,
 1658|      0|                             (size_t)CURVE25519_PUBKEY_SIZE,
 1659|      0|                             session->next_crypto->curve25519_client_pubkey,
 1660|      0|                             SNTRUP761_CIPHERTEXT_SIZE + CURVE25519_PUBKEY_SIZE,
 1661|      0|                             (size_t)SNTRUP761_CIPHERTEXT_SIZE,
 1662|      0|                             session->next_crypto->sntrup761_ciphertext,
 1663|      0|                             (size_t)CURVE25519_PUBKEY_SIZE,
 1664|      0|                             session->next_crypto->curve25519_server_pubkey);
 1665|       |
 1666|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1666:13): [True: 0, False: 0]
  ------------------
 1667|      0|            ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1668|      0|                          SSH_FATAL,
 1669|      0|                          "Failed to pack SNTRU Prime params");
 1670|      0|            goto error;
 1671|      0|        }
 1672|      0|        break;
 1673|      0|#endif /* HAVE_SNTRUP761 */
 1674|      0|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (1674:5): [True: 0, False: 185]
  ------------------
 1675|      0|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (1675:5): [True: 0, False: 185]
  ------------------
 1676|       |#ifdef HAVE_MLKEM1024
 1677|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
 1678|       |#endif
 1679|      0|        rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1680|      0|                             "SS",
 1681|      0|                             session->next_crypto->hybrid_client_init,
 1682|      0|                             session->next_crypto->hybrid_server_reply);
 1683|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1683:13): [True: 0, False: 0]
  ------------------
 1684|      0|            ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1685|      0|                          SSH_FATAL,
 1686|      0|                          "Failed to pack ML-KEM individual components");
 1687|      0|            goto error;
 1688|      0|        }
 1689|      0|        break;
 1690|      0|    default:
  ------------------
  |  Branch (1690:5): [True: 0, False: 185]
  ------------------
 1691|       |        /* Handle unsupported kex types - this should not happen in normal operation */
 1692|      0|        rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1693|      0|        ssh_set_error(session, SSH_FATAL, "Unsupported KEX algorithm");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1694|      0|        goto error;
 1695|    185|    }
 1696|    185|    switch (session->next_crypto->kex_type) {
 1697|      0|    case SSH_KEX_SNTRUP761X25519_SHA512:
  ------------------
  |  Branch (1697:5): [True: 0, False: 185]
  ------------------
 1698|      0|    case SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM:
  ------------------
  |  Branch (1698:5): [True: 0, False: 185]
  ------------------
 1699|      0|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (1699:5): [True: 0, False: 185]
  ------------------
 1700|      0|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (1700:5): [True: 0, False: 185]
  ------------------
 1701|       |#ifdef HAVE_MLKEM1024
 1702|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
 1703|       |#endif
 1704|      0|        rc = ssh_buffer_pack(buf, "S", session->next_crypto->hybrid_shared_secret);
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1705|      0|        break;
 1706|    185|    default:
  ------------------
  |  Branch (1706:5): [True: 185, False: 0]
  ------------------
 1707|    185|        rc = ssh_buffer_pack(buf, "B", session->next_crypto->shared_secret);
  ------------------
  |  |   50|    185|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|    185|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|    185|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|    185|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|    185|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|    185|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    185|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1708|    185|        break;
 1709|    185|    }
 1710|    185|    if (rc != SSH_OK) {
  ------------------
  |  |  315|    185|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1710:9): [True: 0, False: 185]
  ------------------
 1711|      0|        ssh_set_error(session, SSH_FATAL, "Failed to pack shared secret");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1712|      0|        goto error;
 1713|      0|    }
 1714|       |
 1715|       |#ifdef DEBUG_CRYPTO
 1716|       |    ssh_log_hexdump("hash buffer", ssh_buffer_get(buf), ssh_buffer_get_len(buf));
 1717|       |#endif
 1718|       |
 1719|       |    /* Set rc for the following switch statement in case we goto error. */
 1720|    185|    rc = SSH_ERROR;
  ------------------
  |  |  316|    185|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1721|    185|    switch (session->next_crypto->kex_type) {
 1722|      0|    case SSH_KEX_DH_GROUP1_SHA1:
  ------------------
  |  Branch (1722:5): [True: 0, False: 185]
  ------------------
 1723|      0|    case SSH_KEX_DH_GROUP14_SHA1:
  ------------------
  |  Branch (1723:5): [True: 0, False: 185]
  ------------------
 1724|      0|#ifdef WITH_GEX
 1725|      0|    case SSH_KEX_DH_GEX_SHA1:
  ------------------
  |  Branch (1725:5): [True: 0, False: 185]
  ------------------
 1726|      0|#endif /* WITH_GEX */
 1727|      0|        session->next_crypto->digest_len = SHA_DIGEST_LENGTH;
 1728|      0|        session->next_crypto->digest_type = SSH_KDF_SHA1;
 1729|      0|        session->next_crypto->secret_hash = malloc(session->next_crypto->digest_len);
 1730|      0|        if (session->next_crypto->secret_hash == NULL) {
  ------------------
  |  Branch (1730:13): [True: 0, False: 0]
  ------------------
 1731|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1732|      0|            goto error;
 1733|      0|        }
 1734|      0|        sha1(ssh_buffer_get(buf), ssh_buffer_get_len(buf),
 1735|      0|                                   session->next_crypto->secret_hash);
 1736|      0|        break;
 1737|      2|    case SSH_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (1737:5): [True: 2, False: 183]
  ------------------
 1738|      2|    case SSH_GSS_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (1738:5): [True: 0, False: 185]
  ------------------
 1739|      2|    case SSH_KEX_ECDH_SHA2_NISTP256:
  ------------------
  |  Branch (1739:5): [True: 0, False: 185]
  ------------------
 1740|    185|    case SSH_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (1740:5): [True: 183, False: 2]
  ------------------
 1741|    185|    case SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG:
  ------------------
  |  Branch (1741:5): [True: 0, False: 185]
  ------------------
 1742|    185|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (1742:5): [True: 0, False: 185]
  ------------------
 1743|    185|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (1743:5): [True: 0, False: 185]
  ------------------
 1744|    185|    case SSH_GSS_KEX_ECDH_NISTP256_SHA256:
  ------------------
  |  Branch (1744:5): [True: 0, False: 185]
  ------------------
 1745|    185|    case SSH_GSS_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (1745:5): [True: 0, False: 185]
  ------------------
 1746|    185|#ifdef WITH_GEX
 1747|    185|    case SSH_KEX_DH_GEX_SHA256:
  ------------------
  |  Branch (1747:5): [True: 0, False: 185]
  ------------------
 1748|    185|#endif /* WITH_GEX */
 1749|    185|        session->next_crypto->digest_len = SHA256_DIGEST_LENGTH;
 1750|    185|        session->next_crypto->digest_type = SSH_KDF_SHA256;
 1751|    185|        session->next_crypto->secret_hash = malloc(session->next_crypto->digest_len);
 1752|    185|        if (session->next_crypto->secret_hash == NULL) {
  ------------------
  |  Branch (1752:13): [True: 0, False: 185]
  ------------------
 1753|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1754|      0|            goto error;
 1755|      0|        }
 1756|    185|        sha256(ssh_buffer_get(buf), ssh_buffer_get_len(buf),
 1757|    185|                                     session->next_crypto->secret_hash);
 1758|    185|        break;
 1759|      0|    case SSH_KEX_ECDH_SHA2_NISTP384:
  ------------------
  |  Branch (1759:5): [True: 0, False: 185]
  ------------------
 1760|       |#ifdef HAVE_MLKEM1024
 1761|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
 1762|       |#endif
 1763|      0|        session->next_crypto->digest_len = SHA384_DIGEST_LENGTH;
 1764|      0|        session->next_crypto->digest_type = SSH_KDF_SHA384;
 1765|      0|        session->next_crypto->secret_hash = malloc(session->next_crypto->digest_len);
 1766|      0|        if (session->next_crypto->secret_hash == NULL) {
  ------------------
  |  Branch (1766:13): [True: 0, False: 0]
  ------------------
 1767|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1768|      0|            goto error;
 1769|      0|        }
 1770|      0|        sha384(ssh_buffer_get(buf), ssh_buffer_get_len(buf),
 1771|      0|                                     session->next_crypto->secret_hash);
 1772|      0|        break;
 1773|      0|    case SSH_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (1773:5): [True: 0, False: 185]
  ------------------
 1774|      0|    case SSH_GSS_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (1774:5): [True: 0, False: 185]
  ------------------
 1775|      0|    case SSH_KEX_DH_GROUP18_SHA512:
  ------------------
  |  Branch (1775:5): [True: 0, False: 185]
  ------------------
 1776|      0|    case SSH_KEX_ECDH_SHA2_NISTP521:
  ------------------
  |  Branch (1776:5): [True: 0, False: 185]
  ------------------
 1777|      0|    case SSH_KEX_SNTRUP761X25519_SHA512:
  ------------------
  |  Branch (1777:5): [True: 0, False: 185]
  ------------------
 1778|      0|    case SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM:
  ------------------
  |  Branch (1778:5): [True: 0, False: 185]
  ------------------
 1779|      0|        session->next_crypto->digest_len = SHA512_DIGEST_LENGTH;
 1780|      0|        session->next_crypto->digest_type = SSH_KDF_SHA512;
 1781|      0|        session->next_crypto->secret_hash = malloc(session->next_crypto->digest_len);
 1782|      0|        if (session->next_crypto->secret_hash == NULL) {
  ------------------
  |  Branch (1782:13): [True: 0, False: 0]
  ------------------
 1783|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1784|      0|            goto error;
 1785|      0|        }
 1786|      0|        sha512(ssh_buffer_get(buf),
 1787|      0|               ssh_buffer_get_len(buf),
 1788|      0|               session->next_crypto->secret_hash);
 1789|      0|        break;
 1790|      0|    default:
  ------------------
  |  Branch (1790:5): [True: 0, False: 185]
  ------------------
 1791|       |        /* Handle unsupported kex types - this should not happen in normal operation */
 1792|      0|        ssh_set_error(session, SSH_FATAL, "Unsupported KEX algorithm for hash computation");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1793|      0|        rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1794|      0|        goto error;
 1795|    185|    }
 1796|       |
 1797|       |    /* During the first kex, secret hash and session ID are equal. However, after
 1798|       |     * a key re-exchange, a new secret hash is calculated. This hash will not replace
 1799|       |     * but complement existing session id.
 1800|       |     */
 1801|    185|    if (!session->next_crypto->session_id) {
  ------------------
  |  Branch (1801:9): [True: 185, False: 0]
  ------------------
 1802|    185|        session->next_crypto->session_id = malloc(session->next_crypto->digest_len);
 1803|    185|        if (session->next_crypto->session_id == NULL) {
  ------------------
  |  Branch (1803:13): [True: 0, False: 185]
  ------------------
 1804|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1805|      0|            rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1806|      0|            goto error;
 1807|      0|        }
 1808|    185|        memcpy(session->next_crypto->session_id, session->next_crypto->secret_hash,
 1809|    185|                session->next_crypto->digest_len);
 1810|       |	/* Initial length is the same as secret hash */
 1811|    185|	session->next_crypto->session_id_len = session->next_crypto->digest_len;
 1812|    185|    }
 1813|       |#ifdef DEBUG_CRYPTO
 1814|       |    SSH_LOG(SSH_LOG_DEBUG, "Session hash: \n");
 1815|       |    ssh_log_hexdump("secret hash", session->next_crypto->secret_hash, session->next_crypto->digest_len);
 1816|       |    ssh_log_hexdump("session id", session->next_crypto->session_id, session->next_crypto->session_id_len);
 1817|       |#endif /* DEBUG_CRYPTO */
 1818|       |
 1819|    185|    rc = SSH_OK;
  ------------------
  |  |  315|    185|#define SSH_OK 0     /* No error */
  ------------------
 1820|    185|error:
 1821|    185|    SSH_BUFFER_FREE(buf);
  ------------------
  |  |  924|    185|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 185, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 185]
  |  |  ------------------
  ------------------
 1822|    185|    SSH_BUFFER_FREE(client_hash);
  ------------------
  |  |  924|    185|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 185, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 185]
  |  |  ------------------
  ------------------
 1823|    185|    SSH_BUFFER_FREE(server_hash);
  ------------------
  |  |  924|    185|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 185, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 185]
  |  |  ------------------
  ------------------
 1824|       |
 1825|    185|    session->in_hashbuf = NULL;
 1826|    185|    session->out_hashbuf = NULL;
 1827|       |
 1828|    185|    SSH_STRING_FREE(num);
  ------------------
  |  |  882|    185|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 185]
  |  |  |  Branch (882:69): [Folded, False: 185]
  |  |  ------------------
  ------------------
 1829|    185|#if defined(HAVE_LIBCRYPTO) && OPENSSL_VERSION_NUMBER >= 0x30000000L
 1830|    185|    bignum_safe_free(client_pubkey);
  ------------------
  |  |   71|    185|#define bignum_safe_free(num) do { \
  |  |   72|    185|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 185]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|    185|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 185]
  |  |  ------------------
  ------------------
 1831|    185|    bignum_safe_free(server_pubkey);
  ------------------
  |  |   71|    185|#define bignum_safe_free(num) do { \
  |  |   72|    185|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 185]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|    185|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 185]
  |  |  ------------------
  ------------------
 1832|    185|#endif /* OPENSSL_VERSION_NUMBER */
 1833|       |
 1834|    185|    return rc;
 1835|    185|}
ssh_hashbufout_add_cookie:
 1838|    298|{
 1839|    298|    int rc;
 1840|       |
 1841|    298|    session->out_hashbuf = ssh_buffer_new();
 1842|    298|    if (session->out_hashbuf == NULL) {
  ------------------
  |  Branch (1842:9): [True: 0, False: 298]
  ------------------
 1843|      0|        return -1;
 1844|      0|    }
 1845|       |
 1846|    298|    rc = ssh_buffer_allocate_size(session->out_hashbuf,
 1847|    298|            sizeof(uint8_t) + 16);
 1848|    298|    if (rc < 0) {
  ------------------
  |  Branch (1848:9): [True: 0, False: 298]
  ------------------
 1849|      0|        ssh_buffer_reinit(session->out_hashbuf);
 1850|      0|        return -1;
 1851|      0|    }
 1852|       |
 1853|    298|    if (ssh_buffer_add_u8(session->out_hashbuf, 20) < 0) {
  ------------------
  |  Branch (1853:9): [True: 0, False: 298]
  ------------------
 1854|      0|        ssh_buffer_reinit(session->out_hashbuf);
 1855|      0|        return -1;
 1856|      0|    }
 1857|       |
 1858|    298|    if (session->server) {
  ------------------
  |  Branch (1858:9): [True: 298, False: 0]
  ------------------
 1859|    298|        if (ssh_buffer_add_data(session->out_hashbuf,
  ------------------
  |  Branch (1859:13): [True: 0, False: 298]
  ------------------
 1860|    298|                    session->next_crypto->server_kex.cookie, 16) < 0) {
 1861|      0|            ssh_buffer_reinit(session->out_hashbuf);
 1862|      0|            return -1;
 1863|      0|        }
 1864|    298|    } else {
 1865|      0|        if (ssh_buffer_add_data(session->out_hashbuf,
  ------------------
  |  Branch (1865:13): [True: 0, False: 0]
  ------------------
 1866|      0|                    session->next_crypto->client_kex.cookie, 16) < 0) {
 1867|      0|            ssh_buffer_reinit(session->out_hashbuf);
 1868|      0|            return -1;
 1869|      0|        }
 1870|      0|    }
 1871|       |
 1872|    298|    return 0;
 1873|    298|}
ssh_hashbufin_add_cookie:
 1876|    260|{
 1877|    260|    int rc;
 1878|       |
 1879|    260|    session->in_hashbuf = ssh_buffer_new();
 1880|    260|    if (session->in_hashbuf == NULL) {
  ------------------
  |  Branch (1880:9): [True: 0, False: 260]
  ------------------
 1881|      0|        return -1;
 1882|      0|    }
 1883|       |
 1884|    260|    rc = ssh_buffer_allocate_size(session->in_hashbuf,
 1885|    260|            sizeof(uint8_t) + 20 + 16);
 1886|    260|    if (rc < 0) {
  ------------------
  |  Branch (1886:9): [True: 0, False: 260]
  ------------------
 1887|      0|        ssh_buffer_reinit(session->in_hashbuf);
 1888|      0|        return -1;
 1889|      0|    }
 1890|       |
 1891|    260|    if (ssh_buffer_add_u8(session->in_hashbuf, 20) < 0) {
  ------------------
  |  Branch (1891:9): [True: 0, False: 260]
  ------------------
 1892|      0|        ssh_buffer_reinit(session->in_hashbuf);
 1893|      0|        return -1;
 1894|      0|    }
 1895|    260|    if (ssh_buffer_add_data(session->in_hashbuf,cookie, 16) < 0) {
  ------------------
  |  Branch (1895:9): [True: 0, False: 260]
  ------------------
 1896|      0|        ssh_buffer_reinit(session->in_hashbuf);
 1897|      0|        return -1;
 1898|      0|    }
 1899|       |
 1900|    260|    return 0;
 1901|    260|}
ssh_generate_session_keys:
 1904|    185|{
 1905|    185|    ssh_string k_string = NULL;
 1906|    185|    struct ssh_crypto_struct *crypto = session->next_crypto;
 1907|    185|    unsigned char *key = NULL;
 1908|    185|    unsigned char *IV_cli_to_srv = NULL;
 1909|    185|    unsigned char *IV_srv_to_cli = NULL;
 1910|    185|    unsigned char *enckey_cli_to_srv = NULL;
 1911|    185|    unsigned char *enckey_srv_to_cli = NULL;
 1912|    185|    unsigned char *intkey_cli_to_srv = NULL;
 1913|    185|    unsigned char *intkey_srv_to_cli = NULL;
 1914|    185|    size_t key_len = 0;
 1915|    185|    size_t IV_len = 0;
 1916|    185|    size_t enckey_cli_to_srv_len = 0;
 1917|    185|    size_t enckey_srv_to_cli_len = 0;
 1918|    185|    size_t intkey_cli_to_srv_len = 0;
 1919|    185|    size_t intkey_srv_to_cli_len = 0;
 1920|    185|    int rc = -1;
 1921|       |
 1922|    185|    switch (session->next_crypto->kex_type) {
 1923|      0|    case SSH_KEX_SNTRUP761X25519_SHA512:
  ------------------
  |  Branch (1923:5): [True: 0, False: 185]
  ------------------
 1924|      0|    case SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM:
  ------------------
  |  Branch (1924:5): [True: 0, False: 185]
  ------------------
 1925|      0|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (1925:5): [True: 0, False: 185]
  ------------------
 1926|      0|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (1926:5): [True: 0, False: 185]
  ------------------
 1927|       |#ifdef HAVE_MLKEM1024
 1928|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
 1929|       |#endif
 1930|      0|        k_string = ssh_string_copy(crypto->hybrid_shared_secret);
 1931|      0|        break;
 1932|    185|    default:
  ------------------
  |  Branch (1932:5): [True: 185, False: 0]
  ------------------
 1933|    185|        k_string = ssh_make_bignum_string(crypto->shared_secret);
 1934|    185|        break;
 1935|    185|    }
 1936|    185|    if (k_string == NULL) {
  ------------------
  |  Branch (1936:9): [True: 0, False: 185]
  ------------------
 1937|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1938|      0|        goto error;
 1939|      0|    }
 1940|       |    /* See RFC4251 Section 5 for the definition of mpint which is the
 1941|       |     * encoding we need to use for key in the SSH KDF */
 1942|    185|    key = (unsigned char *)k_string;
 1943|    185|    key_len = ssh_string_len(k_string) + 4;
 1944|       |
 1945|    185|    IV_len = crypto->digest_len;
 1946|    185|    if (session->client) {
  ------------------
  |  Branch (1946:9): [True: 0, False: 185]
  ------------------
 1947|      0|        enckey_cli_to_srv_len = crypto->out_cipher->keysize / 8;
 1948|      0|        enckey_srv_to_cli_len = crypto->in_cipher->keysize / 8;
 1949|      0|        intkey_cli_to_srv_len = hmac_digest_len(crypto->out_hmac);
 1950|      0|        intkey_srv_to_cli_len = hmac_digest_len(crypto->in_hmac);
 1951|    185|    } else {
 1952|    185|        enckey_cli_to_srv_len = crypto->in_cipher->keysize / 8;
 1953|    185|        enckey_srv_to_cli_len = crypto->out_cipher->keysize / 8;
 1954|    185|        intkey_cli_to_srv_len = hmac_digest_len(crypto->in_hmac);
 1955|    185|        intkey_srv_to_cli_len = hmac_digest_len(crypto->out_hmac);
 1956|    185|    }
 1957|       |
 1958|    185|    IV_cli_to_srv = malloc(IV_len);
 1959|    185|    IV_srv_to_cli = malloc(IV_len);
 1960|    185|    enckey_cli_to_srv = malloc(enckey_cli_to_srv_len);
 1961|    185|    enckey_srv_to_cli = malloc(enckey_srv_to_cli_len);
 1962|    185|    intkey_cli_to_srv = malloc(intkey_cli_to_srv_len);
 1963|    185|    intkey_srv_to_cli = malloc(intkey_srv_to_cli_len);
 1964|    185|    if (IV_cli_to_srv == NULL || IV_srv_to_cli == NULL ||
  ------------------
  |  Branch (1964:9): [True: 0, False: 185]
  |  Branch (1964:34): [True: 0, False: 185]
  ------------------
 1965|    185|        enckey_cli_to_srv == NULL || enckey_srv_to_cli == NULL ||
  ------------------
  |  Branch (1965:9): [True: 0, False: 185]
  |  Branch (1965:38): [True: 0, False: 185]
  ------------------
 1966|    185|        intkey_cli_to_srv == NULL || intkey_srv_to_cli == NULL) {
  ------------------
  |  Branch (1966:9): [True: 0, False: 185]
  |  Branch (1966:38): [True: 0, False: 185]
  ------------------
 1967|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1968|      0|        goto error;
 1969|      0|    }
 1970|       |
 1971|       |    /* IV */
 1972|    185|    rc = ssh_kdf(crypto, key, key_len, 'A', IV_cli_to_srv, IV_len);
 1973|    185|    if (rc < 0) {
  ------------------
  |  Branch (1973:9): [True: 0, False: 185]
  ------------------
 1974|      0|        goto error;
 1975|      0|    }
 1976|    185|    rc = ssh_kdf(crypto, key, key_len, 'B', IV_srv_to_cli, IV_len);
 1977|    185|    if (rc < 0) {
  ------------------
  |  Branch (1977:9): [True: 0, False: 185]
  ------------------
 1978|      0|        goto error;
 1979|      0|    }
 1980|       |    /* Encryption Key */
 1981|    185|    rc = ssh_kdf(crypto, key, key_len, 'C', enckey_cli_to_srv,
 1982|    185|                 enckey_cli_to_srv_len);
 1983|    185|    if (rc < 0) {
  ------------------
  |  Branch (1983:9): [True: 0, False: 185]
  ------------------
 1984|      0|        goto error;
 1985|      0|    }
 1986|    185|    rc = ssh_kdf(crypto, key, key_len, 'D', enckey_srv_to_cli,
 1987|    185|                 enckey_srv_to_cli_len);
 1988|    185|    if (rc < 0) {
  ------------------
  |  Branch (1988:9): [True: 0, False: 185]
  ------------------
 1989|      0|        goto error;
 1990|      0|    }
 1991|       |    /* Integrity Key */
 1992|    185|    rc = ssh_kdf(crypto, key, key_len, 'E', intkey_cli_to_srv,
 1993|    185|                 intkey_cli_to_srv_len);
 1994|    185|    if (rc < 0) {
  ------------------
  |  Branch (1994:9): [True: 0, False: 185]
  ------------------
 1995|      0|        goto error;
 1996|      0|    }
 1997|    185|    rc = ssh_kdf(crypto, key, key_len, 'F', intkey_srv_to_cli,
 1998|    185|                 intkey_srv_to_cli_len);
 1999|    185|    if (rc < 0) {
  ------------------
  |  Branch (1999:9): [True: 0, False: 185]
  ------------------
 2000|      0|        goto error;
 2001|      0|    }
 2002|       |
 2003|    185|    if (session->client) {
  ------------------
  |  Branch (2003:9): [True: 0, False: 185]
  ------------------
 2004|      0|        crypto->encryptIV = IV_cli_to_srv;
 2005|      0|        crypto->decryptIV = IV_srv_to_cli;
 2006|      0|        crypto->encryptkey = enckey_cli_to_srv;
 2007|      0|        crypto->decryptkey = enckey_srv_to_cli;
 2008|      0|        crypto->encryptMAC = intkey_cli_to_srv;
 2009|      0|        crypto->decryptMAC = intkey_srv_to_cli;
 2010|    185|    } else {
 2011|    185|        crypto->encryptIV = IV_srv_to_cli;
 2012|    185|        crypto->decryptIV = IV_cli_to_srv;
 2013|    185|        crypto->encryptkey = enckey_srv_to_cli;
 2014|    185|        crypto->decryptkey = enckey_cli_to_srv;
 2015|    185|        crypto->encryptMAC = intkey_srv_to_cli;
 2016|    185|        crypto->decryptMAC = intkey_cli_to_srv;
 2017|    185|    }
 2018|       |
 2019|       |#ifdef DEBUG_CRYPTO
 2020|       |    ssh_log_hexdump("Client to Server IV", IV_cli_to_srv, IV_len);
 2021|       |    ssh_log_hexdump("Server to Client IV", IV_srv_to_cli, IV_len);
 2022|       |    ssh_log_hexdump("Client to Server Encryption Key", enckey_cli_to_srv,
 2023|       |                   enckey_cli_to_srv_len);
 2024|       |    ssh_log_hexdump("Server to Client Encryption Key", enckey_srv_to_cli,
 2025|       |                   enckey_srv_to_cli_len);
 2026|       |    ssh_log_hexdump("Client to Server Integrity Key", intkey_cli_to_srv,
 2027|       |                   intkey_cli_to_srv_len);
 2028|       |    ssh_log_hexdump("Server to Client Integrity Key", intkey_srv_to_cli,
 2029|       |                   intkey_srv_to_cli_len);
 2030|       |#endif /* DEBUG_CRYPTO */
 2031|       |
 2032|    185|    rc = 0;
 2033|    185|error:
 2034|    185|    ssh_string_burn(k_string);
 2035|    185|    SSH_STRING_FREE(k_string);
  ------------------
  |  |  882|    185|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 185, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 185]
  |  |  ------------------
  ------------------
 2036|    185|    if (rc != 0) {
  ------------------
  |  Branch (2036:9): [True: 0, False: 185]
  ------------------
 2037|      0|        BURN_FREE(IV_cli_to_srv, IV_len);
  ------------------
  |  |  414|      0|    do {                           \
  |  |  415|      0|        if ((x) != NULL) {         \
  |  |  ------------------
  |  |  |  Branch (415:13): [True: 0, False: 0]
  |  |  ------------------
  |  |  416|      0|            burn_free((x), (len)); \
  |  |  417|      0|            (x) = NULL;            \
  |  |  418|      0|        }                          \
  |  |  419|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (419:14): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2038|      0|        BURN_FREE(IV_srv_to_cli, IV_len);
  ------------------
  |  |  414|      0|    do {                           \
  |  |  415|      0|        if ((x) != NULL) {         \
  |  |  ------------------
  |  |  |  Branch (415:13): [True: 0, False: 0]
  |  |  ------------------
  |  |  416|      0|            burn_free((x), (len)); \
  |  |  417|      0|            (x) = NULL;            \
  |  |  418|      0|        }                          \
  |  |  419|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (419:14): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2039|      0|        BURN_FREE(enckey_cli_to_srv, enckey_cli_to_srv_len);
  ------------------
  |  |  414|      0|    do {                           \
  |  |  415|      0|        if ((x) != NULL) {         \
  |  |  ------------------
  |  |  |  Branch (415:13): [True: 0, False: 0]
  |  |  ------------------
  |  |  416|      0|            burn_free((x), (len)); \
  |  |  417|      0|            (x) = NULL;            \
  |  |  418|      0|        }                          \
  |  |  419|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (419:14): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2040|      0|        BURN_FREE(enckey_srv_to_cli, enckey_srv_to_cli_len);
  ------------------
  |  |  414|      0|    do {                           \
  |  |  415|      0|        if ((x) != NULL) {         \
  |  |  ------------------
  |  |  |  Branch (415:13): [True: 0, False: 0]
  |  |  ------------------
  |  |  416|      0|            burn_free((x), (len)); \
  |  |  417|      0|            (x) = NULL;            \
  |  |  418|      0|        }                          \
  |  |  419|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (419:14): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2041|      0|        BURN_FREE(intkey_cli_to_srv, intkey_cli_to_srv_len);
  ------------------
  |  |  414|      0|    do {                           \
  |  |  415|      0|        if ((x) != NULL) {         \
  |  |  ------------------
  |  |  |  Branch (415:13): [True: 0, False: 0]
  |  |  ------------------
  |  |  416|      0|            burn_free((x), (len)); \
  |  |  417|      0|            (x) = NULL;            \
  |  |  418|      0|        }                          \
  |  |  419|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (419:14): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2042|      0|        BURN_FREE(intkey_srv_to_cli, intkey_srv_to_cli_len);
  ------------------
  |  |  414|      0|    do {                           \
  |  |  415|      0|        if ((x) != NULL) {         \
  |  |  ------------------
  |  |  |  Branch (415:13): [True: 0, False: 0]
  |  |  ------------------
  |  |  416|      0|            burn_free((x), (len)); \
  |  |  417|      0|            (x) = NULL;            \
  |  |  418|      0|        }                          \
  |  |  419|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (419:14): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2043|      0|    }
 2044|       |
 2045|    185|    return rc;
 2046|    185|}
ssh_kex_is_gss:
 2055|      2|{
 2056|      2|    switch (crypto->kex_type) {
 2057|      0|    case SSH_GSS_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (2057:5): [True: 0, False: 2]
  ------------------
 2058|      0|    case SSH_GSS_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (2058:5): [True: 0, False: 2]
  ------------------
 2059|      0|    case SSH_GSS_KEX_ECDH_NISTP256_SHA256:
  ------------------
  |  Branch (2059:5): [True: 0, False: 2]
  ------------------
 2060|      0|    case SSH_GSS_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (2060:5): [True: 0, False: 2]
  ------------------
 2061|      0|        return true;
 2062|      2|    default:
  ------------------
  |  Branch (2062:5): [True: 2, False: 0]
  ------------------
 2063|       |        return false;
 2064|      2|    }
 2065|      2|}
kex.c:cmp_first_kex_algo:
  361|      7|                              const char *server_str) {
  362|      7|    size_t client_kex_len;
  363|      7|    size_t server_kex_len;
  364|       |
  365|      7|    const char *colon = NULL;
  366|       |
  367|      7|    int is_wrong = 1;
  368|       |
  369|      7|    if (client_str == NULL || server_str == NULL) {
  ------------------
  |  Branch (369:9): [True: 0, False: 7]
  |  Branch (369:31): [True: 0, False: 7]
  ------------------
  370|      0|        return is_wrong;
  371|      0|    }
  372|       |
  373|      7|    colon = strchr(client_str, ',');
  374|      7|    if (colon == NULL) {
  ------------------
  |  Branch (374:9): [True: 2, False: 5]
  ------------------
  375|      2|        client_kex_len = strlen(client_str);
  376|      5|    } else {
  377|      5|        client_kex_len = colon - client_str;
  378|      5|    }
  379|       |
  380|      7|    colon = strchr(server_str, ',');
  381|      7|    if (colon == NULL) {
  ------------------
  |  Branch (381:9): [True: 0, False: 7]
  ------------------
  382|      0|        server_kex_len = strlen(server_str);
  383|      7|    } else {
  384|      7|        server_kex_len = colon - server_str;
  385|      7|    }
  386|       |
  387|      7|    if (client_kex_len != server_kex_len) {
  ------------------
  |  Branch (387:9): [True: 5, False: 2]
  ------------------
  388|      5|        return is_wrong;
  389|      5|    }
  390|       |
  391|      2|    is_wrong = (strncmp(client_str, server_str, client_kex_len) != 0);
  392|       |
  393|      2|    return is_wrong;
  394|      7|}
kex.c:ssh_find_aead_hmac:
  952|    436|{
  953|    436|    if (cipher == NULL) {
  ------------------
  |  Branch (953:9): [True: 0, False: 436]
  ------------------
  954|      0|        return NULL;
  955|    436|    } else if (strcmp(cipher, "chacha20-poly1305@openssh.com") == 0) {
  ------------------
  |  Branch (955:16): [True: 0, False: 436]
  ------------------
  956|      0|        return "aead-poly1305";
  957|    436|    } else if (strcmp(cipher, "aes256-gcm@openssh.com") == 0) {
  ------------------
  |  Branch (957:16): [True: 0, False: 436]
  ------------------
  958|      0|        return "aead-gcm";
  959|    436|    } else if (strcmp(cipher, "aes128-gcm@openssh.com") == 0) {
  ------------------
  |  Branch (959:16): [True: 0, False: 436]
  ------------------
  960|      0|        return "aead-gcm";
  961|      0|    }
  962|    436|    return NULL;
  963|    436|}
kex.c:kex_select_kex_type:
  967|    218|{
  968|    218|    if (strcmp(kex, "diffie-hellman-group1-sha1") == 0) {
  ------------------
  |  Branch (968:9): [True: 0, False: 218]
  ------------------
  969|      0|        return SSH_KEX_DH_GROUP1_SHA1;
  970|    218|    } else if (strncmp(kex, "gss-group14-sha256-", 19) == 0) {
  ------------------
  |  Branch (970:16): [True: 0, False: 218]
  ------------------
  971|      0|        return SSH_GSS_KEX_DH_GROUP14_SHA256;
  972|    218|    } else if (strncmp(kex, "gss-group16-sha512-", 19) == 0) {
  ------------------
  |  Branch (972:16): [True: 0, False: 218]
  ------------------
  973|      0|        return SSH_GSS_KEX_DH_GROUP16_SHA512;
  974|    218|    } else if (strncmp(kex, "gss-nistp256-sha256-", 20) == 0) {
  ------------------
  |  Branch (974:16): [True: 0, False: 218]
  ------------------
  975|      0|        return SSH_GSS_KEX_ECDH_NISTP256_SHA256;
  976|    218|    } else if (strncmp(kex, "gss-curve25519-sha256-", 22) == 0) {
  ------------------
  |  Branch (976:16): [True: 0, False: 218]
  ------------------
  977|      0|        return SSH_GSS_KEX_CURVE25519_SHA256;
  978|    218|    } else if (strcmp(kex, "diffie-hellman-group14-sha1") == 0) {
  ------------------
  |  Branch (978:16): [True: 0, False: 218]
  ------------------
  979|      0|        return SSH_KEX_DH_GROUP14_SHA1;
  980|    218|    } else if (strcmp(kex, "diffie-hellman-group14-sha256") == 0) {
  ------------------
  |  Branch (980:16): [True: 3, False: 215]
  ------------------
  981|      3|        return SSH_KEX_DH_GROUP14_SHA256;
  982|    215|    } else if (strcmp(kex, "diffie-hellman-group16-sha512") == 0) {
  ------------------
  |  Branch (982:16): [True: 0, False: 215]
  ------------------
  983|      0|        return SSH_KEX_DH_GROUP16_SHA512;
  984|    215|    } else if (strcmp(kex, "diffie-hellman-group18-sha512") == 0) {
  ------------------
  |  Branch (984:16): [True: 0, False: 215]
  ------------------
  985|      0|        return SSH_KEX_DH_GROUP18_SHA512;
  986|      0|#ifdef WITH_GEX
  987|    215|    } else if (strcmp(kex, "diffie-hellman-group-exchange-sha1") == 0) {
  ------------------
  |  Branch (987:16): [True: 0, False: 215]
  ------------------
  988|      0|        return SSH_KEX_DH_GEX_SHA1;
  989|    215|    } else if (strcmp(kex, "diffie-hellman-group-exchange-sha256") == 0) {
  ------------------
  |  Branch (989:16): [True: 23, False: 192]
  ------------------
  990|     23|        return SSH_KEX_DH_GEX_SHA256;
  991|     23|#endif /* WITH_GEX */
  992|    192|    } else if (strcmp(kex, "ecdh-sha2-nistp256") == 0) {
  ------------------
  |  Branch (992:16): [True: 0, False: 192]
  ------------------
  993|      0|        return SSH_KEX_ECDH_SHA2_NISTP256;
  994|    192|    } else if (strcmp(kex, "ecdh-sha2-nistp384") == 0) {
  ------------------
  |  Branch (994:16): [True: 0, False: 192]
  ------------------
  995|      0|        return SSH_KEX_ECDH_SHA2_NISTP384;
  996|    192|    } else if (strcmp(kex, "ecdh-sha2-nistp521") == 0) {
  ------------------
  |  Branch (996:16): [True: 0, False: 192]
  ------------------
  997|      0|        return SSH_KEX_ECDH_SHA2_NISTP521;
  998|    192|    } else if (strcmp(kex, "curve25519-sha256@libssh.org") == 0) {
  ------------------
  |  Branch (998:16): [True: 0, False: 192]
  ------------------
  999|      0|        return SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG;
 1000|    192|    } else if (strcmp(kex, "curve25519-sha256") == 0) {
  ------------------
  |  Branch (1000:16): [True: 192, False: 0]
  ------------------
 1001|    192|        return SSH_KEX_CURVE25519_SHA256;
 1002|    192|    } else if (strcmp(kex, "sntrup761x25519-sha512@openssh.com") == 0) {
  ------------------
  |  Branch (1002:16): [True: 0, False: 0]
  ------------------
 1003|      0|        return SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM;
 1004|      0|    } else if (strcmp(kex, "sntrup761x25519-sha512") == 0) {
  ------------------
  |  Branch (1004:16): [True: 0, False: 0]
  ------------------
 1005|      0|        return SSH_KEX_SNTRUP761X25519_SHA512;
 1006|      0|    } else if (strcmp(kex, "mlkem768x25519-sha256") == 0) {
  ------------------
  |  Branch (1006:16): [True: 0, False: 0]
  ------------------
 1007|      0|        return SSH_KEX_MLKEM768X25519_SHA256;
 1008|      0|    } else if (strcmp(kex, "mlkem768nistp256-sha256") == 0) {
  ------------------
  |  Branch (1008:16): [True: 0, False: 0]
  ------------------
 1009|      0|        return SSH_KEX_MLKEM768NISTP256_SHA256;
 1010|       |#ifdef HAVE_MLKEM1024
 1011|       |    } else if (strcmp(kex, "mlkem1024nistp384-sha384") == 0) {
 1012|       |        return SSH_KEX_MLKEM1024NISTP384_SHA384;
 1013|       |#endif
 1014|      0|    }
 1015|       |    /* should not happen. We should be getting only valid names at this stage */
 1016|      0|    return 0;
 1017|    218|}

ssh_reseed:
   94|    319|void ssh_reseed(void){
   95|    319|#ifndef _WIN32
   96|    319|    struct timeval tv;
   97|       |    gettimeofday(&tv, NULL);
   98|    319|    RAND_add(&tv, sizeof(tv), 0.0);
   99|    319|#endif
  100|    319|}
ssh_kdf:
  204|  1.11k|{
  205|  1.11k|    int ret = SSH_ERROR, rv;
  ------------------
  |  |  316|  1.11k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  206|       |#if OPENSSL_VERSION_NUMBER < 0x30000000L
  207|       |    EVP_KDF_CTX *ctx = EVP_KDF_CTX_new_id(EVP_KDF_SSHKDF);
  208|       |#else
  209|  1.11k|    EVP_KDF_CTX *ctx = NULL;
  210|  1.11k|    OSSL_PARAM_BLD *param_bld = NULL;
  211|  1.11k|    OSSL_PARAM *params = NULL;
  212|  1.11k|    const char *md = NULL;
  213|  1.11k|    EVP_KDF *kdf = NULL;
  214|       |
  215|  1.11k|    md = sshkdf_digest_to_md(crypto->digest_type);
  216|  1.11k|    if (md == NULL) {
  ------------------
  |  Branch (216:9): [True: 0, False: 1.11k]
  ------------------
  217|      0|        return -1;
  218|      0|    }
  219|       |
  220|  1.11k|    kdf = EVP_KDF_fetch(NULL, "SSHKDF", NULL);
  221|  1.11k|    if (kdf == NULL) {
  ------------------
  |  Branch (221:9): [True: 0, False: 1.11k]
  ------------------
  222|      0|        return -1;
  223|      0|    }
  224|  1.11k|    ctx = EVP_KDF_CTX_new(kdf);
  225|  1.11k|    EVP_KDF_free(kdf);
  226|       |
  227|  1.11k|    param_bld = OSSL_PARAM_BLD_new();
  228|  1.11k|    if (param_bld == NULL) {
  ------------------
  |  Branch (228:9): [True: 0, False: 1.11k]
  ------------------
  229|      0|        EVP_KDF_CTX_free(ctx);
  230|      0|        return -1;
  231|      0|    }
  232|  1.11k|#endif /* OPENSSL_VERSION_NUMBER */
  233|       |
  234|  1.11k|    if (ctx == NULL) {
  ------------------
  |  Branch (234:9): [True: 0, False: 1.11k]
  ------------------
  235|      0|        goto out;
  236|      0|    }
  237|       |
  238|       |#if OPENSSL_VERSION_NUMBER < 0x30000000L
  239|       |    rv = EVP_KDF_ctrl(ctx,
  240|       |                      EVP_KDF_CTRL_SET_MD,
  241|       |                      sshkdf_digest_to_md(crypto->digest_type));
  242|       |    if (rv != 1) {
  243|       |        goto out;
  244|       |    }
  245|       |    rv = EVP_KDF_ctrl(ctx, EVP_KDF_CTRL_SET_KEY, key, key_len);
  246|       |    if (rv != 1) {
  247|       |        goto out;
  248|       |    }
  249|       |    rv = EVP_KDF_ctrl(ctx,
  250|       |                      EVP_KDF_CTRL_SET_SSHKDF_XCGHASH,
  251|       |                      crypto->secret_hash,
  252|       |                      crypto->digest_len);
  253|       |    if (rv != 1) {
  254|       |        goto out;
  255|       |    }
  256|       |    rv = EVP_KDF_ctrl(ctx, EVP_KDF_CTRL_SET_SSHKDF_TYPE, key_type);
  257|       |    if (rv != 1) {
  258|       |        goto out;
  259|       |    }
  260|       |    rv = EVP_KDF_ctrl(ctx,
  261|       |                      EVP_KDF_CTRL_SET_SSHKDF_SESSION_ID,
  262|       |                      crypto->session_id,
  263|       |                      crypto->session_id_len);
  264|       |    if (rv != 1) {
  265|       |        goto out;
  266|       |    }
  267|       |    rv = EVP_KDF_derive(ctx, output, requested_len);
  268|       |    if (rv != 1) {
  269|       |        goto out;
  270|       |    }
  271|       |#else
  272|  1.11k|    rv = OSSL_PARAM_BLD_push_utf8_string(param_bld,
  273|  1.11k|                                         OSSL_KDF_PARAM_DIGEST,
  274|  1.11k|                                         md,
  275|  1.11k|                                         strlen(md));
  276|  1.11k|    if (rv != 1) {
  ------------------
  |  Branch (276:9): [True: 0, False: 1.11k]
  ------------------
  277|      0|        goto out;
  278|      0|    }
  279|  1.11k|    rv = OSSL_PARAM_BLD_push_octet_string(param_bld,
  280|  1.11k|                                          OSSL_KDF_PARAM_KEY,
  281|  1.11k|                                          key,
  282|  1.11k|                                          key_len);
  283|  1.11k|    if (rv != 1) {
  ------------------
  |  Branch (283:9): [True: 0, False: 1.11k]
  ------------------
  284|      0|        goto out;
  285|      0|    }
  286|  1.11k|    rv = OSSL_PARAM_BLD_push_octet_string(param_bld,
  287|  1.11k|                                          OSSL_KDF_PARAM_SSHKDF_XCGHASH,
  288|  1.11k|                                          crypto->secret_hash,
  289|  1.11k|                                          crypto->digest_len);
  290|  1.11k|    if (rv != 1) {
  ------------------
  |  Branch (290:9): [True: 0, False: 1.11k]
  ------------------
  291|      0|        goto out;
  292|      0|    }
  293|  1.11k|    rv = OSSL_PARAM_BLD_push_octet_string(param_bld,
  294|  1.11k|                                          OSSL_KDF_PARAM_SSHKDF_SESSION_ID,
  295|  1.11k|                                          crypto->session_id,
  296|  1.11k|                                          crypto->session_id_len);
  297|  1.11k|    if (rv != 1) {
  ------------------
  |  Branch (297:9): [True: 0, False: 1.11k]
  ------------------
  298|      0|        goto out;
  299|      0|    }
  300|  1.11k|    rv = OSSL_PARAM_BLD_push_utf8_string(param_bld,
  301|  1.11k|                                         OSSL_KDF_PARAM_SSHKDF_TYPE,
  302|  1.11k|                                         (const char *)&key_type,
  303|  1.11k|                                         1);
  304|  1.11k|    if (rv != 1) {
  ------------------
  |  Branch (304:9): [True: 0, False: 1.11k]
  ------------------
  305|      0|        goto out;
  306|      0|    }
  307|       |
  308|  1.11k|    params = OSSL_PARAM_BLD_to_param(param_bld);
  309|  1.11k|    if (params == NULL) {
  ------------------
  |  Branch (309:9): [True: 0, False: 1.11k]
  ------------------
  310|      0|        goto out;
  311|      0|    }
  312|       |
  313|  1.11k|    rv = EVP_KDF_derive(ctx, output, requested_len, params);
  314|  1.11k|    if (rv != 1) {
  ------------------
  |  Branch (314:9): [True: 0, False: 1.11k]
  ------------------
  315|      0|        goto out;
  316|      0|    }
  317|  1.11k|#endif /* OPENSSL_VERSION_NUMBER */
  318|  1.11k|    ret = SSH_OK;
  ------------------
  |  |  315|  1.11k|#define SSH_OK 0     /* No error */
  ------------------
  319|       |
  320|  1.11k|out:
  321|  1.11k|#if OPENSSL_VERSION_NUMBER >= 0x30000000L
  322|  1.11k|    OSSL_PARAM_BLD_free(param_bld);
  323|  1.11k|    OSSL_PARAM_free(params);
  324|  1.11k|#endif
  325|  1.11k|    EVP_KDF_CTX_free(ctx);
  326|  1.11k|    if (ret < 0) {
  ------------------
  |  Branch (326:9): [True: 0, False: 1.11k]
  ------------------
  327|      0|        return ret;
  328|      0|    }
  329|  1.11k|    return 0;
  330|  1.11k|}
ssh_get_ciphertab:
 1394|    654|{
 1395|    654|    return ssh_ciphertab;
 1396|    654|}
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|}
evp_build_pkey:
 1501|  1.35k|{
 1502|  1.35k|    int rc;
 1503|  1.35k|    EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new_from_name(NULL, name, NULL);
 1504|  1.35k|    OSSL_PARAM *params = NULL;
 1505|       |
 1506|  1.35k|    if (ctx == NULL) {
  ------------------
  |  Branch (1506:9): [True: 0, False: 1.35k]
  ------------------
 1507|      0|        return -1;
 1508|      0|    }
 1509|       |
 1510|  1.35k|    params = OSSL_PARAM_BLD_to_param(param_bld);
 1511|  1.35k|    if (params == NULL) {
  ------------------
  |  Branch (1511:9): [True: 0, False: 1.35k]
  ------------------
 1512|      0|        EVP_PKEY_CTX_free(ctx);
 1513|      0|        return -1;
 1514|      0|    }
 1515|       |
 1516|  1.35k|    rc = EVP_PKEY_fromdata_init(ctx);
 1517|  1.35k|    if (rc != 1) {
  ------------------
  |  Branch (1517:9): [True: 0, False: 1.35k]
  ------------------
 1518|      0|        OSSL_PARAM_free(params);
 1519|      0|        EVP_PKEY_CTX_free(ctx);
 1520|      0|        return -1;
 1521|      0|    }
 1522|       |
 1523|  1.35k|    rc = EVP_PKEY_fromdata(ctx, pkey, selection, params);
 1524|  1.35k|    if (rc != 1) {
  ------------------
  |  Branch (1524:9): [True: 0, False: 1.35k]
  ------------------
 1525|      0|        SSH_LOG(SSH_LOG_WARNING,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1526|      0|                "Failed to import private key: %s\n",
 1527|      0|                ERR_error_string(ERR_get_error(), NULL));
 1528|      0|        OSSL_PARAM_free(params);
 1529|      0|        EVP_PKEY_CTX_free(ctx);
 1530|      0|        return -1;
 1531|      0|    }
 1532|       |
 1533|  1.35k|    OSSL_PARAM_free(params);
 1534|  1.35k|    EVP_PKEY_CTX_free(ctx);
 1535|       |
 1536|  1.35k|    return SSH_OK;
  ------------------
  |  |  315|  1.35k|#define SSH_OK 0     /* No error */
  ------------------
 1537|  1.35k|}
evp_dup_rsa_pkey:
 1616|    504|{
 1617|       |    return evp_dup_pkey(SN_rsa, key, demote, new_key);
 1618|    504|}
libcrypto.c:sshkdf_digest_to_md:
  185|  1.11k|{
  186|  1.11k|    switch (digest_type) {
  ------------------
  |  Branch (186:13): [True: 1.11k, False: 0]
  ------------------
  187|      0|    case SSH_KDF_SHA1:
  ------------------
  |  Branch (187:5): [True: 0, False: 1.11k]
  ------------------
  188|      0|        return SN_sha1;
  189|  1.11k|    case SSH_KDF_SHA256:
  ------------------
  |  Branch (189:5): [True: 1.11k, False: 0]
  ------------------
  190|  1.11k|        return SN_sha256;
  191|      0|    case SSH_KDF_SHA384:
  ------------------
  |  Branch (191:5): [True: 0, False: 1.11k]
  ------------------
  192|      0|        return SN_sha384;
  193|      0|    case SSH_KDF_SHA512:
  ------------------
  |  Branch (193:5): [True: 0, False: 1.11k]
  ------------------
  194|      0|        return SN_sha512;
  195|  1.11k|    }
  196|      0|    return NULL;
  197|  1.11k|}
libcrypto.c:none_crypt:
 1217|  22.4k|{
 1218|  22.4k|    memcpy(out, in, len);
 1219|  22.4k|}
libcrypto.c:evp_dup_pkey:
 1556|    504|{
 1557|    504|    int rc;
 1558|    504|    EVP_PKEY_CTX *ctx = NULL;
 1559|    504|    OSSL_PARAM *params = NULL;
 1560|       |
 1561|       |    /* The simple case -- just reference the existing key */
 1562|    504|    if (!demote || (key->flags & SSH_KEY_FLAG_PRIVATE) == 0) {
  ------------------
  |  |   55|    185|#define SSH_KEY_FLAG_PRIVATE 0x0002
  ------------------
  |  Branch (1562:9): [True: 319, False: 185]
  |  Branch (1562:20): [True: 0, False: 185]
  ------------------
 1563|    319|        rc = EVP_PKEY_up_ref(key->key);
 1564|    319|        if (rc != 1) {
  ------------------
  |  Branch (1564:13): [True: 0, False: 319]
  ------------------
 1565|      0|            return -1;
 1566|      0|        }
 1567|    319|        new_key->key = key->key;
 1568|    319|        return SSH_OK;
  ------------------
  |  |  315|    319|#define SSH_OK 0     /* No error */
  ------------------
 1569|    319|    }
 1570|       |
 1571|       |    /* demote == 1 */
 1572|    185|    ctx = EVP_PKEY_CTX_new_from_name(NULL, name, NULL);
 1573|    185|    if (ctx == NULL) {
  ------------------
  |  Branch (1573:9): [True: 0, False: 185]
  ------------------
 1574|      0|        return -1;
 1575|      0|    }
 1576|       |
 1577|    185|    rc = EVP_PKEY_todata(key->key, EVP_PKEY_PUBLIC_KEY, &params);
 1578|    185|    if (rc != 1) {
  ------------------
  |  Branch (1578:9): [True: 0, False: 185]
  ------------------
 1579|      0|        EVP_PKEY_CTX_free(ctx);
 1580|      0|        return -1;
 1581|      0|    }
 1582|       |
 1583|    185|    if (strcmp(name, "EC") == 0) {
  ------------------
  |  Branch (1583:9): [True: 0, False: 185]
  ------------------
 1584|      0|        OSSL_PARAM *locate_param = NULL;
 1585|       |        /* For ECC keys provided by engine or provider, we need to have the
 1586|       |         * explicit public part available, otherwise the key will not be
 1587|       |         * usable */
 1588|      0|        locate_param = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_PUB_KEY);
 1589|      0|        if (locate_param == NULL) {
  ------------------
  |  Branch (1589:13): [True: 0, False: 0]
  ------------------
 1590|      0|            EVP_PKEY_CTX_free(ctx);
 1591|      0|            OSSL_PARAM_free(params);
 1592|      0|            return -1;
 1593|      0|        }
 1594|      0|    }
 1595|    185|    rc = EVP_PKEY_fromdata_init(ctx);
 1596|    185|    if (rc != 1) {
  ------------------
  |  Branch (1596:9): [True: 0, False: 185]
  ------------------
 1597|      0|        EVP_PKEY_CTX_free(ctx);
 1598|      0|        OSSL_PARAM_free(params);
 1599|      0|        return -1;
 1600|      0|    }
 1601|       |
 1602|    185|    rc = EVP_PKEY_fromdata(ctx, &(new_key->key), EVP_PKEY_PUBLIC_KEY, params);
 1603|    185|    if (rc != 1) {
  ------------------
  |  Branch (1603:9): [True: 0, False: 185]
  ------------------
 1604|      0|        EVP_PKEY_CTX_free(ctx);
 1605|      0|        OSSL_PARAM_free(params);
 1606|      0|        return -1;
 1607|      0|    }
 1608|       |
 1609|    185|    OSSL_PARAM_free(params);
 1610|    185|    EVP_PKEY_CTX_free(ctx);
 1611|       |
 1612|    185|    return SSH_OK;
  ------------------
  |  |  315|    185|#define SSH_OK 0     /* No error */
  ------------------
 1613|    185|}

_ssh_log:
  168|   203k|{
  169|   203k|    va_list va;
  170|       |
  171|   203k|    if (verbosity <= ssh_get_log_level()) {
  ------------------
  |  Branch (171:9): [True: 0, False: 203k]
  ------------------
  172|      0|        va_start(va, format);
  173|      0|        ssh_vlog(verbosity, function, format, &va);
  174|       |        va_end(va);
  175|      0|    }
  176|   203k|}
ssh_get_log_level:
  252|   205k|int ssh_get_log_level(void) {
  253|   205k|  return ssh_log_level;
  254|   205k|}
ssh_get_log_callback:
  275|    831|ssh_logging_callback ssh_get_log_callback(void) {
  276|    831|  return ssh_log_cb;
  277|    831|}

match_group:
  589|    612|{
  590|    612|    const char *a = NULL;
  591|    612|    const char *z = NULL;
  592|    612|    int cmp;
  593|       |
  594|    612|    if (group == NULL || object == NULL) {
  ------------------
  |  Branch (594:9): [True: 0, False: 612]
  |  Branch (594:26): [True: 0, False: 612]
  ------------------
  595|      0|        return 0;
  596|      0|    }
  597|       |
  598|    612|    z = group;
  599|  1.95k|    do {
  600|  1.95k|        a = strchr(z, ',');
  601|  1.95k|        if (a == NULL) {
  ------------------
  |  Branch (601:13): [True: 610, False: 1.34k]
  ------------------
  602|    610|            cmp = strcmp(z, object);
  603|    610|            if (cmp == 0) {
  ------------------
  |  Branch (603:17): [True: 53, False: 557]
  ------------------
  604|     53|                return 1;
  605|     53|            }
  606|    557|            return 0;
  607|  1.34k|        } else {
  608|  1.34k|            cmp = strncmp(z, object, a - z);
  609|  1.34k|            if (cmp == 0 && object[a - z] == '\0') {
  ------------------
  |  Branch (609:17): [True: 418, False: 928]
  |  Branch (609:29): [True: 2, False: 416]
  ------------------
  610|      2|                return 1;
  611|      2|            }
  612|  1.34k|        }
  613|  1.34k|        z = a + 1;
  614|  1.34k|    } while (1);
  ------------------
  |  Branch (614:14): [True: 1.34k, Folded]
  ------------------
  615|       |
  616|       |    /* not reached */
  617|      0|    return 0;
  618|    612|}

sha256_init:
   97|    185|{
   98|    185|    int rc;
   99|    185|    SHA256CTX c = EVP_MD_CTX_new();
  100|    185|    if (c == NULL) {
  ------------------
  |  Branch (100:9): [True: 0, False: 185]
  ------------------
  101|      0|        return NULL;
  102|      0|    }
  103|    185|    rc = EVP_DigestInit_ex(c, EVP_sha256(), NULL);
  104|    185|    if (rc == 0) {
  ------------------
  |  Branch (104:9): [True: 0, False: 185]
  ------------------
  105|      0|        EVP_MD_CTX_free(c);
  106|       |        c = NULL;
  107|      0|    }
  108|    185|    return c;
  109|    185|}
sha256_update:
  119|    185|{
  120|    185|    int rc = EVP_DigestUpdate(c, data, len);
  121|    185|    if (rc != 1) {
  ------------------
  |  Branch (121:9): [True: 0, False: 185]
  ------------------
  122|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  123|      0|    }
  124|    185|    return SSH_OK;
  ------------------
  |  |  315|    185|#define SSH_OK 0     /* No error */
  ------------------
  125|    185|}
sha256_final:
  129|    185|{
  130|    185|    unsigned int mdlen = 0;
  131|    185|    int rc = EVP_DigestFinal(c, md, &mdlen);
  132|       |
  133|    185|    EVP_MD_CTX_free(c);
  134|    185|    if (rc != 1) {
  ------------------
  |  Branch (134:9): [True: 0, False: 185]
  ------------------
  135|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  136|      0|    }
  137|    185|    return SSH_OK;
  ------------------
  |  |  315|    185|#define SSH_OK 0     /* No error */
  ------------------
  138|    185|}
sha256:
  142|    185|{
  143|    185|    SHA256CTX c = sha256_init();
  144|    185|    int rc;
  145|       |
  146|    185|    if (c == NULL) {
  ------------------
  |  Branch (146:9): [True: 0, False: 185]
  ------------------
  147|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  148|      0|    }
  149|    185|    rc = sha256_update(c, digest, len);
  150|    185|    if (rc != SSH_OK) {
  ------------------
  |  |  315|    185|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (150:9): [True: 0, False: 185]
  ------------------
  151|      0|        EVP_MD_CTX_free(c);
  152|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  153|      0|    }
  154|    185|    return sha256_final(hash, c);
  155|    185|}

ssh_message_free:
  724|  5.31k|{
  725|  5.31k|    if (msg == NULL) {
  ------------------
  |  Branch (725:9): [True: 0, False: 5.31k]
  ------------------
  726|      0|        return;
  727|      0|    }
  728|       |
  729|  5.31k|    switch (msg->type) {
  ------------------
  |  Branch (729:13): [True: 5.31k, False: 0]
  ------------------
  730|  5.26k|    case SSH_REQUEST_AUTH:
  ------------------
  |  Branch (730:5): [True: 5.26k, False: 49]
  ------------------
  731|  5.26k|        SAFE_FREE(msg->auth_request.username);
  ------------------
  |  |  375|  5.26k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 2.31k, False: 2.95k]
  |  |  |  Branch (375:71): [Folded, False: 5.26k]
  |  |  ------------------
  ------------------
  732|  5.26k|        SAFE_FREE(msg->auth_request.sigtype);
  ------------------
  |  |  375|  5.26k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 1.17k, False: 4.09k]
  |  |  |  Branch (375:71): [Folded, False: 5.26k]
  |  |  ------------------
  ------------------
  733|  5.26k|        if (msg->auth_request.password) {
  ------------------
  |  Branch (733:13): [True: 1, False: 5.26k]
  ------------------
  734|      1|            ssh_burn(msg->auth_request.password,
  ------------------
  |  |  390|      1|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  735|      1|                     strlen(msg->auth_request.password));
  736|      1|            SAFE_FREE(msg->auth_request.password);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  737|      1|        }
  738|  5.26k|        ssh_key_free(msg->auth_request.pubkey);
  739|  5.26k|        ssh_key_free(msg->auth_request.server_pubkey);
  740|  5.26k|        break;
  741|     48|    case SSH_REQUEST_CHANNEL_OPEN:
  ------------------
  |  Branch (741:5): [True: 48, False: 5.26k]
  ------------------
  742|     48|        SAFE_FREE(msg->channel_request_open.originator);
  ------------------
  |  |  375|     48|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 1, False: 47]
  |  |  |  Branch (375:71): [Folded, False: 48]
  |  |  ------------------
  ------------------
  743|     48|        SAFE_FREE(msg->channel_request_open.destination);
  ------------------
  |  |  375|     48|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 1, False: 47]
  |  |  |  Branch (375:71): [Folded, False: 48]
  |  |  ------------------
  ------------------
  744|     48|        break;
  745|      0|    case SSH_REQUEST_CHANNEL:
  ------------------
  |  Branch (745:5): [True: 0, False: 5.31k]
  ------------------
  746|      0|        SAFE_FREE(msg->channel_request.TERM);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  747|      0|        SAFE_FREE(msg->channel_request.modes);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  748|      0|        SAFE_FREE(msg->channel_request.var_name);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  749|      0|        SAFE_FREE(msg->channel_request.var_value);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  750|      0|        SAFE_FREE(msg->channel_request.command);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  751|      0|        SAFE_FREE(msg->channel_request.subsystem);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  752|      0|        switch (msg->channel_request.type) {
  ------------------
  |  Branch (752:17): [True: 0, False: 0]
  ------------------
  753|      0|        case SSH_CHANNEL_REQUEST_EXEC:
  ------------------
  |  Branch (753:9): [True: 0, False: 0]
  ------------------
  754|      0|            SAFE_FREE(msg->channel_request.command);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  755|      0|            break;
  756|      0|        case SSH_CHANNEL_REQUEST_ENV:
  ------------------
  |  Branch (756:9): [True: 0, False: 0]
  ------------------
  757|      0|            SAFE_FREE(msg->channel_request.var_name);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  758|      0|            SAFE_FREE(msg->channel_request.var_value);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  759|      0|            break;
  760|      0|        case SSH_CHANNEL_REQUEST_PTY:
  ------------------
  |  Branch (760:9): [True: 0, False: 0]
  ------------------
  761|      0|            SAFE_FREE(msg->channel_request.TERM);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  762|      0|            break;
  763|      0|        case SSH_CHANNEL_REQUEST_SUBSYSTEM:
  ------------------
  |  Branch (763:9): [True: 0, False: 0]
  ------------------
  764|      0|            SAFE_FREE(msg->channel_request.subsystem);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  765|      0|            break;
  766|      0|        case SSH_CHANNEL_REQUEST_X11:
  ------------------
  |  Branch (766:9): [True: 0, False: 0]
  ------------------
  767|      0|            SAFE_FREE(msg->channel_request.x11_auth_protocol);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  768|      0|            SAFE_FREE(msg->channel_request.x11_auth_cookie);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  769|      0|            break;
  770|      0|        }
  771|      0|        break;
  772|      1|    case SSH_REQUEST_SERVICE:
  ------------------
  |  Branch (772:5): [True: 1, False: 5.31k]
  ------------------
  773|      1|        SAFE_FREE(msg->service_request.service);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  774|      1|        break;
  775|      0|    case SSH_REQUEST_GLOBAL:
  ------------------
  |  Branch (775:5): [True: 0, False: 5.31k]
  ------------------
  776|      0|        SAFE_FREE(msg->global_request.bind_address);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  777|      0|        break;
  778|  5.31k|    }
  779|  5.31k|    ZERO_STRUCTP(msg);
  ------------------
  |  |  381|  5.31k|#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((x), 0, sizeof(*(x))); } while(0)
  |  |  ------------------
  |  |  |  Branch (381:34): [True: 5.31k, False: 0]
  |  |  |  Branch (381:85): [Folded, False: 5.31k]
  |  |  ------------------
  ------------------
  780|       |    SAFE_FREE(msg);
  ------------------
  |  |  375|  5.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 5.31k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 5.31k]
  |  |  ------------------
  ------------------
  781|  5.31k|}
ssh_packet_service_request:
  786|      3|{
  787|      3|    char *service_c = NULL;
  788|      3|    ssh_message msg = NULL;
  789|      3|    int rc;
  790|       |
  791|      3|    (void)type;
  792|      3|    (void)user;
  793|       |
  794|      3|    rc = ssh_buffer_unpack(packet,
  ------------------
  |  |   60|      3|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      3|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      3|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      3|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      3|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      3|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      3|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  795|      3|                           "s",
  796|      3|                           &service_c);
  797|      3|    if (rc != SSH_OK) {
  ------------------
  |  |  315|      3|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (797:9): [True: 2, False: 1]
  ------------------
  798|      2|        ssh_set_error(session,
  ------------------
  |  |  313|      2|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  799|      2|                      SSH_FATAL,
  800|      2|                      "Invalid SSH_MSG_SERVICE_REQUEST packet");
  801|      2|        goto error;
  802|      2|    }
  803|       |
  804|      1|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|      1|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  805|      1|            "Received a SERVICE_REQUEST for service %s",
  806|      1|            service_c);
  807|       |
  808|      1|    msg = ssh_message_new(session);
  809|      1|    if (msg == NULL) {
  ------------------
  |  Branch (809:9): [True: 0, False: 1]
  ------------------
  810|      0|        SAFE_FREE(service_c);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  811|      0|        goto error;
  812|      0|    }
  813|       |
  814|      1|    msg->type = SSH_REQUEST_SERVICE;
  815|      1|    msg->service_request.service = service_c;
  816|       |
  817|      1|    ssh_message_queue(session, msg);
  818|      3|error:
  819|       |
  820|      3|    return SSH_PACKET_USED;
  ------------------
  |  |  638|      3|#define SSH_PACKET_USED 1
  ------------------
  821|      1|}
ssh_packet_userauth_request:
  903|  5.26k|{
  904|  5.26k|    ssh_message msg = NULL;
  905|  5.26k|    ssh_signature sig = NULL;
  906|  5.26k|    char *service = NULL;
  907|  5.26k|    char *method = NULL;
  908|  5.26k|    int cmp;
  909|  5.26k|    int rc;
  910|       |
  911|  5.26k|    (void)user;
  912|  5.26k|    (void)type;
  913|       |
  914|  5.26k|    msg = ssh_message_new(session);
  915|  5.26k|    if (msg == NULL) {
  ------------------
  |  Branch (915:9): [True: 0, False: 5.26k]
  ------------------
  916|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  917|      0|        goto error;
  918|      0|    }
  919|  5.26k|    msg->type = SSH_REQUEST_AUTH;
  920|  5.26k|    rc = ssh_buffer_unpack(packet,
  ------------------
  |  |   60|  5.26k|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|  5.26k|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|  5.26k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|  5.26k|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|  5.26k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|  5.26k|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|  5.26k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  921|  5.26k|                           "sss",
  922|  5.26k|                           &msg->auth_request.username,
  923|  5.26k|                           &service,
  924|  5.26k|                           &method);
  925|       |
  926|  5.26k|    if (rc != SSH_OK) {
  ------------------
  |  |  315|  5.26k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (926:9): [True: 2.95k, False: 2.31k]
  ------------------
  927|  2.95k|        goto error;
  928|  2.95k|    }
  929|       |
  930|  2.31k|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|  2.31k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  931|  2.31k|            "Auth request for service %s, method %s for user '%s'",
  932|  2.31k|            service,
  933|  2.31k|            method,
  934|  2.31k|            msg->auth_request.username);
  935|       |
  936|  2.31k|    cmp = strcmp(service, "ssh-connection");
  937|  2.31k|    if (cmp != 0) {
  ------------------
  |  Branch (937:9): [True: 89, False: 2.22k]
  ------------------
  938|     89|        SSH_LOG(SSH_LOG_TRACE, "Invalid service request: %s", service);
  ------------------
  |  |  283|     89|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  939|     89|        goto end;
  940|     89|    }
  941|       |
  942|  2.22k|    if (strcmp(method, "none") == 0) {
  ------------------
  |  Branch (942:9): [True: 69, False: 2.15k]
  ------------------
  943|     69|        msg->auth_request.method = SSH_AUTH_METHOD_NONE;
  ------------------
  |  |  155|     69|#define SSH_AUTH_METHOD_NONE         0x0001u
  ------------------
  944|     69|        goto end;
  945|     69|    }
  946|       |
  947|  2.15k|    if (strcmp(method, "password") == 0) {
  ------------------
  |  Branch (947:9): [True: 2, False: 2.15k]
  ------------------
  948|      2|        uint8_t tmp;
  949|       |
  950|      2|        msg->auth_request.method = SSH_AUTH_METHOD_PASSWORD;
  ------------------
  |  |  156|      2|#define SSH_AUTH_METHOD_PASSWORD     0x0002u
  ------------------
  951|      2|        rc = ssh_buffer_unpack(packet, "bs", &tmp, &msg->auth_request.password);
  ------------------
  |  |   60|      2|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      2|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      2|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      2|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      2|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      2|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      2|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  952|      2|        if (rc != SSH_OK) {
  ------------------
  |  |  315|      2|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (952:13): [True: 1, False: 1]
  ------------------
  953|      1|            goto error;
  954|      1|        }
  955|      1|        goto end;
  956|      2|    }
  957|       |
  958|  2.15k|    if (strcmp(method, "keyboard-interactive") == 0) {
  ------------------
  |  Branch (958:9): [True: 0, False: 2.15k]
  ------------------
  959|      0|        ssh_string lang = NULL;
  960|      0|        ssh_string submethods = NULL;
  961|       |
  962|      0|        msg->auth_request.method = SSH_AUTH_METHOD_INTERACTIVE;
  ------------------
  |  |  159|      0|#define SSH_AUTH_METHOD_INTERACTIVE  0x0010u
  ------------------
  963|      0|        lang = ssh_buffer_get_ssh_string(packet);
  964|      0|        if (lang == NULL) {
  ------------------
  |  Branch (964:13): [True: 0, False: 0]
  ------------------
  965|      0|            goto error;
  966|      0|        }
  967|       |        /* from the RFC 4256
  968|       |         * 3.1.  Initial Exchange
  969|       |         * "The language tag is deprecated and SHOULD be the empty string."
  970|       |         */
  971|      0|        SSH_STRING_FREE(lang);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  972|       |
  973|      0|        submethods = ssh_buffer_get_ssh_string(packet);
  974|      0|        if (submethods == NULL) {
  ------------------
  |  Branch (974:13): [True: 0, False: 0]
  ------------------
  975|      0|            goto error;
  976|      0|        }
  977|       |        /* from the RFC 4256
  978|       |         * 3.1.  Initial Exchange
  979|       |         * "One possible implementation strategy of the submethods field on the
  980|       |         *  server is that, unless the user may use multiple different
  981|       |         *  submethods, the server ignores this field."
  982|       |         */
  983|      0|        SSH_STRING_FREE(submethods);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  984|       |
  985|      0|        goto end;
  986|      0|    }
  987|       |
  988|  2.15k|    if (strcmp(method, "publickey") == 0 ||
  ------------------
  |  Branch (988:9): [True: 1.91k, False: 242]
  ------------------
  989|  1.91k|        strcmp(method, "publickey-hostbound-v00@openssh.com") == 0) {
  ------------------
  |  Branch (989:9): [True: 3, False: 239]
  ------------------
  990|  1.91k|        ssh_string algo = NULL;
  991|  1.91k|        ssh_string pubkey_blob = NULL;
  992|  1.91k|        ssh_string server_pubkey_blob = NULL;
  993|  1.91k|        uint8_t has_sign;
  994|       |
  995|  1.91k|        msg->auth_request.method = SSH_AUTH_METHOD_PUBLICKEY;
  ------------------
  |  |  157|  1.91k|#define SSH_AUTH_METHOD_PUBLICKEY    0x0004u
  ------------------
  996|       |
  997|  1.91k|        rc = ssh_buffer_unpack(packet, "bSS", &has_sign, &algo, &pubkey_blob);
  ------------------
  |  |   60|  1.91k|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|  1.91k|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|  1.91k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|  1.91k|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|  1.91k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|  1.91k|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|  1.91k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  998|       |
  999|  1.91k|        if (rc != SSH_OK) {
  ------------------
  |  |  315|  1.91k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (999:13): [True: 163, False: 1.75k]
  ------------------
 1000|    163|            goto error;
 1001|    163|        }
 1002|       |
 1003|  1.75k|        cmp = strcmp(method, "publickey-hostbound-v00@openssh.com");
 1004|  1.75k|        if (cmp == 0) {
  ------------------
  |  Branch (1004:13): [True: 3, False: 1.74k]
  ------------------
 1005|      3|            server_pubkey_blob = ssh_buffer_get_ssh_string(packet);
 1006|      3|            if (server_pubkey_blob == NULL) {
  ------------------
  |  Branch (1006:17): [True: 0, False: 3]
  ------------------
 1007|      0|                SSH_STRING_FREE(pubkey_blob);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1008|      0|                SSH_STRING_FREE(algo);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1009|      0|                goto error;
 1010|      0|            }
 1011|       |
 1012|      3|            rc = ssh_pki_import_pubkey_blob(server_pubkey_blob,
 1013|      3|                                            &msg->auth_request.server_pubkey);
 1014|      3|            SSH_STRING_FREE(server_pubkey_blob);
  ------------------
  |  |  882|      3|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 3, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 3]
  |  |  ------------------
  ------------------
 1015|       |
 1016|      3|            if (rc < 0) {
  ------------------
  |  Branch (1016:17): [True: 3, False: 0]
  ------------------
 1017|      3|                SSH_STRING_FREE(pubkey_blob);
  ------------------
  |  |  882|      3|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 3, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 3]
  |  |  ------------------
  ------------------
 1018|      3|                SSH_STRING_FREE(algo);
  ------------------
  |  |  882|      3|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 3, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 3]
  |  |  ------------------
  ------------------
 1019|      3|                goto error;
 1020|      3|            }
 1021|      3|        }
 1022|       |
 1023|  1.74k|        rc = ssh_pki_import_pubkey_blob(pubkey_blob, &msg->auth_request.pubkey);
 1024|  1.74k|        SSH_STRING_FREE(pubkey_blob);
  ------------------
  |  |  882|  1.74k|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 1.74k, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 1.74k]
  |  |  ------------------
  ------------------
 1025|  1.74k|        pubkey_blob = NULL;
 1026|  1.74k|        if (rc < 0) {
  ------------------
  |  Branch (1026:13): [True: 573, False: 1.17k]
  ------------------
 1027|    573|            SSH_STRING_FREE(algo);
  ------------------
  |  |  882|    573|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 573, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 573]
  |  |  ------------------
  ------------------
 1028|    573|            algo = NULL;
 1029|    573|            goto error;
 1030|    573|        }
 1031|  1.17k|        msg->auth_request.signature_state = SSH_PUBLICKEY_STATE_NONE;
 1032|  1.17k|        msg->auth_request.sigtype = strdup(ssh_string_get_char(algo));
 1033|  1.17k|        if (msg->auth_request.sigtype == NULL) {
  ------------------
  |  Branch (1033:13): [True: 0, False: 1.17k]
  ------------------
 1034|      0|            msg->auth_request.signature_state = SSH_PUBLICKEY_STATE_ERROR;
 1035|      0|            SSH_STRING_FREE(algo);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1036|      0|            algo = NULL;
 1037|      0|            goto error;
 1038|      0|        }
 1039|       |
 1040|       |        // has a valid signature ?
 1041|  1.17k|        if (has_sign) {
  ------------------
  |  Branch (1041:13): [True: 1.17k, False: 1]
  ------------------
 1042|  1.17k|            ssh_string sig_blob = NULL;
 1043|  1.17k|            ssh_buffer digest = NULL;
 1044|       |
 1045|  1.17k|            sig_blob = ssh_buffer_get_ssh_string(packet);
 1046|  1.17k|            if (sig_blob == NULL) {
  ------------------
  |  Branch (1046:17): [True: 1.17k, False: 0]
  ------------------
 1047|  1.17k|                SSH_LOG(SSH_LOG_PACKET, "Invalid signature packet from peer");
  ------------------
  |  |  283|  1.17k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1048|  1.17k|                msg->auth_request.signature_state = SSH_PUBLICKEY_STATE_ERROR;
 1049|  1.17k|                SSH_STRING_FREE(algo);
  ------------------
  |  |  882|  1.17k|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 1.17k, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 1.17k]
  |  |  ------------------
  ------------------
 1050|  1.17k|                algo = NULL;
 1051|  1.17k|                goto error;
 1052|  1.17k|            }
 1053|       |
 1054|      0|            digest = ssh_msg_userauth_build_digest(session,
 1055|      0|                                                   msg,
 1056|      0|                                                   service,
 1057|      0|                                                   algo,
 1058|      0|                                                   method);
 1059|      0|            SSH_STRING_FREE(algo);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1060|      0|            algo = NULL;
 1061|      0|            if (digest == NULL) {
  ------------------
  |  Branch (1061:17): [True: 0, False: 0]
  ------------------
 1062|      0|                SSH_STRING_FREE(sig_blob);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1063|      0|                SSH_LOG(SSH_LOG_PACKET, "Failed to get digest");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1064|      0|                msg->auth_request.signature_state = SSH_PUBLICKEY_STATE_WRONG;
 1065|      0|                goto error;
 1066|      0|            }
 1067|       |
 1068|      0|            rc = ssh_pki_import_signature_blob(sig_blob,
 1069|      0|                                               msg->auth_request.pubkey,
 1070|      0|                                               &sig);
 1071|      0|            if (rc == SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1071:17): [True: 0, False: 0]
  ------------------
 1072|       |                /* Check if the signature from client matches server preferences
 1073|       |                 */
 1074|      0|                if (session->opts.pubkey_accepted_types) {
  ------------------
  |  Branch (1074:21): [True: 0, False: 0]
  ------------------
 1075|      0|                    cmp = match_group(session->opts.pubkey_accepted_types,
 1076|      0|                                      sig->type_c);
 1077|      0|                    if (cmp != 1) {
  ------------------
  |  Branch (1077:25): [True: 0, False: 0]
  ------------------
 1078|      0|                        ssh_set_error(
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1079|      0|                            session,
 1080|      0|                            SSH_FATAL,
 1081|      0|                            "Public key from client (%s) doesn't match server "
 1082|      0|                            "preference (%s)",
 1083|      0|                            sig->type_c,
 1084|      0|                            session->opts.pubkey_accepted_types);
 1085|      0|                        rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1086|      0|                    }
 1087|      0|                }
 1088|       |
 1089|      0|                if (rc == SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1089:21): [True: 0, False: 0]
  ------------------
 1090|      0|                    rc = ssh_pki_signature_verify(session,
 1091|      0|                                                  sig,
 1092|      0|                                                  msg->auth_request.pubkey,
 1093|      0|                                                  ssh_buffer_get(digest),
 1094|      0|                                                  ssh_buffer_get_len(digest));
 1095|      0|                }
 1096|      0|            }
 1097|      0|            SSH_STRING_FREE(sig_blob);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1098|      0|            SSH_BUFFER_FREE(digest);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1099|      0|            ssh_signature_free(sig);
 1100|      0|            if (rc < 0) {
  ------------------
  |  Branch (1100:17): [True: 0, False: 0]
  ------------------
 1101|      0|                SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1102|      0|                        "Received an invalid signature from peer");
 1103|      0|                msg->auth_request.signature_state = SSH_PUBLICKEY_STATE_WRONG;
 1104|      0|                goto error;
 1105|      0|            }
 1106|       |
 1107|      0|            SSH_LOG(SSH_LOG_PACKET, "Valid signature received");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1108|       |
 1109|      0|            cmp = strcmp(method, "publickey-hostbound-v00@openssh.com");
 1110|      0|            if (cmp == 0) {
  ------------------
  |  Branch (1110:17): [True: 0, False: 0]
  ------------------
 1111|      0|                ssh_key server_key = NULL;
 1112|       |
 1113|      0|                if (msg->auth_request.server_pubkey == NULL) {
  ------------------
  |  Branch (1113:21): [True: 0, False: 0]
  ------------------
 1114|      0|                    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1115|      0|                            "Server public key not provided by client");
 1116|      0|                    msg->auth_request.signature_state =
 1117|      0|                        SSH_PUBLICKEY_STATE_WRONG;
 1118|      0|                    goto error;
 1119|      0|                }
 1120|       |
 1121|      0|                rc = ssh_get_server_publickey(session, &server_key);
 1122|      0|                if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1122:21): [True: 0, False: 0]
  ------------------
 1123|      0|                    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1124|      0|                            "Failed to get server public key for hostbound "
 1125|      0|                            "verification");
 1126|      0|                    msg->auth_request.signature_state =
 1127|      0|                        SSH_PUBLICKEY_STATE_ERROR;
 1128|      0|                    ssh_key_free(server_key);
 1129|      0|                    goto error;
 1130|      0|                }
 1131|       |
 1132|      0|                if (ssh_key_cmp(server_key,
  ------------------
  |  Branch (1132:21): [True: 0, False: 0]
  ------------------
 1133|      0|                                msg->auth_request.server_pubkey,
 1134|      0|                                SSH_KEY_CMP_PUBLIC) != 0) {
 1135|      0|                    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1136|      0|                            "Server public key doesn't match the one provided "
 1137|      0|                            "by client");
 1138|      0|                    msg->auth_request.signature_state =
 1139|      0|                        SSH_PUBLICKEY_STATE_WRONG;
 1140|      0|                    ssh_key_free(server_key);
 1141|      0|                    goto error;
 1142|      0|                }
 1143|      0|                ssh_key_free(server_key);
 1144|      0|            }
 1145|       |
 1146|      0|            msg->auth_request.signature_state = SSH_PUBLICKEY_STATE_VALID;
 1147|      0|        }
 1148|       |
 1149|      1|        SAFE_FREE(method);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1150|      1|        SSH_STRING_FREE(algo);
  ------------------
  |  |  882|      1|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 1, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 1]
  |  |  ------------------
  ------------------
 1151|      1|        goto end;
 1152|  1.17k|    }
 1153|       |#ifdef WITH_GSSAPI
 1154|       |    if (strcmp(method, "gssapi-with-mic") == 0) {
 1155|       |        uint32_t n_oid;
 1156|       |        ssh_string *oids = NULL;
 1157|       |        ssh_string oid = NULL;
 1158|       |        char *hexa = NULL;
 1159|       |        int i;
 1160|       |        rc = ssh_buffer_get_u32(packet, &n_oid);
 1161|       |        if (rc != sizeof(uint32_t)) {
 1162|       |            ssh_set_error(session,
 1163|       |                          SSH_FATAL,
 1164|       |                          "USERAUTH_REQUEST: Failed to unpack OIDs");
 1165|       |            goto error;
 1166|       |        }
 1167|       |        n_oid = ntohl(n_oid);
 1168|       |        if (n_oid > 100) {
 1169|       |            ssh_set_error(
 1170|       |                session,
 1171|       |                SSH_FATAL,
 1172|       |                "USERAUTH_REQUEST: gssapi-with-mic OID count too big (%d)",
 1173|       |                n_oid);
 1174|       |            goto error;
 1175|       |        }
 1176|       |        SSH_LOG(SSH_LOG_PACKET, "gssapi: %d OIDs", n_oid);
 1177|       |        oids = calloc(n_oid, sizeof(ssh_string));
 1178|       |        if (oids == NULL) {
 1179|       |            ssh_set_error_oom(session);
 1180|       |            goto error;
 1181|       |        }
 1182|       |        for (i = 0; i < (int)n_oid; ++i) {
 1183|       |            oid = ssh_buffer_get_ssh_string(packet);
 1184|       |            if (oid == NULL) {
 1185|       |                for (i = i - 1; i >= 0; --i) {
 1186|       |                    SAFE_FREE(oids[i]);
 1187|       |                }
 1188|       |                SAFE_FREE(oids);
 1189|       |                ssh_set_error(session,
 1190|       |                              SSH_LOG_PACKET,
 1191|       |                              "USERAUTH_REQUEST: gssapi-with-mic missing OID");
 1192|       |                goto error;
 1193|       |            }
 1194|       |            oids[i] = oid;
 1195|       |            if (session->common.log_verbosity >= SSH_LOG_PACKET) {
 1196|       |                hexa = ssh_get_hexa(ssh_string_data(oid), ssh_string_len(oid));
 1197|       |                SSH_LOG(SSH_LOG_PACKET, "gssapi: OID %d: %s", i, hexa);
 1198|       |                SAFE_FREE(hexa);
 1199|       |            }
 1200|       |        }
 1201|       |        ssh_gssapi_handle_userauth(session,
 1202|       |                                   msg->auth_request.username,
 1203|       |                                   n_oid,
 1204|       |                                   oids);
 1205|       |
 1206|       |        for (i = 0; i < (int)n_oid; ++i) {
 1207|       |            SAFE_FREE(oids[i]);
 1208|       |        }
 1209|       |        SAFE_FREE(oids);
 1210|       |        /* bypass the message queue thing */
 1211|       |        SAFE_FREE(service);
 1212|       |        SAFE_FREE(method);
 1213|       |        SSH_MESSAGE_FREE(msg);
 1214|       |
 1215|       |        return SSH_PACKET_USED;
 1216|       |    }
 1217|       |    if (strcmp(method, "gssapi-keyex") == 0) {
 1218|       |        gss_buffer_desc received_mic = GSS_C_EMPTY_BUFFER;
 1219|       |        gss_buffer_desc mic_buf = GSS_C_EMPTY_BUFFER;
 1220|       |        ssh_string mic_token_string = NULL;
 1221|       |        OM_uint32 maj_stat, min_stat;
 1222|       |        ssh_buffer buf = NULL;
 1223|       |        ssh_server_callbacks callbacks = session->server_callbacks;
 1224|       |
 1225|       |        if (!ssh_session_kex_is_gss(session)) {
 1226|       |            ssh_set_error(session,
 1227|       |                          SSH_FATAL,
 1228|       |                          "Attempt to authenticate with gssapi-keyex without "
 1229|       |                          "doing GSSAPI Key Exchange.");
 1230|       |            ssh_auth_reply_default(session, 0);
 1231|       |            goto error;
 1232|       |        }
 1233|       |
 1234|       |        if (session->gssapi == NULL || session->gssapi->ctx == NULL) {
 1235|       |            ssh_set_error(session, SSH_FATAL, "GSSAPI context not initialized");
 1236|       |            ssh_auth_reply_default(session, 0);
 1237|       |            goto error;
 1238|       |        }
 1239|       |
 1240|       |        rc = ssh_buffer_unpack(packet, "S", &mic_token_string);
 1241|       |        if (rc != SSH_OK) {
 1242|       |            ssh_auth_reply_default(session, 0);
 1243|       |            goto error;
 1244|       |        }
 1245|       |        received_mic.length = ssh_string_len(mic_token_string);
 1246|       |        received_mic.value = ssh_string_data(mic_token_string);
 1247|       |
 1248|       |        SAFE_FREE(session->gssapi->user);
 1249|       |        session->gssapi->user = strdup(msg->auth_request.username);
 1250|       |        buf = ssh_gssapi_build_mic(session, "gssapi-keyex");
 1251|       |        if (buf == NULL) {
 1252|       |            ssh_set_error_oom(session);
 1253|       |            SSH_STRING_FREE(mic_token_string);
 1254|       |            ssh_auth_reply_default(session, 0);
 1255|       |            goto error;
 1256|       |        }
 1257|       |
 1258|       |        mic_buf.length = ssh_buffer_get_len(buf);
 1259|       |        mic_buf.value = ssh_buffer_get(buf);
 1260|       |
 1261|       |        maj_stat = gss_verify_mic(&min_stat,
 1262|       |                                  session->gssapi->ctx,
 1263|       |                                  &mic_buf,
 1264|       |                                  &received_mic,
 1265|       |                                  NULL);
 1266|       |        if (maj_stat != GSS_S_COMPLETE) {
 1267|       |            ssh_set_error(session,
 1268|       |                          SSH_FATAL,
 1269|       |                          "Failed to verify MIC for gssapi-keyex auth");
 1270|       |            SSH_BUFFER_FREE(buf);
 1271|       |            SSH_STRING_FREE(mic_token_string);
 1272|       |            ssh_auth_reply_default(session, 0);
 1273|       |            goto error;
 1274|       |        }
 1275|       |
 1276|       |        if (ssh_callbacks_exists(callbacks, auth_gssapi_mic_function)) {
 1277|       |            rc = callbacks->auth_gssapi_mic_function(session,
 1278|       |                                                     session->gssapi->user,
 1279|       |                                                     session->gssapi->canonic_user,
 1280|       |                                                     callbacks->userdata);
 1281|       |            switch (rc) {
 1282|       |            case SSH_AUTH_SUCCESS:
 1283|       |                ssh_auth_reply_success(session, 0);
 1284|       |                break;
 1285|       |            case SSH_AUTH_PARTIAL:
 1286|       |                ssh_auth_reply_success(session, 1);
 1287|       |                break;
 1288|       |            default:
 1289|       |                ssh_auth_reply_default(session, 0);
 1290|       |                break;
 1291|       |            }
 1292|       |        }
 1293|       |
 1294|       |        /* bypass the message queue thing */
 1295|       |        SAFE_FREE(service);
 1296|       |        SAFE_FREE(method);
 1297|       |        SSH_BUFFER_FREE(buf);
 1298|       |        SSH_MESSAGE_FREE(msg);
 1299|       |        SSH_STRING_FREE(mic_token_string);
 1300|       |
 1301|       |        return SSH_PACKET_USED;
 1302|       |    }
 1303|       |#endif
 1304|       |
 1305|    239|    msg->auth_request.method = SSH_AUTH_METHOD_UNKNOWN;
  ------------------
  |  |  154|    239|#define SSH_AUTH_METHOD_UNKNOWN      0x0000u
  ------------------
 1306|    239|    SAFE_FREE(method);
  ------------------
  |  |  375|    239|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 239, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 239]
  |  |  ------------------
  ------------------
 1307|    239|    goto end;
 1308|  4.86k|error:
 1309|  4.86k|    SAFE_FREE(service);
  ------------------
  |  |  375|  4.86k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 1.91k, False: 2.95k]
  |  |  |  Branch (375:71): [Folded, False: 4.86k]
  |  |  ------------------
  ------------------
 1310|  4.86k|    SAFE_FREE(method);
  ------------------
  |  |  375|  4.86k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 1.91k, False: 2.95k]
  |  |  |  Branch (375:71): [Folded, False: 4.86k]
  |  |  ------------------
  ------------------
 1311|       |
 1312|  4.86k|    SSH_MESSAGE_FREE(msg);
  ------------------
  |  |  685|  4.86k|    do { if ((x) != NULL) { ssh_message_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (685:14): [True: 4.86k, False: 0]
  |  |  |  Branch (685:72): [Folded, False: 4.86k]
  |  |  ------------------
  ------------------
 1313|       |
 1314|  4.86k|    return SSH_PACKET_USED;
  ------------------
  |  |  638|  4.86k|#define SSH_PACKET_USED 1
  ------------------
 1315|    399|end:
 1316|    399|    SAFE_FREE(service);
  ------------------
  |  |  375|    399|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 399, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 399]
  |  |  ------------------
  ------------------
 1317|    399|    SAFE_FREE(method);
  ------------------
  |  |  375|    399|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 159, False: 240]
  |  |  |  Branch (375:71): [Folded, False: 399]
  |  |  ------------------
  ------------------
 1318|       |
 1319|    399|    ssh_message_queue(session, msg);
 1320|       |
 1321|    399|    return SSH_PACKET_USED;
  ------------------
  |  |  638|    399|#define SSH_PACKET_USED 1
  ------------------
 1322|  2.15k|}
ssh_packet_channel_open:
 1471|     48|{
 1472|     48|    ssh_message msg = NULL;
 1473|     48|    char *type_c = NULL;
 1474|     48|    uint32_t originator_port, destination_port;
 1475|     48|    int rc;
 1476|       |
 1477|     48|    (void)type;
 1478|     48|    (void)user;
 1479|       |
 1480|     48|    msg = ssh_message_new(session);
 1481|     48|    if (msg == NULL) {
  ------------------
  |  Branch (1481:9): [True: 0, False: 48]
  ------------------
 1482|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1483|      0|        goto error;
 1484|      0|    }
 1485|       |
 1486|     48|    msg->type = SSH_REQUEST_CHANNEL_OPEN;
 1487|     48|    rc = ssh_buffer_unpack(packet, "s", &type_c);
  ------------------
  |  |   60|     48|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|     48|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|     48|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|     48|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|     48|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|     48|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     48|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1488|     48|    if (rc != SSH_OK) {
  ------------------
  |  |  315|     48|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1488:9): [True: 2, False: 46]
  ------------------
 1489|      2|        goto error;
 1490|      2|    }
 1491|       |
 1492|     46|    SSH_LOG(SSH_LOG_PACKET, "Clients wants to open a %s channel", type_c);
  ------------------
  |  |  283|     46|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1493|       |
 1494|     46|    rc = ssh_buffer_unpack(packet,
  ------------------
  |  |   60|     46|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|     46|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|     46|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|     46|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|     46|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|     46|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     46|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1495|     46|                           "ddd",
 1496|     46|                           &msg->channel_request_open.sender,
 1497|     46|                           &msg->channel_request_open.window,
 1498|     46|                           &msg->channel_request_open.packet_size);
 1499|     46|    if (rc != SSH_OK) {
  ------------------
  |  |  315|     46|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1499:9): [True: 0, False: 46]
  ------------------
 1500|      0|        goto error;
 1501|      0|    }
 1502|       |
 1503|     46|    if (msg->channel_request_open.packet_size == 0) {
  ------------------
  |  Branch (1503:9): [True: 3, False: 43]
  ------------------
 1504|      3|        ssh_set_error(session,
  ------------------
  |  |  313|      3|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1505|      3|                      SSH_FATAL,
 1506|      3|                      "Invalid maximum packet size 0 in SSH2_MSG_CHANNEL_OPEN");
 1507|      3|        goto error;
 1508|      3|    }
 1509|       |
 1510|     43|    if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1510:9): [True: 0, False: 43]
  ------------------
 1511|      0|        ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1512|      0|                      SSH_FATAL,
 1513|      0|                      "Invalid state when receiving channel open request "
 1514|      0|                      "(must be authenticated)");
 1515|      0|        goto error;
 1516|      0|    }
 1517|       |
 1518|     43|    if (strcmp(type_c, "session") == 0) {
  ------------------
  |  Branch (1518:9): [True: 17, False: 26]
  ------------------
 1519|     17|        if (session->flags & SSH_SESSION_FLAG_NO_MORE_SESSIONS) {
  ------------------
  |  |   81|     17|#define SSH_SESSION_FLAG_NO_MORE_SESSIONS 0x0004
  ------------------
  |  Branch (1519:13): [True: 0, False: 17]
  ------------------
 1520|      0|            ssh_session_set_disconnect_message(session,
 1521|      0|                                               "No more sessions allowed!");
 1522|      0|            ssh_set_error(session, SSH_FATAL, "No more sessions allowed!");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1523|      0|            session->session_state = SSH_SESSION_STATE_ERROR;
 1524|      0|            ssh_send_disconnect(session);
 1525|      0|            goto error;
 1526|      0|        }
 1527|       |
 1528|     17|        msg->channel_request_open.type = SSH_CHANNEL_SESSION;
 1529|     17|        SAFE_FREE(type_c);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1530|     17|        goto end;
 1531|     17|    }
 1532|       |
 1533|     26|    if (strcmp(type_c, "direct-tcpip") == 0) {
  ------------------
  |  Branch (1533:9): [True: 2, False: 24]
  ------------------
 1534|      2|        rc = ssh_buffer_unpack(packet,
  ------------------
  |  |   60|      2|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      2|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      2|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      2|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      2|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      2|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      2|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1535|      2|                               "sdsd",
 1536|      2|                               &msg->channel_request_open.destination,
 1537|      2|                               &destination_port,
 1538|      2|                               &msg->channel_request_open.originator,
 1539|      2|                               &originator_port);
 1540|      2|        if (rc != SSH_OK) {
  ------------------
  |  |  315|      2|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1540:13): [True: 1, False: 1]
  ------------------
 1541|      1|            goto error;
 1542|      1|        }
 1543|       |
 1544|      1|        msg->channel_request_open.destination_port = (uint16_t)destination_port;
 1545|      1|        msg->channel_request_open.originator_port = (uint16_t)originator_port;
 1546|      1|        msg->channel_request_open.type = SSH_CHANNEL_DIRECT_TCPIP;
 1547|      1|        goto end;
 1548|      2|    }
 1549|       |
 1550|     24|    if (strcmp(type_c, "forwarded-tcpip") == 0) {
  ------------------
  |  Branch (1550:9): [True: 0, False: 24]
  ------------------
 1551|      0|        rc = ssh_buffer_unpack(packet,
  ------------------
  |  |   60|      0|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1552|      0|                               "sdsd",
 1553|      0|                               &msg->channel_request_open.destination,
 1554|      0|                               &destination_port,
 1555|      0|                               &msg->channel_request_open.originator,
 1556|      0|                               &originator_port);
 1557|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1557:13): [True: 0, False: 0]
  ------------------
 1558|      0|            goto error;
 1559|      0|        }
 1560|      0|        msg->channel_request_open.destination_port = (uint16_t)destination_port;
 1561|      0|        msg->channel_request_open.originator_port = (uint16_t)originator_port;
 1562|      0|        msg->channel_request_open.type = SSH_CHANNEL_FORWARDED_TCPIP;
 1563|      0|        goto end;
 1564|      0|    }
 1565|       |
 1566|     24|    if (strcmp(type_c, "x11") == 0) {
  ------------------
  |  Branch (1566:9): [True: 0, False: 24]
  ------------------
 1567|      0|        rc = ssh_buffer_unpack(packet,
  ------------------
  |  |   60|      0|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1568|      0|                               "sd",
 1569|      0|                               &msg->channel_request_open.originator,
 1570|      0|                               &originator_port);
 1571|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1571:13): [True: 0, False: 0]
  ------------------
 1572|      0|            goto error;
 1573|      0|        }
 1574|      0|        msg->channel_request_open.originator_port = (uint16_t)originator_port;
 1575|      0|        msg->channel_request_open.type = SSH_CHANNEL_X11;
 1576|      0|        goto end;
 1577|      0|    }
 1578|       |
 1579|     24|    if (strcmp(type_c, "auth-agent") == 0 ||
  ------------------
  |  Branch (1579:9): [True: 0, False: 24]
  ------------------
 1580|     24|        strcmp(type_c, "auth-agent@openssh.com") == 0) {
  ------------------
  |  Branch (1580:9): [True: 0, False: 24]
  ------------------
 1581|      0|        msg->channel_request_open.type = SSH_CHANNEL_AUTH_AGENT;
 1582|      0|        goto end;
 1583|      0|    }
 1584|       |
 1585|     24|    msg->channel_request_open.type = SSH_CHANNEL_UNKNOWN;
 1586|     24|    goto end;
 1587|       |
 1588|      6|error:
 1589|      6|    SSH_MESSAGE_FREE(msg);
  ------------------
  |  |  685|      6|    do { if ((x) != NULL) { ssh_message_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (685:14): [True: 6, False: 0]
  |  |  |  Branch (685:72): [Folded, False: 6]
  |  |  ------------------
  ------------------
 1590|       |
 1591|     48|end:
 1592|     48|    SAFE_FREE(type_c);
  ------------------
  |  |  375|     48|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 29, False: 19]
  |  |  |  Branch (375:71): [Folded, False: 48]
  |  |  ------------------
  ------------------
 1593|     48|    if (msg != NULL)
  ------------------
  |  Branch (1593:9): [True: 42, False: 6]
  ------------------
 1594|     42|        ssh_message_queue(session, msg);
 1595|       |
 1596|     48|    return SSH_PACKET_USED;
  ------------------
  |  |  638|     48|#define SSH_PACKET_USED 1
  ------------------
 1597|      6|}
ssh_message_channel_request_open_reply_accept_channel:
 1612|     17|{
 1613|     17|    ssh_session session = NULL;
 1614|     17|    int rc;
 1615|       |
 1616|     17|    if (msg == NULL) {
  ------------------
  |  Branch (1616:9): [True: 0, False: 17]
  ------------------
 1617|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1618|      0|    }
 1619|       |
 1620|     17|    session = msg->session;
 1621|       |
 1622|     17|    chan->local_channel = ssh_channel_new_id(session);
 1623|     17|    chan->local_maxpacket = 35000;
 1624|     17|    chan->local_window = 32000;
 1625|     17|    chan->remote_channel = msg->channel_request_open.sender;
 1626|     17|    chan->remote_maxpacket = msg->channel_request_open.packet_size;
 1627|     17|    chan->remote_window = msg->channel_request_open.window;
 1628|     17|    chan->state = SSH_CHANNEL_STATE_OPEN;
 1629|     17|    chan->flags &= ~SSH_CHANNEL_FLAG_NOT_BOUND;
  ------------------
  |  |   64|     17|#define SSH_CHANNEL_FLAG_NOT_BOUND 0x0008
  ------------------
 1630|       |
 1631|     17|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|     17|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|     17|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|     17|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|     17|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|     17|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|     17|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     17|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1632|     17|                         "bdddd",
 1633|     17|                         SSH2_MSG_CHANNEL_OPEN_CONFIRMATION,
 1634|     17|                         chan->remote_channel,
 1635|     17|                         chan->local_channel,
 1636|     17|                         chan->local_window,
 1637|     17|                         chan->local_maxpacket);
 1638|     17|    if (rc != SSH_OK) {
  ------------------
  |  |  315|     17|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1638:9): [True: 0, False: 17]
  ------------------
 1639|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1640|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1641|      0|    }
 1642|       |
 1643|     17|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|     17|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1644|     17|            "Accepting a channel request_open for chan %" PRIu32,
 1645|     17|            chan->remote_channel);
 1646|       |
 1647|     17|    rc = ssh_packet_send(session);
 1648|       |
 1649|     17|    return rc;
 1650|     17|}
ssh_packet_global_request:
 1868|      2|{
 1869|      2|    ssh_message msg = NULL;
 1870|      2|    char *request = NULL;
 1871|      2|    uint8_t want_reply;
 1872|      2|    uint32_t bind_port = 0;
 1873|      2|    int rc = SSH_PACKET_USED;
  ------------------
  |  |  638|      2|#define SSH_PACKET_USED 1
  ------------------
 1874|      2|    int r;
 1875|       |
 1876|      2|    (void)user;
 1877|      2|    (void)type;
 1878|      2|    (void)packet;
 1879|       |
 1880|      2|    SSH_LOG(SSH_LOG_DEBUG,"Received SSH_MSG_GLOBAL_REQUEST packet");
  ------------------
  |  |  283|      2|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1881|      2|    r = ssh_buffer_unpack(packet, "sb", &request, &want_reply);
  ------------------
  |  |   60|      2|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      2|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      2|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      2|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      2|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      2|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      2|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1882|      2|    if (r != SSH_OK) {
  ------------------
  |  |  315|      2|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1882:9): [True: 2, False: 0]
  ------------------
 1883|      2|        goto error;
 1884|      2|    }
 1885|       |
 1886|      0|    msg = ssh_message_new(session);
 1887|      0|    if (msg == NULL) {
  ------------------
  |  Branch (1887:9): [True: 0, False: 0]
  ------------------
 1888|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1889|      0|        goto error;
 1890|      0|    }
 1891|      0|    msg->type = SSH_REQUEST_GLOBAL;
 1892|       |
 1893|      0|    if (strcmp(request, "tcpip-forward") == 0) {
  ------------------
  |  Branch (1893:9): [True: 0, False: 0]
  ------------------
 1894|       |
 1895|       |        /* According to RFC4254, the client SHOULD reject this message */
 1896|      0|        if (session->client) {
  ------------------
  |  Branch (1896:13): [True: 0, False: 0]
  ------------------
 1897|      0|            goto reply_with_failure;
 1898|      0|        }
 1899|       |
 1900|      0|        r = ssh_buffer_unpack(packet,
  ------------------
  |  |   60|      0|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1901|      0|                              "sd",
 1902|      0|                              &msg->global_request.bind_address,
 1903|      0|                              &bind_port);
 1904|      0|        if (r != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1904:13): [True: 0, False: 0]
  ------------------
 1905|      0|            goto reply_with_failure;
 1906|      0|        }
 1907|      0|        msg->global_request.bind_port = (uint16_t)bind_port;
 1908|      0|        msg->global_request.type = SSH_GLOBAL_REQUEST_TCPIP_FORWARD;
 1909|      0|        msg->global_request.want_reply = want_reply;
 1910|       |
 1911|      0|        SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1912|      0|                "Received SSH_MSG_GLOBAL_REQUEST %s %hhu %s:%d",
 1913|      0|                request,
 1914|      0|                want_reply,
 1915|      0|                msg->global_request.bind_address,
 1916|      0|                msg->global_request.bind_port);
 1917|       |
 1918|      0|        if (ssh_callbacks_exists(session->common.callbacks,
  ------------------
  |  |  548|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  549|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  ------------------
  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  Branch (549:18): [True: 0, False: 0]
  |  |  ------------------
  |  |  550|      0|  ((p)-> c != NULL) \
  |  |  ------------------
  |  |  |  Branch (550:3): [True: 0, False: 0]
  |  |  ------------------
  |  |  551|      0|  )
  ------------------
 1919|      0|                                 global_request_function)) {
 1920|      0|            SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1921|      0|                    "Calling callback for SSH_MSG_GLOBAL_REQUEST %s %hhu %s:%d",
 1922|      0|                    request,
 1923|      0|                    want_reply,
 1924|      0|                    msg->global_request.bind_address,
 1925|      0|                    msg->global_request.bind_port);
 1926|      0|            session->common.callbacks->global_request_function(
 1927|      0|                session,
 1928|      0|                msg,
 1929|      0|                session->common.callbacks->userdata);
 1930|      0|        } else {
 1931|      0|            SAFE_FREE(request);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1932|      0|            ssh_message_queue(session, msg);
 1933|      0|            return rc;
 1934|      0|        }
 1935|      0|    } else if (strcmp(request, "cancel-tcpip-forward") == 0) {
  ------------------
  |  Branch (1935:16): [True: 0, False: 0]
  ------------------
 1936|       |
 1937|       |        /* According to RFC4254, the client SHOULD reject this message */
 1938|      0|        if (session->client) {
  ------------------
  |  Branch (1938:13): [True: 0, False: 0]
  ------------------
 1939|      0|            goto reply_with_failure;
 1940|      0|        }
 1941|       |
 1942|      0|        r = ssh_buffer_unpack(packet,
  ------------------
  |  |   60|      0|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1943|      0|                              "sd",
 1944|      0|                              &msg->global_request.bind_address,
 1945|      0|                              &bind_port);
 1946|      0|        if (r != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1946:13): [True: 0, False: 0]
  ------------------
 1947|      0|            goto reply_with_failure;
 1948|      0|        }
 1949|      0|        msg->global_request.bind_port = (uint16_t)bind_port;
 1950|      0|        msg->global_request.type = SSH_GLOBAL_REQUEST_CANCEL_TCPIP_FORWARD;
 1951|      0|        msg->global_request.want_reply = want_reply;
 1952|       |
 1953|      0|        SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1954|      0|                "Received SSH_MSG_GLOBAL_REQUEST %s %hhu %s:%d",
 1955|      0|                request,
 1956|      0|                want_reply,
 1957|      0|                msg->global_request.bind_address,
 1958|      0|                msg->global_request.bind_port);
 1959|       |
 1960|      0|        if (ssh_callbacks_exists(session->common.callbacks,
  ------------------
  |  |  548|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  549|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  ------------------
  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  Branch (549:18): [True: 0, False: 0]
  |  |  ------------------
  |  |  550|      0|  ((p)-> c != NULL) \
  |  |  ------------------
  |  |  |  Branch (550:3): [True: 0, False: 0]
  |  |  ------------------
  |  |  551|      0|  )
  ------------------
 1961|      0|                                 global_request_function)) {
 1962|      0|            session->common.callbacks->global_request_function(
 1963|      0|                session,
 1964|      0|                msg,
 1965|      0|                session->common.callbacks->userdata);
 1966|      0|        } else {
 1967|      0|            SAFE_FREE(request);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1968|      0|            ssh_message_queue(session, msg);
 1969|      0|            return rc;
 1970|      0|        }
 1971|      0|    } else if(strcmp(request, "keepalive@openssh.com") == 0) {
  ------------------
  |  Branch (1971:15): [True: 0, False: 0]
  ------------------
 1972|      0|        msg->global_request.type = SSH_GLOBAL_REQUEST_KEEPALIVE;
 1973|      0|        msg->global_request.want_reply = want_reply;
 1974|      0|        SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1975|      0|                "Received keepalive@openssh.com %hhu",
 1976|      0|                want_reply);
 1977|      0|        if (ssh_callbacks_exists(session->common.callbacks,
  ------------------
  |  |  548|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  549|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  ------------------
  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  Branch (549:18): [True: 0, False: 0]
  |  |  ------------------
  |  |  550|      0|  ((p)-> c != NULL) \
  |  |  ------------------
  |  |  |  Branch (550:3): [True: 0, False: 0]
  |  |  ------------------
  |  |  551|      0|  )
  ------------------
 1978|      0|                                 global_request_function)) {
 1979|      0|            SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1980|      0|                    "Calling callback for SSH_MSG_GLOBAL_REQUEST %s %hhu",
 1981|      0|                    request,
 1982|      0|                    want_reply);
 1983|      0|            session->common.callbacks->global_request_function(
 1984|      0|                session,
 1985|      0|                msg,
 1986|      0|                session->common.callbacks->userdata);
 1987|      0|        } else if (want_reply) {
  ------------------
  |  Branch (1987:20): [True: 0, False: 0]
  ------------------
 1988|      0|            ssh_message_global_request_reply_success(msg, 0);
 1989|      0|        }
 1990|      0|    } else if (strcmp(request, "no-more-sessions@openssh.com") == 0) {
  ------------------
  |  Branch (1990:16): [True: 0, False: 0]
  ------------------
 1991|      0|        msg->global_request.type = SSH_GLOBAL_REQUEST_NO_MORE_SESSIONS;
 1992|      0|        msg->global_request.want_reply = want_reply;
 1993|       |
 1994|      0|        SSH_LOG(SSH_LOG_PROTOCOL,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1995|      0|                "Received no-more-sessions@openssh.com %hhu",
 1996|      0|                want_reply);
 1997|      0|        if (ssh_callbacks_exists(session->common.callbacks,
  ------------------
  |  |  548|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  549|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  ------------------
  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  Branch (549:18): [True: 0, False: 0]
  |  |  ------------------
  |  |  550|      0|  ((p)-> c != NULL) \
  |  |  ------------------
  |  |  |  Branch (550:3): [True: 0, False: 0]
  |  |  ------------------
  |  |  551|      0|  )
  ------------------
 1998|      0|                                 global_request_function)) {
 1999|      0|            SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2000|      0|                    "Calling callback for SSH_MSG_GLOBAL_REQUEST %s %hhu",
 2001|      0|                    request,
 2002|      0|                    want_reply);
 2003|      0|            session->common.callbacks->global_request_function(
 2004|      0|                session,
 2005|      0|                msg,
 2006|      0|                session->common.callbacks->userdata);
 2007|      0|        } else if (want_reply) {
  ------------------
  |  Branch (2007:20): [True: 0, False: 0]
  ------------------
 2008|      0|            ssh_message_global_request_reply_success(msg, 0);
 2009|      0|        }
 2010|       |
 2011|      0|        session->flags |= SSH_SESSION_FLAG_NO_MORE_SESSIONS;
  ------------------
  |  |   81|      0|#define SSH_SESSION_FLAG_NO_MORE_SESSIONS 0x0004
  ------------------
 2012|      0|    } else {
 2013|      0|        SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2014|      0|                "UNKNOWN SSH_MSG_GLOBAL_REQUEST %s, want_reply = %hhu",
 2015|      0|                request,
 2016|      0|                want_reply);
 2017|      0|        goto reply_with_failure;
 2018|      0|    }
 2019|       |
 2020|      0|    SSH_MESSAGE_FREE(msg);
  ------------------
  |  |  685|      0|    do { if ((x) != NULL) { ssh_message_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (685:14): [True: 0, False: 0]
  |  |  |  Branch (685:72): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2021|      0|    SAFE_FREE(request);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 2022|      0|    return rc;
 2023|       |
 2024|      0|reply_with_failure:
 2025|       |    /* Only report the failure if requested */
 2026|      0|    if (want_reply) {
  ------------------
  |  Branch (2026:9): [True: 0, False: 0]
  ------------------
 2027|      0|        r = ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_REQUEST_FAILURE);
  ------------------
  |  |   53|      0|#define SSH2_MSG_REQUEST_FAILURE 82
  ------------------
 2028|      0|        if (r < 0) {
  ------------------
  |  Branch (2028:13): [True: 0, False: 0]
  ------------------
 2029|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2030|      0|            goto error;
 2031|      0|        }
 2032|       |
 2033|      0|        r = ssh_packet_send(session);
 2034|      0|        if (r != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2034:13): [True: 0, False: 0]
  ------------------
 2035|      0|            goto error;
 2036|      0|        }
 2037|      0|    } else {
 2038|      0|        SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2039|      0|                "The requester doesn't want to know the request failed!");
 2040|      0|    }
 2041|       |
 2042|       |    /* Consume the message to avoid sending UNIMPLEMENTED later */
 2043|      0|    rc = SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
 2044|      2|error:
 2045|      2|    SSH_MESSAGE_FREE(msg);
  ------------------
  |  |  685|      2|    do { if ((x) != NULL) { ssh_message_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (685:14): [True: 0, False: 2]
  |  |  |  Branch (685:72): [Folded, False: 2]
  |  |  ------------------
  ------------------
 2046|      2|    SAFE_FREE(request);
  ------------------
  |  |  375|      2|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 2]
  |  |  |  Branch (375:71): [Folded, False: 2]
  |  |  ------------------
  ------------------
 2047|      2|    SSH_LOG(SSH_LOG_TRACE, "Invalid SSH_MSG_GLOBAL_REQUEST packet");
  ------------------
  |  |  283|      2|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2048|      2|    return rc;
 2049|      0|}
messages.c:ssh_message_new:
   67|  5.31k|{
   68|  5.31k|    ssh_message msg = calloc(1, sizeof(struct ssh_message_struct));
   69|  5.31k|    if (msg == NULL) {
  ------------------
  |  Branch (69:9): [True: 0, False: 5.31k]
  ------------------
   70|      0|        return NULL;
   71|      0|    }
   72|  5.31k|    msg->session = session;
   73|       |
   74|       |    /* Set states explicitly */
   75|  5.31k|    msg->auth_request.signature_state = SSH_PUBLICKEY_STATE_NONE;
   76|       |
   77|  5.31k|    return msg;
   78|  5.31k|}
messages.c:ssh_message_queue:
  539|    442|{
  540|    442|#ifdef WITH_SERVER
  541|    442|    int ret;
  542|    442|#endif
  543|       |
  544|    442|    if (message == NULL) {
  ------------------
  |  Branch (544:9): [True: 0, False: 442]
  ------------------
  545|      0|        return;
  546|      0|    }
  547|       |
  548|    442|#ifdef WITH_SERVER
  549|       |    /* probably not the best place to execute server callbacks, but still better
  550|       |     * than nothing.
  551|       |     */
  552|    442|    ret = ssh_execute_server_callbacks(session, message);
  553|    442|    if (ret == SSH_OK) {
  ------------------
  |  |  315|    442|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (553:9): [True: 86, False: 356]
  ------------------
  554|     86|        SSH_MESSAGE_FREE(message);
  ------------------
  |  |  685|     86|    do { if ((x) != NULL) { ssh_message_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (685:14): [True: 86, False: 0]
  |  |  |  Branch (685:72): [Folded, False: 86]
  |  |  ------------------
  ------------------
  555|     86|        return;
  556|     86|    }
  557|    356|#endif /* WITH_SERVER */
  558|       |
  559|    356|    if (session->ssh_message_callback != NULL) {
  ------------------
  |  Branch (559:9): [True: 0, False: 356]
  ------------------
  560|       |        /* This will transfer the message, do not free. */
  561|      0|        ssh_execute_message_callback(session, message);
  562|      0|        return;
  563|      0|    }
  564|       |
  565|    356|    if (session->server_callbacks != NULL) {
  ------------------
  |  Branch (565:9): [True: 356, False: 0]
  ------------------
  566|       |        /* if we have server callbacks, but nothing was executed, it means we are
  567|       |         * in non-synchronous mode, and we just don't care about the message we
  568|       |         * received. Just send a default response. Do not queue it.
  569|       |         */
  570|    356|        ssh_message_reply_default(message);
  571|    356|        SSH_MESSAGE_FREE(message);
  ------------------
  |  |  685|    356|    do { if ((x) != NULL) { ssh_message_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (685:14): [True: 356, False: 0]
  |  |  |  Branch (685:72): [Folded, False: 356]
  |  |  ------------------
  ------------------
  572|    356|        return;
  573|    356|    }
  574|       |
  575|      0|    if (session->ssh_message_list == NULL) {
  ------------------
  |  Branch (575:9): [True: 0, False: 0]
  ------------------
  576|      0|        session->ssh_message_list = ssh_list_new();
  577|      0|        if (session->ssh_message_list == NULL) {
  ------------------
  |  Branch (577:13): [True: 0, False: 0]
  ------------------
  578|       |            /*
  579|       |             * If the message list couldn't be allocated, the message can't be
  580|       |             * enqueued
  581|       |             */
  582|      0|            ssh_message_reply_default(message);
  583|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  584|      0|            SSH_MESSAGE_FREE(message);
  ------------------
  |  |  685|      0|    do { if ((x) != NULL) { ssh_message_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (685:14): [True: 0, False: 0]
  |  |  |  Branch (685:72): [Folded, False: 0]
  |  |  ------------------
  ------------------
  585|      0|            return;
  586|      0|        }
  587|      0|    }
  588|       |
  589|       |    /* This will transfer the message, do not free. */
  590|      0|    ssh_list_append(session->ssh_message_list, message);
  591|      0|    return;
  592|      0|}
messages.c:ssh_execute_server_callbacks:
  486|    442|{
  487|    442|    int rc = SSH_AGAIN;
  ------------------
  |  |  317|    442|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  488|       |
  489|    442|    if (session->server_callbacks != NULL) {
  ------------------
  |  Branch (489:9): [True: 442, False: 0]
  ------------------
  490|    442|        rc = ssh_execute_server_request(session, msg);
  491|    442|    } else if (session->common.callbacks != NULL) {
  ------------------
  |  Branch (491:16): [True: 0, False: 0]
  ------------------
  492|       |        /* This one is in fact a client callback... */
  493|      0|        rc = ssh_execute_client_request(session, msg);
  494|      0|    }
  495|       |
  496|    442|    return rc;
  497|    442|}
messages.c:ssh_execute_server_request:
  146|    442|{
  147|    442|    ssh_channel channel = NULL;
  148|    442|    int rc;
  149|       |
  150|    442|    switch (msg->type) {
  ------------------
  |  Branch (150:13): [True: 442, False: 0]
  ------------------
  151|    399|    case SSH_REQUEST_AUTH:
  ------------------
  |  Branch (151:5): [True: 399, False: 43]
  ------------------
  152|    399|        if (msg->auth_request.method == SSH_AUTH_METHOD_PASSWORD &&
  ------------------
  |  |  156|    798|#define SSH_AUTH_METHOD_PASSWORD     0x0002u
  ------------------
  |  Branch (152:13): [True: 1, False: 398]
  ------------------
  153|      1|            ssh_callbacks_exists(session->server_callbacks,
  ------------------
  |  |  548|      1|#define ssh_callbacks_exists(p,c) (\
  |  |  549|      1|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  ------------------
  |  |  |  Branch (549:3): [True: 1, False: 0]
  |  |  |  Branch (549:18): [True: 1, False: 0]
  |  |  ------------------
  |  |  550|      1|  ((p)-> c != NULL) \
  |  |  ------------------
  |  |  |  Branch (550:3): [True: 0, False: 1]
  |  |  ------------------
  |  |  551|      1|  )
  ------------------
  154|    399|                                 auth_password_function)) {
  155|      0|            rc = session->server_callbacks->auth_password_function(
  156|      0|                session,
  157|      0|                msg->auth_request.username,
  158|      0|                msg->auth_request.password,
  159|      0|                session->server_callbacks->userdata);
  160|      0|            if (rc == SSH_AUTH_SUCCESS || rc == SSH_AUTH_PARTIAL) {
  ------------------
  |  Branch (160:17): [True: 0, False: 0]
  |  Branch (160:43): [True: 0, False: 0]
  ------------------
  161|      0|                ssh_message_auth_reply_success(msg, rc == SSH_AUTH_PARTIAL);
  162|      0|            } else {
  163|      0|                ssh_message_reply_default(msg);
  164|      0|            }
  165|       |
  166|      0|            return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  167|    399|        } else if (msg->auth_request.method == SSH_AUTH_METHOD_PUBLICKEY &&
  ------------------
  |  |  157|    798|#define SSH_AUTH_METHOD_PUBLICKEY    0x0004u
  ------------------
  |  Branch (167:20): [True: 1, False: 398]
  ------------------
  168|      1|                   ssh_callbacks_exists(session->server_callbacks,
  ------------------
  |  |  548|      1|#define ssh_callbacks_exists(p,c) (\
  |  |  549|      1|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  ------------------
  |  |  |  Branch (549:3): [True: 1, False: 0]
  |  |  |  Branch (549:18): [True: 1, False: 0]
  |  |  ------------------
  |  |  550|      1|  ((p)-> c != NULL) \
  |  |  ------------------
  |  |  |  Branch (550:3): [True: 0, False: 1]
  |  |  ------------------
  |  |  551|      1|  )
  ------------------
  169|    399|                                        auth_pubkey_function)) {
  170|      0|            rc = session->server_callbacks->auth_pubkey_function(
  171|      0|                session,
  172|      0|                msg->auth_request.username,
  173|      0|                msg->auth_request.pubkey,
  174|      0|                msg->auth_request.signature_state,
  175|      0|                session->server_callbacks->userdata);
  176|      0|            if (msg->auth_request.signature_state != SSH_PUBLICKEY_STATE_NONE) {
  ------------------
  |  Branch (176:17): [True: 0, False: 0]
  ------------------
  177|      0|                if (rc == SSH_AUTH_SUCCESS || rc == SSH_AUTH_PARTIAL) {
  ------------------
  |  Branch (177:21): [True: 0, False: 0]
  |  Branch (177:47): [True: 0, False: 0]
  ------------------
  178|      0|                    ssh_message_auth_reply_success(msg, rc == SSH_AUTH_PARTIAL);
  179|      0|                } else {
  180|      0|                    ssh_message_reply_default(msg);
  181|      0|                }
  182|      0|            } else {
  183|      0|                if (rc == SSH_AUTH_SUCCESS) {
  ------------------
  |  Branch (183:21): [True: 0, False: 0]
  ------------------
  184|      0|                    ssh_message_auth_reply_pk_ok_simple(msg);
  185|      0|                } else {
  186|      0|                    ssh_message_reply_default(msg);
  187|      0|                }
  188|      0|            }
  189|       |
  190|      0|            return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  191|    399|        } else if (msg->auth_request.method == SSH_AUTH_METHOD_NONE &&
  ------------------
  |  |  155|    798|#define SSH_AUTH_METHOD_NONE         0x0001u
  ------------------
  |  Branch (191:20): [True: 69, False: 330]
  ------------------
  192|     69|                   ssh_callbacks_exists(session->server_callbacks,
  ------------------
  |  |  548|     69|#define ssh_callbacks_exists(p,c) (\
  |  |  549|     69|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  ------------------
  |  |  |  Branch (549:3): [True: 69, False: 0]
  |  |  |  Branch (549:18): [True: 69, False: 0]
  |  |  ------------------
  |  |  550|     69|  ((p)-> c != NULL) \
  |  |  ------------------
  |  |  |  Branch (550:3): [True: 69, False: 0]
  |  |  ------------------
  |  |  551|     69|  )
  ------------------
  193|    399|                                        auth_none_function)) {
  194|     69|            rc = session->server_callbacks->auth_none_function(
  195|     69|                session,
  196|     69|                msg->auth_request.username,
  197|     69|                session->server_callbacks->userdata);
  198|     69|            if (rc == SSH_AUTH_SUCCESS || rc == SSH_AUTH_PARTIAL) {
  ------------------
  |  Branch (198:17): [True: 33, False: 36]
  |  Branch (198:43): [True: 36, False: 0]
  ------------------
  199|     69|                ssh_message_auth_reply_success(msg, rc == SSH_AUTH_PARTIAL);
  200|     69|            } else {
  201|      0|                ssh_message_reply_default(msg);
  202|      0|            }
  203|       |
  204|     69|            return SSH_OK;
  ------------------
  |  |  315|     69|#define SSH_OK 0     /* No error */
  ------------------
  205|    330|        } else if (msg->auth_request.method == SSH_AUTH_METHOD_INTERACTIVE &&
  ------------------
  |  |  159|    660|#define SSH_AUTH_METHOD_INTERACTIVE  0x0010u
  ------------------
  |  Branch (205:20): [True: 0, False: 330]
  ------------------
  206|      0|                   ssh_callbacks_exists(session->server_callbacks,
  ------------------
  |  |  548|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  549|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  ------------------
  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  Branch (549:18): [True: 0, False: 0]
  |  |  ------------------
  |  |  550|      0|  ((p)-> c != NULL) \
  |  |  ------------------
  |  |  |  Branch (550:3): [True: 0, False: 0]
  |  |  ------------------
  |  |  551|      0|  )
  ------------------
  207|    330|                                        auth_kbdint_function)) {
  208|      0|            rc = session->server_callbacks->auth_kbdint_function(
  209|      0|                msg,
  210|      0|                session,
  211|      0|                session->server_callbacks->userdata);
  212|      0|            if (rc == SSH_AUTH_SUCCESS || rc == SSH_AUTH_PARTIAL) {
  ------------------
  |  Branch (212:17): [True: 0, False: 0]
  |  Branch (212:43): [True: 0, False: 0]
  ------------------
  213|      0|                ssh_message_auth_reply_success(msg, rc == SSH_AUTH_PARTIAL);
  214|      0|            } else if (rc == SSH_AUTH_INFO) {
  ------------------
  |  Branch (214:24): [True: 0, False: 0]
  ------------------
  215|      0|                return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  216|      0|            } else {
  217|      0|                ssh_message_reply_default(msg);
  218|      0|            }
  219|      0|            return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  220|      0|        }
  221|    330|        break;
  222|    330|    case SSH_REQUEST_CHANNEL_OPEN:
  ------------------
  |  Branch (222:5): [True: 42, False: 400]
  ------------------
  223|     42|#define CB channel_open_request_session_function
  224|     42|        if (msg->channel_request_open.type == SSH_CHANNEL_SESSION &&
  ------------------
  |  Branch (224:13): [True: 17, False: 25]
  ------------------
  225|     17|            ssh_callbacks_exists(session->server_callbacks, CB)) {
  ------------------
  |  |  548|     17|#define ssh_callbacks_exists(p,c) (\
  |  |  549|     17|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  ------------------
  |  |  |  Branch (549:3): [True: 17, False: 0]
  |  |  |  Branch (549:18): [True: 17, False: 0]
  |  |  ------------------
  |  |  550|     17|  ((p)-> c != NULL) \
  |  |  ------------------
  |  |  |  Branch (550:3): [True: 17, False: 0]
  |  |  ------------------
  |  |  551|     17|  )
  ------------------
  226|     17|            channel = session->server_callbacks->CB(
  ------------------
  |  |  223|     17|#define CB channel_open_request_session_function
  ------------------
  227|     17|                session,
  228|     17|                session->server_callbacks->userdata);
  229|     17|#undef CB
  230|     17|            if (channel != NULL) {
  ------------------
  |  Branch (230:17): [True: 17, False: 0]
  ------------------
  231|     17|                rc = ssh_message_channel_request_open_reply_accept_channel(
  232|     17|                    msg,
  233|     17|                    channel);
  234|     17|                if (rc != SSH_OK) {
  ------------------
  |  |  315|     17|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (234:21): [True: 0, False: 17]
  ------------------
  235|      0|                    SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  236|      0|                            "Failed to send reply for accepting a channel "
  237|      0|                            "open");
  238|      0|                }
  239|     17|                return SSH_OK;
  ------------------
  |  |  315|     17|#define SSH_OK 0     /* No error */
  ------------------
  240|     17|            } else {
  241|      0|                ssh_message_reply_default(msg);
  242|      0|            }
  243|       |
  244|      0|            return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  245|     17|#define CB channel_open_request_direct_tcpip_function
  246|     25|        } else if (msg->channel_request_open.type == SSH_CHANNEL_DIRECT_TCPIP &&
  ------------------
  |  Branch (246:20): [True: 1, False: 24]
  ------------------
  247|      1|                   ssh_callbacks_exists(session->server_callbacks, CB)) {
  ------------------
  |  |  548|      1|#define ssh_callbacks_exists(p,c) (\
  |  |  549|      1|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  ------------------
  |  |  |  Branch (549:3): [True: 1, False: 0]
  |  |  |  Branch (549:18): [True: 1, False: 0]
  |  |  ------------------
  |  |  550|      1|  ((p)-> c != NULL) \
  |  |  ------------------
  |  |  |  Branch (550:3): [True: 0, False: 1]
  |  |  ------------------
  |  |  551|      1|  )
  ------------------
  248|      0|            struct ssh_channel_request_open *rq = &msg->channel_request_open;
  249|      0|            channel = session->server_callbacks->CB(session,
  ------------------
  |  |  245|      0|#define CB channel_open_request_direct_tcpip_function
  ------------------
  250|      0|                                                    rq->destination,
  251|      0|                                                    rq->destination_port,
  252|      0|                                                    rq->originator,
  253|      0|                                                    rq->originator_port,
  254|      0|                                                    session->server_callbacks->userdata);
  255|      0|#undef CB
  256|      0|            if (channel != NULL) {
  ------------------
  |  Branch (256:17): [True: 0, False: 0]
  ------------------
  257|      0|                rc = ssh_message_channel_request_open_reply_accept_channel(
  258|      0|                    msg,
  259|      0|                    channel);
  260|      0|                if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (260:21): [True: 0, False: 0]
  ------------------
  261|      0|                    SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  262|      0|                            "Failed to send reply for accepting a channel "
  263|      0|                            "open");
  264|      0|                }
  265|      0|                return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  266|      0|            } else {
  267|      0|                ssh_message_reply_default(msg);
  268|      0|            }
  269|       |
  270|      0|            return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  271|      0|        }
  272|       |
  273|     25|        break;
  274|     25|    case SSH_REQUEST_CHANNEL:
  ------------------
  |  Branch (274:5): [True: 0, False: 442]
  ------------------
  275|      0|        channel = msg->channel_request.channel;
  276|       |
  277|      0|        if (msg->channel_request.type == SSH_CHANNEL_REQUEST_PTY) {
  ------------------
  |  Branch (277:13): [True: 0, False: 0]
  ------------------
  278|      0|            ssh_callbacks_iterate (channel->callbacks,
  ------------------
  |  |  599|      0|    do {                                                              \
  |  |  600|      0|        struct ssh_iterator *_cb_i = ssh_list_get_iterator(_cb_list); \
  |  |  601|      0|        _cb_type _cb;                                                 \
  |  |  602|      0|        for (; _cb_i != NULL; _cb_i = _cb_i->next) {                  \
  |  |  ------------------
  |  |  |  Branch (602:16): [True: 0, False: 0]
  |  |  ------------------
  |  |  603|      0|            _cb = ssh_iterator_value(_cb_type, _cb_i);                \
  |  |  ------------------
  |  |  |  |  122|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  604|      0|            if (ssh_callbacks_exists(_cb, _cb_name))
  |  |  ------------------
  |  |  |  |  548|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  549|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (549:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (550:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  551|      0|  )
  |  |  ------------------
  ------------------
  279|      0|                                   ssh_channel_callbacks,
  280|      0|                                   channel_pty_request_function) {
  281|      0|                rc = ssh_callbacks_iterate_exec(channel_pty_request_function,
  ------------------
  |  |  613|      0|                _cb->_cb_name(__VA_ARGS__, _cb->userdata)
  ------------------
  282|      0|                                                session,
  283|      0|                                                channel,
  284|      0|                                                msg->channel_request.TERM,
  285|      0|                                                msg->channel_request.width,
  286|      0|                                                msg->channel_request.height,
  287|      0|                                                msg->channel_request.pxwidth,
  288|      0|                                                msg->channel_request.pxheight);
  289|      0|                if (rc == 0) {
  ------------------
  |  Branch (289:21): [True: 0, False: 0]
  ------------------
  290|      0|                    ssh_message_channel_request_reply_success(msg);
  291|      0|                } else {
  292|      0|                    ssh_message_reply_default(msg);
  293|      0|                }
  294|      0|                return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  295|      0|            }
  296|      0|            ssh_callbacks_iterate_end();
  ------------------
  |  |  619|      0|        }                           \
  |  |  620|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (620:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  297|      0|        } else if (msg->channel_request.type == SSH_CHANNEL_REQUEST_SHELL) {
  ------------------
  |  Branch (297:20): [True: 0, False: 0]
  ------------------
  298|      0|            ssh_callbacks_iterate (channel->callbacks,
  ------------------
  |  |  599|      0|    do {                                                              \
  |  |  600|      0|        struct ssh_iterator *_cb_i = ssh_list_get_iterator(_cb_list); \
  |  |  601|      0|        _cb_type _cb;                                                 \
  |  |  602|      0|        for (; _cb_i != NULL; _cb_i = _cb_i->next) {                  \
  |  |  ------------------
  |  |  |  Branch (602:16): [True: 0, False: 0]
  |  |  ------------------
  |  |  603|      0|            _cb = ssh_iterator_value(_cb_type, _cb_i);                \
  |  |  ------------------
  |  |  |  |  122|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  604|      0|            if (ssh_callbacks_exists(_cb, _cb_name))
  |  |  ------------------
  |  |  |  |  548|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  549|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (549:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (550:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  551|      0|  )
  |  |  ------------------
  ------------------
  299|      0|                                   ssh_channel_callbacks,
  300|      0|                                   channel_shell_request_function) {
  301|      0|                rc = ssh_callbacks_iterate_exec(channel_shell_request_function,
  ------------------
  |  |  613|      0|                _cb->_cb_name(__VA_ARGS__, _cb->userdata)
  ------------------
  302|      0|                                                session,
  303|      0|                                                channel);
  304|      0|                if (rc == 0) {
  ------------------
  |  Branch (304:21): [True: 0, False: 0]
  ------------------
  305|      0|                    ssh_message_channel_request_reply_success(msg);
  306|      0|                } else {
  307|      0|                    ssh_message_reply_default(msg);
  308|      0|                }
  309|      0|                return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  310|      0|            }
  311|      0|            ssh_callbacks_iterate_end();
  ------------------
  |  |  619|      0|        }                           \
  |  |  620|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (620:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  312|      0|        } else if (msg->channel_request.type == SSH_CHANNEL_REQUEST_X11) {
  ------------------
  |  Branch (312:20): [True: 0, False: 0]
  ------------------
  313|      0|            ssh_callbacks_iterate (channel->callbacks,
  ------------------
  |  |  599|      0|    do {                                                              \
  |  |  600|      0|        struct ssh_iterator *_cb_i = ssh_list_get_iterator(_cb_list); \
  |  |  601|      0|        _cb_type _cb;                                                 \
  |  |  602|      0|        for (; _cb_i != NULL; _cb_i = _cb_i->next) {                  \
  |  |  ------------------
  |  |  |  Branch (602:16): [True: 0, False: 0]
  |  |  ------------------
  |  |  603|      0|            _cb = ssh_iterator_value(_cb_type, _cb_i);                \
  |  |  ------------------
  |  |  |  |  122|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  604|      0|            if (ssh_callbacks_exists(_cb, _cb_name))
  |  |  ------------------
  |  |  |  |  548|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  549|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (549:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (550:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  551|      0|  )
  |  |  ------------------
  ------------------
  314|      0|                                   ssh_channel_callbacks,
  315|      0|                                   channel_x11_req_function) {
  316|      0|                ssh_callbacks_iterate_exec(channel_x11_req_function,
  ------------------
  |  |  613|      0|                _cb->_cb_name(__VA_ARGS__, _cb->userdata)
  ------------------
  317|      0|                                           session,
  318|      0|                                           channel,
  319|      0|                                           msg->channel_request.x11_single_connection,
  320|      0|                                           msg->channel_request.x11_auth_protocol,
  321|      0|                                           msg->channel_request.x11_auth_cookie,
  322|      0|                                           msg->channel_request.x11_screen_number);
  323|      0|                ssh_message_channel_request_reply_success(msg);
  324|      0|                return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  325|      0|            }
  326|      0|            ssh_callbacks_iterate_end();
  ------------------
  |  |  619|      0|        }                           \
  |  |  620|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (620:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  327|      0|        } else if (msg->channel_request.type == SSH_CHANNEL_REQUEST_WINDOW_CHANGE) {
  ------------------
  |  Branch (327:20): [True: 0, False: 0]
  ------------------
  328|      0|            ssh_callbacks_iterate (channel->callbacks,
  ------------------
  |  |  599|      0|    do {                                                              \
  |  |  600|      0|        struct ssh_iterator *_cb_i = ssh_list_get_iterator(_cb_list); \
  |  |  601|      0|        _cb_type _cb;                                                 \
  |  |  602|      0|        for (; _cb_i != NULL; _cb_i = _cb_i->next) {                  \
  |  |  ------------------
  |  |  |  Branch (602:16): [True: 0, False: 0]
  |  |  ------------------
  |  |  603|      0|            _cb = ssh_iterator_value(_cb_type, _cb_i);                \
  |  |  ------------------
  |  |  |  |  122|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  604|      0|            if (ssh_callbacks_exists(_cb, _cb_name))
  |  |  ------------------
  |  |  |  |  548|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  549|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (549:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (550:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  551|      0|  )
  |  |  ------------------
  ------------------
  329|      0|                                   ssh_channel_callbacks,
  330|      0|                                   channel_pty_window_change_function) {
  331|      0|                rc = ssh_callbacks_iterate_exec(channel_pty_window_change_function,
  ------------------
  |  |  613|      0|                _cb->_cb_name(__VA_ARGS__, _cb->userdata)
  ------------------
  332|      0|                                                session,
  333|      0|                                                channel,
  334|      0|                                                msg->channel_request.width,
  335|      0|                                                msg->channel_request.height,
  336|      0|                                                msg->channel_request.pxwidth,
  337|      0|                                                msg->channel_request.pxheight);
  338|      0|                if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (338:21): [True: 0, False: 0]
  ------------------
  339|      0|                    SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  340|      0|                            "Failed to iterate callbacks for window change");
  341|      0|                }
  342|      0|                return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  343|      0|            }
  344|      0|            ssh_callbacks_iterate_end();
  ------------------
  |  |  619|      0|        }                           \
  |  |  620|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (620:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  345|      0|        } else if (msg->channel_request.type == SSH_CHANNEL_REQUEST_EXEC) {
  ------------------
  |  Branch (345:20): [True: 0, False: 0]
  ------------------
  346|      0|            ssh_callbacks_iterate (channel->callbacks,
  ------------------
  |  |  599|      0|    do {                                                              \
  |  |  600|      0|        struct ssh_iterator *_cb_i = ssh_list_get_iterator(_cb_list); \
  |  |  601|      0|        _cb_type _cb;                                                 \
  |  |  602|      0|        for (; _cb_i != NULL; _cb_i = _cb_i->next) {                  \
  |  |  ------------------
  |  |  |  Branch (602:16): [True: 0, False: 0]
  |  |  ------------------
  |  |  603|      0|            _cb = ssh_iterator_value(_cb_type, _cb_i);                \
  |  |  ------------------
  |  |  |  |  122|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  604|      0|            if (ssh_callbacks_exists(_cb, _cb_name))
  |  |  ------------------
  |  |  |  |  548|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  549|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (549:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (550:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  551|      0|  )
  |  |  ------------------
  ------------------
  347|      0|                                   ssh_channel_callbacks,
  348|      0|                                   channel_exec_request_function) {
  349|      0|                rc = ssh_callbacks_iterate_exec(channel_exec_request_function,
  ------------------
  |  |  613|      0|                _cb->_cb_name(__VA_ARGS__, _cb->userdata)
  ------------------
  350|      0|                                                session,
  351|      0|                                                channel,
  352|      0|                                                msg->channel_request.command);
  353|      0|                if (rc == 0) {
  ------------------
  |  Branch (353:21): [True: 0, False: 0]
  ------------------
  354|      0|                    ssh_message_channel_request_reply_success(msg);
  355|      0|                } else {
  356|      0|                    ssh_message_reply_default(msg);
  357|      0|                }
  358|       |
  359|      0|                return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  360|      0|            }
  361|      0|            ssh_callbacks_iterate_end();
  ------------------
  |  |  619|      0|        }                           \
  |  |  620|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (620:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  362|      0|        } else if (msg->channel_request.type == SSH_CHANNEL_REQUEST_ENV) {
  ------------------
  |  Branch (362:20): [True: 0, False: 0]
  ------------------
  363|      0|            ssh_callbacks_iterate (channel->callbacks,
  ------------------
  |  |  599|      0|    do {                                                              \
  |  |  600|      0|        struct ssh_iterator *_cb_i = ssh_list_get_iterator(_cb_list); \
  |  |  601|      0|        _cb_type _cb;                                                 \
  |  |  602|      0|        for (; _cb_i != NULL; _cb_i = _cb_i->next) {                  \
  |  |  ------------------
  |  |  |  Branch (602:16): [True: 0, False: 0]
  |  |  ------------------
  |  |  603|      0|            _cb = ssh_iterator_value(_cb_type, _cb_i);                \
  |  |  ------------------
  |  |  |  |  122|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  604|      0|            if (ssh_callbacks_exists(_cb, _cb_name))
  |  |  ------------------
  |  |  |  |  548|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  549|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (549:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (550:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  551|      0|  )
  |  |  ------------------
  ------------------
  364|      0|                                   ssh_channel_callbacks,
  365|      0|                                   channel_env_request_function) {
  366|      0|                rc = ssh_callbacks_iterate_exec(channel_env_request_function,
  ------------------
  |  |  613|      0|                _cb->_cb_name(__VA_ARGS__, _cb->userdata)
  ------------------
  367|      0|                                                session,
  368|      0|                                                channel,
  369|      0|                                                msg->channel_request.var_name,
  370|      0|                                                msg->channel_request.var_value);
  371|      0|                if (rc == 0) {
  ------------------
  |  Branch (371:21): [True: 0, False: 0]
  ------------------
  372|      0|                    ssh_message_channel_request_reply_success(msg);
  373|      0|                } else {
  374|      0|                    ssh_message_reply_default(msg);
  375|      0|                }
  376|      0|                return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  377|      0|            }
  378|      0|            ssh_callbacks_iterate_end();
  ------------------
  |  |  619|      0|        }                           \
  |  |  620|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (620:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  379|      0|        } else if (msg->channel_request.type == SSH_CHANNEL_REQUEST_SUBSYSTEM) {
  ------------------
  |  Branch (379:20): [True: 0, False: 0]
  ------------------
  380|      0|            ssh_callbacks_iterate (channel->callbacks,
  ------------------
  |  |  599|      0|    do {                                                              \
  |  |  600|      0|        struct ssh_iterator *_cb_i = ssh_list_get_iterator(_cb_list); \
  |  |  601|      0|        _cb_type _cb;                                                 \
  |  |  602|      0|        for (; _cb_i != NULL; _cb_i = _cb_i->next) {                  \
  |  |  ------------------
  |  |  |  Branch (602:16): [True: 0, False: 0]
  |  |  ------------------
  |  |  603|      0|            _cb = ssh_iterator_value(_cb_type, _cb_i);                \
  |  |  ------------------
  |  |  |  |  122|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  604|      0|            if (ssh_callbacks_exists(_cb, _cb_name))
  |  |  ------------------
  |  |  |  |  548|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  549|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (549:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (550:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  551|      0|  )
  |  |  ------------------
  ------------------
  381|      0|                                   ssh_channel_callbacks,
  382|      0|                                   channel_subsystem_request_function) {
  383|      0|                rc = ssh_callbacks_iterate_exec(
  ------------------
  |  |  613|      0|                _cb->_cb_name(__VA_ARGS__, _cb->userdata)
  ------------------
  384|      0|                    channel_subsystem_request_function,
  385|      0|                    session,
  386|      0|                    channel,
  387|      0|                    msg->channel_request.subsystem);
  388|      0|                if (rc == 0) {
  ------------------
  |  Branch (388:21): [True: 0, False: 0]
  ------------------
  389|      0|                    ssh_message_channel_request_reply_success(msg);
  390|      0|                } else {
  391|      0|                    ssh_message_reply_default(msg);
  392|      0|                }
  393|       |
  394|      0|                return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  395|      0|            }
  396|      0|            ssh_callbacks_iterate_end();
  ------------------
  |  |  619|      0|        }                           \
  |  |  620|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (620:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  397|      0|        }
  398|      0|        break;
  399|      1|    case SSH_REQUEST_SERVICE:
  ------------------
  |  Branch (399:5): [True: 1, False: 441]
  ------------------
  400|      1|        if (ssh_callbacks_exists(session->server_callbacks,
  ------------------
  |  |  548|      1|#define ssh_callbacks_exists(p,c) (\
  |  |  549|      1|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  ------------------
  |  |  |  Branch (549:3): [True: 1, False: 0]
  |  |  |  Branch (549:18): [True: 1, False: 0]
  |  |  ------------------
  |  |  550|      1|  ((p)-> c != NULL) \
  |  |  ------------------
  |  |  |  Branch (550:3): [True: 0, False: 1]
  |  |  ------------------
  |  |  551|      1|  )
  ------------------
  401|      1|                                 service_request_function)) {
  402|      0|            rc = session->server_callbacks->service_request_function(
  403|      0|                session,
  404|      0|                msg->service_request.service,
  405|      0|                session->server_callbacks->userdata);
  406|      0|            if (rc == 0) {
  ------------------
  |  Branch (406:17): [True: 0, False: 0]
  ------------------
  407|      0|                ssh_message_reply_default(msg);
  408|      0|            } else {
  409|      0|                ssh_send_disconnect(session);
  410|      0|            }
  411|       |
  412|      0|            return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  413|      0|        }
  414|       |
  415|      1|        return SSH_AGAIN;
  ------------------
  |  |  317|      1|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  416|      0|    case SSH_REQUEST_GLOBAL:
  ------------------
  |  Branch (416:5): [True: 0, False: 442]
  ------------------
  417|      0|        break;
  418|    442|    }
  419|       |
  420|    355|    return SSH_AGAIN;
  ------------------
  |  |  317|    355|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  421|    442|}

ssh_list_new:
  858|  1.94k|{
  859|  1.94k|    struct ssh_list *ret = malloc(sizeof(struct ssh_list));
  860|  1.94k|    if (ret == NULL) {
  ------------------
  |  Branch (860:9): [True: 0, False: 1.94k]
  ------------------
  861|      0|        return NULL;
  862|      0|    }
  863|  1.94k|    ret->root = ret->end = NULL;
  864|  1.94k|    return ret;
  865|  1.94k|}
ssh_list_free:
  875|  2.93k|{
  876|  2.93k|    struct ssh_iterator *ptr = NULL, *next = NULL;
  877|  2.93k|    if (!list)
  ------------------
  |  Branch (877:9): [True: 989, False: 1.94k]
  ------------------
  878|    989|        return;
  879|  1.94k|    ptr = list->root;
  880|  2.34k|    while (ptr) {
  ------------------
  |  Branch (880:12): [True: 403, False: 1.94k]
  ------------------
  881|    403|        next = ptr->next;
  882|    403|        SAFE_FREE(ptr);
  ------------------
  |  |  375|    403|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 403, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 403]
  |  |  ------------------
  ------------------
  883|    403|        ptr = next;
  884|    403|    }
  885|       |    SAFE_FREE(list);
  ------------------
  |  |  375|  1.94k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 1.94k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 1.94k]
  |  |  ------------------
  ------------------
  886|  1.94k|}
ssh_list_get_iterator:
  896|  38.1k|{
  897|  38.1k|    if (!list)
  ------------------
  |  Branch (897:9): [True: 2.30k, False: 35.8k]
  ------------------
  898|  2.30k|        return NULL;
  899|  35.8k|    return list->root;
  900|  38.1k|}
ssh_list_find:
  911|    203|{
  912|    203|    struct ssh_iterator *it = NULL;
  913|       |
  914|    389|    for (it = ssh_list_get_iterator(list); it != NULL ; it = it->next)
  ------------------
  |  Branch (914:44): [True: 389, False: 0]
  ------------------
  915|    389|        if (it->data == value)
  ------------------
  |  Branch (915:13): [True: 203, False: 186]
  ------------------
  916|    203|            return it;
  917|      0|    return NULL;
  918|    203|}
ssh_list_append:
  962|  2.56k|{
  963|  2.56k|  struct ssh_iterator *iterator = NULL;
  964|       |
  965|  2.56k|  if (list == NULL) {
  ------------------
  |  Branch (965:7): [True: 0, False: 2.56k]
  ------------------
  966|      0|      return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  967|      0|  }
  968|       |
  969|  2.56k|  iterator = ssh_iterator_new(data);
  970|  2.56k|  if (iterator == NULL) {
  ------------------
  |  Branch (970:7): [True: 0, False: 2.56k]
  ------------------
  971|      0|      return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  972|      0|  }
  973|       |
  974|  2.56k|  if(!list->end){
  ------------------
  |  Branch (974:6): [True: 1.03k, False: 1.53k]
  ------------------
  975|       |    /* list is empty */
  976|  1.03k|    list->root=list->end=iterator;
  977|  1.53k|  } else {
  978|       |    /* put it on end of list */
  979|  1.53k|    list->end->next=iterator;
  980|  1.53k|    list->end=iterator;
  981|  1.53k|  }
  982|  2.56k|  return SSH_OK;
  ------------------
  |  |  315|  2.56k|#define SSH_OK 0     /* No error */
  ------------------
  983|  2.56k|}
ssh_list_prepend:
  994|     17|{
  995|     17|  struct ssh_iterator *it = NULL;
  996|       |
  997|     17|  if (list == NULL) {
  ------------------
  |  Branch (997:7): [True: 0, False: 17]
  ------------------
  998|      0|      return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  999|      0|  }
 1000|       |
 1001|     17|  it = ssh_iterator_new(data);
 1002|     17|  if (it == NULL) {
  ------------------
  |  Branch (1002:7): [True: 0, False: 17]
  ------------------
 1003|      0|    return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1004|      0|  }
 1005|       |
 1006|     17|  if (list->end == NULL) {
  ------------------
  |  Branch (1006:7): [True: 12, False: 5]
  ------------------
 1007|       |    /* list is empty */
 1008|     12|    list->root = list->end = it;
 1009|     12|  } else {
 1010|       |    /* set as new root */
 1011|      5|    it->next = list->root;
 1012|      5|    list->root = it;
 1013|      5|  }
 1014|       |
 1015|     17|  return SSH_OK;
  ------------------
  |  |  315|     17|#define SSH_OK 0     /* No error */
  ------------------
 1016|     17|}
ssh_list_remove:
 1025|    220|{
 1026|    220|    struct ssh_iterator *ptr = NULL, *prev = NULL;
 1027|       |
 1028|    220|    if (list == NULL) {
  ------------------
  |  Branch (1028:9): [True: 0, False: 220]
  ------------------
 1029|      0|        return;
 1030|      0|    }
 1031|       |
 1032|    220|    prev = NULL;
 1033|    220|    ptr = list->root;
 1034|    411|    while (ptr && ptr != iterator) {
  ------------------
  |  Branch (1034:12): [True: 394, False: 17]
  |  Branch (1034:19): [True: 191, False: 203]
  ------------------
 1035|    191|        prev = ptr;
 1036|    191|        ptr = ptr->next;
 1037|    191|    }
 1038|    220|    if (!ptr) {
  ------------------
  |  Branch (1038:9): [True: 17, False: 203]
  ------------------
 1039|       |        /* we did not find the element */
 1040|     17|        return;
 1041|     17|    }
 1042|       |    /* unlink it */
 1043|    203|    if (prev)
  ------------------
  |  Branch (1043:9): [True: 186, False: 17]
  ------------------
 1044|    186|        prev->next = ptr->next;
 1045|       |    /* if iterator was the head */
 1046|    203|    if (list->root == iterator)
  ------------------
  |  Branch (1046:9): [True: 17, False: 186]
  ------------------
 1047|     17|        list->root = iterator->next;
 1048|       |    /* if iterator was the tail */
 1049|    203|    if (list->end == iterator)
  ------------------
  |  Branch (1049:9): [True: 198, False: 5]
  ------------------
 1050|    198|        list->end = prev;
 1051|       |    SAFE_FREE(iterator);
  ------------------
  |  |  375|    203|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 203, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 203]
  |  |  ------------------
  ------------------
 1052|    203|}
_ssh_list_pop_head:
 1066|  4.30k|{
 1067|  4.30k|  struct ssh_iterator *iterator = NULL;
 1068|  4.30k|  const void *data = NULL;
 1069|       |
 1070|  4.30k|  if (list == NULL) {
  ------------------
  |  Branch (1070:7): [True: 1.00k, False: 3.30k]
  ------------------
 1071|  1.00k|      return NULL;
 1072|  1.00k|  }
 1073|       |
 1074|  3.30k|  iterator = list->root;
 1075|  3.30k|  if (iterator == NULL) {
  ------------------
  |  Branch (1075:7): [True: 1.32k, False: 1.98k]
  ------------------
 1076|  1.32k|      return NULL;
 1077|  1.32k|  }
 1078|  1.98k|  data=iterator->data;
 1079|  1.98k|  list->root=iterator->next;
 1080|  1.98k|  if(list->end==iterator)
  ------------------
  |  Branch (1080:6): [True: 660, False: 1.32k]
  ------------------
 1081|    660|    list->end=NULL;
 1082|       |  SAFE_FREE(iterator);
  ------------------
  |  |  375|  1.98k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 1.98k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 1.98k]
  |  |  ------------------
  ------------------
 1083|  1.98k|  return data;
 1084|  3.30k|}
ssh_analyze_banner:
 1748|    307|{
 1749|    307|    const char *banner = NULL;
 1750|    307|    const char *openssh = NULL;
 1751|    307|    const char *ios = NULL;
 1752|       |
 1753|    307|    if (server) {
  ------------------
  |  Branch (1753:9): [True: 307, False: 0]
  ------------------
 1754|    307|        banner = session->clientbanner;
 1755|    307|    } else {
 1756|      0|        banner = session->serverbanner;
 1757|      0|    }
 1758|       |
 1759|    307|    if (banner == NULL) {
  ------------------
  |  Branch (1759:9): [True: 0, False: 307]
  ------------------
 1760|      0|        ssh_set_error(session, SSH_FATAL, "Invalid banner");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1761|      0|        return -1;
 1762|      0|    }
 1763|       |
 1764|       |    /*
 1765|       |     * Typical banners e.g. are:
 1766|       |     *
 1767|       |     * SSH-1.5-openSSH_5.4
 1768|       |     * SSH-1.99-openSSH_3.0
 1769|       |     *
 1770|       |     * SSH-2.0-something
 1771|       |     * 012345678901234567890
 1772|       |     */
 1773|    307|    if (strlen(banner) < 6 ||
  ------------------
  |  Branch (1773:9): [True: 5, False: 302]
  ------------------
 1774|    302|        strncmp(banner, "SSH-", 4) != 0) {
  ------------------
  |  Branch (1774:9): [True: 4, False: 298]
  ------------------
 1775|      9|          ssh_set_error(session, SSH_FATAL, "Protocol mismatch: %s", banner);
  ------------------
  |  |  313|      9|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1776|      9|          return -1;
 1777|      9|    }
 1778|       |
 1779|    298|    SSH_LOG(SSH_LOG_DEBUG, "Analyzing banner: %s", banner);
  ------------------
  |  |  283|    298|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1780|       |
 1781|    298|    switch (banner[4]) {
 1782|    294|        case '2':
  ------------------
  |  Branch (1782:9): [True: 294, False: 4]
  ------------------
 1783|    294|            break;
 1784|      3|        case '1':
  ------------------
  |  Branch (1784:9): [True: 3, False: 295]
  ------------------
 1785|      3|            if (strlen(banner) > 6) {
  ------------------
  |  Branch (1785:17): [True: 3, False: 0]
  ------------------
 1786|      3|                if (banner[6] == '9') {
  ------------------
  |  Branch (1786:21): [True: 0, False: 3]
  ------------------
 1787|      0|                    break;
 1788|      0|                }
 1789|      3|            }
 1790|      3|            FALL_THROUGH;
  ------------------
  |  |  496|      3|#  define FALL_THROUGH __attribute__ ((fallthrough))
  ------------------
 1791|      4|        default:
  ------------------
  |  Branch (1791:9): [True: 1, False: 297]
  ------------------
 1792|      4|            ssh_set_error(session, SSH_FATAL, "Protocol mismatch: %s", banner);
  ------------------
  |  |  313|      4|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1793|      4|            return -1;
 1794|    298|    }
 1795|       |
 1796|       |    /* Clear the Cisco scp quirk a previous banner may have set */
 1797|    294|    session->flags &= ~SSH_SESSION_FLAG_SCP_QUOTING_BROKEN;
  ------------------
  |  |   95|    294|#define SSH_SESSION_FLAG_SCP_QUOTING_BROKEN 0x0040
  ------------------
 1798|       |
 1799|       |    /* Make a best-effort to extract OpenSSH version numbers. */
 1800|    294|    session->openssh = 0;
 1801|    294|    openssh = strstr(banner, "OpenSSH");
 1802|    294|    if (openssh != NULL) {
  ------------------
  |  Branch (1802:9): [True: 40, False: 254]
  ------------------
 1803|     40|        char *tmp = NULL;
 1804|     40|        unsigned long int major = 0UL;
 1805|     40|        unsigned long int minor = 0UL;
 1806|     40|        const char *minor_str = NULL;
 1807|       |
 1808|       |        /*
 1809|       |         * The banner is typical:
 1810|       |         * OpenSSH_5.4
 1811|       |         * 012345678901234567890
 1812|       |         */
 1813|     40|        if (strlen(openssh) > 9) {
  ------------------
  |  Branch (1813:13): [True: 40, False: 0]
  ------------------
 1814|     40|            errno = 0;
 1815|     40|            major = strtoul(openssh + 8, &tmp, 10);
 1816|     40|            if ((tmp == (openssh + 8)) ||
  ------------------
  |  Branch (1816:17): [True: 1, False: 39]
  ------------------
 1817|     39|                ((errno == ERANGE) && (major == ULONG_MAX)) ||
  ------------------
  |  Branch (1817:18): [True: 0, False: 39]
  |  Branch (1817:39): [True: 0, False: 0]
  ------------------
 1818|     39|                ((errno != 0) && (major == 0)) ||
  ------------------
  |  Branch (1818:18): [True: 0, False: 39]
  |  Branch (1818:34): [True: 0, False: 0]
  ------------------
 1819|     39|                ((major < 1) || (major > 100))) {
  ------------------
  |  Branch (1819:18): [True: 0, False: 39]
  |  Branch (1819:33): [True: 23, False: 16]
  ------------------
 1820|       |                /* invalid major */
 1821|     24|                errno = 0;
 1822|     24|                goto done;
 1823|     24|            }
 1824|       |
 1825|       |            /* The minor version follows the dot after the major version */
 1826|     16|            if (*tmp != '.') {
  ------------------
  |  Branch (1826:17): [True: 4, False: 12]
  ------------------
 1827|      4|                goto done;
 1828|      4|            }
 1829|       |
 1830|       |            /* strtoul() would skip whitespace and accept a sign */
 1831|     12|            minor_str = tmp + 1;
 1832|     12|            if (!isdigit((unsigned char)*minor_str)) {
  ------------------
  |  Branch (1832:17): [True: 1, False: 11]
  ------------------
 1833|      1|                goto done;
 1834|      1|            }
 1835|       |
 1836|     12|            errno = 0;
 1837|     11|            minor = strtoul(minor_str, &tmp, 10);
 1838|     11|            if ((tmp == minor_str) ||
  ------------------
  |  Branch (1838:17): [True: 0, False: 11]
  ------------------
 1839|     11|                ((errno == ERANGE) && (minor == ULONG_MAX)) ||
  ------------------
  |  Branch (1839:18): [True: 0, False: 11]
  |  Branch (1839:39): [True: 0, False: 0]
  ------------------
 1840|     11|                ((errno != 0) && (minor == 0)) || (minor > 100)) {
  ------------------
  |  Branch (1840:18): [True: 0, False: 11]
  |  Branch (1840:34): [True: 0, False: 0]
  |  Branch (1840:51): [True: 6, False: 5]
  ------------------
 1841|       |                /* invalid minor */
 1842|      6|                errno = 0;
 1843|      6|                goto done;
 1844|      6|            }
 1845|       |
 1846|      5|            session->openssh = SSH_VERSION_INT(((int) major), ((int) minor), 0);
  ------------------
  |  |   25|      5|#define SSH_VERSION_INT(a, b, c) ((a) << 16 | (b) << 8 | (c))
  ------------------
 1847|       |
 1848|      5|            SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  283|     10|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (283:34): [True: 5, False: 0]
  |  |  ------------------
  ------------------
 1849|      5|                    "We are talking to an OpenSSH %s version: %lu.%lu (%x)",
 1850|      5|                    server ? "client" : "server",
 1851|      5|                    major, minor, session->openssh);
 1852|      5|        }
 1853|     40|    }
 1854|       |    /* Cisco devices have odd scp implementation which breaks */
 1855|    259|    ios = strstr(banner, "Cisco");
 1856|    259|    if (ios != NULL) {
  ------------------
  |  Branch (1856:9): [True: 0, False: 259]
  ------------------
 1857|      0|        session->flags |= SSH_SESSION_FLAG_SCP_QUOTING_BROKEN;
  ------------------
  |  |   95|      0|#define SSH_SESSION_FLAG_SCP_QUOTING_BROKEN 0x0040
  ------------------
 1858|      0|    }
 1859|       |
 1860|    294|done:
 1861|    294|    return 0;
 1862|    259|}
ssh_timestamp_init:
 1877|  2.80k|{
 1878|  2.80k|#ifdef HAVE_CLOCK_GETTIME
 1879|  2.80k|  struct timespec tp;
 1880|  2.80k|  clock_gettime(CLOCK, &tp);
  ------------------
  |  | 1866|  2.80k|#define CLOCK CLOCK_MONOTONIC
  ------------------
 1881|  2.80k|  ts->useconds = tp.tv_nsec / 1000;
 1882|       |#else
 1883|       |  struct timeval tp;
 1884|       |  gettimeofday(&tp, NULL);
 1885|       |  ts->useconds = tp.tv_usec;
 1886|       |#endif
 1887|  2.80k|  ts->seconds = tp.tv_sec;
 1888|  2.80k|}
ssh_timeout_elapsed:
 1960|    797|{
 1961|    797|    struct ssh_timestamp now;
 1962|       |
 1963|    797|    switch(timeout) {
 1964|      0|        case -2: /*
  ------------------
  |  Branch (1964:9): [True: 0, False: 797]
  ------------------
 1965|       |                  * -2 means user-defined timeout as available in
 1966|       |                  * session->timeout, session->timeout_usec.
 1967|       |                  */
 1968|      0|            SSH_LOG(SSH_LOG_DEBUG, "ssh_timeout_elapsed called with -2. this needs to "
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1969|      0|                            "be fixed. please set a breakpoint on misc.c:%d and "
 1970|      0|                            "fix the caller\n", __LINE__);
 1971|      0|            return 0;
 1972|    797|        case -1: /* -1 means infinite timeout */
  ------------------
  |  Branch (1972:9): [True: 797, False: 0]
  ------------------
 1973|    797|            return 0;
 1974|      0|        case 0: /* 0 means no timeout */
  ------------------
  |  Branch (1974:9): [True: 0, False: 797]
  ------------------
 1975|      0|            return 1;
 1976|      0|        default:
  ------------------
  |  Branch (1976:9): [True: 0, False: 797]
  ------------------
 1977|      0|            break;
 1978|    797|    }
 1979|       |
 1980|      0|    ssh_timestamp_init(&now);
 1981|       |
 1982|      0|    return (ssh_timestamp_difference(ts,&now) >= timeout);
 1983|    797|}
ssh_timeout_update:
 1993|  2.45k|{
 1994|  2.45k|  struct ssh_timestamp now;
 1995|  2.45k|  int ms, ret;
 1996|  2.45k|  if (timeout <= 0) {
  ------------------
  |  Branch (1996:7): [True: 1.63k, False: 824]
  ------------------
 1997|  1.63k|      return timeout;
 1998|  1.63k|  }
 1999|    824|  ssh_timestamp_init(&now);
 2000|    824|  ms = ssh_timestamp_difference(ts,&now);
 2001|    824|  if(ms < 0)
  ------------------
  |  Branch (2001:6): [True: 0, False: 824]
  ------------------
 2002|      0|    ms = 0;
 2003|    824|  ret = timeout - ms;
 2004|    824|  return ret >= 0 ? ret: 0;
  ------------------
  |  Branch (2004:10): [True: 824, False: 0]
  ------------------
 2005|  2.45k|}
burn_free:
 2019|    742|{
 2020|    742|    if (ptr == NULL) {
  ------------------
  |  Branch (2020:9): [True: 0, False: 742]
  ------------------
 2021|      0|        return;
 2022|      0|    }
 2023|       |
 2024|       |    /* BURN_FREE() clears the pointer, so always free it, even when there is
 2025|       |     * nothing to wipe (e.g. a zero-length buffer such as the MAC key with no
 2026|       |     * MAC, or a signature reported with zero length) */
 2027|    742|    if (len > 0) {
  ------------------
  |  Branch (2027:9): [True: 372, False: 370]
  ------------------
 2028|    372|        ssh_burn(ptr, len);
  ------------------
  |  |  390|    372|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
 2029|    372|    }
 2030|    742|    free(ptr);
 2031|    742|}
ssh_strerror:
 2428|     66|{
 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|     66|    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|     66|    rv = strerror_r(err_num, buf, buflen);
 2440|     66|#endif /* _WIN32 */
 2441|       |
 2442|       |    /* make sure the buffer is initialized and terminated with NULL */
 2443|     66|    if (-rv == ERANGE) {
  ------------------
  |  Branch (2443:9): [True: 0, False: 66]
  ------------------
 2444|      0|        buf[0] = '\0';
 2445|      0|    }
 2446|     66|    return buf;
 2447|     66|#endif /* ((defined(__linux__) && defined(__GLIBC__)) || defined(__CYGWIN__)) && defined(_GNU_SOURCE) */
 2448|     66|}
ssh_proxyjumps_free:
 2685|    831|{
 2686|    831|    struct ssh_jump_info_struct *jump = NULL;
 2687|       |
 2688|    831|    for (jump =
 2689|    831|             ssh_list_pop_head(struct ssh_jump_info_struct *, proxy_jump_list);
  ------------------
  |  |  130|    831|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2690|    831|         jump != NULL;
  ------------------
  |  Branch (2690:10): [True: 0, False: 831]
  ------------------
 2691|    831|         jump = ssh_list_pop_head(struct ssh_jump_info_struct *,
  ------------------
  |  |  130|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2692|    831|                                  proxy_jump_list)) {
 2693|      0|        ssh_jump_info_free(jump);
 2694|      0|    }
 2695|    831|}
ssh_strict_fopen:
 2729|      4|{
 2730|      4|    FILE *f = NULL;
 2731|      4|    struct stat sb;
 2732|      4|    int r, fd;
 2733|       |
 2734|       |    /* open first to avoid TOCTOU */
 2735|      4|    fd = open(filename, O_RDONLY);
 2736|      4|    if (fd == -1) {
  ------------------
  |  Branch (2736:9): [True: 4, False: 0]
  ------------------
 2737|      4|        SSH_LOG_STRERROR(SSH_LOG_TRACE,
  ------------------
  |  |  285|      4|    do {                                                            \
  |  |  286|      4|        char err_msg[SSH_ERRNO_MSG_MAX] = {0};                      \
  |  |  287|      4|        _ssh_log(priority,                                          \
  |  |  288|      4|                 __func__,                                          \
  |  |  289|      4|                 __VA_ARGS__,                                       \
  |  |  290|      4|                 ssh_strerror(errnum, err_msg, SSH_ERRNO_MSG_MAX)); \
  |  |  ------------------
  |  |  |  |  522|      4|#define SSH_ERRNO_MSG_MAX   1024
  |  |  ------------------
  |  |  291|      4|    } while (0)
  |  |  ------------------
  |  |  |  Branch (291:14): [Folded, False: 4]
  |  |  ------------------
  ------------------
 2738|      4|                         errno,
 2739|      4|                         "Failed to open a file %s for reading: %s",
 2740|      4|                         filename);
 2741|      4|        return NULL;
 2742|      4|    }
 2743|       |
 2744|       |    /* Check the file is sensible for a configuration file */
 2745|      0|    r = fstat(fd, &sb);
 2746|      0|    if (r != 0) {
  ------------------
  |  Branch (2746:9): [True: 0, False: 0]
  ------------------
 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|      0|    if ((sb.st_mode & S_IFMT) != S_IFREG) {
  ------------------
  |  Branch (2754:9): [True: 0, False: 0]
  ------------------
 2755|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2756|      0|                "The file %s is not a regular file: skipping",
 2757|      0|                filename);
 2758|      0|        close(fd);
 2759|      0|        return NULL;
 2760|      0|    }
 2761|       |
 2762|      0|    if ((size_t)sb.st_size > max_file_size) {
  ------------------
  |  Branch (2762:9): [True: 0, False: 0]
  ------------------
 2763|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2764|      0|                "The file %s is too large (%jd MB > %zu MB): skipping",
 2765|      0|                filename,
 2766|      0|                (intmax_t)sb.st_size / 1024 / 1024,
 2767|      0|                max_file_size / 1024 / 1024);
 2768|      0|        close(fd);
 2769|      0|        return NULL;
 2770|      0|    }
 2771|       |
 2772|      0|    f = fdopen(fd, "r");
 2773|      0|    if (f == NULL) {
  ------------------
  |  Branch (2773:9): [True: 0, False: 0]
  ------------------
 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|      0|    return f;
 2784|      0|}
misc.c:ssh_iterator_new:
  940|  2.58k|{
  941|  2.58k|    struct ssh_iterator *iterator = malloc(sizeof(struct ssh_iterator));
  942|       |
  943|  2.58k|    if (iterator == NULL) {
  ------------------
  |  Branch (943:9): [True: 0, False: 2.58k]
  ------------------
  944|      0|        return NULL;
  945|      0|    }
  946|  2.58k|    iterator->next = NULL;
  947|  2.58k|    iterator->data = data;
  948|  2.58k|    return iterator;
  949|  2.58k|}
misc.c:ssh_timestamp_difference:
 1902|    824|{
 1903|    824|    long seconds, usecs, msecs;
 1904|    824|    seconds = new->seconds - old->seconds;
 1905|    824|    usecs = new->useconds - old->useconds;
 1906|    824|    if (usecs < 0){
  ------------------
  |  Branch (1906:9): [True: 0, False: 824]
  ------------------
 1907|      0|        seconds--;
 1908|      0|        usecs += 1000000;
 1909|      0|    }
 1910|    824|    msecs = seconds * 1000 + usecs/1000;
 1911|    824|    return msecs;
 1912|    824|}

ssh_options_set_algo:
  470|  1.59k|{
  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|  1.59k|    char *p = (char *)list;
  475|       |
  476|       |    /* Clear errno so ENOMEM means allocation failure (best-effort). */
  477|  1.59k|    errno = 0;
  478|       |
  479|  1.59k|    if (algo < SSH_COMP_C_S) {
  ------------------
  |  Branch (479:9): [True: 1.59k, False: 0]
  ------------------
  480|  1.59k|        if (list[0] == '+') {
  ------------------
  |  Branch (480:13): [True: 0, False: 1.59k]
  ------------------
  481|      0|            p = ssh_add_to_default_algos(algo, list+1);
  482|  1.59k|        } else if (list[0] == '-') {
  ------------------
  |  Branch (482:20): [True: 0, False: 1.59k]
  ------------------
  483|      0|            p = ssh_remove_from_default_algos(algo, list+1);
  484|  1.59k|        } else if (list[0] == '^') {
  ------------------
  |  Branch (484:20): [True: 0, False: 1.59k]
  ------------------
  485|      0|            p = ssh_prefix_default_algos(algo, list+1);
  486|      0|        }
  487|  1.59k|    }
  488|       |
  489|  1.59k|    if (p == list) {
  ------------------
  |  Branch (489:9): [True: 1.59k, False: 0]
  ------------------
  490|  1.59k|        bool fips = ssh_fips_mode();
  ------------------
  |  |  117|  1.59k|#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|  1.59k|        errno = 0;
  497|       |
  498|  1.59k|        if (fips) {
  ------------------
  |  Branch (498:13): [True: 0, False: 1.59k]
  ------------------
  499|      0|            p = ssh_keep_fips_algos(algo, list);
  500|  1.59k|        } else {
  501|  1.59k|            p = ssh_keep_known_algos(algo, list);
  502|  1.59k|        }
  503|  1.59k|    }
  504|       |
  505|  1.59k|    if (p == NULL) {
  ------------------
  |  Branch (505:9): [True: 0, False: 1.59k]
  ------------------
  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|  1.59k|    SAFE_FREE(*place);
  ------------------
  |  |  375|  1.59k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 4, False: 1.59k]
  |  |  |  Branch (375:71): [Folded, False: 1.59k]
  |  |  ------------------
  ------------------
  518|  1.59k|    *place = p;
  519|       |
  520|  1.59k|    return 0;
  521|  1.59k|}
ssh_bind_options_set:
 3725|  2.25k|{
 3726|  2.25k|    bool allowed;
 3727|  2.25k|    char *p = NULL, *q = NULL;
 3728|  2.25k|    const char *v = NULL;
 3729|  2.25k|    int i, rc;
 3730|  2.25k|    char **wanted_methods = sshbind->wanted_methods;
 3731|       |
 3732|  2.25k|    if (sshbind == NULL) {
  ------------------
  |  Branch (3732:9): [True: 0, False: 2.25k]
  ------------------
 3733|      0|        return -1;
 3734|      0|    }
 3735|       |
 3736|  2.25k|    switch (type) {
 3737|      0|    case SSH_BIND_OPTIONS_RSAKEY:
  ------------------
  |  Branch (3737:5): [True: 0, False: 2.25k]
  ------------------
 3738|      0|    case SSH_BIND_OPTIONS_ECDSAKEY:
  ------------------
  |  Branch (3738:5): [True: 0, False: 2.25k]
  ------------------
 3739|       |        /* deprecated */
 3740|    660|    case SSH_BIND_OPTIONS_HOSTKEY:
  ------------------
  |  Branch (3740:5): [True: 660, False: 1.59k]
  ------------------
 3741|    660|    case SSH_BIND_OPTIONS_IMPORT_KEY:
  ------------------
  |  Branch (3741:5): [True: 0, False: 2.25k]
  ------------------
 3742|    660|    case SSH_BIND_OPTIONS_IMPORT_KEY_STR:
  ------------------
  |  Branch (3742:5): [True: 0, False: 2.25k]
  ------------------
 3743|    660|        if (value == NULL) {
  ------------------
  |  Branch (3743:13): [True: 0, False: 660]
  ------------------
 3744|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3745|      0|            return -1;
 3746|    660|        } else {
 3747|    660|            int key_type;
 3748|    660|            ssh_key *bind_key_loc = NULL;
 3749|    660|            ssh_key key = NULL;
 3750|    660|            char **bind_key_path_loc = NULL;
 3751|       |
 3752|    660|            if (type == SSH_BIND_OPTIONS_IMPORT_KEY_STR) {
  ------------------
  |  Branch (3752:17): [True: 0, False: 660]
  ------------------
 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|    660|            } else if (type == SSH_BIND_OPTIONS_IMPORT_KEY) {
  ------------------
  |  Branch (3765:24): [True: 0, False: 660]
  ------------------
 3766|      0|                key = (ssh_key)value;
 3767|    660|            } else {
 3768|    660|                rc = ssh_pki_import_privkey_file(value, NULL, NULL, NULL, &key);
 3769|    660|                if (rc != SSH_OK) {
  ------------------
  |  |  315|    660|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (3769:21): [True: 341, False: 319]
  ------------------
 3770|    341|                    return -1;
 3771|    341|                }
 3772|    660|            }
 3773|    319|            allowed = ssh_bind_key_size_allowed(sshbind, key);
 3774|    319|            if (!allowed) {
  ------------------
  |  Branch (3774:17): [True: 0, False: 319]
  ------------------
 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|    319|            key_type = ssh_key_type(key);
 3785|    319|            switch (key_type) {
 3786|      0|            case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (3786:13): [True: 0, False: 319]
  ------------------
 3787|      0|            case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (3787:13): [True: 0, False: 319]
  ------------------
 3788|      0|            case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (3788:13): [True: 0, False: 319]
  ------------------
 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|    319|            case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (3799:13): [True: 319, False: 0]
  ------------------
 3800|    319|                bind_key_loc = &sshbind->rsa;
 3801|    319|                bind_key_path_loc = &sshbind->rsakey;
 3802|    319|                break;
 3803|      0|            case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (3803:13): [True: 0, False: 319]
  ------------------
 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: 319]
  ------------------
 3808|      0|                ssh_set_error(sshbind,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 3809|    319|                              SSH_FATAL,
 3810|    319|                              "Unsupported key type %d",
 3811|    319|                              key_type);
 3812|    319|            }
 3813|    319|            if (type == SSH_BIND_OPTIONS_RSAKEY ||
  ------------------
  |  Branch (3813:17): [True: 0, False: 319]
  ------------------
 3814|    319|                type == SSH_BIND_OPTIONS_ECDSAKEY ||
  ------------------
  |  Branch (3814:17): [True: 0, False: 319]
  ------------------
 3815|    319|                type == SSH_BIND_OPTIONS_HOSTKEY) {
  ------------------
  |  Branch (3815:17): [True: 319, False: 0]
  ------------------
 3816|    319|                if (bind_key_loc == NULL) {
  ------------------
  |  Branch (3816:21): [True: 0, False: 319]
  ------------------
 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|    319|                rc = ssh_bind_set_key(sshbind, bind_key_path_loc, value);
 3823|    319|                if (rc < 0) {
  ------------------
  |  Branch (3823:21): [True: 0, False: 319]
  ------------------
 3824|      0|                    ssh_key_free(key);
 3825|      0|                    return -1;
 3826|      0|                }
 3827|    319|            } 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|    319|            ssh_key_free(*bind_key_loc);
 3838|    319|            *bind_key_loc = key;
 3839|    319|        }
 3840|    319|        break;
 3841|    319|    case SSH_BIND_OPTIONS_BINDADDR:
  ------------------
  |  Branch (3841:5): [True: 0, False: 2.25k]
  ------------------
 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: 2.25k]
  ------------------
 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: 2.25k]
  ------------------
 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|      0|    case SSH_BIND_OPTIONS_LOG_VERBOSITY:
  ------------------
  |  Branch (3883:5): [True: 0, False: 2.25k]
  ------------------
 3884|      0|        if (value == NULL) {
  ------------------
  |  Branch (3884:13): [True: 0, False: 0]
  ------------------
 3885|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3886|      0|            return -1;
 3887|      0|        } else {
 3888|      0|            int *x = (int *)value;
 3889|      0|            ssh_set_log_level(*x & 0xffffU);
 3890|      0|        }
 3891|      0|        break;
 3892|      0|    case SSH_BIND_OPTIONS_LOG_VERBOSITY_STR:
  ------------------
  |  Branch (3892:5): [True: 0, False: 2.25k]
  ------------------
 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: 2.25k]
  ------------------
 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|    319|    case SSH_BIND_OPTIONS_CIPHERS_C_S:
  ------------------
  |  Branch (3925:5): [True: 319, False: 1.93k]
  ------------------
 3926|    319|        v = value;
 3927|    319|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (3927:13): [True: 0, False: 319]
  |  Branch (3927:26): [True: 0, False: 319]
  ------------------
 3928|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3929|      0|            return -1;
 3930|    319|        } else {
 3931|    319|            rc = ssh_bind_set_algo(sshbind,
 3932|    319|                                   SSH_CRYPT_C_S,
 3933|    319|                                   v,
 3934|    319|                                   &wanted_methods[SSH_CRYPT_C_S]);
 3935|    319|            if (rc < 0) {
  ------------------
  |  Branch (3935:17): [True: 0, False: 319]
  ------------------
 3936|      0|                return -1;
 3937|      0|            }
 3938|    319|        }
 3939|    319|        break;
 3940|    319|    case SSH_BIND_OPTIONS_CIPHERS_S_C:
  ------------------
  |  Branch (3940:5): [True: 319, False: 1.93k]
  ------------------
 3941|    319|        v = value;
 3942|    319|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (3942:13): [True: 0, False: 319]
  |  Branch (3942:26): [True: 0, False: 319]
  ------------------
 3943|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3944|      0|            return -1;
 3945|    319|        } else {
 3946|    319|            rc = ssh_bind_set_algo(sshbind,
 3947|    319|                                   SSH_CRYPT_S_C,
 3948|    319|                                   v,
 3949|    319|                                   &wanted_methods[SSH_CRYPT_S_C]);
 3950|    319|            if (rc < 0) {
  ------------------
  |  Branch (3950:17): [True: 0, False: 319]
  ------------------
 3951|      0|                return -1;
 3952|      0|            }
 3953|    319|        }
 3954|    319|        break;
 3955|    319|    case SSH_BIND_OPTIONS_KEY_EXCHANGE:
  ------------------
  |  Branch (3955:5): [True: 0, False: 2.25k]
  ------------------
 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|    319|    case SSH_BIND_OPTIONS_HMAC_C_S:
  ------------------
  |  Branch (3970:5): [True: 319, False: 1.93k]
  ------------------
 3971|    319|        v = value;
 3972|    319|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (3972:13): [True: 0, False: 319]
  |  Branch (3972:26): [True: 0, False: 319]
  ------------------
 3973|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3974|      0|            return -1;
 3975|    319|        } else {
 3976|    319|            rc = ssh_bind_set_algo(sshbind,
 3977|    319|                                   SSH_MAC_C_S,
 3978|    319|                                   v,
 3979|    319|                                   &wanted_methods[SSH_MAC_C_S]);
 3980|    319|            if (rc < 0) {
  ------------------
  |  Branch (3980:17): [True: 0, False: 319]
  ------------------
 3981|      0|                return -1;
 3982|      0|            }
 3983|    319|        }
 3984|    319|        break;
 3985|    319|    case SSH_BIND_OPTIONS_HMAC_S_C:
  ------------------
  |  Branch (3985:5): [True: 319, False: 1.93k]
  ------------------
 3986|    319|        v = value;
 3987|    319|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (3987:13): [True: 0, False: 319]
  |  Branch (3987:26): [True: 0, False: 319]
  ------------------
 3988|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3989|      0|            return -1;
 3990|    319|        } else {
 3991|    319|            rc = ssh_bind_set_algo(sshbind,
 3992|    319|                                   SSH_MAC_S_C,
 3993|    319|                                   v,
 3994|    319|                                   &wanted_methods[SSH_MAC_S_C]);
 3995|    319|            if (rc < 0) {
  ------------------
  |  Branch (3995:17): [True: 0, False: 319]
  ------------------
 3996|      0|                return -1;
 3997|      0|            }
 3998|    319|        }
 3999|    319|        break;
 4000|    319|    case SSH_BIND_OPTIONS_CONFIG_DIR:
  ------------------
  |  Branch (4000:5): [True: 0, False: 2.25k]
  ------------------
 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: 2.25k]
  ------------------
 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|      0|    case SSH_BIND_OPTIONS_HOSTKEY_ALGORITHMS:
  ------------------
  |  Branch (4031:5): [True: 0, False: 2.25k]
  ------------------
 4032|      0|        v = value;
 4033|      0|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (4033:13): [True: 0, False: 0]
  |  Branch (4033:26): [True: 0, False: 0]
  ------------------
 4034|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 4035|      0|            return -1;
 4036|      0|        } else {
 4037|      0|            rc = ssh_bind_set_algo(sshbind,
 4038|      0|                                   SSH_HOSTKEYS,
 4039|      0|                                   v,
 4040|      0|                                   &wanted_methods[SSH_HOSTKEYS]);
 4041|      0|            if (rc < 0) {
  ------------------
  |  Branch (4041:17): [True: 0, False: 0]
  ------------------
 4042|      0|                return -1;
 4043|      0|            }
 4044|      0|        }
 4045|      0|        break;
 4046|    319|    case SSH_BIND_OPTIONS_PROCESS_CONFIG:
  ------------------
  |  Branch (4046:5): [True: 319, False: 1.93k]
  ------------------
 4047|    319|        if (value == NULL) {
  ------------------
  |  Branch (4047:13): [True: 0, False: 319]
  ------------------
 4048|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 4049|      0|            return -1;
 4050|    319|        } else {
 4051|    319|            bool *x = (bool *)value;
 4052|    319|            sshbind->config_processed = !(*x);
 4053|    319|        }
 4054|    319|        break;
 4055|    319|    case SSH_BIND_OPTIONS_MODULI:
  ------------------
  |  Branch (4055:5): [True: 0, False: 2.25k]
  ------------------
 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|      0|    case SSH_BIND_OPTIONS_RSA_MIN_SIZE:
  ------------------
  |  Branch (4068:5): [True: 0, False: 2.25k]
  ------------------
 4069|      0|        if (value == NULL) {
  ------------------
  |  Branch (4069:13): [True: 0, False: 0]
  ------------------
 4070|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 4071|      0|            return -1;
 4072|      0|        } else {
 4073|      0|            int *x = (int *)value;
 4074|       |
 4075|      0|            if (*x < 0) {
  ------------------
  |  Branch (4075:17): [True: 0, False: 0]
  ------------------
 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|      0|            if (*x > 0 && *x < RSA_MIN_KEY_SIZE) {
  ------------------
  |  |   49|      0|#define RSA_MIN_KEY_SIZE      1024
  ------------------
  |  Branch (4082:17): [True: 0, False: 0]
  |  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|      0|            sshbind->rsa_min_size = *x;
 4092|      0|        }
 4093|      0|        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|      0|    default:
  ------------------
  |  Branch (4123:5): [True: 0, False: 2.25k]
  ------------------
 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|  2.25k|    }
 4131|       |
 4132|  1.91k|    return 0;
 4133|  2.25k|}
options.c:ssh_bind_key_size_allowed:
 3505|    319|{
 3506|    319|    int min_size = 0;
 3507|       |
 3508|    319|    switch (ssh_key_type(key)) {
 3509|    319|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (3509:5): [True: 319, False: 0]
  ------------------
 3510|    319|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (3510:5): [True: 0, False: 319]
  ------------------
 3511|    319|        min_size = sshbind->rsa_min_size;
 3512|    319|        return ssh_key_size_allowed_rsa(min_size, key);
 3513|      0|    default:
  ------------------
  |  Branch (3513:5): [True: 0, False: 319]
  ------------------
 3514|       |        return true;
 3515|    319|    }
 3516|    319|}
options.c:ssh_bind_set_key:
 3524|    319|{
 3525|    319|    if (value == NULL) {
  ------------------
  |  Branch (3525:9): [True: 0, False: 319]
  ------------------
 3526|      0|        ssh_set_error_invalid(sshbind);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3527|      0|        return -1;
 3528|    319|    } else {
 3529|    319|        SAFE_FREE(*key_loc);
  ------------------
  |  |  375|    319|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 319]
  |  |  |  Branch (375:71): [Folded, False: 319]
  |  |  ------------------
  ------------------
 3530|    319|        *key_loc = strdup(value);
 3531|    319|        if (*key_loc == NULL) {
  ------------------
  |  Branch (3531:13): [True: 0, False: 319]
  ------------------
 3532|      0|            ssh_set_error_oom(sshbind);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 3533|      0|            return -1;
 3534|      0|        }
 3535|    319|    }
 3536|    319|    return 0;
 3537|    319|}
options.c:ssh_bind_set_algo:
 3543|  1.27k|{
 3544|       |    /* sshbind is needed only for ssh_set_error which takes void*
 3545|       |     * the typecast is only to satisfy function parameter type */
 3546|  1.27k|    return ssh_options_set_algo((ssh_session)sshbind, algo, list, place);
 3547|  1.27k|}

ssh_packet_get_current_crypto:
 1159|   150k|{
 1160|   150k|    struct ssh_crypto_struct *crypto = NULL;
 1161|       |
 1162|   150k|    if (session == NULL) {
  ------------------
  |  Branch (1162:9): [True: 0, False: 150k]
  ------------------
 1163|      0|        return NULL;
 1164|      0|    }
 1165|       |
 1166|   150k|    if (session->current_crypto != NULL &&
  ------------------
  |  Branch (1166:9): [True: 53.7k, False: 96.2k]
  ------------------
 1167|  53.7k|        session->current_crypto->used & direction) {
  ------------------
  |  Branch (1167:9): [True: 53.7k, False: 0]
  ------------------
 1168|  53.7k|        crypto = session->current_crypto;
 1169|  96.2k|    } else if (session->next_crypto != NULL &&
  ------------------
  |  Branch (1169:16): [True: 96.2k, False: 0]
  ------------------
 1170|  96.2k|               session->next_crypto->used & direction) {
  ------------------
  |  Branch (1170:16): [True: 18, False: 96.2k]
  ------------------
 1171|     18|        crypto = session->next_crypto;
 1172|  96.2k|    } else {
 1173|  96.2k|        return NULL;
 1174|  96.2k|    }
 1175|       |
 1176|  53.8k|    switch (direction) {
  ------------------
  |  Branch (1176:13): [True: 53.8k, False: 0]
  ------------------
 1177|  41.4k|    case SSH_DIRECTION_IN:
  ------------------
  |  Branch (1177:5): [True: 41.4k, False: 12.3k]
  ------------------
 1178|  41.4k|        if (crypto->in_cipher != NULL) {
  ------------------
  |  Branch (1178:13): [True: 41.4k, False: 0]
  ------------------
 1179|  41.4k|            return crypto;
 1180|  41.4k|        }
 1181|      0|        break;
 1182|  10.5k|    case SSH_DIRECTION_OUT:
  ------------------
  |  Branch (1182:5): [True: 10.5k, False: 43.2k]
  ------------------
 1183|  10.5k|        if (crypto->out_cipher != NULL) {
  ------------------
  |  Branch (1183:13): [True: 10.5k, False: 0]
  ------------------
 1184|  10.5k|            return crypto;
 1185|  10.5k|        }
 1186|      0|        break;
 1187|  1.80k|    case SSH_DIRECTION_BOTH:
  ------------------
  |  Branch (1187:5): [True: 1.80k, False: 52.0k]
  ------------------
 1188|  1.80k|        if (crypto->in_cipher != NULL &&
  ------------------
  |  Branch (1188:13): [True: 1.80k, False: 0]
  ------------------
 1189|  1.80k|            crypto->out_cipher != NULL) {
  ------------------
  |  Branch (1189:13): [True: 1.80k, False: 0]
  ------------------
 1190|  1.80k|            return crypto;
 1191|  1.80k|        }
 1192|  53.8k|    }
 1193|       |
 1194|      0|    return NULL;
 1195|  53.8k|}
ssh_packet_socket_callback:
 1287|  51.0k|{
 1288|  51.0k|    ssh_session session = (ssh_session)user;
 1289|  51.0k|    uint32_t blocksize = 8;
 1290|  51.0k|    uint32_t lenfield_blocksize = 8;
 1291|  51.0k|    size_t current_macsize = 0;
 1292|  51.0k|    uint8_t *ptr = NULL;
 1293|  51.0k|    ssize_t to_be_read;
 1294|  51.0k|    int rc;
 1295|  51.0k|    uint8_t *cleartext_packet = NULL;
 1296|  51.0k|    uint8_t *packet_second_block = NULL;
 1297|  51.0k|    uint8_t *mac = NULL;
 1298|  51.0k|    size_t packet_remaining, packet_offset;
 1299|  51.0k|    uint32_t packet_len, compsize, payloadsize;
 1300|  51.0k|    uint8_t padding;
 1301|  51.0k|    size_t processed = 0; /* number of bytes processed from the callback */
 1302|  51.0k|    enum ssh_packet_filter_result_e filter_result;
 1303|  51.0k|    struct ssh_crypto_struct *crypto = NULL;
 1304|  51.0k|    bool etm = false;
 1305|  51.0k|    uint32_t etm_packet_offset = 0;
 1306|  51.0k|    bool ok;
 1307|       |
 1308|  51.0k|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_IN);
 1309|  51.0k|    if (crypto != NULL) {
  ------------------
  |  Branch (1309:9): [True: 12.5k, False: 38.5k]
  ------------------
 1310|  12.5k|        current_macsize = hmac_digest_len(crypto->in_hmac);
 1311|  12.5k|        blocksize = crypto->in_cipher->blocksize;
 1312|  12.5k|        lenfield_blocksize = crypto->in_cipher->lenfield_blocksize;
 1313|  12.5k|        etm = crypto->in_hmac_etm;
 1314|  12.5k|    }
 1315|       |
 1316|  51.0k|    if (etm) {
  ------------------
  |  Branch (1316:9): [True: 0, False: 51.0k]
  ------------------
 1317|       |        /* In EtM mode packet size is unencrypted. This means
 1318|       |         * we need to use this offset and set the block size
 1319|       |         * that is part of the encrypted part to 0.
 1320|       |         */
 1321|      0|        etm_packet_offset = sizeof(uint32_t);
 1322|      0|        lenfield_blocksize = 0;
 1323|  51.0k|    } else if (lenfield_blocksize == 0) {
  ------------------
  |  Branch (1323:16): [True: 12.5k, False: 38.5k]
  ------------------
 1324|  12.5k|        lenfield_blocksize = blocksize;
 1325|  12.5k|    }
 1326|  51.0k|    if (data == NULL) {
  ------------------
  |  Branch (1326:9): [True: 0, False: 51.0k]
  ------------------
 1327|      0|        goto error;
 1328|      0|    }
 1329|       |
 1330|  51.0k|    if (session->session_state == SSH_SESSION_STATE_ERROR) {
  ------------------
  |  Branch (1330:9): [True: 528, False: 50.5k]
  ------------------
 1331|    528|        goto error;
 1332|    528|    }
 1333|       |#ifdef DEBUG_PACKET
 1334|       |    SSH_LOG(SSH_LOG_PACKET,
 1335|       |            "rcv packet cb (len=%zu, state=%s)",
 1336|       |            receivedlen,
 1337|       |            session->packet_state == PACKET_STATE_INIT ?
 1338|       |                "INIT" :
 1339|       |                session->packet_state == PACKET_STATE_SIZEREAD ?
 1340|       |                    "SIZE_READ" :
 1341|       |                    session->packet_state == PACKET_STATE_PROCESSING ?
 1342|       |                    "PROCESSING" : "unknown");
 1343|       |#endif
 1344|  50.5k|    switch (session->packet_state) {
  ------------------
  |  Branch (1344:13): [True: 50.5k, False: 0]
  ------------------
 1345|  49.7k|        case PACKET_STATE_INIT:
  ------------------
  |  Branch (1345:9): [True: 49.7k, False: 805]
  ------------------
 1346|  49.7k|            if (receivedlen < lenfield_blocksize + etm_packet_offset) {
  ------------------
  |  Branch (1346:17): [True: 125, False: 49.6k]
  ------------------
 1347|       |                /*
 1348|       |                 * We didn't receive enough data to read either at least one
 1349|       |                 * block size or the unencrypted length in EtM mode.
 1350|       |                 */
 1351|       |#ifdef DEBUG_PACKET
 1352|       |                SSH_LOG(SSH_LOG_PACKET,
 1353|       |                        "Waiting for more data (%zu < %u)",
 1354|       |                        receivedlen,
 1355|       |                        lenfield_blocksize);
 1356|       |#endif
 1357|    125|                return 0;
 1358|    125|            }
 1359|       |
 1360|  49.6k|            session->in_packet = (struct packet_struct) {
 1361|  49.6k|                .type = 0,
 1362|  49.6k|            };
 1363|       |
 1364|  49.6k|            if (session->in_buffer) {
  ------------------
  |  Branch (1364:17): [True: 49.6k, False: 0]
  ------------------
 1365|  49.6k|                rc = ssh_buffer_reinit(session->in_buffer);
 1366|  49.6k|                if (rc < 0) {
  ------------------
  |  Branch (1366:21): [True: 0, False: 49.6k]
  ------------------
 1367|      0|                    goto error;
 1368|      0|                }
 1369|  49.6k|            } else {
 1370|      0|                session->in_buffer = ssh_buffer_new();
 1371|      0|                if (session->in_buffer == NULL) {
  ------------------
  |  Branch (1371:21): [True: 0, False: 0]
  ------------------
 1372|      0|                    goto error;
 1373|      0|                }
 1374|      0|            }
 1375|       |
 1376|  49.6k|            if (!etm) {
  ------------------
  |  Branch (1376:17): [True: 49.6k, False: 0]
  ------------------
 1377|  49.6k|                ptr = ssh_buffer_allocate(session->in_buffer,
 1378|  49.6k|                                          lenfield_blocksize);
 1379|  49.6k|                if (ptr == NULL) {
  ------------------
  |  Branch (1379:21): [True: 0, False: 49.6k]
  ------------------
 1380|      0|                    goto error;
 1381|      0|                }
 1382|  49.6k|                packet_len = ssh_packet_decrypt_len(session, ptr,
 1383|  49.6k|                                                    (uint8_t *)data);
 1384|  49.6k|                to_be_read = packet_len - lenfield_blocksize + sizeof(uint32_t);
 1385|  49.6k|            } else {
 1386|       |                /* Length is unencrypted in case of Encrypt-then-MAC */
 1387|      0|                packet_len = PULL_BE_U32(data, 0);
  ------------------
  |  |   75|      0|    ((((uint32_t)PULL_BE_U16(data, pos)) << 16) | (uint32_t)(PULL_BE_U16(data, (pos) + 2)))
  |  |  ------------------
  |  |  |  |   72|      0|    ((((uint16_t)(PULL_BE_U8(data, pos))) << 8) | (uint16_t)PULL_BE_U8(data, (pos) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   69|      0|    (_DATA_BYTE_CONST(data, pos))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   28|      0|    ((uint8_t)(((const uint8_t *)(data))[(pos)]))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |                   ((((uint16_t)(PULL_BE_U8(data, pos))) << 8) | (uint16_t)PULL_BE_U8(data, (pos) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   69|      0|    (_DATA_BYTE_CONST(data, pos))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   28|      0|    ((uint8_t)(((const uint8_t *)(data))[(pos)]))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   ((((uint32_t)PULL_BE_U16(data, pos)) << 16) | (uint32_t)(PULL_BE_U16(data, (pos) + 2)))
  |  |  ------------------
  |  |  |  |   72|      0|    ((((uint16_t)(PULL_BE_U8(data, pos))) << 8) | (uint16_t)PULL_BE_U8(data, (pos) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   69|      0|    (_DATA_BYTE_CONST(data, pos))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   28|      0|    ((uint8_t)(((const uint8_t *)(data))[(pos)]))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |                   ((((uint16_t)(PULL_BE_U8(data, pos))) << 8) | (uint16_t)PULL_BE_U8(data, (pos) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   69|      0|    (_DATA_BYTE_CONST(data, pos))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   28|      0|    ((uint8_t)(((const uint8_t *)(data))[(pos)]))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1388|      0|                to_be_read = packet_len - etm_packet_offset;
 1389|      0|            }
 1390|       |
 1391|  49.6k|            processed += lenfield_blocksize + etm_packet_offset;
 1392|  49.6k|            if (packet_len > MAX_PACKET_LEN) {
  ------------------
  |  |  216|  49.6k|#define MAX_PACKET_LEN 262144
  ------------------
  |  Branch (1392:17): [True: 147, False: 49.4k]
  ------------------
 1393|    147|                ssh_set_error(session,
  ------------------
  |  |  313|    147|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1394|    147|                              SSH_FATAL,
 1395|    147|                              "read_packet(): Packet len too high(%" PRIu32 " %.4" PRIx32 ")",
 1396|    147|                              packet_len, packet_len);
 1397|    147|                goto error;
 1398|    147|            }
 1399|  49.4k|            if (to_be_read < 0) {
  ------------------
  |  Branch (1399:17): [True: 0, False: 49.4k]
  ------------------
 1400|       |                /* remote sshd sends invalid sizes? */
 1401|      0|                ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1402|      0|                              SSH_FATAL,
 1403|      0|                              "Given numbers of bytes left to be read < 0 (%zd)!",
 1404|      0|                              to_be_read);
 1405|      0|                goto error;
 1406|      0|            }
 1407|       |
 1408|  49.4k|            session->in_packet.len = packet_len;
 1409|  49.4k|            session->packet_state = PACKET_STATE_SIZEREAD;
 1410|  49.4k|            FALL_THROUGH;
  ------------------
  |  |  496|  49.4k|#  define FALL_THROUGH __attribute__ ((fallthrough))
  ------------------
 1411|  50.2k|        case PACKET_STATE_SIZEREAD:
  ------------------
  |  Branch (1411:9): [True: 805, False: 49.7k]
  ------------------
 1412|  50.2k|            packet_len = session->in_packet.len;
 1413|  50.2k|            packet_offset = processed = lenfield_blocksize + etm_packet_offset;
 1414|  50.2k|            to_be_read = packet_len + sizeof(uint32_t) + current_macsize;
 1415|       |            /* if to_be_read is zero, the whole packet was blocksize bytes. */
 1416|  50.2k|            if (to_be_read != 0) {
  ------------------
  |  Branch (1416:17): [True: 50.2k, False: 0]
  ------------------
 1417|  50.2k|                if (receivedlen < (unsigned long)to_be_read) {
  ------------------
  |  Branch (1417:21): [True: 838, False: 49.4k]
  ------------------
 1418|       |                    /* give up, not enough data in buffer */
 1419|    838|                    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|    838|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1420|    838|                            "packet: partial packet (read len) "
 1421|    838|                            "[len=%" PRIu32 ", receivedlen=%zu, to_be_read=%zd]",
 1422|    838|                            packet_len,
 1423|    838|                            receivedlen,
 1424|    838|                            to_be_read);
 1425|    838|                    return 0;
 1426|    838|                }
 1427|       |
 1428|  49.4k|                packet_second_block = (uint8_t*)data + packet_offset;
 1429|  49.4k|                processed = to_be_read - current_macsize;
 1430|  49.4k|            }
 1431|       |
 1432|  49.4k|            if (packet_offset - sizeof(uint32_t) > (size_t)packet_len) {
  ------------------
  |  Branch (1432:17): [True: 18, False: 49.4k]
  ------------------
 1433|     18|                ssh_set_error(session,
  ------------------
  |  |  313|     18|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1434|     18|                              SSH_FATAL,
 1435|     18|                              "Invalid packet length %" PRIu32 ", required %zu",
 1436|     18|                              packet_len,
 1437|     18|                              packet_offset + sizeof(uint32_t));
 1438|     18|                goto error;
 1439|     18|            }
 1440|       |
 1441|       |            /* remaining encrypted bytes from the packet, MAC not included */
 1442|  49.4k|            packet_remaining = packet_len - (packet_offset - sizeof(uint32_t));
 1443|  49.4k|            cleartext_packet = ssh_buffer_allocate(session->in_buffer,
 1444|  49.4k|                                                   (uint32_t)packet_remaining);
 1445|  49.4k|            if (cleartext_packet == NULL) {
  ------------------
  |  Branch (1445:17): [True: 0, False: 49.4k]
  ------------------
 1446|      0|                goto error;
 1447|      0|            }
 1448|       |
 1449|  49.4k|            if (packet_second_block != NULL) {
  ------------------
  |  Branch (1449:17): [True: 49.4k, False: 0]
  ------------------
 1450|  49.4k|                if (crypto != NULL) {
  ------------------
  |  Branch (1450:21): [True: 11.4k, False: 37.9k]
  ------------------
 1451|  11.4k|                    mac = packet_second_block + packet_remaining;
 1452|       |
 1453|  11.4k|                    if (crypto->in_hmac != SSH_HMAC_NONE && etm) {
  ------------------
  |  Branch (1453:25): [True: 0, False: 11.4k]
  |  Branch (1453:61): [True: 0, False: 0]
  ------------------
 1454|      0|                        rc = ssh_packet_hmac_verify(session,
 1455|      0|                                                    data,
 1456|      0|                                                    processed,
 1457|      0|                                                    mac,
 1458|      0|                                                    crypto->in_hmac);
 1459|      0|                        if (rc < 0) {
  ------------------
  |  Branch (1459:29): [True: 0, False: 0]
  ------------------
 1460|      0|                            ssh_set_error(session, SSH_FATAL, "HMAC error");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1461|      0|                            goto error;
 1462|      0|                        }
 1463|      0|                    }
 1464|       |                    /*
 1465|       |                     * Decrypt the packet. In case of EtM mode, the length is
 1466|       |                     * already known as it's unencrypted. In the other case,
 1467|       |                     * lenfield_blocksize bytes already have been decrypted.
 1468|       |                     */
 1469|  11.4k|                    if (packet_remaining > 0) {
  ------------------
  |  Branch (1469:25): [True: 5.50k, False: 5.97k]
  ------------------
 1470|  5.50k|                        rc = ssh_packet_decrypt(session,
 1471|  5.50k|                                                cleartext_packet,
 1472|  5.50k|                                                (uint8_t *)data,
 1473|  5.50k|                                                packet_offset,
 1474|  5.50k|                                                processed - packet_offset);
 1475|  5.50k|                        if (rc < 0) {
  ------------------
  |  Branch (1475:29): [True: 14, False: 5.49k]
  ------------------
 1476|     14|                            ssh_set_error(session,
  ------------------
  |  |  313|     14|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1477|     14|                                          SSH_FATAL,
 1478|     14|                                          "Decryption error");
 1479|     14|                            goto error;
 1480|     14|                        }
 1481|  5.50k|                    }
 1482|       |
 1483|  11.4k|                    if (crypto->in_hmac != SSH_HMAC_NONE && !etm) {
  ------------------
  |  Branch (1483:25): [True: 0, False: 11.4k]
  |  Branch (1483:61): [True: 0, False: 0]
  ------------------
 1484|      0|                        ssh_buffer in = session->in_buffer;
 1485|      0|                        rc = ssh_packet_hmac_verify(session,
 1486|      0|                                                    ssh_buffer_get(in),
 1487|      0|                                                    ssh_buffer_get_len(in),
 1488|      0|                                                    mac,
 1489|      0|                                                    crypto->in_hmac);
 1490|      0|                        if (rc < 0) {
  ------------------
  |  Branch (1490:29): [True: 0, False: 0]
  ------------------
 1491|      0|                            ssh_set_error(session, SSH_FATAL, "HMAC error");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1492|      0|                            goto error;
 1493|      0|                        }
 1494|      0|                    }
 1495|  11.4k|                    processed += current_macsize;
 1496|  37.9k|                } else {
 1497|  37.9k|                    memcpy(cleartext_packet,
 1498|  37.9k|                           packet_second_block,
 1499|  37.9k|                           packet_remaining);
 1500|  37.9k|                }
 1501|  49.4k|            }
 1502|       |
 1503|  49.4k|#ifdef WITH_PCAP
 1504|  49.4k|            if (session->pcap_ctx != NULL) {
  ------------------
  |  Branch (1504:17): [True: 0, False: 49.4k]
  ------------------
 1505|      0|                ssh_pcap_context_write(session->pcap_ctx,
 1506|      0|                                       SSH_PCAP_DIR_IN,
 1507|      0|                                       ssh_buffer_get(session->in_buffer),
 1508|      0|                                       ssh_buffer_get_len(session->in_buffer),
 1509|      0|                                       ssh_buffer_get_len(session->in_buffer));
 1510|      0|            }
 1511|  49.4k|#endif
 1512|       |
 1513|  49.4k|            if (!etm) {
  ------------------
  |  Branch (1513:17): [True: 49.4k, False: 0]
  ------------------
 1514|       |                /* skip the size field which has been processed before */
 1515|  49.4k|                ssh_buffer_pass_bytes(session->in_buffer, sizeof(uint32_t));
 1516|  49.4k|            }
 1517|       |
 1518|  49.4k|            rc = ssh_buffer_get_u8(session->in_buffer, &padding);
 1519|  49.4k|            if (rc == 0) {
  ------------------
  |  Branch (1519:17): [True: 0, False: 49.4k]
  ------------------
 1520|      0|                ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1521|      0|                              SSH_FATAL,
 1522|      0|                              "Packet too short to read padding");
 1523|      0|                goto error;
 1524|      0|            }
 1525|       |
 1526|  49.4k|            if (padding > ssh_buffer_get_len(session->in_buffer)) {
  ------------------
  |  Branch (1526:17): [True: 2, False: 49.4k]
  ------------------
 1527|      2|                ssh_set_error(session,
  ------------------
  |  |  313|      2|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1528|      2|                              SSH_FATAL,
 1529|      2|                              "Invalid padding: %d (%" PRIu32 " left)",
 1530|      2|                              padding,
 1531|      2|                              ssh_buffer_get_len(session->in_buffer));
 1532|      2|                goto error;
 1533|      2|            }
 1534|  49.4k|            ssh_buffer_pass_bytes_end(session->in_buffer, padding);
 1535|  49.4k|            compsize = ssh_buffer_get_len(session->in_buffer);
 1536|       |
 1537|  49.4k|            if (crypto && crypto->do_compress_in &&
  ------------------
  |  Branch (1537:17): [True: 11.4k, False: 37.9k]
  |  Branch (1537:27): [True: 0, False: 11.4k]
  ------------------
 1538|      0|                ssh_buffer_get_len(session->in_buffer) > 0) {
  ------------------
  |  Branch (1538:17): [True: 0, False: 0]
  ------------------
 1539|      0|                rc = decompress_buffer(session, session->in_buffer,
 1540|      0|                                       MAX_PACKET_LEN);
  ------------------
  |  |  216|      0|#define MAX_PACKET_LEN 262144
  ------------------
 1541|      0|                if (rc < 0) {
  ------------------
  |  Branch (1541:21): [True: 0, False: 0]
  ------------------
 1542|      0|                    goto error;
 1543|      0|                }
 1544|      0|            }
 1545|  49.4k|            payloadsize = ssh_buffer_get_len(session->in_buffer);
 1546|  49.4k|            if (session->recv_seq == UINT32_MAX) {
  ------------------
  |  Branch (1546:17): [True: 0, False: 49.4k]
  ------------------
 1547|       |                /* Overflowing sequence numbers is always fishy */
 1548|      0|                if (crypto == NULL) {
  ------------------
  |  Branch (1548:21): [True: 0, False: 0]
  ------------------
 1549|       |                    /* don't allow sequence number overflow when unencrypted */
 1550|      0|                    ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1551|      0|                                  SSH_FATAL,
 1552|      0|                                  "Incoming sequence number overflow");
 1553|      0|                    goto error;
 1554|      0|                } else {
 1555|      0|                    SSH_LOG(SSH_LOG_WARNING,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1556|      0|                            "Incoming sequence number overflow");
 1557|      0|                }
 1558|      0|            }
 1559|  49.4k|            session->recv_seq++;
 1560|  49.4k|            if (crypto != NULL) {
  ------------------
  |  Branch (1560:17): [True: 11.4k, False: 37.9k]
  ------------------
 1561|  11.4k|                struct ssh_cipher_struct *cipher = NULL;
 1562|       |
 1563|  11.4k|                cipher = crypto->in_cipher;
 1564|  11.4k|                cipher->packets++;
 1565|  11.4k|                cipher->blocks += payloadsize / cipher->blocksize;
 1566|  11.4k|            }
 1567|  49.4k|            if (session->raw_counter != NULL) {
  ------------------
  |  Branch (1567:17): [True: 0, False: 49.4k]
  ------------------
 1568|      0|                session->raw_counter->in_bytes += payloadsize;
 1569|      0|                session->raw_counter->in_packets++;
 1570|      0|            }
 1571|       |
 1572|       |            /*
 1573|       |             * We don't want to rewrite a new packet while still executing the
 1574|       |             * packet callbacks
 1575|       |             */
 1576|  49.4k|            session->packet_state = PACKET_STATE_PROCESSING;
 1577|  49.4k|            ssh_packet_parse_type(session);
 1578|  49.4k|            SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|  49.4k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1579|  49.4k|                    "packet: read type %hhd [len=%" PRIu32 ",padding=%hhd,"
 1580|  49.4k|                    "comp=%" PRIu32 ",payload=%" PRIu32 "]",
 1581|  49.4k|                    session->in_packet.type, packet_len, padding, compsize,
 1582|  49.4k|                    payloadsize);
 1583|  49.4k|            if (crypto == NULL) {
  ------------------
  |  Branch (1583:17): [True: 37.9k, False: 11.4k]
  ------------------
 1584|       |                /* In strict kex, only a few packets are allowed. Taint the session
 1585|       |                 * if we received packets that are normally allowed but to be
 1586|       |                 * refused if we are in strict kex when KEX is over.
 1587|       |                 */
 1588|  37.9k|                uint8_t type = session->in_packet.type;
 1589|       |
 1590|  37.9k|                if (type != SSH2_MSG_KEXINIT && type != SSH2_MSG_NEWKEYS &&
  ------------------
  |  |   12|  75.9k|#define SSH2_MSG_KEXINIT	 20
  ------------------
                              if (type != SSH2_MSG_KEXINIT && type != SSH2_MSG_NEWKEYS &&
  ------------------
  |  |   13|  75.6k|#define SSH2_MSG_NEWKEYS 21
  ------------------
  |  Branch (1590:21): [True: 37.6k, False: 256]
  |  Branch (1590:49): [True: 37.5k, False: 181]
  ------------------
 1591|  37.5k|                    (type < SSH2_MSG_KEXDH_INIT ||
  ------------------
  |  |   15|  75.0k|#define SSH2_MSG_KEXDH_INIT 30
  ------------------
  |  Branch (1591:22): [True: 33.1k, False: 4.35k]
  ------------------
 1592|  36.3k|                     type > SSH2_MSG_KEX_DH_GEX_REQUEST)) {
  ------------------
  |  |   26|  4.35k|#define SSH2_MSG_KEX_DH_GEX_REQUEST 34
  ------------------
  |  Branch (1592:22): [True: 3.21k, False: 1.14k]
  ------------------
 1593|  36.3k|                    session->flags |= SSH_SESSION_FLAG_KEX_TAINTED;
  ------------------
  |  |   92|  36.3k|#define SSH_SESSION_FLAG_KEX_TAINTED 0x0020
  ------------------
 1594|  36.3k|                }
 1595|  37.9k|            }
 1596|       |            /* Check if the packet is expected */
 1597|  49.4k|            filter_result = ssh_packet_incoming_filter(session);
 1598|       |
 1599|  49.4k|            switch (filter_result) {
  ------------------
  |  Branch (1599:21): [True: 49.4k, False: 0]
  ------------------
 1600|  35.1k|            case SSH_PACKET_ALLOWED:
  ------------------
  |  Branch (1600:13): [True: 35.1k, False: 14.2k]
  ------------------
 1601|       |                /* Execute callbacks */
 1602|  35.1k|                ssh_packet_process(session, session->in_packet.type);
 1603|  35.1k|                break;
 1604|     17|            case SSH_PACKET_DENIED:
  ------------------
  |  Branch (1604:13): [True: 17, False: 49.4k]
  ------------------
 1605|     17|                ssh_set_error(session,
  ------------------
  |  |  313|     17|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1606|     17|                              SSH_FATAL,
 1607|     17|                              "Packet filter: rejected packet (type %d)",
 1608|     17|                              session->in_packet.type);
 1609|     17|                goto error;
 1610|  14.2k|            case SSH_PACKET_UNKNOWN:
  ------------------
  |  Branch (1610:13): [True: 14.2k, False: 35.1k]
  ------------------
 1611|  14.2k|                if (crypto == NULL) {
  ------------------
  |  Branch (1611:21): [True: 9.14k, False: 5.08k]
  ------------------
 1612|  9.14k|                    session->flags |= SSH_SESSION_FLAG_KEX_TAINTED;
  ------------------
  |  |   92|  9.14k|#define SSH_SESSION_FLAG_KEX_TAINTED 0x0020
  ------------------
 1613|  9.14k|                }
 1614|  14.2k|                ssh_packet_send_unimplemented(session, session->recv_seq - 1);
 1615|  14.2k|                break;
 1616|  49.4k|            }
 1617|       |
 1618|  49.4k|            session->packet_state = PACKET_STATE_INIT;
 1619|  49.4k|            if (processed < receivedlen) {
  ------------------
  |  Branch (1619:17): [True: 49.3k, False: 21]
  ------------------
 1620|  49.3k|                SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|  49.3k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1621|  49.3k|                        "packet: %zu bytes still remaining in socket buffer "
 1622|  49.3k|                        "after processing",
 1623|  49.3k|                        receivedlen-processed);
 1624|  49.3k|            }
 1625|       |
 1626|  49.4k|            ok = ssh_packet_need_rekey(session, 0);
 1627|  49.4k|            if (ok) {
  ------------------
  |  Branch (1627:17): [True: 0, False: 49.4k]
  ------------------
 1628|      0|                SSH_LOG(SSH_LOG_PACKET, "Incoming packet triggered rekey");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1629|      0|                rc = ssh_send_rekex(session);
 1630|      0|                if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1630:21): [True: 0, False: 0]
  ------------------
 1631|      0|                    SSH_LOG(SSH_LOG_PACKET, "Rekey failed: rc = %d", rc);
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1632|      0|                    goto error;
 1633|      0|                }
 1634|      0|            }
 1635|       |
 1636|  49.4k|            return processed;
 1637|      0|        case PACKET_STATE_PROCESSING:
  ------------------
  |  Branch (1637:9): [True: 0, False: 50.5k]
  ------------------
 1638|      0|            SSH_LOG(SSH_LOG_PACKET, "Nested packet processing. Delaying.");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1639|      0|            return 0;
 1640|  50.5k|    }
 1641|       |
 1642|      0|    ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1643|      0|                  SSH_FATAL,
 1644|      0|                  "Invalid state into packet_read2(): %d",
 1645|      0|                  session->packet_state);
 1646|       |
 1647|    726|error:
 1648|    726|    session->session_state = SSH_SESSION_STATE_ERROR;
 1649|    726|    SSH_LOG(SSH_LOG_PACKET, "Packet: processed %zu bytes", processed);
  ------------------
  |  |  283|    726|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1650|    726|    return processed;
 1651|      0|}
ssh_packet_register_socket_callback:
 1680|    294|{
 1681|    294|    struct ssh_socket_callbacks_struct *callbacks = &session->socket_callbacks;
 1682|       |
 1683|    294|    callbacks->data = ssh_packet_socket_callback;
 1684|       |    callbacks->connected = NULL;
 1685|    294|    callbacks->controlflow = ssh_packet_socket_controlflow_callback;
 1686|    294|    callbacks->userdata = session;
 1687|    294|    ssh_socket_set_callbacks(s, callbacks);
 1688|    294|}
ssh_packet_set_callbacks:
 1695|    512|{
 1696|    512|    if (session->packet_callbacks == NULL) {
  ------------------
  |  Branch (1696:9): [True: 294, False: 218]
  ------------------
 1697|    294|        session->packet_callbacks = ssh_list_new();
 1698|    294|        if (session->packet_callbacks == NULL) {
  ------------------
  |  Branch (1698:13): [True: 0, False: 294]
  ------------------
 1699|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1700|      0|            return;
 1701|      0|        }
 1702|    294|    }
 1703|    512|    ssh_list_append(session->packet_callbacks, callbacks);
 1704|    512|}
ssh_packet_remove_callbacks:
 1711|    186|{
 1712|    186|    struct ssh_iterator *it = NULL;
 1713|       |
 1714|    186|    it = ssh_list_find(session->packet_callbacks, callbacks);
 1715|    186|    if (it != NULL) {
  ------------------
  |  Branch (1715:9): [True: 186, False: 0]
  ------------------
 1716|    186|        ssh_list_remove(session->packet_callbacks, it);
 1717|    186|    }
 1718|    186|}
ssh_packet_set_default_callbacks:
 1724|    294|{
 1725|    294|    struct ssh_packet_callbacks_struct *c = &session->default_packet_callbacks;
 1726|       |
 1727|    294|    c->start = 1;
 1728|    294|    c->n_callbacks = sizeof(default_packet_handlers) / sizeof(ssh_packet_callback);
 1729|    294|    c->user = session;
 1730|    294|    c->callbacks = default_packet_handlers;
 1731|    294|    ssh_packet_set_callbacks(session, c);
 1732|    294|}
ssh_packet_process:
 1739|  35.1k|{
 1740|  35.1k|    struct ssh_iterator *i = NULL;
 1741|  35.1k|    int rc = SSH_PACKET_NOT_USED;
  ------------------
  |  |  641|  35.1k|#define SSH_PACKET_NOT_USED 2
  ------------------
 1742|  35.1k|    ssh_packet_callbacks cb;
 1743|       |
 1744|  35.1k|    SSH_LOG(SSH_LOG_PACKET, "Dispatching handler for packet type %d", type);
  ------------------
  |  |  283|  35.1k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1745|  35.1k|    if (session->packet_callbacks == NULL) {
  ------------------
  |  Branch (1745:9): [True: 0, False: 35.1k]
  ------------------
 1746|      0|        SSH_LOG(SSH_LOG_RARE, "Packet callback is not initialized !");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1747|      0|        return;
 1748|      0|    }
 1749|       |
 1750|  35.1k|    i = ssh_list_get_iterator(session->packet_callbacks);
 1751|  36.3k|    while (i != NULL) {
  ------------------
  |  Branch (1751:12): [True: 36.3k, False: 6]
  ------------------
 1752|  36.3k|        cb = ssh_iterator_value(ssh_packet_callbacks, i);
  ------------------
  |  |  122|  36.3k|  ((type)((iterator)->data))
  ------------------
 1753|  36.3k|        i = i->next;
 1754|       |
 1755|  36.3k|        if (!cb) {
  ------------------
  |  Branch (1755:13): [True: 0, False: 36.3k]
  ------------------
 1756|      0|            continue;
 1757|      0|        }
 1758|       |
 1759|  36.3k|        if (cb->start > type) {
  ------------------
  |  Branch (1759:13): [True: 0, False: 36.3k]
  ------------------
 1760|      0|            continue;
 1761|      0|        }
 1762|       |
 1763|  36.3k|        if (cb->start + cb->n_callbacks <= type) {
  ------------------
  |  Branch (1763:13): [True: 6, False: 36.3k]
  ------------------
 1764|      6|            continue;
 1765|      6|        }
 1766|       |
 1767|  36.3k|        if (cb->callbacks[type - cb->start] == NULL) {
  ------------------
  |  Branch (1767:13): [True: 956, False: 35.3k]
  ------------------
 1768|    956|            continue;
 1769|    956|        }
 1770|       |
 1771|  35.3k|        rc = cb->callbacks[type - cb->start](session, type, session->in_buffer,
 1772|  35.3k|                                             cb->user);
 1773|  35.3k|        if (rc == SSH_PACKET_USED) {
  ------------------
  |  |  638|  35.3k|#define SSH_PACKET_USED 1
  ------------------
  |  Branch (1773:13): [True: 35.1k, False: 186]
  ------------------
 1774|  35.1k|            break;
 1775|  35.1k|        }
 1776|  35.3k|    }
 1777|       |
 1778|  35.1k|    if (rc == SSH_PACKET_NOT_USED) {
  ------------------
  |  |  641|  35.1k|#define SSH_PACKET_NOT_USED 2
  ------------------
  |  Branch (1778:9): [True: 6, False: 35.1k]
  ------------------
 1779|      6|        SSH_LOG(SSH_LOG_RARE, "Couldn't do anything with packet type %d", type);
  ------------------
  |  |  283|      6|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1780|      6|        rc = ssh_packet_send_unimplemented(session, session->recv_seq - 1);
 1781|      6|        if (rc != SSH_OK) {
  ------------------
  |  |  315|      6|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1781:13): [True: 0, False: 6]
  ------------------
 1782|      0|            SSH_LOG(SSH_LOG_RARE, "Failed to send unimplemented: %s",
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1783|      0|                    ssh_get_error(session));
 1784|      0|        }
 1785|      6|        if (session->current_crypto == NULL) {
  ------------------
  |  Branch (1785:13): [True: 6, False: 0]
  ------------------
 1786|      6|            session->flags |= SSH_SESSION_FLAG_KEX_TAINTED;
  ------------------
  |  |   92|      6|#define SSH_SESSION_FLAG_KEX_TAINTED 0x0020
  ------------------
 1787|      6|        }
 1788|      6|    }
 1789|  35.1k|}
ssh_packet_send_newkeys:
 1797|    185|{
 1798|    185|    int rc;
 1799|       |
 1800|       |    /* Send the MSG_NEWKEYS */
 1801|    185|    rc = ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_NEWKEYS);
  ------------------
  |  |   13|    185|#define SSH2_MSG_NEWKEYS 21
  ------------------
 1802|    185|    if (rc < 0) {
  ------------------
  |  Branch (1802:9): [True: 0, False: 185]
  ------------------
 1803|      0|        return rc;
 1804|      0|    }
 1805|       |
 1806|    185|    rc = ssh_packet_send(session);
 1807|    185|    if (rc == SSH_ERROR) {
  ------------------
  |  |  316|    185|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1807:9): [True: 0, False: 185]
  ------------------
 1808|      0|        return rc;
 1809|      0|    }
 1810|    185|    SSH_LOG(SSH_LOG_DEBUG, "SSH_MSG_NEWKEYS sent");
  ------------------
  |  |  283|    185|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1811|    185|    return rc;
 1812|    185|}
ssh_packet_send_unimplemented:
 1820|  14.2k|int ssh_packet_send_unimplemented(ssh_session session, uint32_t seqnum){
 1821|  14.2k|    int rc;
 1822|       |
 1823|  14.2k|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|  14.2k|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|  14.2k|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|  14.2k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|  14.2k|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|  14.2k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|  14.2k|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|  14.2k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1824|  14.2k|                         "bd",
 1825|  14.2k|                         SSH2_MSG_UNIMPLEMENTED,
 1826|  14.2k|                         seqnum);
 1827|  14.2k|    if (rc != SSH_OK) {
  ------------------
  |  |  315|  14.2k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1827:9): [True: 0, False: 14.2k]
  ------------------
 1828|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1829|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1830|      0|    }
 1831|  14.2k|    rc = ssh_packet_send(session);
 1832|       |
 1833|  14.2k|    return rc;
 1834|  14.2k|}
ssh_packet_unimplemented:
 1839|  12.9k|SSH_PACKET_CALLBACK(ssh_packet_unimplemented){
 1840|  12.9k|    uint32_t seq;
 1841|  12.9k|    int rc;
 1842|       |
 1843|  12.9k|    (void)session; /* unused */
 1844|  12.9k|    (void)type;
 1845|  12.9k|    (void)user;
 1846|       |
 1847|  12.9k|    rc = ssh_buffer_unpack(packet, "d", &seq);
  ------------------
  |  |   60|  12.9k|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|  12.9k|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|  12.9k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|  12.9k|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|  12.9k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|  12.9k|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|  12.9k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1848|  12.9k|    if (rc != SSH_OK) {
  ------------------
  |  |  315|  12.9k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1848:9): [True: 4.29k, False: 8.61k]
  ------------------
 1849|  4.29k|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|  4.29k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1850|  4.29k|                "Could not unpack SSH_MSG_UNIMPLEMENTED packet");
 1851|  4.29k|        return SSH_PACKET_USED;
  ------------------
  |  |  638|  4.29k|#define SSH_PACKET_USED 1
  ------------------
 1852|  4.29k|    }
 1853|       |
 1854|  8.61k|    SSH_LOG(SSH_LOG_RARE,
  ------------------
  |  |  283|  8.61k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1855|  8.61k|            "Received SSH_MSG_UNIMPLEMENTED (sequence number %" PRIu32 ")",seq);
 1856|       |
 1857|  8.61k|    return SSH_PACKET_USED;
  ------------------
  |  |  638|  8.61k|#define SSH_PACKET_USED 1
  ------------------
 1858|  12.9k|}
ssh_packet_parse_type:
 1864|  49.4k|{
 1865|  49.4k|    session->in_packet = (struct packet_struct) {
 1866|  49.4k|        .type = 0,
 1867|  49.4k|    };
 1868|       |
 1869|  49.4k|    if (session->in_buffer == NULL) {
  ------------------
  |  Branch (1869:9): [True: 0, False: 49.4k]
  ------------------
 1870|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1871|      0|    }
 1872|       |
 1873|  49.4k|    if (ssh_buffer_get_u8(session->in_buffer, &session->in_packet.type) == 0) {
  ------------------
  |  Branch (1873:9): [True: 531, False: 48.8k]
  ------------------
 1874|    531|        ssh_set_error(session, SSH_FATAL, "Packet too short to read type");
  ------------------
  |  |  313|    531|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1875|    531|        return SSH_ERROR;
  ------------------
  |  |  316|    531|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1876|    531|    }
 1877|       |
 1878|  48.8k|    session->in_packet.valid = 1;
 1879|       |
 1880|  48.8k|    return SSH_OK;
  ------------------
  |  |  315|  48.8k|#define SSH_OK 0     /* No error */
  ------------------
 1881|  49.4k|}
ssh_packet_send:
 2069|  15.1k|{
 2070|  15.1k|    uint32_t payloadsize;
 2071|  15.1k|    uint8_t type, *payload;
 2072|  15.1k|    bool need_rekey, in_rekey;
 2073|  15.1k|    int rc;
 2074|       |
 2075|  15.1k|    if (session->socket == NULL || !ssh_socket_is_open(session->socket)) {
  ------------------
  |  Branch (2075:9): [True: 0, False: 15.1k]
  |  Branch (2075:36): [True: 0, False: 15.1k]
  ------------------
 2076|      0|        ssh_buffer_reinit(session->out_buffer);
 2077|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2078|      0|    }
 2079|       |
 2080|  15.1k|    payloadsize = ssh_buffer_get_len(session->out_buffer);
 2081|  15.1k|    if (payloadsize < 1) {
  ------------------
  |  Branch (2081:9): [True: 0, False: 15.1k]
  ------------------
 2082|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2083|      0|    }
 2084|       |
 2085|  15.1k|    payload = (uint8_t *)ssh_buffer_get(session->out_buffer);
 2086|  15.1k|    type = payload[0]; /* type is the first byte of the packet now */
 2087|  15.1k|    need_rekey = ssh_packet_need_rekey(session, payloadsize);
 2088|  15.1k|    in_rekey = ssh_packet_in_rekey(session);
 2089|       |
 2090|       |    /* The rekey is triggered here. After that, only the key exchange
 2091|       |     * packets can be sent, until we send our NEWKEYS.
 2092|       |     */
 2093|  15.1k|    if (need_rekey || (in_rekey && !ssh_packet_is_kex(type))) {
  ------------------
  |  Branch (2093:9): [True: 0, False: 15.1k]
  |  Branch (2093:24): [True: 7, False: 15.1k]
  |  Branch (2093:36): [True: 0, False: 7]
  ------------------
 2094|      0|        if (need_rekey) {
  ------------------
  |  Branch (2094:13): [True: 0, False: 0]
  ------------------
 2095|      0|            SSH_LOG(SSH_LOG_PACKET, "Outgoing packet triggered rekey");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2096|      0|        }
 2097|       |        /* Queue the current packet -- we will send it after the rekey */
 2098|      0|        SSH_LOG(SSH_LOG_PACKET, "Queuing packet type %d", type);
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2099|      0|        rc = ssh_list_append(session->out_queue, session->out_buffer);
 2100|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2100:13): [True: 0, False: 0]
  ------------------
 2101|      0|            return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2102|      0|        }
 2103|      0|        session->out_buffer = ssh_buffer_new();
 2104|      0|        if (session->out_buffer == NULL) {
  ------------------
  |  Branch (2104:13): [True: 0, False: 0]
  ------------------
 2105|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2106|      0|            return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2107|      0|        }
 2108|       |
 2109|      0|        if (need_rekey) {
  ------------------
  |  Branch (2109:13): [True: 0, False: 0]
  ------------------
 2110|       |            /* Send the KEXINIT packet instead.
 2111|       |             * This recursively calls the packet_send(), but it should
 2112|       |             * not get into rekeying again.
 2113|       |             * After that we need to handle the key exchange responses
 2114|       |             * up to the point where we can send the rest of the queue.
 2115|       |             */
 2116|      0|            return ssh_send_rekex(session);
 2117|      0|        }
 2118|      0|        return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
 2119|      0|    }
 2120|       |
 2121|       |    /* Send the packet normally */
 2122|  15.1k|    rc = packet_send2(session);
 2123|       |
 2124|       |    /* We finished the key exchange so we can try to send our queue now */
 2125|  15.1k|    if (rc == SSH_OK && type == SSH2_MSG_NEWKEYS) {
  ------------------
  |  |  315|  30.3k|#define SSH_OK 0     /* No error */
  ------------------
                  if (rc == SSH_OK && type == SSH2_MSG_NEWKEYS) {
  ------------------
  |  |   13|  15.1k|#define SSH2_MSG_NEWKEYS 21
  ------------------
  |  Branch (2125:9): [True: 15.1k, False: 0]
  |  Branch (2125:25): [True: 185, False: 14.9k]
  ------------------
 2126|    185|        struct ssh_iterator *it = NULL;
 2127|       |
 2128|    185|        if (session->flags & SSH_SESSION_FLAG_KEX_STRICT) {
  ------------------
  |  |   90|    185|#define SSH_SESSION_FLAG_KEX_STRICT 0x0010
  ------------------
  |  Branch (2128:13): [True: 2, False: 183]
  ------------------
 2129|       |            /* reset packet sequence number when running in strict kex mode */
 2130|      2|            session->send_seq = 0;
 2131|      2|        }
 2132|    185|        for (it = ssh_list_get_iterator(session->out_queue);
 2133|    185|             it != NULL;
  ------------------
  |  Branch (2133:14): [True: 0, False: 185]
  ------------------
 2134|    185|             it = ssh_list_get_iterator(session->out_queue)) {
 2135|      0|            struct ssh_buffer_struct *next_buffer = NULL;
 2136|       |
 2137|       |            /* Peek only -- do not remove from queue yet */
 2138|      0|            next_buffer = ssh_iterator_value(struct ssh_buffer_struct *, it);
  ------------------
  |  |  122|      0|  ((type)((iterator)->data))
  ------------------
 2139|      0|            payloadsize = ssh_buffer_get_len(next_buffer);
 2140|      0|            if (ssh_packet_need_rekey(session, payloadsize)) {
  ------------------
  |  Branch (2140:17): [True: 0, False: 0]
  ------------------
 2141|       |                /* Sigh ... we still can not send this packet. Repeat. */
 2142|      0|                SSH_LOG(SSH_LOG_PACKET, "Queued packet triggered rekey");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2143|      0|                return ssh_send_rekex(session);
 2144|      0|            }
 2145|      0|            SSH_BUFFER_FREE(session->out_buffer);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2146|      0|            session->out_buffer = ssh_list_pop_head(struct ssh_buffer_struct *,
  ------------------
  |  |  130|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2147|      0|                                                    session->out_queue);
 2148|      0|            payload = (uint8_t *)ssh_buffer_get(session->out_buffer);
 2149|      0|            type = payload[0];
 2150|      0|            SSH_LOG(SSH_LOG_PACKET, "Dequeue packet type %d", type);
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2151|      0|            rc = packet_send2(session);
 2152|      0|            if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2152:17): [True: 0, False: 0]
  ------------------
 2153|      0|                return rc;
 2154|      0|            }
 2155|      0|        }
 2156|    185|    }
 2157|       |
 2158|  15.1k|    return rc;
 2159|  15.1k|}
ssh_packet_set_newkeys:
 2274|    365|{
 2275|    365|    struct ssh_cipher_struct *in_cipher = NULL, *out_cipher = NULL;
 2276|    365|    int rc;
 2277|       |
 2278|    365|    SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|  1.46k|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (283:34): [True: 180, False: 185]
  |  |  |  Branch (283:34): [True: 185, False: 180]
  |  |  ------------------
  ------------------
 2279|    365|            "called, direction =%s%s",
 2280|    365|            direction & SSH_DIRECTION_IN ? " IN " : "",
 2281|    365|            direction & SSH_DIRECTION_OUT ? " OUT " : "");
 2282|       |
 2283|    365|    if (session->next_crypto == NULL) {
  ------------------
  |  Branch (2283:9): [True: 0, False: 365]
  ------------------
 2284|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2285|      0|    }
 2286|       |
 2287|    365|    session->next_crypto->used |= direction;
 2288|    365|    if (session->current_crypto != NULL) {
  ------------------
  |  Branch (2288:9): [True: 0, False: 365]
  ------------------
 2289|      0|        if (session->current_crypto->used & direction) {
  ------------------
  |  Branch (2289:13): [True: 0, False: 0]
  ------------------
 2290|      0|            SSH_LOG(SSH_LOG_TRACE, "This direction isn't used anymore.");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2291|      0|        }
 2292|       |        /* Mark the current requested direction unused */
 2293|      0|        session->current_crypto->used &= ~direction;
 2294|      0|    }
 2295|       |
 2296|       |    /* Both sides switched: do the actual switch now */
 2297|    365|    if (session->next_crypto->used == SSH_DIRECTION_BOTH) {
  ------------------
  |  Branch (2297:9): [True: 180, False: 185]
  ------------------
 2298|    180|        size_t session_id_len;
 2299|       |
 2300|    180|        if (session->current_crypto != NULL) {
  ------------------
  |  Branch (2300:13): [True: 0, False: 180]
  ------------------
 2301|      0|            crypto_free(session->current_crypto);
 2302|      0|            session->current_crypto = NULL;
 2303|      0|        }
 2304|       |
 2305|    180|        session->current_crypto = session->next_crypto;
 2306|    180|        session->current_crypto->used = SSH_DIRECTION_BOTH;
 2307|       |
 2308|       |        /* Initialize the next_crypto structure */
 2309|    180|        session->next_crypto = crypto_new();
 2310|    180|        if (session->next_crypto == NULL) {
  ------------------
  |  Branch (2310:13): [True: 0, False: 180]
  ------------------
 2311|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2312|      0|            return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2313|      0|        }
 2314|       |
 2315|    180|        session_id_len = session->current_crypto->session_id_len;
 2316|    180|        session->next_crypto->session_id = malloc(session_id_len);
 2317|    180|        if (session->next_crypto->session_id == NULL) {
  ------------------
  |  Branch (2317:13): [True: 0, False: 180]
  ------------------
 2318|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2319|      0|            return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2320|      0|        }
 2321|       |
 2322|    180|        memcpy(session->next_crypto->session_id,
 2323|    180|               session->current_crypto->session_id,
 2324|    180|               session_id_len);
 2325|    180|        session->next_crypto->session_id_len = session_id_len;
 2326|       |
 2327|    180|        return SSH_OK;
  ------------------
  |  |  315|    180|#define SSH_OK 0     /* No error */
  ------------------
 2328|    180|    }
 2329|       |
 2330|       |    /* Initialize common structures so the next context can be used in
 2331|       |     * either direction */
 2332|    185|    if (session->client) {
  ------------------
  |  Branch (2332:9): [True: 0, False: 185]
  ------------------
 2333|       |        /* The server has this part already done */
 2334|      0|        rc = ssh_make_sessionid(session);
 2335|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2335:13): [True: 0, False: 0]
  ------------------
 2336|      0|            return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2337|      0|        }
 2338|       |
 2339|       |        /*
 2340|       |         * Set the cryptographic functions for the next crypto
 2341|       |         * (it is needed for ssh_generate_session_keys for key lengths)
 2342|       |         */
 2343|      0|        rc = crypt_set_algorithms_client(session);
 2344|      0|        if (rc < 0) {
  ------------------
  |  Branch (2344:13): [True: 0, False: 0]
  ------------------
 2345|      0|            return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2346|      0|        }
 2347|      0|    }
 2348|       |
 2349|    185|    if (ssh_generate_session_keys(session) < 0) {
  ------------------
  |  Branch (2349:9): [True: 0, False: 185]
  ------------------
 2350|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2351|      0|    }
 2352|       |
 2353|    185|    in_cipher = session->next_crypto->in_cipher;
 2354|    185|    out_cipher = session->next_crypto->out_cipher;
 2355|    185|    if (in_cipher == NULL || out_cipher == NULL) {
  ------------------
  |  Branch (2355:9): [True: 0, False: 185]
  |  Branch (2355:30): [True: 0, False: 185]
  ------------------
 2356|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2357|      0|    }
 2358|       |
 2359|       |    /* Initialize rekeying states */
 2360|    185|    ssh_init_rekey_state(session, out_cipher);
 2361|    185|    ssh_init_rekey_state(session, in_cipher);
 2362|    185|    if (session->opts.rekey_time != 0) {
  ------------------
  |  Branch (2362:9): [True: 0, False: 185]
  ------------------
 2363|      0|        ssh_timestamp_init(&session->last_rekey_time);
 2364|      0|        SSH_LOG(SSH_LOG_DEBUG, "Set rekey after %" PRIu32 " seconds",
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2365|      0|                session->opts.rekey_time/1000);
 2366|      0|    }
 2367|       |
 2368|    185|    if (in_cipher->set_decrypt_key) {
  ------------------
  |  Branch (2368:9): [True: 0, False: 185]
  ------------------
 2369|       |        /* Initialize the encryption and decryption keys in next_crypto */
 2370|      0|        rc = in_cipher->set_decrypt_key(in_cipher,
 2371|      0|                                        session->next_crypto->decryptkey,
 2372|      0|                                        session->next_crypto->decryptIV);
 2373|      0|        if (rc < 0) {
  ------------------
  |  Branch (2373:13): [True: 0, False: 0]
  ------------------
 2374|       |            /* On error, make sure it is not used */
 2375|      0|            session->next_crypto->used = 0;
 2376|      0|            return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2377|      0|        }
 2378|      0|    }
 2379|       |
 2380|    185|    if (out_cipher->set_encrypt_key) {
  ------------------
  |  Branch (2380:9): [True: 0, False: 185]
  ------------------
 2381|      0|        rc = out_cipher->set_encrypt_key(out_cipher,
 2382|      0|                                         session->next_crypto->encryptkey,
 2383|      0|                                         session->next_crypto->encryptIV);
 2384|      0|        if (rc < 0) {
  ------------------
  |  Branch (2384:13): [True: 0, False: 0]
  ------------------
 2385|       |            /* On error, make sure it is not used */
 2386|      0|            session->next_crypto->used = 0;
 2387|      0|            return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2388|      0|        }
 2389|      0|    }
 2390|       |
 2391|    185|    return SSH_OK;
  ------------------
  |  |  315|    185|#define SSH_OK 0     /* No error */
  ------------------
 2392|    185|}
packet.c:ssh_packet_incoming_filter:
  143|  49.4k|{
  144|  49.4k|    enum ssh_packet_filter_result_e rc;
  145|       |
  146|       |#ifdef DEBUG_PACKET
  147|       |    SSH_LOG(SSH_LOG_PACKET, "Filtering packet type %d",
  148|       |            session->in_packet.type);
  149|       |#endif
  150|       |
  151|  49.4k|    switch(session->in_packet.type) {
  152|      0|    case SSH2_MSG_DISCONNECT:                         // 1
  ------------------
  |  |    4|      0|#define SSH2_MSG_DISCONNECT 1
  ------------------
  |  Branch (152:5): [True: 0, False: 49.4k]
  ------------------
  153|       |        /*
  154|       |         * States required:
  155|       |         * - None
  156|       |         *
  157|       |         * Transitions:
  158|       |         * - session->socket->state = SSH_SOCKET_CLOSED
  159|       |         * - session->session_state = SSH_SESSION_STATE_ERROR
  160|       |         * */
  161|       |
  162|       |        /* Always allowed */
  163|      0|        rc = SSH_PACKET_ALLOWED;
  164|      0|        break;
  165|      1|    case SSH2_MSG_IGNORE:                             // 2
  ------------------
  |  |    5|      1|#define SSH2_MSG_IGNORE	 2
  ------------------
  |  Branch (165:5): [True: 1, False: 49.4k]
  ------------------
  166|       |        /*
  167|       |         * States required:
  168|       |         * - None
  169|       |         *
  170|       |         * Transitions:
  171|       |         * - None
  172|       |         * */
  173|       |
  174|       |        /* Always allowed */
  175|      1|        rc = SSH_PACKET_ALLOWED;
  176|      1|        break;
  177|  12.9k|    case SSH2_MSG_UNIMPLEMENTED:                      // 3
  ------------------
  |  |    6|  12.9k|#define SSH2_MSG_UNIMPLEMENTED 3
  ------------------
  |  Branch (177:5): [True: 12.9k, False: 36.5k]
  ------------------
  178|       |        /*
  179|       |         * States required:
  180|       |         * - None
  181|       |         *
  182|       |         * Transitions:
  183|       |         * - None
  184|       |         * */
  185|       |
  186|       |        /* Always allowed */
  187|  12.9k|        rc = SSH_PACKET_ALLOWED;
  188|  12.9k|        break;
  189|  14.3k|    case SSH2_MSG_DEBUG:                              // 4
  ------------------
  |  |    7|  14.3k|#define SSH2_MSG_DEBUG	4
  ------------------
  |  Branch (189:5): [True: 14.3k, False: 35.1k]
  ------------------
  190|       |        /*
  191|       |         * States required:
  192|       |         * - None
  193|       |         *
  194|       |         * Transitions:
  195|       |         * - None
  196|       |         * */
  197|       |
  198|       |        /* Always allowed */
  199|  14.3k|        rc = SSH_PACKET_ALLOWED;
  200|  14.3k|        break;
  201|      3|    case SSH2_MSG_SERVICE_REQUEST:                    // 5
  ------------------
  |  |    8|      3|#define SSH2_MSG_SERVICE_REQUEST	5
  ------------------
  |  Branch (201:5): [True: 3, False: 49.4k]
  ------------------
  202|       |        /* Server only */
  203|       |
  204|       |        /*
  205|       |         * States required:
  206|       |         * - session->session_state == SSH_SESSION_STATE_AUTHENTICATING
  207|       |         *   or session->session_state == SSH_SESSION_STATE_AUTHENTICATED
  208|       |         * - session->dh_handshake_state == DH_STATE_FINISHED
  209|       |         *
  210|       |         * Transitions:
  211|       |         * - None
  212|       |         * */
  213|       |
  214|       |        /* If this is a client, reject the message */
  215|      3|        if (session->client) {
  ------------------
  |  Branch (215:13): [True: 0, False: 3]
  ------------------
  216|      0|            rc = SSH_PACKET_DENIED;
  217|      0|            break;
  218|      0|        }
  219|       |
  220|      3|        if ((session->session_state != SSH_SESSION_STATE_AUTHENTICATING) &&
  ------------------
  |  Branch (220:13): [True: 1, False: 2]
  ------------------
  221|      1|            (session->session_state != SSH_SESSION_STATE_AUTHENTICATED))
  ------------------
  |  Branch (221:13): [True: 0, False: 1]
  ------------------
  222|      0|        {
  223|      0|            rc = SSH_PACKET_DENIED;
  224|      0|            break;
  225|      0|        }
  226|       |
  227|      3|        if (session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (227:13): [True: 0, False: 3]
  ------------------
  228|      0|            rc = SSH_PACKET_DENIED;
  229|      0|            break;
  230|      0|        }
  231|       |
  232|      3|        rc = SSH_PACKET_ALLOWED;
  233|      3|        break;
  234|      0|    case SSH2_MSG_SERVICE_ACCEPT:                     // 6
  ------------------
  |  |    9|      0|#define SSH2_MSG_SERVICE_ACCEPT 6
  ------------------
  |  Branch (234:5): [True: 0, False: 49.4k]
  ------------------
  235|       |        /*
  236|       |         * States required:
  237|       |         * - session->session_state == SSH_SESSION_STATE_AUTHENTICATING
  238|       |         *   or session->session_state == SSH_SESSION_STATE_AUTHENTICATED
  239|       |         * - session->dh_handshake_state == DH_STATE_FINISHED
  240|       |         * - session->auth.service_state == SSH_AUTH_SERVICE_SENT
  241|       |         *
  242|       |         * Transitions:
  243|       |         * - auth.service_state = SSH_AUTH_SERVICE_ACCEPTED
  244|       |         * */
  245|       |
  246|      0|        if ((session->session_state != SSH_SESSION_STATE_AUTHENTICATING) &&
  ------------------
  |  Branch (246:13): [True: 0, False: 0]
  ------------------
  247|      0|            (session->session_state != SSH_SESSION_STATE_AUTHENTICATED))
  ------------------
  |  Branch (247:13): [True: 0, False: 0]
  ------------------
  248|      0|        {
  249|      0|            rc = SSH_PACKET_DENIED;
  250|      0|            break;
  251|      0|        }
  252|       |
  253|      0|        if (session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (253:13): [True: 0, False: 0]
  ------------------
  254|      0|            rc = SSH_PACKET_DENIED;
  255|      0|            break;
  256|      0|        }
  257|       |
  258|       |        /* TODO check if only auth service can be requested */
  259|      0|        if (session->auth.service_state != SSH_AUTH_SERVICE_SENT) {
  ------------------
  |  Branch (259:13): [True: 0, False: 0]
  ------------------
  260|      0|            rc = SSH_PACKET_DENIED;
  261|      0|            break;
  262|      0|        }
  263|       |
  264|      0|        rc = SSH_PACKET_ALLOWED;
  265|      0|        break;
  266|    236|    case SSH2_MSG_EXT_INFO:                           // 7
  ------------------
  |  |   10|    236|#define SSH2_MSG_EXT_INFO 7
  ------------------
  |  Branch (266:5): [True: 236, False: 49.1k]
  ------------------
  267|       |        /*
  268|       |         * States required:
  269|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATING
  270|       |         *   or session->session_state == SSH_SESSION_STATE_AUTHENTICATED
  271|       |         *   (re-exchange)
  272|       |         * - dh_handshake_state == DH_STATE_FINISHED
  273|       |         *
  274|       |         * Transitions:
  275|       |         * - None
  276|       |         * */
  277|       |
  278|    236|        if ((session->session_state != SSH_SESSION_STATE_AUTHENTICATING) &&
  ------------------
  |  Branch (278:13): [True: 1, False: 235]
  ------------------
  279|      1|            (session->session_state != SSH_SESSION_STATE_AUTHENTICATED))
  ------------------
  |  Branch (279:13): [True: 1, False: 0]
  ------------------
  280|      1|        {
  281|      1|            rc = SSH_PACKET_DENIED;
  282|      1|            break;
  283|      1|        }
  284|       |
  285|    235|        if (session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (285:13): [True: 0, False: 235]
  ------------------
  286|      0|            rc = SSH_PACKET_DENIED;
  287|      0|            break;
  288|      0|        }
  289|       |
  290|    235|        rc = SSH_PACKET_ALLOWED;
  291|    235|        break;
  292|    260|    case SSH2_MSG_KEXINIT:                            // 20
  ------------------
  |  |   12|    260|#define SSH2_MSG_KEXINIT	 20
  ------------------
  |  Branch (292:5): [True: 260, False: 49.1k]
  ------------------
  293|       |        /*
  294|       |         * States required:
  295|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  296|       |         *   or session_state == SSH_SESSION_STATE_INITIAL_KEX
  297|       |         * - dh_handshake_state == DH_STATE_INIT
  298|       |         *   or dh_handshake_state == DH_STATE_INIT_SENT (re-exchange)
  299|       |         *   or dh_handshake_state == DH_STATE_REQUEST_SENT (dh-gex)
  300|       |         *   or dh_handshake_state == DH_STATE_FINISHED (re-exchange)
  301|       |         *
  302|       |         * Transitions:
  303|       |         * - session->dh_handshake_state = DH_STATE_INIT
  304|       |         * - session->session_state = SSH_SESSION_STATE_KEXINIT_RECEIVED
  305|       |         *
  306|       |         * On server:
  307|       |         * - session->session_state = SSH_SESSION_STATE_DH
  308|       |         * */
  309|       |
  310|    260|        if ((session->session_state != SSH_SESSION_STATE_AUTHENTICATED) &&
  ------------------
  |  Branch (310:13): [True: 256, False: 4]
  ------------------
  311|    256|            (session->session_state != SSH_SESSION_STATE_INITIAL_KEX))
  ------------------
  |  Branch (311:13): [True: 0, False: 256]
  ------------------
  312|      0|        {
  313|      0|            rc = SSH_PACKET_DENIED;
  314|      0|            break;
  315|      0|        }
  316|       |
  317|    260|        if ((session->dh_handshake_state != DH_STATE_INIT) &&
  ------------------
  |  Branch (317:13): [True: 4, False: 256]
  ------------------
  318|      4|            (session->dh_handshake_state != DH_STATE_INIT_SENT) &&
  ------------------
  |  Branch (318:13): [True: 4, False: 0]
  ------------------
  319|      4|            (session->dh_handshake_state != DH_STATE_REQUEST_SENT) &&
  ------------------
  |  Branch (319:13): [True: 4, False: 0]
  ------------------
  320|      4|            (session->dh_handshake_state != DH_STATE_FINISHED))
  ------------------
  |  Branch (320:13): [True: 0, False: 4]
  ------------------
  321|      0|        {
  322|      0|            rc = SSH_PACKET_DENIED;
  323|      0|            break;
  324|      0|        }
  325|       |
  326|    260|        rc = SSH_PACKET_ALLOWED;
  327|    260|        break;
  328|    182|    case SSH2_MSG_NEWKEYS:                            // 21
  ------------------
  |  |   13|    182|#define SSH2_MSG_NEWKEYS 21
  ------------------
  |  Branch (328:5): [True: 182, False: 49.2k]
  ------------------
  329|       |        /*
  330|       |         * States required:
  331|       |         * - session_state == SSH_SESSION_STATE_DH
  332|       |         * - dh_handshake_state == DH_STATE_NEWKEYS_SENT
  333|       |         *
  334|       |         * Transitions:
  335|       |         * - session->dh_handshake_state = DH_STATE_FINISHED
  336|       |         * - session->session_state = SSH_SESSION_STATE_AUTHENTICATING
  337|       |         * if session->flags & SSH_SESSION_FLAG_AUTHENTICATED
  338|       |         * - session->session_state = SSH_SESSION_STATE_AUTHENTICATED
  339|       |         * */
  340|       |
  341|       |        /* If DH has not been started, reject message */
  342|    182|        if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (342:13): [True: 2, False: 180]
  ------------------
  343|      2|            rc = SSH_PACKET_DENIED;
  344|      2|            break;
  345|      2|        }
  346|       |
  347|       |        /* Only allowed if dh_handshake_state is in NEWKEYS_SENT state */
  348|    180|        if (session->dh_handshake_state != DH_STATE_NEWKEYS_SENT) {
  ------------------
  |  Branch (348:13): [True: 0, False: 180]
  ------------------
  349|      0|            rc = SSH_PACKET_DENIED;
  350|      0|            break;
  351|      0|        }
  352|       |
  353|    180|        rc = SSH_PACKET_ALLOWED;
  354|    180|        break;
  355|    186|    case SSH2_MSG_KEXDH_INIT:                         // 30
  ------------------
  |  |   15|    186|#define SSH2_MSG_KEXDH_INIT 30
  ------------------
  |  Branch (355:5): [True: 186, False: 49.2k]
  ------------------
  356|       |      // SSH2_MSG_KEX_ECDH_INIT:                      // 30
  357|       |      // SSH2_MSG_KEX_HYBRID_INIT:                    // 30
  358|       |      // SSH2_MSG_KEX_DH_GEX_REQUEST_OLD:             // 30
  359|       |
  360|       |        /* Server only */
  361|       |
  362|       |        /*
  363|       |         * States required:
  364|       |         * - session_state == SSH_SESSION_STATE_DH
  365|       |         * - dh_handshake_state == DH_STATE_INIT
  366|       |         *
  367|       |         * Transitions:
  368|       |         * - session->dh_handshake_state = DH_STATE_INIT_SENT
  369|       |         * then calls dh_handshake_server which triggers:
  370|       |         * - session->dh_handshake_state = DH_STATE_NEWKEYS_SENT
  371|       |         * */
  372|       |
  373|    186|        if (session->client) {
  ------------------
  |  Branch (373:13): [True: 0, False: 186]
  ------------------
  374|      0|            rc = SSH_PACKET_DENIED;
  375|      0|            break;
  376|      0|        }
  377|       |
  378|    186|        if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (378:13): [True: 0, False: 186]
  ------------------
  379|      0|            rc = SSH_PACKET_DENIED;
  380|      0|            break;
  381|      0|        }
  382|       |
  383|       |        /* Only allowed if dh_handshake_state is in initial state */
  384|    186|        if (session->dh_handshake_state != DH_STATE_INIT) {
  ------------------
  |  Branch (384:13): [True: 0, False: 186]
  ------------------
  385|      0|            rc = SSH_PACKET_DENIED;
  386|      0|            break;
  387|      0|        }
  388|       |
  389|    186|        rc = SSH_PACKET_ALLOWED;
  390|    186|        break;
  391|      1|    case SSH2_MSG_KEXDH_REPLY:                        // 31
  ------------------
  |  |   16|      1|#define SSH2_MSG_KEXDH_REPLY 31
  ------------------
  |  Branch (391:5): [True: 1, False: 49.4k]
  ------------------
  392|       |      // SSH2_MSG_KEX_ECDH_REPLY:                     // 31
  393|       |      // SSH2_MSG_KEX_HYBRID_REPLY:                   // 31
  394|       |      // SSH2_MSG_KEX_DH_GEX_GROUP:                   // 31
  395|       |
  396|       |        /* Client only */
  397|       |
  398|       |        /*
  399|       |         * States required:
  400|       |         * - session_state == SSH_SESSION_STATE_DH
  401|       |         * - dh_handshake_state == DH_STATE_INIT_SENT
  402|       |         *   or dh_handshake_state == DH_STATE_REQUEST_SENT (dh-gex)
  403|       |         *
  404|       |         * Transitions:
  405|       |         * - session->dh_handshake_state = DH_STATE_NEWKEYS_SENT
  406|       |         * */
  407|       |
  408|      1|        if (session->server) {
  ------------------
  |  Branch (408:13): [True: 1, False: 0]
  ------------------
  409|      1|            rc = SSH_PACKET_DENIED;
  410|      1|            break;
  411|      1|        }
  412|       |
  413|      0|        if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (413:13): [True: 0, False: 0]
  ------------------
  414|      0|            rc = SSH_PACKET_DENIED;
  415|      0|            break;
  416|      0|        }
  417|       |
  418|      0|        if (session->dh_handshake_state != DH_STATE_INIT_SENT &&
  ------------------
  |  Branch (418:13): [True: 0, False: 0]
  ------------------
  419|      0|            session->dh_handshake_state != DH_STATE_REQUEST_SENT) {
  ------------------
  |  Branch (419:13): [True: 0, False: 0]
  ------------------
  420|      0|            rc = SSH_PACKET_DENIED;
  421|      0|            break;
  422|      0|        }
  423|       |
  424|      0|        rc = SSH_PACKET_ALLOWED;
  425|      0|        break;
  426|      2|    case SSH2_MSG_KEX_DH_GEX_INIT:                    // 32
  ------------------
  |  |   24|      2|#define SSH2_MSG_KEX_DH_GEX_INIT 32
  ------------------
  |  Branch (426:5): [True: 2, False: 49.4k]
  ------------------
  427|       |      // SSH2_MSG_KEXGSS_COMPLETE:                    // 32
  428|      2|        if (ssh_kex_is_gss(session->next_crypto)) {
  ------------------
  |  Branch (428:13): [True: 0, False: 2]
  ------------------
  429|       |            /* SSH2_MSG_KEXGSS_COMPLETE */
  430|       |            /* Client only */
  431|       |
  432|       |            /*
  433|       |             * States required:
  434|       |             * - session_state == SSH_SESSION_STATE_DH
  435|       |             * - dh_handshake_state == DH_STATE_INIT_SENT
  436|       |             *
  437|       |             * Transitions:
  438|       |             * - session->dh_handshake_state = DH_STATE_INIT_SENT
  439|       |             * then calls ssh_packet_client_gss_kex_reply which triggers:
  440|       |             * - session->dh_handshake_state = DH_STATE_NEWKEYS_SENT
  441|       |             * */
  442|       |
  443|      0|            if (!session->client) {
  ------------------
  |  Branch (443:17): [True: 0, False: 0]
  ------------------
  444|      0|                rc = SSH_PACKET_DENIED;
  445|      0|                break;
  446|      0|            }
  447|       |
  448|      0|            if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (448:17): [True: 0, False: 0]
  ------------------
  449|      0|                rc = SSH_PACKET_DENIED;
  450|      0|                break;
  451|      0|            }
  452|       |
  453|      0|            if (session->dh_handshake_state != DH_STATE_INIT_SENT) {
  ------------------
  |  Branch (453:17): [True: 0, False: 0]
  ------------------
  454|      0|                rc = SSH_PACKET_DENIED;
  455|      0|                break;
  456|      0|            }
  457|      2|        } else {
  458|       |            /* SSH2_MSG_KEX_DH_GEX_INIT */
  459|       |            /* Server only */
  460|       |
  461|       |            /*
  462|       |             * States required:
  463|       |             * - session_state == SSH_SESSION_STATE_DH
  464|       |             * - dh_handshake_state == DH_STATE_GROUP_SENT
  465|       |             *
  466|       |             * Transitions:
  467|       |             * - session->dh_handshake_state = DH_STATE_GROUP_SENT
  468|       |             * then calls ssh_packet_server_dhgex_init which triggers:
  469|       |             * - session->dh_handshake_state = DH_STATE_NEWKEYS_SENT
  470|       |             * */
  471|       |
  472|      2|            if (session->client) {
  ------------------
  |  Branch (472:17): [True: 0, False: 2]
  ------------------
  473|      0|                rc = SSH_PACKET_DENIED;
  474|      0|                break;
  475|      0|            }
  476|       |
  477|      2|            if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (477:17): [True: 2, False: 0]
  ------------------
  478|      2|                rc = SSH_PACKET_DENIED;
  479|      2|                break;
  480|      2|            }
  481|       |
  482|       |            /* Only allowed if dh_handshake_state is in initial state */
  483|      0|            if (session->dh_handshake_state != DH_STATE_GROUP_SENT) {
  ------------------
  |  Branch (483:17): [True: 0, False: 0]
  ------------------
  484|      0|                rc = SSH_PACKET_DENIED;
  485|      0|                break;
  486|      0|            }
  487|      0|        }
  488|      0|        rc = SSH_PACKET_ALLOWED;
  489|      0|        break;
  490|      0|    case SSH2_MSG_KEX_DH_GEX_REPLY:                   // 33
  ------------------
  |  |   25|      0|#define SSH2_MSG_KEX_DH_GEX_REPLY 33
  ------------------
  |  Branch (490:5): [True: 0, False: 49.4k]
  ------------------
  491|       |
  492|       |        /* Client only */
  493|       |
  494|       |        /*
  495|       |         * States required:
  496|       |         * - session_state == SSH_SESSION_STATE_DH
  497|       |         * - dh_handshake_state == DH_STATE_INIT_SENT
  498|       |         *
  499|       |         * Transitions:
  500|       |         * - session->dh_handshake_state = DH_STATE_NEWKEYS_SENT
  501|       |         * */
  502|       |
  503|      0|        if (session->server) {
  ------------------
  |  Branch (503:13): [True: 0, False: 0]
  ------------------
  504|      0|            rc = SSH_PACKET_DENIED;
  505|      0|            break;
  506|      0|        }
  507|       |
  508|      0|        if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (508:13): [True: 0, False: 0]
  ------------------
  509|      0|            rc = SSH_PACKET_DENIED;
  510|      0|            break;
  511|      0|        }
  512|       |
  513|      0|        if (session->dh_handshake_state != DH_STATE_INIT_SENT) {
  ------------------
  |  Branch (513:13): [True: 0, False: 0]
  ------------------
  514|      0|            rc = SSH_PACKET_DENIED;
  515|      0|            break;
  516|      0|        }
  517|       |
  518|      0|        rc = SSH_PACKET_ALLOWED;
  519|      0|        break;
  520|    957|    case SSH2_MSG_KEX_DH_GEX_REQUEST:                 // 34
  ------------------
  |  |   26|    957|#define SSH2_MSG_KEX_DH_GEX_REQUEST 34
  ------------------
  |  Branch (520:5): [True: 957, False: 48.4k]
  ------------------
  521|       |
  522|       |        /* Server only */
  523|       |
  524|       |        /*
  525|       |         * States required:
  526|       |         * - session_state == SSH_SESSION_STATE_DH
  527|       |         * - dh_handshake_state == DH_STATE_INIT
  528|       |         *
  529|       |         * Transitions:
  530|       |         * - session->dh_handshake_state = DH_STATE_INIT_SENT
  531|       |         * then calls ssh_packet_server_dhgex_request which triggers:
  532|       |         * - session->dh_handshake_state = DH_STATE_GROUP_SENT
  533|       |         * */
  534|       |
  535|    957|        if (session->client) {
  ------------------
  |  Branch (535:13): [True: 0, False: 957]
  ------------------
  536|      0|            rc = SSH_PACKET_DENIED;
  537|      0|            break;
  538|      0|        }
  539|       |
  540|    957|        if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (540:13): [True: 1, False: 956]
  ------------------
  541|      1|            rc = SSH_PACKET_DENIED;
  542|      1|            break;
  543|      1|        }
  544|       |
  545|       |        /* Only allowed if dh_handshake_state is in initial state */
  546|    956|        if (session->dh_handshake_state != DH_STATE_INIT) {
  ------------------
  |  Branch (546:13): [True: 0, False: 956]
  ------------------
  547|      0|            rc = SSH_PACKET_DENIED;
  548|      0|            break;
  549|      0|        }
  550|       |
  551|    956|        rc = SSH_PACKET_ALLOWED;
  552|    956|        break;
  553|  5.26k|    case SSH2_MSG_USERAUTH_REQUEST:                   // 50
  ------------------
  |  |   36|  5.26k|#define SSH2_MSG_USERAUTH_REQUEST 50
  ------------------
  |  Branch (553:5): [True: 5.26k, False: 44.1k]
  ------------------
  554|       |        /* Server only */
  555|       |
  556|       |        /*
  557|       |         * States required:
  558|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATING
  559|       |         * - dh_handshake_state == DH_STATE_FINISHED
  560|       |         *
  561|       |         * Transitions:
  562|       |         * - if authentication was successful:
  563|       |         *   - session_state = SSH_SESSION_STATE_AUTHENTICATED
  564|       |         * */
  565|       |
  566|       |        /* If this is a client, reject the message */
  567|  5.26k|        if (session->client) {
  ------------------
  |  Branch (567:13): [True: 0, False: 5.26k]
  ------------------
  568|      0|            rc = SSH_PACKET_DENIED;
  569|      0|            break;
  570|      0|        }
  571|       |
  572|  5.26k|        if (session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (572:13): [True: 1, False: 5.26k]
  ------------------
  573|      1|            rc = SSH_PACKET_DENIED;
  574|      1|            break;
  575|      1|        }
  576|       |
  577|  5.26k|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATING) {
  ------------------
  |  Branch (577:13): [True: 1, False: 5.26k]
  ------------------
  578|      1|            rc = SSH_PACKET_DENIED;
  579|      1|            break;
  580|      1|        }
  581|       |
  582|  5.26k|        rc = SSH_PACKET_ALLOWED;
  583|  5.26k|        break;
  584|      0|    case SSH2_MSG_USERAUTH_FAILURE:                   // 51
  ------------------
  |  |   37|      0|#define SSH2_MSG_USERAUTH_FAILURE 51
  ------------------
  |  Branch (584:5): [True: 0, False: 49.4k]
  ------------------
  585|       |        /*
  586|       |         * States required:
  587|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATING
  588|       |         * - dh_handshake_state == DH_STATE_FINISHED
  589|       |         * - session->auth.state == SSH_AUTH_STATE_KBDINT_SENT
  590|       |         *   or session->auth.state == SSH_AUTH_STATE_PUBKEY_OFFER_SENT
  591|       |         *   or session->auth.state == SSH_AUTH_STATE_PUBKEY_AUTH_SENT
  592|       |         *   or session->auth.state == SSH_AUTH_STATE_PASSWORD_AUTH_SENT
  593|       |         *   or session->auth.state == SSH_AUTH_STATE_GSSAPI_MIC_SENT
  594|       |         *
  595|       |         * Transitions:
  596|       |         * - if unpacking failed:
  597|       |         *   - session->auth.state = SSH_AUTH_ERROR
  598|       |         * - if failure was partial:
  599|       |         *   - session->auth.state = SSH_AUTH_PARTIAL
  600|       |         * - else:
  601|       |         *   - session->auth.state = SSH_AUTH_STATE_FAILED
  602|       |         * */
  603|       |
  604|       |        /* If this is a server, reject the message */
  605|      0|        if (session->server) {
  ------------------
  |  Branch (605:13): [True: 0, False: 0]
  ------------------
  606|      0|            rc = SSH_PACKET_DENIED;
  607|      0|            break;
  608|      0|        }
  609|       |
  610|      0|        if (session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (610:13): [True: 0, False: 0]
  ------------------
  611|      0|            rc = SSH_PACKET_DENIED;
  612|      0|            break;
  613|      0|        }
  614|       |
  615|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATING) {
  ------------------
  |  Branch (615:13): [True: 0, False: 0]
  ------------------
  616|      0|            rc = SSH_PACKET_DENIED;
  617|      0|            break;
  618|      0|        }
  619|       |
  620|      0|        rc = SSH_PACKET_ALLOWED;
  621|      0|        break;
  622|      1|    case SSH2_MSG_USERAUTH_SUCCESS:                   // 52
  ------------------
  |  |   38|      1|#define SSH2_MSG_USERAUTH_SUCCESS 52
  ------------------
  |  Branch (622:5): [True: 1, False: 49.4k]
  ------------------
  623|       |        /*
  624|       |         * States required:
  625|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATING
  626|       |         * - dh_handshake_state == DH_STATE_FINISHED
  627|       |         * - session->auth.state == SSH_AUTH_STATE_KBDINT_SENT
  628|       |         *   or session->auth.state == SSH_AUTH_STATE_PUBKEY_AUTH_SENT
  629|       |         *   or session->auth.state == SSH_AUTH_STATE_PASSWORD_AUTH_SENT
  630|       |         *   or session->auth.state == SSH_AUTH_STATE_GSSAPI_MIC_SENT
  631|       |         *   or session->auth.state == SSH_AUTH_STATE_GSSAPI_KEYEX_MIC_SENT
  632|       |         *   or session->auth.state == SSH_AUTH_STATE_AUTH_NONE_SENT
  633|       |         *
  634|       |         * Transitions:
  635|       |         * - session->auth.state = SSH_AUTH_STATE_SUCCESS
  636|       |         * - session->session_state = SSH_SESSION_STATE_AUTHENTICATED
  637|       |         * - session->flags |= SSH_SESSION_FLAG_AUTHENTICATED
  638|       |         * - sessions->auth.current_method = SSH_AUTH_METHOD_UNKNOWN
  639|       |         * */
  640|       |
  641|       |        /* If this is a server, reject the message */
  642|      1|        if (session->server) {
  ------------------
  |  Branch (642:13): [True: 1, False: 0]
  ------------------
  643|      1|            rc = SSH_PACKET_DENIED;
  644|      1|            break;
  645|      1|        }
  646|       |
  647|      0|        if (session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (647:13): [True: 0, False: 0]
  ------------------
  648|      0|            rc = SSH_PACKET_DENIED;
  649|      0|            break;
  650|      0|        }
  651|       |
  652|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATING) {
  ------------------
  |  Branch (652:13): [True: 0, False: 0]
  ------------------
  653|      0|            rc = SSH_PACKET_DENIED;
  654|      0|            break;
  655|      0|        }
  656|       |
  657|      0|        if ((session->auth.state != SSH_AUTH_STATE_KBDINT_SENT) &&
  ------------------
  |  Branch (657:13): [True: 0, False: 0]
  ------------------
  658|      0|            (session->auth.state != SSH_AUTH_STATE_PUBKEY_AUTH_SENT) &&
  ------------------
  |  Branch (658:13): [True: 0, False: 0]
  ------------------
  659|      0|            (session->auth.state != SSH_AUTH_STATE_PASSWORD_AUTH_SENT) &&
  ------------------
  |  Branch (659:13): [True: 0, False: 0]
  ------------------
  660|      0|            (session->auth.state != SSH_AUTH_STATE_GSSAPI_MIC_SENT) &&
  ------------------
  |  Branch (660:13): [True: 0, False: 0]
  ------------------
  661|      0|            (session->auth.state != SSH_AUTH_STATE_GSSAPI_KEYEX_MIC_SENT) &&
  ------------------
  |  Branch (661:13): [True: 0, False: 0]
  ------------------
  662|      0|            (session->auth.state != SSH_AUTH_STATE_AUTH_NONE_SENT)) {
  ------------------
  |  Branch (662:13): [True: 0, False: 0]
  ------------------
  663|      0|            rc = SSH_PACKET_DENIED;
  664|      0|            break;
  665|      0|        }
  666|       |
  667|      0|        rc = SSH_PACKET_ALLOWED;
  668|      0|        break;
  669|    560|    case SSH2_MSG_USERAUTH_BANNER:                    // 53
  ------------------
  |  |   39|    560|#define SSH2_MSG_USERAUTH_BANNER 53
  ------------------
  |  Branch (669:5): [True: 560, False: 48.8k]
  ------------------
  670|       |        /*
  671|       |         * States required:
  672|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATING
  673|       |         *
  674|       |         * Transitions:
  675|       |         * - None
  676|       |         * */
  677|       |
  678|    560|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATING) {
  ------------------
  |  Branch (678:13): [True: 0, False: 560]
  ------------------
  679|      0|            rc = SSH_PACKET_DENIED;
  680|      0|            break;
  681|      0|        }
  682|       |
  683|    560|        rc = SSH_PACKET_ALLOWED;
  684|    560|        break;
  685|      0|    case SSH2_MSG_USERAUTH_PK_OK:                     // 60
  ------------------
  |  |   40|      0|#define SSH2_MSG_USERAUTH_PK_OK 60
  ------------------
  |  Branch (685:5): [True: 0, False: 49.4k]
  ------------------
  686|       |      // SSH2_MSG_USERAUTH_PASSWD_CHANGEREQ:          // 60
  687|       |      // SSH2_MSG_USERAUTH_INFO_REQUEST:              // 60
  688|       |      // SSH2_MSG_USERAUTH_GSSAPI_RESPONSE:           // 60
  689|       |
  690|       |        /*
  691|       |         * States required:
  692|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATING
  693|       |         * - session->auth.state == SSH_AUTH_STATE_KBDINT_SENT
  694|       |         *   or
  695|       |         *   session->auth.state == SSH_AUTH_STATE_GSSAPI_REQUEST_SENT
  696|       |         *   or
  697|       |         *   session->auth.state == SSH_AUTH_STATE_PUBKEY_OFFER_SENT
  698|       |         *
  699|       |         * Transitions:
  700|       |         * Depending on the current state, the message is treated
  701|       |         * differently:
  702|       |         * - session->auth.state == SSH_AUTH_STATE_KBDINT_SENT
  703|       |         *   - session->auth.state = SSH_AUTH_STATE_INFO
  704|       |         * - session->auth.state == SSH_AUTH_STATE_GSSAPI_REQUEST_SENT
  705|       |         *   - session->auth.state = SSH_AUTH_STATE_GSSAPI_TOKEN
  706|       |         * - session->auth.state == SSH_AUTH_STATE_PUBKEY_OFFER_SENT
  707|       |         *   - session->auth.state = SSH_AUTH_STATE_PK_OK
  708|       |         * */
  709|       |
  710|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATING) {
  ------------------
  |  Branch (710:13): [True: 0, False: 0]
  ------------------
  711|      0|            rc = SSH_PACKET_DENIED;
  712|      0|            break;
  713|      0|        }
  714|       |
  715|      0|        if ((session->auth.state != SSH_AUTH_STATE_KBDINT_SENT) &&
  ------------------
  |  Branch (715:13): [True: 0, False: 0]
  ------------------
  716|      0|            (session->auth.state != SSH_AUTH_STATE_PUBKEY_OFFER_SENT) &&
  ------------------
  |  Branch (716:13): [True: 0, False: 0]
  ------------------
  717|      0|            (session->auth.state != SSH_AUTH_STATE_GSSAPI_REQUEST_SENT))
  ------------------
  |  Branch (717:13): [True: 0, False: 0]
  ------------------
  718|      0|        {
  719|      0|            rc = SSH_PACKET_DENIED;
  720|      0|            break;
  721|      0|        }
  722|       |
  723|      0|        rc = SSH_PACKET_ALLOWED;
  724|      0|        break;
  725|      0|    case SSH2_MSG_USERAUTH_INFO_RESPONSE:             // 61
  ------------------
  |  |   44|      0|#define SSH2_MSG_USERAUTH_INFO_RESPONSE 61
  ------------------
  |  Branch (725:5): [True: 0, False: 49.4k]
  ------------------
  726|       |      // SSH2_MSG_USERAUTH_GSSAPI_TOKEN:              // 61
  727|       |
  728|       |        /*
  729|       |         * States required:
  730|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATING
  731|       |         * - session_state->auth.state == SSH_SESSION_STATE_GSSAPI_TOKEN
  732|       |         *   or
  733|       |         *   session_state->auth.state == SSH_SESSION_STATE_INFO
  734|       |         *
  735|       |         * Transitions:
  736|       |         * - None
  737|       |         * */
  738|       |
  739|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATING) {
  ------------------
  |  Branch (739:13): [True: 0, False: 0]
  ------------------
  740|      0|            rc = SSH_PACKET_DENIED;
  741|      0|            break;
  742|      0|        }
  743|       |
  744|      0|        if ((session->auth.state != SSH_AUTH_STATE_INFO) &&
  ------------------
  |  Branch (744:13): [True: 0, False: 0]
  ------------------
  745|      0|            (session->auth.state != SSH_AUTH_STATE_GSSAPI_TOKEN))
  ------------------
  |  Branch (745:13): [True: 0, False: 0]
  ------------------
  746|      0|        {
  747|      0|            rc = SSH_PACKET_DENIED;
  748|      0|            break;
  749|      0|        }
  750|       |
  751|      0|        rc = SSH_PACKET_ALLOWED;
  752|      0|        break;
  753|      0|    case SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE:  // 63
  ------------------
  |  |   46|      0|#define SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE 63
  ------------------
  |  Branch (753:5): [True: 0, False: 49.4k]
  ------------------
  754|       |        /* Server only */
  755|       |        /*
  756|       |         * States required:
  757|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATING
  758|       |         * - session->gssapi->state == SSH_GSSAPI_STATE_RCV_MIC
  759|       |         *
  760|       |         * Transitions:
  761|       |         * - None
  762|       |         */
  763|       |#ifdef WITH_GSSAPI
  764|       |        if (session->client) {
  765|       |            rc = SSH_PACKET_DENIED;
  766|       |            break;
  767|       |        }
  768|       |        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATING) {
  769|       |            rc = SSH_PACKET_DENIED;
  770|       |            break;
  771|       |        }
  772|       |        if (session->gssapi == NULL) {
  773|       |            rc = SSH_PACKET_DENIED;
  774|       |            break;
  775|       |        }
  776|       |        if (session->gssapi->state != SSH_GSSAPI_STATE_RCV_MIC) {
  777|       |            rc = SSH_PACKET_DENIED;
  778|       |            break;
  779|       |        }
  780|       |        rc = SSH_PACKET_ALLOWED;
  781|       |        break;
  782|       |#else
  783|      0|        rc = SSH_PACKET_DENIED;
  784|      0|        break;
  785|      0|#endif  /* WITH_GSSAPI */
  786|      0|    case SSH2_MSG_USERAUTH_GSSAPI_ERROR:              // 64
  ------------------
  |  |   47|      0|#define SSH2_MSG_USERAUTH_GSSAPI_ERROR 64
  ------------------
  |  Branch (786:5): [True: 0, False: 49.4k]
  ------------------
  787|       |        /* Client only */
  788|       |        /*
  789|       |         * States required:
  790|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATING
  791|       |         *
  792|       |         * Transitions:
  793|       |         * - None
  794|       |         */
  795|       |#ifdef WITH_GSSAPI
  796|       |        if (session->server) {
  797|       |            rc = SSH_PACKET_DENIED;
  798|       |            break;
  799|       |        }
  800|       |        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATING) {
  801|       |            rc = SSH_PACKET_DENIED;
  802|       |            break;
  803|       |        }
  804|       |
  805|       |        rc = SSH_PACKET_ALLOWED;
  806|       |        break;
  807|       |#else
  808|      0|        rc = SSH_PACKET_DENIED;
  809|      0|        break;
  810|      0|#endif  /* WITH_GSSAPI */
  811|      1|    case SSH2_MSG_USERAUTH_GSSAPI_ERRTOK:             // 65
  ------------------
  |  |   48|      1|#define SSH2_MSG_USERAUTH_GSSAPI_ERRTOK 65
  ------------------
  |  Branch (811:5): [True: 1, False: 49.4k]
  ------------------
  812|       |        /*
  813|       |         * States required:
  814|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATING
  815|       |         *
  816|       |         * Transitions:
  817|       |         * - None
  818|       |         */
  819|       |#ifdef WITH_GSSAPI
  820|       |        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATING) {
  821|       |            rc = SSH_PACKET_DENIED;
  822|       |            break;
  823|       |        }
  824|       |
  825|       |        rc = SSH_PACKET_ALLOWED;
  826|       |        break;
  827|       |#else
  828|      1|        rc = SSH_PACKET_DENIED;
  829|      1|        break;
  830|      0|#endif  /* WITH_GSSAPI */
  831|      0|    case SSH2_MSG_USERAUTH_GSSAPI_MIC:                // 66
  ------------------
  |  |   49|      0|#define SSH2_MSG_USERAUTH_GSSAPI_MIC 66
  ------------------
  |  Branch (831:5): [True: 0, False: 49.4k]
  ------------------
  832|       |        /* Server only */
  833|       |
  834|       |        /*
  835|       |         * States required:
  836|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATING
  837|       |         * - session->gssapi->state == SSH_GSSAPI_STATE_RCV_MIC
  838|       |         *
  839|       |         * Transitions:
  840|       |         * Depending on the result of the verification, the states are
  841|       |         * changed:
  842|       |         * - SSH_AUTH_SUCCESS:
  843|       |         *   - session->session_state = SSH_SESSION_STATE_AUTHENTICATED
  844|       |         *   - session->flags != SSH_SESSION_FLAG_AUTHENTICATED
  845|       |         * - SSH_AUTH_PARTIAL:
  846|       |         *   - None
  847|       |         * - any other case:
  848|       |         *   - None
  849|       |         * */
  850|       |#ifdef WITH_GSSAPI
  851|       |        /* If this is a client, reject the message */
  852|       |        if (session->client) {
  853|       |            rc = SSH_PACKET_DENIED;
  854|       |            break;
  855|       |        }
  856|       |
  857|       |        if (session->dh_handshake_state != DH_STATE_FINISHED) {
  858|       |            rc = SSH_PACKET_DENIED;
  859|       |            break;
  860|       |        }
  861|       |
  862|       |        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATING) {
  863|       |            rc = SSH_PACKET_DENIED;
  864|       |            break;
  865|       |        }
  866|       |
  867|       |        rc = SSH_PACKET_ALLOWED;
  868|       |        break;
  869|       |#else
  870|      0|        rc = SSH_PACKET_DENIED;
  871|      0|        break;
  872|      0|#endif  /* WITH_GSSAPI */
  873|      3|    case SSH2_MSG_GLOBAL_REQUEST:                     // 80
  ------------------
  |  |   51|      3|#define SSH2_MSG_GLOBAL_REQUEST 80
  ------------------
  |  Branch (873:5): [True: 3, False: 49.4k]
  ------------------
  874|       |        /*
  875|       |         * States required:
  876|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  877|       |         *
  878|       |         * Transitions:
  879|       |         * - None
  880|       |         * */
  881|       |
  882|      3|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (882:13): [True: 1, False: 2]
  ------------------
  883|      1|            rc = SSH_PACKET_DENIED;
  884|      1|            break;
  885|      1|        }
  886|       |
  887|      2|        rc = SSH_PACKET_ALLOWED;
  888|      2|        break;
  889|      1|    case SSH2_MSG_REQUEST_SUCCESS:                    // 81
  ------------------
  |  |   52|      1|#define SSH2_MSG_REQUEST_SUCCESS 81
  ------------------
  |  Branch (889:5): [True: 1, False: 49.4k]
  ------------------
  890|       |        /*
  891|       |         * States required:
  892|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  893|       |         *
  894|       |         * Transitions:
  895|       |         * - From channel->request_state == SSH_CHANNEL_REQ_STATE_PENDING
  896|       |         * - To   channel->request_state = SSH_CHANNEL_REQ_STATE_ACCEPTED
  897|       |         *
  898|       |         * If not in a pending state, message is ignored in the callback handler.
  899|       |         * */
  900|       |
  901|      1|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (901:13): [True: 0, False: 1]
  ------------------
  902|      0|            rc = SSH_PACKET_DENIED;
  903|      0|            break;
  904|      0|        }
  905|       |
  906|      1|        rc = SSH_PACKET_ALLOWED;
  907|      1|        break;
  908|      2|    case SSH2_MSG_REQUEST_FAILURE:                    // 82
  ------------------
  |  |   53|      2|#define SSH2_MSG_REQUEST_FAILURE 82
  ------------------
  |  Branch (908:5): [True: 2, False: 49.4k]
  ------------------
  909|       |        /*
  910|       |         * States required:
  911|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  912|       |         *
  913|       |         * Transitions:
  914|       |         * - From channel->request_state == SSH_CHANNEL_REQ_STATE_PENDING
  915|       |         * - To   channel->request_state = SSH_CHANNEL_REQ_STATE_ACCEPTED
  916|       |         *
  917|       |         * If not in a pending state, message is ignored in the callback handler.
  918|       |         * */
  919|       |
  920|      2|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (920:13): [True: 1, False: 1]
  ------------------
  921|      1|            rc = SSH_PACKET_DENIED;
  922|      1|            break;
  923|      1|        }
  924|       |
  925|      1|        rc = SSH_PACKET_ALLOWED;
  926|      1|        break;
  927|     49|    case SSH2_MSG_CHANNEL_OPEN:                       // 90
  ------------------
  |  |   54|     49|#define SSH2_MSG_CHANNEL_OPEN 90
  ------------------
  |  Branch (927:5): [True: 49, False: 49.3k]
  ------------------
  928|       |        /*
  929|       |         * States required:
  930|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  931|       |         *
  932|       |         * Transitions:
  933|       |         * - None
  934|       |         * */
  935|       |
  936|     49|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (936:13): [True: 1, False: 48]
  ------------------
  937|      1|            rc = SSH_PACKET_DENIED;
  938|      1|            break;
  939|      1|        }
  940|       |
  941|     48|        rc = SSH_PACKET_ALLOWED;
  942|     48|        break;
  943|      0|    case SSH2_MSG_CHANNEL_OPEN_CONFIRMATION:          // 91
  ------------------
  |  |   55|      0|#define SSH2_MSG_CHANNEL_OPEN_CONFIRMATION 91
  ------------------
  |  Branch (943:5): [True: 0, False: 49.4k]
  ------------------
  944|       |        /*
  945|       |         * States required:
  946|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  947|       |         *
  948|       |         * Transitions:
  949|       |         * - channel->state = SSH_CHANNEL_STATE_OPEN
  950|       |         * - channel->flags &= ~SSH_CHANNEL_FLAG_NOT_BOUND
  951|       |         * */
  952|       |
  953|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (953:13): [True: 0, False: 0]
  ------------------
  954|      0|            rc = SSH_PACKET_DENIED;
  955|      0|            break;
  956|      0|        }
  957|       |
  958|      0|        rc = SSH_PACKET_ALLOWED;
  959|      0|        break;
  960|     14|    case SSH2_MSG_CHANNEL_OPEN_FAILURE:               // 92
  ------------------
  |  |   56|     14|#define SSH2_MSG_CHANNEL_OPEN_FAILURE 92
  ------------------
  |  Branch (960:5): [True: 14, False: 49.4k]
  ------------------
  961|       |        /*
  962|       |         * States required:
  963|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  964|       |         *
  965|       |         * Transitions:
  966|       |         * - channel->state = SSH_CHANNEL_STATE_OPEN_DENIED
  967|       |         * */
  968|       |
  969|     14|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (969:13): [True: 0, False: 14]
  ------------------
  970|      0|            rc = SSH_PACKET_DENIED;
  971|      0|            break;
  972|      0|        }
  973|       |
  974|     14|        rc = SSH_PACKET_ALLOWED;
  975|     14|        break;
  976|    117|    case SSH2_MSG_CHANNEL_WINDOW_ADJUST:              // 93
  ------------------
  |  |   57|    117|#define SSH2_MSG_CHANNEL_WINDOW_ADJUST 93
  ------------------
  |  Branch (976:5): [True: 117, False: 49.3k]
  ------------------
  977|       |        /*
  978|       |         * States required:
  979|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  980|       |         *
  981|       |         * Transitions:
  982|       |         * - None
  983|       |         * */
  984|       |
  985|    117|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (985:13): [True: 0, False: 117]
  ------------------
  986|      0|            rc = SSH_PACKET_DENIED;
  987|      0|            break;
  988|      0|        }
  989|       |
  990|    117|        rc = SSH_PACKET_ALLOWED;
  991|    117|        break;
  992|     64|    case SSH2_MSG_CHANNEL_DATA:                       // 94
  ------------------
  |  |   58|     64|#define SSH2_MSG_CHANNEL_DATA 94
  ------------------
  |  Branch (992:5): [True: 64, False: 49.3k]
  ------------------
  993|       |        /*
  994|       |         * States required:
  995|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  996|       |         *
  997|       |         * Transitions:
  998|       |         * - None
  999|       |         * */
 1000|       |
 1001|     64|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1001:13): [True: 0, False: 64]
  ------------------
 1002|      0|            rc = SSH_PACKET_DENIED;
 1003|      0|            break;
 1004|      0|        }
 1005|       |
 1006|     64|        rc = SSH_PACKET_ALLOWED;
 1007|     64|        break;
 1008|     14|    case SSH2_MSG_CHANNEL_EXTENDED_DATA:              // 95
  ------------------
  |  |   59|     14|#define SSH2_MSG_CHANNEL_EXTENDED_DATA 95
  ------------------
  |  Branch (1008:5): [True: 14, False: 49.4k]
  ------------------
 1009|       |        /*
 1010|       |         * States required:
 1011|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
 1012|       |         *
 1013|       |         * Transitions:
 1014|       |         * - None
 1015|       |         * */
 1016|       |
 1017|     14|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1017:13): [True: 1, False: 13]
  ------------------
 1018|      1|            rc = SSH_PACKET_DENIED;
 1019|      1|            break;
 1020|      1|        }
 1021|       |
 1022|     13|        rc = SSH_PACKET_ALLOWED;
 1023|     13|        break;
 1024|     41|    case SSH2_MSG_CHANNEL_EOF:                        // 96
  ------------------
  |  |   60|     41|#define SSH2_MSG_CHANNEL_EOF	96
  ------------------
  |  Branch (1024:5): [True: 41, False: 49.3k]
  ------------------
 1025|       |        /*
 1026|       |         * States required:
 1027|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
 1028|       |         *
 1029|       |         * Transitions:
 1030|       |         * - None
 1031|       |         * */
 1032|       |
 1033|     41|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1033:13): [True: 0, False: 41]
  ------------------
 1034|      0|            rc = SSH_PACKET_DENIED;
 1035|      0|            break;
 1036|      0|        }
 1037|       |
 1038|     41|        rc = SSH_PACKET_ALLOWED;
 1039|     41|        break;
 1040|      0|    case SSH2_MSG_CHANNEL_CLOSE:                      // 97
  ------------------
  |  |   61|      0|#define SSH2_MSG_CHANNEL_CLOSE 97
  ------------------
  |  Branch (1040:5): [True: 0, False: 49.4k]
  ------------------
 1041|       |        /*
 1042|       |         * States required:
 1043|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
 1044|       |         *
 1045|       |         * Transitions:
 1046|       |         * - channel->state = SSH_CHANNEL_STATE_CLOSED
 1047|       |         * - channel->flags |= SSH_CHANNEL_FLAG_CLOSED_REMOTE
 1048|       |         * */
 1049|       |
 1050|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1050:13): [True: 0, False: 0]
  ------------------
 1051|      0|            rc = SSH_PACKET_DENIED;
 1052|      0|            break;
 1053|      0|        }
 1054|       |
 1055|      0|        rc = SSH_PACKET_ALLOWED;
 1056|      0|        break;
 1057|      2|    case SSH2_MSG_CHANNEL_REQUEST:                    // 98
  ------------------
  |  |   62|      2|#define SSH2_MSG_CHANNEL_REQUEST 98
  ------------------
  |  Branch (1057:5): [True: 2, False: 49.4k]
  ------------------
 1058|       |        /*
 1059|       |         * States required:
 1060|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
 1061|       |         *
 1062|       |         * Transitions:
 1063|       |         * - Depends on the request
 1064|       |         * */
 1065|       |
 1066|      2|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1066:13): [True: 1, False: 1]
  ------------------
 1067|      1|            rc = SSH_PACKET_DENIED;
 1068|      1|            break;
 1069|      1|        }
 1070|       |
 1071|      1|        rc = SSH_PACKET_ALLOWED;
 1072|      1|        break;
 1073|      1|    case SSH2_MSG_CHANNEL_SUCCESS:                    // 99
  ------------------
  |  |   63|      1|#define SSH2_MSG_CHANNEL_SUCCESS 99
  ------------------
  |  Branch (1073:5): [True: 1, False: 49.4k]
  ------------------
 1074|       |        /*
 1075|       |         * States required:
 1076|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
 1077|       |         *
 1078|       |         * Transitions:
 1079|       |         * - From channel->request_state == SSH_CHANNEL_REQ_STATE_PENDING
 1080|       |         * - To   channel->request_state = SSH_CHANNEL_REQ_STATE_ACCEPTED
 1081|       |         *
 1082|       |         * If not in a pending state, message is ignored in the callback handler.
 1083|       |         * */
 1084|       |
 1085|      1|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1085:13): [True: 0, False: 1]
  ------------------
 1086|      0|            rc = SSH_PACKET_DENIED;
 1087|      0|            break;
 1088|      0|        }
 1089|       |
 1090|      1|        rc = SSH_PACKET_ALLOWED;
 1091|      1|        break;
 1092|      1|    case SSH2_MSG_CHANNEL_FAILURE:                    // 100
  ------------------
  |  |   64|      1|#define SSH2_MSG_CHANNEL_FAILURE 100
  ------------------
  |  Branch (1092:5): [True: 1, False: 49.4k]
  ------------------
 1093|       |        /*
 1094|       |         * States required:
 1095|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
 1096|       |         *
 1097|       |         * Transitions:
 1098|       |         * - From channel->request_state == SSH_CHANNEL_REQ_STATE_PENDING
 1099|       |         * - To   channel->request_state = SSH_CHANNEL_REQ_STATE_ACCEPTED
 1100|       |         *
 1101|       |         * If not in a pending state, message is ignored in the callback handler.
 1102|       |         * */
 1103|       |
 1104|      1|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1104:13): [True: 1, False: 0]
  ------------------
 1105|      1|            rc = SSH_PACKET_DENIED;
 1106|      1|            break;
 1107|      1|        }
 1108|       |
 1109|      0|        rc = SSH_PACKET_ALLOWED;
 1110|      0|        break;
 1111|      0|    case SSH2_MSG_PING: // 192
  ------------------
  |  |   69|      0|#define SSH2_MSG_PING 192
  ------------------
  |  Branch (1111:5): [True: 0, False: 49.4k]
  ------------------
 1112|      0|    case SSH2_MSG_PONG: // 193
  ------------------
  |  |   70|      0|#define SSH2_MSG_PONG 193
  ------------------
  |  Branch (1112:5): [True: 0, False: 49.4k]
  ------------------
 1113|       |        /*
 1114|       |         * Transport-level ping/pong messages.
 1115|       |         *
 1116|       |         * Always allow PING and PONG messages through the filter.
 1117|       |         * State checking (auth/rekey) is handled in the packet handler itself,
 1118|       |         * following OpenSSH's approach of treating these as implicit
 1119|       |         * transport-level messages (like IGNORE and DEBUG).
 1120|       |         *
 1121|       |         * States required:
 1122|       |         * - None (always allowed)
 1123|       |         *
 1124|       |         * Transitions:
 1125|       |         * - None
 1126|       |         */
 1127|      0|        rc = SSH_PACKET_ALLOWED;
 1128|      0|        break;
 1129|  14.2k|    default:
  ------------------
  |  Branch (1129:5): [True: 14.2k, False: 35.1k]
  ------------------
 1130|       |        /* Unknown message, do not filter */
 1131|  14.2k|        rc = SSH_PACKET_UNKNOWN;
 1132|  14.2k|        goto end;
 1133|  49.4k|    }
 1134|       |
 1135|  49.4k|end:
 1136|       |#ifdef DEBUG_PACKET
 1137|       |    if (rc == SSH_PACKET_DENIED) {
 1138|       |        SSH_LOG(SSH_LOG_PACKET, "REJECTED packet type %d: ",
 1139|       |                session->in_packet.type);
 1140|       |    }
 1141|       |
 1142|       |    if (rc == SSH_PACKET_UNKNOWN) {
 1143|       |        SSH_LOG(SSH_LOG_PACKET, "UNKNOWN packet type %d",
 1144|       |                session->in_packet.type);
 1145|       |    }
 1146|       |#endif
 1147|       |
 1148|  49.4k|    return rc;
 1149|  49.4k|}
packet.c:ssh_packet_need_rekey:
 1201|  64.5k|{
 1202|  64.5k|    bool data_rekey_needed = false;
 1203|  64.5k|    struct ssh_crypto_struct *crypto = NULL;
 1204|  64.5k|    struct ssh_cipher_struct *out_cipher = NULL, *in_cipher = NULL;
 1205|  64.5k|    uint32_t next_blocks;
 1206|       |
 1207|       |    /* We can safely rekey only in authenticated state */
 1208|  64.5k|    if ((session->flags & SSH_SESSION_FLAG_AUTHENTICATED) == 0) {
  ------------------
  |  |   78|  64.5k|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (1208:9): [True: 62.7k, False: 1.81k]
  ------------------
 1209|  62.7k|        return false;
 1210|  62.7k|    }
 1211|       |
 1212|       |    /* Do not rekey if the rekey/key-exchange is in progress */
 1213|  1.81k|    if (session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (1213:9): [True: 14, False: 1.80k]
  ------------------
 1214|     14|        return false;
 1215|     14|    }
 1216|       |
 1217|  1.80k|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_BOTH);
 1218|  1.80k|    if (crypto == NULL) {
  ------------------
  |  Branch (1218:9): [True: 0, False: 1.80k]
  ------------------
 1219|      0|        return false;
 1220|      0|    }
 1221|       |
 1222|  1.80k|    out_cipher = crypto->out_cipher;
 1223|  1.80k|    in_cipher = crypto->in_cipher;
 1224|       |
 1225|       |    /* Make sure we can send at least something for very small limits */
 1226|  1.80k|    if ((out_cipher->packets == 0) && (in_cipher->packets == 0)) {
  ------------------
  |  Branch (1226:9): [True: 0, False: 1.80k]
  |  Branch (1226:39): [True: 0, False: 0]
  ------------------
 1227|      0|        return false;
 1228|      0|    }
 1229|       |
 1230|       |    /* Time based rekeying */
 1231|  1.80k|    if (session->opts.rekey_time != 0 &&
  ------------------
  |  Branch (1231:9): [True: 0, False: 1.80k]
  ------------------
 1232|      0|        ssh_timeout_elapsed(&session->last_rekey_time,
  ------------------
  |  Branch (1232:9): [True: 0, False: 0]
  ------------------
 1233|      0|                            session->opts.rekey_time)) {
 1234|      0|        return true;
 1235|      0|    }
 1236|       |
 1237|       |    /* RFC4344, Section 3.1 Recommends rekeying after 2^31 packets in either
 1238|       |     * direction to avoid possible information leakage through the MAC tag
 1239|       |     */
 1240|  1.80k|    if (out_cipher->packets > MAX_PACKETS ||
  ------------------
  |  | 1197|  3.60k|#define MAX_PACKETS    (1UL<<31)
  ------------------
  |  Branch (1240:9): [True: 0, False: 1.80k]
  ------------------
 1241|  1.80k|        in_cipher->packets > MAX_PACKETS) {
  ------------------
  |  | 1197|  1.80k|#define MAX_PACKETS    (1UL<<31)
  ------------------
  |  Branch (1241:9): [True: 0, False: 1.80k]
  ------------------
 1242|      0|        return true;
 1243|      0|    }
 1244|       |
 1245|       |    /* Data-based rekeying:
 1246|       |     *  * For outgoing packets we can still delay them
 1247|       |     *  * Incoming packets need to be processed anyway, but we can
 1248|       |     *    signalize our intention to rekey
 1249|       |     */
 1250|  1.80k|    next_blocks = payloadsize / out_cipher->blocksize;
 1251|  1.80k|    data_rekey_needed = (out_cipher->max_blocks != 0 &&
  ------------------
  |  Branch (1251:26): [True: 1.80k, False: 0]
  ------------------
 1252|  1.80k|                         out_cipher->blocks + next_blocks > out_cipher->max_blocks) ||
  ------------------
  |  Branch (1252:26): [True: 0, False: 1.80k]
  ------------------
 1253|  1.80k|                         (in_cipher->max_blocks != 0 &&
  ------------------
  |  Branch (1253:27): [True: 1.80k, False: 0]
  ------------------
 1254|  1.80k|                         in_cipher->blocks + next_blocks > in_cipher->max_blocks);
  ------------------
  |  Branch (1254:26): [True: 0, False: 1.80k]
  ------------------
 1255|       |
 1256|  1.80k|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|  1.80k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1257|  1.80k|            "rekey: [data_rekey_needed=%d, out_blocks=%" PRIu64 ", in_blocks=%" PRIu64 "]",
 1258|  1.80k|            data_rekey_needed,
 1259|  1.80k|            out_cipher->blocks + next_blocks,
 1260|  1.80k|            in_cipher->blocks + next_blocks);
 1261|       |
 1262|  1.80k|    return data_rekey_needed;
 1263|  1.80k|}
packet.c:ssh_packet_socket_controlflow_callback:
 1654|    817|{
 1655|    817|    ssh_session session = userdata;
 1656|    817|    struct ssh_iterator *it = NULL;
 1657|    817|    ssh_channel channel = NULL;
 1658|       |
 1659|    817|    if (code == SSH_SOCKET_FLOW_WRITEWONTBLOCK) {
  ------------------
  |  |  519|    817|#define SSH_SOCKET_FLOW_WRITEWONTBLOCK 2
  ------------------
  |  Branch (1659:9): [True: 817, False: 0]
  ------------------
 1660|    817|        SSH_LOG(SSH_LOG_TRACE, "sending channel_write_wontblock callback");
  ------------------
  |  |  283|    817|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1661|       |
 1662|       |        /* the out pipe is empty so we can forward this to channels */
 1663|    817|        it = ssh_list_get_iterator(session->channels);
 1664|    914|        while (it != NULL) {
  ------------------
  |  Branch (1664:16): [True: 97, False: 817]
  ------------------
 1665|     97|            channel = ssh_iterator_value(ssh_channel, it);
  ------------------
  |  |  122|     97|  ((type)((iterator)->data))
  ------------------
 1666|     97|            if (channel->remote_window > 0) {
  ------------------
  |  Branch (1666:17): [True: 49, False: 48]
  ------------------
 1667|       |                ssh_callbacks_execute_list(channel->callbacks,
  ------------------
  |  |  567|     49|    do {                                                      \
  |  |  568|     49|        struct ssh_iterator *i = ssh_list_get_iterator(list); \
  |  |  569|     49|        cbtype cb;                                            \
  |  |  570|     49|        while (i != NULL){                                    \
  |  |  ------------------
  |  |  |  Branch (570:16): [True: 0, False: 49]
  |  |  ------------------
  |  |  571|      0|            cb = ssh_iterator_value(cbtype, i);               \
  |  |  ------------------
  |  |  |  |  122|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  572|      0|            if (ssh_callbacks_exists(cb, c))                  \
  |  |  ------------------
  |  |  |  |  548|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  549|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (549:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (550:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  551|      0|  )
  |  |  ------------------
  |  |  573|      0|                cb-> c (__VA_ARGS__, cb->userdata);           \
  |  |  574|      0|            i = i->next;                                      \
  |  |  575|      0|        }                                                     \
  |  |  576|     49|    } while(0)
  |  |  ------------------
  |  |  |  Branch (576:13): [Folded, False: 49]
  |  |  ------------------
  ------------------
 1668|     49|                                           ssh_channel_callbacks,
 1669|     49|                                           channel_write_wontblock_function,
 1670|     49|                                           session,
 1671|     49|                                           channel,
 1672|     49|                                           channel->remote_window);
 1673|     49|            }
 1674|     97|            it = it->next;
 1675|     97|        }
 1676|    817|    }
 1677|    817|}
packet.c:ssh_packet_in_rekey:
 2058|  15.1k|{
 2059|       |    /* We know we are rekeying if we are authenticated and the DH
 2060|       |     * status is not finished, but we only queue packets until we've
 2061|       |     * sent our NEWKEYS.
 2062|       |     */
 2063|  15.1k|    return (session->flags & SSH_SESSION_FLAG_AUTHENTICATED) &&
  ------------------
  |  |   78|  15.1k|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (2063:12): [True: 772, False: 14.3k]
  ------------------
 2064|    772|           (session->dh_handshake_state != DH_STATE_FINISHED) &&
  ------------------
  |  Branch (2064:12): [True: 7, False: 765]
  ------------------
 2065|      7|           (session->dh_handshake_state != DH_STATE_NEWKEYS_SENT);
  ------------------
  |  Branch (2065:12): [True: 7, False: 0]
  ------------------
 2066|  15.1k|}
packet.c:ssh_packet_is_kex:
 2047|      7|{
 2048|      7|    return type >= SSH2_MSG_DISCONNECT &&
  ------------------
  |  |    4|     14|#define SSH2_MSG_DISCONNECT 1
  ------------------
  |  Branch (2048:12): [True: 7, False: 0]
  ------------------
 2049|      7|           type <= SSH2_MSG_KEX_DH_GEX_REQUEST &&
  ------------------
  |  |   26|     14|#define SSH2_MSG_KEX_DH_GEX_REQUEST 34
  ------------------
  |  Branch (2049:12): [True: 7, False: 0]
  ------------------
 2050|      7|           type != SSH2_MSG_SERVICE_REQUEST &&
  ------------------
  |  |    8|     14|#define SSH2_MSG_SERVICE_REQUEST	5
  ------------------
  |  Branch (2050:12): [True: 7, False: 0]
  ------------------
 2051|      7|           type != SSH2_MSG_SERVICE_ACCEPT &&
  ------------------
  |  |    9|     14|#define SSH2_MSG_SERVICE_ACCEPT 6
  ------------------
  |  Branch (2051:12): [True: 7, False: 0]
  ------------------
 2052|      7|           type != SSH2_MSG_IGNORE &&
  ------------------
  |  |    5|     14|#define SSH2_MSG_IGNORE	 2
  ------------------
  |  Branch (2052:12): [True: 7, False: 0]
  ------------------
 2053|      7|           type != SSH2_MSG_EXT_INFO;
  ------------------
  |  |   10|     14|#define SSH2_MSG_EXT_INFO 7
  ------------------
  |  Branch (2053:12): [True: 7, False: 0]
  ------------------
 2054|      7|}
packet.c:packet_send2:
 1898|  15.1k|{
 1899|  15.1k|    unsigned int blocksize = 8;
 1900|  15.1k|    unsigned int lenfield_blocksize = 0;
 1901|  15.1k|    enum ssh_hmac_e hmac_type;
 1902|  15.1k|    uint32_t currentlen = ssh_buffer_get_len(session->out_buffer);
 1903|  15.1k|    struct ssh_crypto_struct *crypto = NULL;
 1904|  15.1k|    unsigned char *hmac = NULL;
 1905|  15.1k|    uint8_t padding_data[32] = { 0 };
 1906|  15.1k|    uint8_t padding_size;
 1907|  15.1k|    uint32_t finallen, payloadsize, compsize;
 1908|  15.1k|    uint8_t header[5] = {0};
 1909|  15.1k|    uint8_t type, *payload;
 1910|  15.1k|    int rc = SSH_ERROR;
  ------------------
  |  |  316|  15.1k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1911|  15.1k|    bool etm = false;
 1912|  15.1k|    int etm_packet_offset = 0;
 1913|       |
 1914|  15.1k|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_OUT);
 1915|  15.1k|    if (crypto) {
  ------------------
  |  Branch (1915:9): [True: 5.28k, False: 9.86k]
  ------------------
 1916|  5.28k|        blocksize = crypto->out_cipher->blocksize;
 1917|  5.28k|        lenfield_blocksize = crypto->out_cipher->lenfield_blocksize;
 1918|  5.28k|        hmac_type = crypto->out_hmac;
 1919|  5.28k|        etm = crypto->out_hmac_etm;
 1920|  9.86k|    } else {
 1921|  9.86k|        hmac_type = session->next_crypto->out_hmac;
 1922|  9.86k|    }
 1923|       |
 1924|  15.1k|    payload = (uint8_t *)ssh_buffer_get(session->out_buffer);
 1925|  15.1k|    type = payload[0]; /* type is the first byte of the packet now */
 1926|       |
 1927|  15.1k|    payloadsize = currentlen;
 1928|  15.1k|    if (etm) {
  ------------------
  |  Branch (1928:9): [True: 0, False: 15.1k]
  ------------------
 1929|      0|        etm_packet_offset = sizeof(uint32_t);
 1930|      0|        lenfield_blocksize = 0;
 1931|      0|    }
 1932|       |
 1933|  15.1k|    if (crypto != NULL && crypto->do_compress_out &&
  ------------------
  |  Branch (1933:9): [True: 5.28k, False: 9.86k]
  |  Branch (1933:27): [True: 0, False: 5.28k]
  ------------------
 1934|      0|        ssh_buffer_get_len(session->out_buffer) > 0) {
  ------------------
  |  Branch (1934:9): [True: 0, False: 0]
  ------------------
 1935|      0|        rc = compress_buffer(session,session->out_buffer);
 1936|      0|        if (rc < 0) {
  ------------------
  |  Branch (1936:13): [True: 0, False: 0]
  ------------------
 1937|      0|            goto error;
 1938|      0|        }
 1939|      0|        currentlen = ssh_buffer_get_len(session->out_buffer);
 1940|      0|    }
 1941|  15.1k|    compsize = currentlen;
 1942|       |    /* compressed payload + packet len (4) + padding_size len (1) */
 1943|       |    /* totallen - lenfield_blocksize - etm_packet_offset must be equal to 0 (mod blocksize) */
 1944|  15.1k|    padding_size = (blocksize - ((blocksize - lenfield_blocksize - etm_packet_offset + currentlen + 5) % blocksize));
 1945|  15.1k|    if (padding_size < 4) {
  ------------------
  |  Branch (1945:9): [True: 445, False: 14.7k]
  ------------------
 1946|    445|        padding_size += blocksize;
 1947|    445|    }
 1948|       |
 1949|  15.1k|    if (crypto != NULL) {
  ------------------
  |  Branch (1949:9): [True: 5.28k, False: 9.86k]
  ------------------
 1950|  5.28k|        int ok;
 1951|       |
 1952|  5.28k|        ok = ssh_get_random(padding_data, padding_size, 0);
 1953|  5.28k|        if (!ok) {
  ------------------
  |  Branch (1953:13): [True: 0, False: 5.28k]
  ------------------
 1954|      0|            ssh_set_error(session, SSH_FATAL, "PRNG error");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1955|      0|            goto error;
 1956|      0|        }
 1957|  5.28k|    }
 1958|       |
 1959|  15.1k|    finallen = currentlen - etm_packet_offset + padding_size + 1;
 1960|       |
 1961|  15.1k|    PUSH_BE_U32(header, 0, finallen);
  ------------------
  |  |   89|  15.1k|    (PUSH_BE_U16((data), (pos), (uint16_t)(((uint32_t)(val)) >> 16)), PUSH_BE_U16((data), (pos) + 2, (uint16_t)((val) & 0xffff)))
  |  |  ------------------
  |  |  |  |   86|  15.1k|    (PUSH_BE_U8((data), (pos), (uint8_t)(((uint16_t)(val)) >> 8)), PUSH_BE_U8((data), (pos) + 1, (uint8_t)((val) & 0xff)))
  |  |  |  |  ------------------
  |  |  |  |  |  |   83|  15.1k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|  15.1k|    (((uint8_t *)(data))[(pos)])
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |                   (PUSH_BE_U8((data), (pos), (uint8_t)(((uint16_t)(val)) >> 8)), PUSH_BE_U8((data), (pos) + 1, (uint8_t)((val) & 0xff)))
  |  |  |  |  ------------------
  |  |  |  |  |  |   83|  15.1k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|  15.1k|    (((uint8_t *)(data))[(pos)])
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   (PUSH_BE_U16((data), (pos), (uint16_t)(((uint32_t)(val)) >> 16)), PUSH_BE_U16((data), (pos) + 2, (uint16_t)((val) & 0xffff)))
  |  |  ------------------
  |  |  |  |   86|  15.1k|    (PUSH_BE_U8((data), (pos), (uint8_t)(((uint16_t)(val)) >> 8)), PUSH_BE_U8((data), (pos) + 1, (uint8_t)((val) & 0xff)))
  |  |  |  |  ------------------
  |  |  |  |  |  |   83|  15.1k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|  15.1k|    (((uint8_t *)(data))[(pos)])
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |                   (PUSH_BE_U8((data), (pos), (uint8_t)(((uint16_t)(val)) >> 8)), PUSH_BE_U8((data), (pos) + 1, (uint8_t)((val) & 0xff)))
  |  |  |  |  ------------------
  |  |  |  |  |  |   83|  15.1k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|  15.1k|    (((uint8_t *)(data))[(pos)])
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1962|  15.1k|    PUSH_BE_U8(header, 4, padding_size);
  ------------------
  |  |   83|  15.1k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  ------------------
  |  |  |  |   31|  15.1k|    (((uint8_t *)(data))[(pos)])
  |  |  ------------------
  ------------------
 1963|       |
 1964|  15.1k|    rc = ssh_buffer_prepend_data(session->out_buffer,
 1965|  15.1k|                                 header,
 1966|  15.1k|                                 sizeof(header));
 1967|  15.1k|    if (rc < 0) {
  ------------------
  |  Branch (1967:9): [True: 0, False: 15.1k]
  ------------------
 1968|      0|        goto error;
 1969|      0|    }
 1970|       |
 1971|  15.1k|    rc = ssh_buffer_add_data(session->out_buffer, padding_data, padding_size);
 1972|  15.1k|    if (rc < 0) {
  ------------------
  |  Branch (1972:9): [True: 0, False: 15.1k]
  ------------------
 1973|      0|        goto error;
 1974|      0|    }
 1975|       |
 1976|  15.1k|#ifdef WITH_PCAP
 1977|  15.1k|    if (session->pcap_ctx != NULL) {
  ------------------
  |  Branch (1977:9): [True: 0, False: 15.1k]
  ------------------
 1978|      0|        ssh_pcap_context_write(session->pcap_ctx,
 1979|      0|                               SSH_PCAP_DIR_OUT,
 1980|      0|                               ssh_buffer_get(session->out_buffer),
 1981|      0|                               ssh_buffer_get_len(session->out_buffer),
 1982|      0|                               ssh_buffer_get_len(session->out_buffer));
 1983|      0|    }
 1984|  15.1k|#endif
 1985|       |
 1986|  15.1k|    hmac = ssh_packet_encrypt(session,
 1987|  15.1k|                              ssh_buffer_get(session->out_buffer),
 1988|  15.1k|                              ssh_buffer_get_len(session->out_buffer));
 1989|       |    /* XXX This returns null before switching on crypto, with none MAC
 1990|       |     * and on various errors.
 1991|       |     * We should distinguish between these cases to avoid hiding errors. */
 1992|  15.1k|    if (hmac != NULL) {
  ------------------
  |  Branch (1992:9): [True: 5.28k, False: 9.86k]
  ------------------
 1993|  5.28k|        rc = ssh_buffer_add_data(session->out_buffer,
 1994|  5.28k|                                 hmac,
 1995|  5.28k|                                 (uint32_t)hmac_digest_len(hmac_type));
 1996|  5.28k|        if (rc < 0) {
  ------------------
  |  Branch (1996:13): [True: 0, False: 5.28k]
  ------------------
 1997|      0|            goto error;
 1998|      0|        }
 1999|  5.28k|    }
 2000|       |
 2001|  15.1k|    rc = ssh_packet_write(session);
 2002|  15.1k|    if (rc == SSH_ERROR) {
  ------------------
  |  |  316|  15.1k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (2002:9): [True: 0, False: 15.1k]
  ------------------
 2003|      0|        goto error;
 2004|      0|    }
 2005|  15.1k|    session->send_seq++;
 2006|  15.1k|    if (crypto != NULL) {
  ------------------
  |  Branch (2006:9): [True: 5.28k, False: 9.86k]
  ------------------
 2007|  5.28k|        struct ssh_cipher_struct *cipher = NULL;
 2008|       |
 2009|  5.28k|        cipher = crypto->out_cipher;
 2010|  5.28k|        cipher->packets++;
 2011|  5.28k|        cipher->blocks += payloadsize / cipher->blocksize;
 2012|  5.28k|    }
 2013|  15.1k|    if (session->raw_counter != NULL) {
  ------------------
  |  Branch (2013:9): [True: 0, False: 15.1k]
  ------------------
 2014|      0|        session->raw_counter->out_bytes += payloadsize;
 2015|      0|        session->raw_counter->out_packets++;
 2016|      0|    }
 2017|       |
 2018|  15.1k|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|  15.1k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2019|  15.1k|            "packet: wrote [type=%u, len=%" PRIu32 ", padding_size=%hhd, comp=%" PRIu32 ", "
 2020|  15.1k|            "payload=%" PRIu32 "]",
 2021|  15.1k|            type,
 2022|  15.1k|            finallen,
 2023|  15.1k|            padding_size,
 2024|  15.1k|            compsize,
 2025|  15.1k|            payloadsize);
 2026|       |
 2027|  15.1k|    rc = ssh_buffer_reinit(session->out_buffer);
 2028|  15.1k|    if (rc < 0) {
  ------------------
  |  Branch (2028:9): [True: 0, False: 15.1k]
  ------------------
 2029|      0|        rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2030|      0|        goto error;
 2031|      0|    }
 2032|       |
 2033|       |    /* We sent the NEWKEYS so any further packet needs to be encrypted
 2034|       |     * with the new keys. We can not switch both directions (need to decrypt
 2035|       |     * peer NEWKEYS) and we do not want to wait for the peer NEWKEYS
 2036|       |     * too, so we will switch only the OUT direction now.
 2037|       |     */
 2038|  15.1k|    if (type == SSH2_MSG_NEWKEYS) {
  ------------------
  |  |   13|  15.1k|#define SSH2_MSG_NEWKEYS 21
  ------------------
  |  Branch (2038:9): [True: 185, False: 14.9k]
  ------------------
 2039|    185|        rc = ssh_packet_set_newkeys(session, SSH_DIRECTION_OUT);
 2040|    185|    }
 2041|  15.1k|error:
 2042|  15.1k|    return rc; /* SSH_OK, AGAIN or ERROR */
 2043|  15.1k|}
packet.c:ssh_packet_write:
 1887|  15.1k|static int ssh_packet_write(ssh_session session) {
 1888|  15.1k|  int rc = SSH_ERROR;
  ------------------
  |  |  316|  15.1k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1889|       |
 1890|  15.1k|  rc=ssh_socket_write(session->socket,
 1891|  15.1k|      ssh_buffer_get(session->out_buffer),
 1892|  15.1k|      ssh_buffer_get_len(session->out_buffer));
 1893|       |
 1894|  15.1k|  return rc;
 1895|  15.1k|}
packet.c:ssh_init_rekey_state:
 2243|    370|{
 2244|       |    /* Reset the counters: should be NOOP */
 2245|    370|    cipher->packets = 0;
 2246|    370|    cipher->blocks = 0;
 2247|       |
 2248|       |    /* Default rekey limits for ciphers as specified in RFC4344, Section 3.2 */
 2249|    370|    if (cipher->blocksize >= 16) {
  ------------------
  |  Branch (2249:9): [True: 0, False: 370]
  ------------------
 2250|       |        /* For larger block size (L bits) use maximum of 2**(L/4) blocks */
 2251|      0|        cipher->max_blocks = (uint64_t)1 << (cipher->blocksize*2);
 2252|    370|    } else {
 2253|       |        /* For smaller blocks use limit of 1 GB as recommended in RFC4253 */
 2254|    370|        cipher->max_blocks = ((uint64_t)1 << 30) / cipher->blocksize;
 2255|    370|    }
 2256|       |    /* If we have limit provided by user, use the smaller one */
 2257|    370|    if (session->opts.rekey_data != 0) {
  ------------------
  |  Branch (2257:9): [True: 0, False: 370]
  ------------------
 2258|      0|        cipher->max_blocks = MIN(cipher->max_blocks,
  ------------------
  |  |  367|      0|#define MIN(a,b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (367:19): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 2259|      0|                                 session->opts.rekey_data / cipher->blocksize);
 2260|      0|    }
 2261|       |
 2262|    370|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  283|    370|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2263|    370|            "Set rekey after %" PRIu64 " blocks",
 2264|    370|            cipher->max_blocks);
 2265|    370|}

ssh_packet_ignore_callback:
  102|      1|{
  103|      1|    (void)session; /* unused */
  104|      1|    (void)user;
  105|      1|    (void)type;
  106|      1|    (void)packet;
  107|       |
  108|      1|    SSH_LOG(SSH_LOG_DEBUG, "Received SSH_MSG_IGNORE packet");
  ------------------
  |  |  283|      1|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  109|       |
  110|      1|    return SSH_PACKET_USED;
  ------------------
  |  |  638|      1|#define SSH_PACKET_USED 1
  ------------------
  111|      1|}
ssh_packet_debug_callback:
  119|  14.3k|{
  120|  14.3k|    uint8_t always_display = -1;
  121|  14.3k|    char *message = NULL;
  122|  14.3k|    int rc;
  123|       |
  124|  14.3k|    (void)session; /* unused */
  125|  14.3k|    (void)type;
  126|  14.3k|    (void)user;
  127|       |
  128|  14.3k|    rc = ssh_buffer_unpack(packet, "bs", &always_display, &message);
  ------------------
  |  |   60|  14.3k|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|  14.3k|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|  14.3k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|  14.3k|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|  14.3k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|  14.3k|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|  14.3k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  129|  14.3k|    if (rc != SSH_OK) {
  ------------------
  |  |  315|  14.3k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (129:9): [True: 14.3k, False: 5]
  ------------------
  130|  14.3k|        SSH_LOG(SSH_LOG_PACKET, "Error reading debug message");
  ------------------
  |  |  283|  14.3k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  131|  14.3k|        return SSH_PACKET_USED;
  ------------------
  |  |  638|  14.3k|#define SSH_PACKET_USED 1
  ------------------
  132|  14.3k|    }
  133|      5|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  283|     10|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (283:34): [True: 1, False: 4]
  |  |  ------------------
  ------------------
  134|      5|            "Received SSH_MSG_DEBUG packet with message %s%s",
  135|      5|            message,
  136|      5|            always_display != 0 ? " (always display)" : "");
  137|      5|    SAFE_FREE(message);
  ------------------
  |  |  375|      5|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 5, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 5]
  |  |  ------------------
  ------------------
  138|       |
  139|      5|    return SSH_PACKET_USED;
  ------------------
  |  |  638|      5|#define SSH_PACKET_USED 1
  ------------------
  140|  14.3k|}
ssh_packet_newkeys:
  143|    180|{
  144|    180|    ssh_string sig_blob = NULL;
  145|    180|    ssh_signature sig = NULL;
  146|    180|    int rc;
  147|       |
  148|    180|    (void)packet;
  149|    180|    (void)user;
  150|    180|    (void)type;
  151|       |
  152|    180|    SSH_LOG(SSH_LOG_DEBUG, "Received SSH_MSG_NEWKEYS");
  ------------------
  |  |  283|    180|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  153|       |
  154|    180|    if (session->session_state != SSH_SESSION_STATE_DH ||
  ------------------
  |  Branch (154:9): [True: 0, False: 180]
  ------------------
  155|    180|        session->dh_handshake_state != DH_STATE_NEWKEYS_SENT) {
  ------------------
  |  Branch (155:9): [True: 0, False: 180]
  ------------------
  156|      0|        ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  157|      0|                      SSH_FATAL,
  158|      0|                      "ssh_packet_newkeys called in wrong state : %d:%d",
  159|      0|                      session->session_state,
  160|      0|                      session->dh_handshake_state);
  161|      0|        goto error;
  162|      0|    }
  163|       |
  164|    180|    if (session->flags & SSH_SESSION_FLAG_KEX_STRICT) {
  ------------------
  |  |   90|    180|#define SSH_SESSION_FLAG_KEX_STRICT 0x0010
  ------------------
  |  Branch (164:9): [True: 0, False: 180]
  ------------------
  165|       |        /* reset packet sequence number when running in strict kex mode */
  166|      0|        session->recv_seq = 0;
  167|       |        /* Check that we aren't tainted */
  168|      0|        if (session->flags & SSH_SESSION_FLAG_KEX_TAINTED) {
  ------------------
  |  |   92|      0|#define SSH_SESSION_FLAG_KEX_TAINTED 0x0020
  ------------------
  |  Branch (168:13): [True: 0, False: 0]
  ------------------
  169|      0|            ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  170|      0|                          SSH_FATAL,
  171|      0|                          "Received unexpected packets in strict KEX mode.");
  172|      0|            goto error;
  173|      0|        }
  174|      0|    }
  175|       |
  176|    180|    if (session->server) {
  ------------------
  |  Branch (176:9): [True: 180, False: 0]
  ------------------
  177|       |        /* server things are done in server.c */
  178|    180|        session->dh_handshake_state=DH_STATE_FINISHED;
  179|    180|    } else {
  180|       |#ifdef WITH_GSSAPI
  181|       |        if (ssh_kex_is_gss(session->next_crypto)) {
  182|       |            OM_uint32 maj_stat, min_stat;
  183|       |            gss_buffer_desc mic = GSS_C_EMPTY_BUFFER, msg = GSS_C_EMPTY_BUFFER;
  184|       |
  185|       |            if (session->gssapi == NULL || session->gssapi->ctx == NULL) {
  186|       |                ssh_set_error(session, SSH_FATAL, "GSSAPI context not initialized");
  187|       |                goto error;
  188|       |            }
  189|       |
  190|       |            if (session->gssapi_key_exchange_mic == NULL) {
  191|       |                ssh_set_error(session,
  192|       |                              SSH_FATAL,
  193|       |                              "GSSAPI mic not set");
  194|       |                goto error;
  195|       |            }
  196|       |
  197|       |            mic.length = ssh_string_len(session->gssapi_key_exchange_mic);
  198|       |            mic.value = ssh_string_data(session->gssapi_key_exchange_mic);
  199|       |
  200|       |            msg.length = session->next_crypto->digest_len;
  201|       |            msg.value = session->next_crypto->secret_hash;
  202|       |
  203|       |            maj_stat = gss_verify_mic(&min_stat,
  204|       |                                      session->gssapi->ctx,
  205|       |                                      &msg,
  206|       |                                      &mic,
  207|       |                                      NULL);
  208|       |            if (maj_stat != GSS_S_COMPLETE) {
  209|       |                ssh_set_error(session,
  210|       |                              SSH_FATAL,
  211|       |                              "Failed to verify mic after GSSAPI Key Exchange");
  212|       |                goto error;
  213|       |            }
  214|       |            SSH_STRING_FREE(session->gssapi_key_exchange_mic);
  215|       |        } else
  216|       |#endif
  217|      0|        {
  218|      0|            ssh_key server_key = NULL;
  219|       |
  220|       |            /* client */
  221|       |
  222|       |            /* Verify the host's signature. FIXME do it sooner */
  223|      0|            sig_blob = session->next_crypto->dh_server_signature;
  224|      0|            session->next_crypto->dh_server_signature = NULL;
  225|       |
  226|       |            /* get the server public key */
  227|      0|            server_key = ssh_dh_get_next_server_publickey(session);
  228|      0|            if (server_key == NULL) {
  ------------------
  |  Branch (228:17): [True: 0, False: 0]
  ------------------
  229|      0|                goto error;
  230|      0|            }
  231|       |
  232|      0|            rc = ssh_pki_import_signature_blob(sig_blob, server_key, &sig);
  233|      0|            ssh_string_burn(sig_blob);
  234|      0|            SSH_STRING_FREE(sig_blob);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  235|      0|            if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (235:17): [True: 0, False: 0]
  ------------------
  236|      0|                goto error;
  237|      0|            }
  238|       |
  239|       |            /* Check if signature from server matches user preferences */
  240|      0|            if (session->opts.wanted_methods[SSH_HOSTKEYS]) {
  ------------------
  |  Branch (240:17): [True: 0, False: 0]
  ------------------
  241|      0|                rc = match_group(session->opts.wanted_methods[SSH_HOSTKEYS],
  242|      0|                                 sig->type_c);
  243|      0|                if (rc == 0) {
  ------------------
  |  Branch (243:21): [True: 0, False: 0]
  ------------------
  244|      0|                    ssh_set_error(
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  245|      0|                        session,
  246|      0|                        SSH_FATAL,
  247|      0|                        "Public key from server (%s) doesn't match user "
  248|      0|                        "preference (%s)",
  249|      0|                        sig->type_c,
  250|      0|                        session->opts.wanted_methods[SSH_HOSTKEYS]);
  251|      0|                    goto error;
  252|      0|                }
  253|      0|            }
  254|       |
  255|      0|            rc = ssh_pki_signature_verify(session,
  256|      0|                                          sig,
  257|      0|                                          server_key,
  258|      0|                                          session->next_crypto->secret_hash,
  259|      0|                                          session->next_crypto->digest_len);
  260|      0|            SSH_SIGNATURE_FREE(sig);
  ------------------
  |  |  161|      0|    do { ssh_signature_free(x); x = NULL; } while(0)
  |  |  ------------------
  |  |  |  Branch (161:51): [Folded, False: 0]
  |  |  ------------------
  ------------------
  261|      0|            if (rc == SSH_ERROR) {
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (261:17): [True: 0, False: 0]
  ------------------
  262|      0|                ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  263|      0|                              SSH_FATAL,
  264|      0|                              "Failed to verify server hostkey signature");
  265|      0|                goto error;
  266|      0|            }
  267|      0|        }
  268|      0|        SSH_LOG(SSH_LOG_DEBUG, "Signature verified and valid");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  269|       |
  270|       |        /* When receiving this packet, we switch on the incoming crypto. */
  271|      0|        rc = ssh_packet_set_newkeys(session, SSH_DIRECTION_IN);
  272|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (272:13): [True: 0, False: 0]
  ------------------
  273|      0|            goto error;
  274|      0|        }
  275|      0|    }
  276|    180|    session->dh_handshake_state = DH_STATE_FINISHED;
  277|    180|    session->ssh_connection_callback(session);
  278|    180|    return SSH_PACKET_USED;
  ------------------
  |  |  638|    180|#define SSH_PACKET_USED 1
  ------------------
  279|       |
  280|      0|error:
  281|       |#ifdef WITH_GSSAPI
  282|       |    SSH_STRING_FREE(session->gssapi_key_exchange_mic);
  283|       |#endif
  284|      0|    SSH_SIGNATURE_FREE(sig);
  ------------------
  |  |  161|      0|    do { ssh_signature_free(x); x = NULL; } while(0)
  |  |  ------------------
  |  |  |  Branch (161:51): [Folded, False: 0]
  |  |  ------------------
  ------------------
  285|      0|    ssh_string_burn(sig_blob);
  286|      0|    SSH_STRING_FREE(sig_blob);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  287|      0|    session->session_state = SSH_SESSION_STATE_ERROR;
  288|      0|    return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  289|    180|}
ssh_packet_ext_info:
  314|    235|{
  315|    235|    int rc;
  316|    235|    uint32_t nr_extensions = 0;
  317|    235|    uint32_t i;
  318|       |
  319|    235|    (void)type;
  320|    235|    (void)user;
  321|       |
  322|    235|    SSH_LOG(SSH_LOG_PACKET, "Received SSH_MSG_EXT_INFO");
  ------------------
  |  |  283|    235|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  323|       |
  324|    235|    rc = ssh_buffer_get_u32(packet, &nr_extensions);
  325|    235|    if (rc == 0) {
  ------------------
  |  Branch (325:9): [True: 167, False: 68]
  ------------------
  326|    167|        SSH_LOG(SSH_LOG_PACKET, "Failed to read number of extensions");
  ------------------
  |  |  283|    167|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  327|    167|        return SSH_PACKET_USED;
  ------------------
  |  |  638|    167|#define SSH_PACKET_USED 1
  ------------------
  328|    167|    }
  329|       |
  330|     68|    nr_extensions = ntohl(nr_extensions);
  331|     68|    if (nr_extensions > 128) {
  ------------------
  |  Branch (331:9): [True: 1, False: 67]
  ------------------
  332|      1|        SSH_LOG(SSH_LOG_PACKET, "Invalid number of extensions");
  ------------------
  |  |  283|      1|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  333|      1|        return SSH_PACKET_USED;
  ------------------
  |  |  638|      1|#define SSH_PACKET_USED 1
  ------------------
  334|      1|    }
  335|       |
  336|     67|    SSH_LOG(SSH_LOG_PACKET, "Follows %" PRIu32 " extensions", nr_extensions);
  ------------------
  |  |  283|     67|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  337|       |
  338|    358|    for (i = 0; i < nr_extensions; i++) {
  ------------------
  |  Branch (338:17): [True: 358, False: 0]
  ------------------
  339|    358|        char *name = NULL;
  340|    358|        char *value = NULL;
  341|       |
  342|    358|        rc = ssh_buffer_unpack(packet, "ss", &name, &value);
  ------------------
  |  |   60|    358|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|    358|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|    358|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|    358|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|    358|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|    358|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    358|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  343|    358|        if (rc != SSH_OK) {
  ------------------
  |  |  315|    358|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (343:13): [True: 67, False: 291]
  ------------------
  344|     67|            SSH_LOG(SSH_LOG_PACKET, "Error reading extension name-value pair");
  ------------------
  |  |  283|     67|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  345|     67|            return SSH_PACKET_USED;
  ------------------
  |  |  638|     67|#define SSH_PACKET_USED 1
  ------------------
  346|     67|        }
  347|       |
  348|    291|        if (strcmp(name, "server-sig-algs") == 0) {
  ------------------
  |  Branch (348:13): [True: 56, False: 235]
  ------------------
  349|       |            /* TODO check for NULL bytes */
  350|     56|            SSH_LOG(SSH_LOG_PACKET, "Extension: %s=<%s>", name, value);
  ------------------
  |  |  283|     56|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  351|       |
  352|     56|            rc = match_group(value, "rsa-sha2-512");
  353|     56|            if (rc == 1) {
  ------------------
  |  Branch (353:17): [True: 50, False: 6]
  ------------------
  354|     50|                session->extensions |= SSH_EXT_SIG_RSA_SHA512;
  ------------------
  |  |  127|     50|#define SSH_EXT_SIG_RSA_SHA512  0x04
  ------------------
  355|     50|            }
  356|       |
  357|     56|            rc = match_group(value, "rsa-sha2-256");
  358|     56|            if (rc == 1) {
  ------------------
  |  Branch (358:17): [True: 2, False: 54]
  ------------------
  359|      2|                session->extensions |= SSH_EXT_SIG_RSA_SHA256;
  ------------------
  |  |  126|      2|#define SSH_EXT_SIG_RSA_SHA256  0x02
  ------------------
  360|      2|            }
  361|    235|        } else if (strcmp(name, "publickey-hostbound@openssh.com") == 0) {
  ------------------
  |  Branch (361:20): [True: 0, False: 235]
  ------------------
  362|      0|            SSH_LOG(SSH_LOG_PACKET, "Extension: %s=<%s>", name, value);
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  363|      0|            session->extensions |= SSH_EXT_PUBLICKEY_HOSTBOUND;
  ------------------
  |  |  129|      0|#define SSH_EXT_PUBLICKEY_HOSTBOUND 0x08
  ------------------
  364|    235|        } else if (strcmp(name, "ping@openssh.com") == 0) {
  ------------------
  |  Branch (364:20): [True: 0, False: 235]
  ------------------
  365|      0|            if (strcmp(value, "0") == 0) {
  ------------------
  |  Branch (365:17): [True: 0, False: 0]
  ------------------
  366|      0|                SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  367|      0|                        "Extension: %s=<%s> (supported)",
  368|      0|                        name,
  369|      0|                        value);
  370|      0|                session->extensions |= SSH_EXT_PING;
  ------------------
  |  |  131|      0|#define SSH_EXT_PING 0x10
  ------------------
  371|      0|            } else {
  372|      0|                SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  373|      0|                        "Extension: %s=<%s> (unsupported version, expected 0)",
  374|      0|                        name,
  375|      0|                        value);
  376|      0|            }
  377|    235|        } else {
  378|    235|            SSH_LOG(SSH_LOG_PACKET, "Unknown extension: %s", name);
  ------------------
  |  |  283|    235|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  379|    235|        }
  380|    291|        free(name);
  381|    291|        free(value);
  382|    291|    }
  383|       |
  384|      0|    return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  385|     67|}

ssh_packet_decrypt_len:
   55|  49.6k|{
   56|  49.6k|    struct ssh_crypto_struct *crypto = NULL;
   57|  49.6k|    uint32_t decrypted;
   58|  49.6k|    int rc;
   59|       |
   60|  49.6k|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_IN);
   61|  49.6k|    if (crypto != NULL) {
  ------------------
  |  Branch (61:9): [True: 11.6k, False: 38.0k]
  ------------------
   62|  11.6k|        if (crypto->in_cipher->aead_decrypt_length != NULL) {
  ------------------
  |  Branch (62:13): [True: 0, False: 11.6k]
  ------------------
   63|      0|            rc = crypto->in_cipher->aead_decrypt_length(
   64|      0|                    crypto->in_cipher, source, destination,
   65|      0|                    crypto->in_cipher->lenfield_blocksize,
   66|      0|                    session->recv_seq);
   67|  11.6k|        } else {
   68|  11.6k|            rc = ssh_packet_decrypt(
   69|  11.6k|                    session,
   70|  11.6k|                    destination,
   71|  11.6k|                    source,
   72|  11.6k|                    0,
   73|  11.6k|                    crypto->in_cipher->blocksize);
   74|  11.6k|        }
   75|  11.6k|        if (rc < 0) {
  ------------------
  |  Branch (75:13): [True: 0, False: 11.6k]
  ------------------
   76|      0|            return 0;
   77|      0|        }
   78|  38.0k|    } else {
   79|  38.0k|        memcpy(destination, source, 8);
   80|  38.0k|    }
   81|  49.6k|    memcpy(&decrypted,destination,sizeof(decrypted));
   82|       |
   83|       |    return ntohl(decrypted);
   84|  49.6k|}
ssh_packet_decrypt:
   97|  17.1k|{
   98|  17.1k|    struct ssh_crypto_struct *crypto = NULL;
   99|  17.1k|    struct ssh_cipher_struct *cipher = NULL;
  100|       |
  101|  17.1k|    if (encrypted_size <= 0) {
  ------------------
  |  Branch (101:9): [True: 0, False: 17.1k]
  ------------------
  102|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  103|      0|    }
  104|       |
  105|  17.1k|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_IN);
  106|  17.1k|    if (crypto == NULL) {
  ------------------
  |  Branch (106:9): [True: 0, False: 17.1k]
  ------------------
  107|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  108|      0|    }
  109|  17.1k|    cipher = crypto->in_cipher;
  110|       |
  111|  17.1k|    if (encrypted_size % cipher->blocksize != 0) {
  ------------------
  |  Branch (111:9): [True: 14, False: 17.1k]
  ------------------
  112|     14|        ssh_set_error(session,
  ------------------
  |  |  313|     14|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  113|     14|                      SSH_FATAL,
  114|     14|                      "Cryptographic functions must be used on multiple of "
  115|     14|                      "blocksize (received %zu)",
  116|     14|                      encrypted_size);
  117|     14|        return SSH_ERROR;
  ------------------
  |  |  316|     14|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  118|     14|    }
  119|       |
  120|  17.1k|    if (cipher->aead_decrypt != NULL) {
  ------------------
  |  Branch (120:9): [True: 0, False: 17.1k]
  ------------------
  121|      0|        return cipher->aead_decrypt(cipher,
  122|      0|                                    source,
  123|      0|                                    destination,
  124|      0|                                    encrypted_size,
  125|      0|                                    session->recv_seq);
  126|  17.1k|    } else {
  127|  17.1k|        cipher->decrypt(cipher, source + start, destination, encrypted_size);
  128|  17.1k|    }
  129|       |
  130|  17.1k|    return 0;
  131|  17.1k|}
ssh_packet_encrypt:
  134|  15.1k|{
  135|  15.1k|  struct ssh_crypto_struct *crypto = NULL;
  136|  15.1k|  struct ssh_cipher_struct *cipher = NULL;
  137|  15.1k|  HMACCTX ctx = NULL;
  138|  15.1k|  char *out = NULL;
  139|  15.1k|  int etm_packet_offset = 0, rc;
  140|  15.1k|  unsigned int blocksize;
  141|  15.1k|  size_t finallen = DIGEST_MAX_LEN;
  ------------------
  |  |   56|  15.1k|#define DIGEST_MAX_LEN 64
  ------------------
  142|  15.1k|  uint32_t seq, lenfield_blocksize;
  143|  15.1k|  enum ssh_hmac_e type;
  144|  15.1k|  bool etm;
  145|       |
  146|  15.1k|  assert(len);
  ------------------
  |  Branch (146:3): [True: 0, False: 15.1k]
  |  Branch (146:3): [True: 15.1k, False: 0]
  ------------------
  147|       |
  148|  15.1k|  crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_OUT);
  149|  15.1k|  if (crypto == NULL) {
  ------------------
  |  Branch (149:7): [True: 9.86k, False: 5.28k]
  ------------------
  150|  9.86k|      return NULL; /* nothing to do here */
  151|  9.86k|  }
  152|       |
  153|  5.28k|  blocksize = crypto->out_cipher->blocksize;
  154|  5.28k|  lenfield_blocksize = crypto->out_cipher->lenfield_blocksize;
  155|       |
  156|  5.28k|  type = crypto->out_hmac;
  157|  5.28k|  etm = crypto->out_hmac_etm;
  158|       |
  159|  5.28k|  if (etm) {
  ------------------
  |  Branch (159:7): [True: 0, False: 5.28k]
  ------------------
  160|      0|      etm_packet_offset = sizeof(uint32_t);
  161|      0|  }
  162|       |
  163|  5.28k|  if ((len - lenfield_blocksize - etm_packet_offset) % blocksize != 0) {
  ------------------
  |  Branch (163:7): [True: 0, False: 5.28k]
  ------------------
  164|      0|      ssh_set_error(session, SSH_FATAL, "Cryptographic functions must be set"
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  165|      0|                    " on at least one blocksize (received %zu)", len);
  166|      0|      return NULL;
  167|      0|  }
  168|  5.28k|  out = calloc(1, len);
  169|  5.28k|  if (out == NULL) {
  ------------------
  |  Branch (169:7): [True: 0, False: 5.28k]
  ------------------
  170|      0|    return NULL;
  171|      0|  }
  172|       |
  173|  5.28k|  seq = ntohl(session->send_seq);
  174|  5.28k|  cipher = crypto->out_cipher;
  175|       |
  176|  5.28k|  if (cipher->aead_encrypt != NULL) {
  ------------------
  |  Branch (176:7): [True: 0, False: 5.28k]
  ------------------
  177|      0|      cipher->aead_encrypt(cipher, data, out, len,
  178|      0|            crypto->hmacbuf, session->send_seq);
  179|      0|      memcpy(data, out, len);
  180|  5.28k|  } else {
  181|  5.28k|      if (type != SSH_HMAC_NONE) {
  ------------------
  |  Branch (181:11): [True: 0, False: 5.28k]
  ------------------
  182|      0|          ctx = hmac_init(crypto->encryptMAC, hmac_digest_len(type), type);
  183|      0|          if (ctx == NULL) {
  ------------------
  |  Branch (183:15): [True: 0, False: 0]
  ------------------
  184|      0|              SAFE_FREE(out);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  185|      0|              return NULL;
  186|      0|          }
  187|       |
  188|      0|          if (!etm) {
  ------------------
  |  Branch (188:15): [True: 0, False: 0]
  ------------------
  189|      0|              rc = hmac_update(ctx, (unsigned char *)&seq, sizeof(uint32_t));
  190|      0|              if (rc != 1) {
  ------------------
  |  Branch (190:19): [True: 0, False: 0]
  ------------------
  191|      0|                  SAFE_FREE(out);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  192|      0|                  return NULL;
  193|      0|              }
  194|      0|              rc = hmac_update(ctx, data, len);
  195|      0|              if (rc != 1) {
  ------------------
  |  Branch (195:19): [True: 0, False: 0]
  ------------------
  196|      0|                  SAFE_FREE(out);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  197|      0|                  return NULL;
  198|      0|              }
  199|      0|              rc = hmac_final(ctx, crypto->hmacbuf, &finallen);
  200|      0|              if (rc != 1) {
  ------------------
  |  Branch (200:19): [True: 0, False: 0]
  ------------------
  201|      0|                  SAFE_FREE(out);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  202|      0|                  return NULL;
  203|      0|              }
  204|      0|          }
  205|      0|      }
  206|       |
  207|  5.28k|      cipher->encrypt(cipher, (uint8_t*)data + etm_packet_offset, out, len - etm_packet_offset);
  208|  5.28k|      memcpy((uint8_t*)data + etm_packet_offset, out, len - etm_packet_offset);
  209|       |
  210|  5.28k|      if (type != SSH_HMAC_NONE) {
  ------------------
  |  Branch (210:11): [True: 0, False: 5.28k]
  ------------------
  211|      0|          if (etm) {
  ------------------
  |  Branch (211:15): [True: 0, False: 0]
  ------------------
  212|      0|              PUSH_BE_U32(data, 0, len - etm_packet_offset);
  ------------------
  |  |   89|      0|    (PUSH_BE_U16((data), (pos), (uint16_t)(((uint32_t)(val)) >> 16)), PUSH_BE_U16((data), (pos) + 2, (uint16_t)((val) & 0xffff)))
  |  |  ------------------
  |  |  |  |   86|      0|    (PUSH_BE_U8((data), (pos), (uint8_t)(((uint16_t)(val)) >> 8)), PUSH_BE_U8((data), (pos) + 1, (uint8_t)((val) & 0xff)))
  |  |  |  |  ------------------
  |  |  |  |  |  |   83|      0|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|      0|    (((uint8_t *)(data))[(pos)])
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |                   (PUSH_BE_U8((data), (pos), (uint8_t)(((uint16_t)(val)) >> 8)), PUSH_BE_U8((data), (pos) + 1, (uint8_t)((val) & 0xff)))
  |  |  |  |  ------------------
  |  |  |  |  |  |   83|      0|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|      0|    (((uint8_t *)(data))[(pos)])
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   (PUSH_BE_U16((data), (pos), (uint16_t)(((uint32_t)(val)) >> 16)), PUSH_BE_U16((data), (pos) + 2, (uint16_t)((val) & 0xffff)))
  |  |  ------------------
  |  |  |  |   86|      0|    (PUSH_BE_U8((data), (pos), (uint8_t)(((uint16_t)(val)) >> 8)), PUSH_BE_U8((data), (pos) + 1, (uint8_t)((val) & 0xff)))
  |  |  |  |  ------------------
  |  |  |  |  |  |   83|      0|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|      0|    (((uint8_t *)(data))[(pos)])
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |                   (PUSH_BE_U8((data), (pos), (uint8_t)(((uint16_t)(val)) >> 8)), PUSH_BE_U8((data), (pos) + 1, (uint8_t)((val) & 0xff)))
  |  |  |  |  ------------------
  |  |  |  |  |  |   83|      0|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|      0|    (((uint8_t *)(data))[(pos)])
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  213|      0|              rc = hmac_update(ctx, (unsigned char *)&seq, sizeof(uint32_t));
  214|      0|              if (rc != 1) {
  ------------------
  |  Branch (214:19): [True: 0, False: 0]
  ------------------
  215|      0|                  SAFE_FREE(out);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  216|      0|                  return NULL;
  217|      0|              }
  218|      0|              rc = hmac_update(ctx, data, len);
  219|      0|              if (rc != 1) {
  ------------------
  |  Branch (219:19): [True: 0, False: 0]
  ------------------
  220|      0|                  SAFE_FREE(out);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  221|      0|                  return NULL;
  222|      0|              }
  223|      0|              rc = hmac_final(ctx, crypto->hmacbuf, &finallen);
  224|      0|              if (rc != 1) {
  ------------------
  |  Branch (224:19): [True: 0, False: 0]
  ------------------
  225|      0|                  SAFE_FREE(out);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  226|      0|                  return NULL;
  227|      0|              }
  228|      0|          }
  229|       |#ifdef DEBUG_CRYPTO
  230|       |          ssh_log_hexdump("mac: ", data, len);
  231|       |          if (finallen != hmac_digest_len(type)) {
  232|       |              printf("Final len is %zu\n", finallen);
  233|       |          }
  234|       |          ssh_log_hexdump("Packet hmac", crypto->hmacbuf, hmac_digest_len(type));
  235|       |#endif
  236|      0|      }
  237|  5.28k|  }
  238|  5.28k|  ssh_burn(out, len);
  ------------------
  |  |  390|  5.28k|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  239|  5.28k|  SAFE_FREE(out);
  ------------------
  |  |  375|  5.28k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 5.28k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 5.28k]
  |  |  ------------------
  ------------------
  240|       |
  241|  5.28k|  return crypto->hmacbuf;
  242|  5.28k|}

ssh_key_new:
  113|  2.24k|{
  114|  2.24k|    ssh_key ptr = malloc (sizeof (struct ssh_key_struct));
  115|  2.24k|    if (ptr == NULL) {
  ------------------
  |  Branch (115:9): [True: 0, False: 2.24k]
  ------------------
  116|      0|        return NULL;
  117|      0|    }
  118|  2.24k|    ZERO_STRUCTP(ptr);
  ------------------
  |  |  381|  2.24k|#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((x), 0, sizeof(*(x))); } while(0)
  |  |  ------------------
  |  |  |  Branch (381:34): [True: 2.24k, False: 0]
  |  |  |  Branch (381:85): [Folded, False: 2.24k]
  |  |  ------------------
  ------------------
  119|  2.24k|    return ptr;
  120|  2.24k|}
pki_key_dup_common_init:
  145|    504|{
  146|    504|    ssh_key new = NULL;
  147|       |
  148|    504|    if (key == NULL) {
  ------------------
  |  Branch (148:9): [True: 0, False: 504]
  ------------------
  149|      0|        return NULL;
  150|      0|    }
  151|       |
  152|    504|    new = ssh_key_new();
  153|    504|    if (new == NULL) {
  ------------------
  |  Branch (153:9): [True: 0, False: 504]
  ------------------
  154|      0|        return NULL;
  155|      0|    }
  156|       |
  157|    504|    new->type = key->type;
  158|    504|    new->type_c = key->type_c;
  159|    504|    if (demote) {
  ------------------
  |  Branch (159:9): [True: 185, False: 319]
  ------------------
  160|    185|        new->flags = SSH_KEY_FLAG_PUBLIC;
  ------------------
  |  |   54|    185|#define SSH_KEY_FLAG_PUBLIC  0x0001
  ------------------
  161|    319|    } else {
  162|    319|        new->flags = key->flags;
  163|    319|    }
  164|       |
  165|       |    /* Copy security key fields if present */
  166|    504|    if (is_sk_key_type(key->type)) {
  ------------------
  |  |  153|    504|    ((kt) == SSH_KEYTYPE_SK_ECDSA || (kt) == SSH_KEYTYPE_SK_ED25519 || \
  |  |  ------------------
  |  |  |  Branch (153:6): [True: 0, False: 504]
  |  |  |  Branch (153:38): [True: 0, False: 504]
  |  |  ------------------
  |  |  154|    504|     (kt) == SSH_KEYTYPE_SK_ECDSA_CERT01 ||                            \
  |  |  ------------------
  |  |  |  Branch (154:6): [True: 0, False: 504]
  |  |  ------------------
  |  |  155|    504|     (kt) == SSH_KEYTYPE_SK_ED25519_CERT01)
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 504]
  |  |  ------------------
  ------------------
  167|      0|        new->sk_application = ssh_string_copy(key->sk_application);
  168|      0|        if (new->sk_application == NULL) {
  ------------------
  |  Branch (168:13): [True: 0, False: 0]
  ------------------
  169|      0|            goto fail;
  170|      0|        }
  171|       |
  172|      0|        if (key->sk_user_id != NULL) {
  ------------------
  |  Branch (172:13): [True: 0, False: 0]
  ------------------
  173|      0|            new->sk_user_id = ssh_string_copy(key->sk_user_id);
  174|      0|            if (new->sk_user_id == NULL) {
  ------------------
  |  Branch (174:17): [True: 0, False: 0]
  ------------------
  175|      0|                goto fail;
  176|      0|            }
  177|      0|        }
  178|       |
  179|      0|        if (!demote) {
  ------------------
  |  Branch (179:13): [True: 0, False: 0]
  ------------------
  180|      0|            new->sk_flags = key->sk_flags;
  181|       |
  182|      0|            new->sk_key_handle = ssh_string_copy(key->sk_key_handle);
  183|      0|            if (new->sk_key_handle == NULL) {
  ------------------
  |  Branch (183:17): [True: 0, False: 0]
  ------------------
  184|      0|                goto fail;
  185|      0|            }
  186|       |
  187|      0|            new->sk_reserved = ssh_string_copy(key->sk_reserved);
  188|      0|            if (new->sk_reserved == NULL) {
  ------------------
  |  Branch (188:17): [True: 0, False: 0]
  ------------------
  189|      0|                goto fail;
  190|      0|            }
  191|      0|        }
  192|      0|    }
  193|       |
  194|    504|    return new;
  195|       |
  196|      0|fail:
  197|      0|    SSH_KEY_FREE(new);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  198|       |    return NULL;
  199|    504|}
ssh_key_dup:
  209|    319|{
  210|    319|    if (key == NULL) {
  ------------------
  |  Branch (210:9): [True: 0, False: 319]
  ------------------
  211|      0|        return NULL;
  212|      0|    }
  213|       |
  214|    319|    return pki_key_dup(key, 0);
  215|    319|}
ssh_key_clean:
  222|  2.24k|{
  223|  2.24k|    if (key == NULL)
  ------------------
  |  Branch (223:9): [True: 0, False: 2.24k]
  ------------------
  224|      0|        return;
  225|       |
  226|  2.24k|    pki_key_clean(key);
  227|       |
  228|       |#ifndef HAVE_LIBCRYPTO
  229|       |    if (key->ed25519_privkey != NULL) {
  230|       |        ssh_burn(key->ed25519_privkey, sizeof(ed25519_privkey));
  231|       |        SAFE_FREE(key->ed25519_privkey);
  232|       |    }
  233|       |    SAFE_FREE(key->ed25519_pubkey);
  234|       |#endif /* HAVE_LIBCRYPTO */
  235|  2.24k|    if (key->cert != NULL) {
  ------------------
  |  Branch (235:9): [True: 1.17k, False: 1.07k]
  ------------------
  236|  1.17k|        SSH_BUFFER_FREE(key->cert);
  ------------------
  |  |  924|  1.17k|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 1.17k, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 1.17k]
  |  |  ------------------
  ------------------
  237|  1.17k|    }
  238|  2.24k|    if (is_sk_key_type(key->type)) {
  ------------------
  |  |  153|  2.24k|    ((kt) == SSH_KEYTYPE_SK_ECDSA || (kt) == SSH_KEYTYPE_SK_ED25519 || \
  |  |  ------------------
  |  |  |  Branch (153:6): [True: 1, False: 2.24k]
  |  |  |  Branch (153:38): [True: 0, False: 2.24k]
  |  |  ------------------
  |  |  154|  2.24k|     (kt) == SSH_KEYTYPE_SK_ECDSA_CERT01 ||                            \
  |  |  ------------------
  |  |  |  Branch (154:6): [True: 0, False: 2.24k]
  |  |  ------------------
  |  |  155|  2.24k|     (kt) == SSH_KEYTYPE_SK_ED25519_CERT01)
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 2.24k]
  |  |  ------------------
  ------------------
  239|      1|        ssh_string_burn(key->sk_application);
  240|      1|        ssh_string_free(key->sk_application);
  241|      1|        ssh_string_burn(key->sk_key_handle);
  242|      1|        ssh_string_free(key->sk_key_handle);
  243|      1|        ssh_string_burn(key->sk_reserved);
  244|      1|        ssh_string_free(key->sk_reserved);
  245|      1|        ssh_string_burn(key->sk_user_id);
  246|      1|        ssh_string_free(key->sk_user_id);
  247|      1|        key->sk_flags = 0;
  248|      1|    }
  249|  2.24k|    key->cert_type = SSH_KEYTYPE_UNKNOWN;
  250|  2.24k|    key->flags = SSH_KEY_FLAG_EMPTY;
  ------------------
  |  |   53|  2.24k|#define SSH_KEY_FLAG_EMPTY   0x0
  ------------------
  251|  2.24k|    key->type = SSH_KEYTYPE_UNKNOWN;
  252|  2.24k|    key->ecdsa_nid = 0;
  253|       |    key->type_c = NULL;
  254|  2.24k|}
ssh_key_free:
  261|  18.2k|{
  262|  18.2k|    if (key) {
  ------------------
  |  Branch (262:9): [True: 2.24k, False: 16.0k]
  ------------------
  263|  2.24k|        ssh_key_clean(key);
  264|       |        SAFE_FREE(key);
  ------------------
  |  |  375|  2.24k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 2.24k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 2.24k]
  |  |  ------------------
  ------------------
  265|  2.24k|    }
  266|  18.2k|}
ssh_key_type:
  280|  1.14k|{
  281|  1.14k|    if (key == NULL) {
  ------------------
  |  Branch (281:9): [True: 0, False: 1.14k]
  ------------------
  282|      0|        return SSH_KEYTYPE_UNKNOWN;
  283|      0|    }
  284|  1.14k|    return key->type;
  285|  1.14k|}
ssh_key_signature_to_char:
  367|    185|{
  368|    185|    switch (type) {
  369|    185|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (369:5): [True: 185, False: 0]
  ------------------
  370|    185|        switch (hash_type) {
  371|    172|        case SSH_DIGEST_SHA256:
  ------------------
  |  Branch (371:9): [True: 172, False: 13]
  ------------------
  372|    172|            return "rsa-sha2-256";
  373|     13|        case SSH_DIGEST_SHA512:
  ------------------
  |  Branch (373:9): [True: 13, False: 172]
  ------------------
  374|     13|            return "rsa-sha2-512";
  375|      0|        case SSH_DIGEST_SHA1:
  ------------------
  |  Branch (375:9): [True: 0, False: 185]
  ------------------
  376|      0|        case SSH_DIGEST_AUTO:
  ------------------
  |  Branch (376:9): [True: 0, False: 185]
  ------------------
  377|      0|            return "ssh-rsa";
  378|      0|        default:
  ------------------
  |  Branch (378:9): [True: 0, False: 185]
  ------------------
  379|      0|            return NULL;
  380|    185|        }
  381|      0|        break;
  382|      0|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (382:5): [True: 0, False: 185]
  ------------------
  383|      0|        switch (hash_type) {
  384|      0|        case SSH_DIGEST_SHA256:
  ------------------
  |  Branch (384:9): [True: 0, False: 0]
  ------------------
  385|      0|            return "rsa-sha2-256-cert-v01@openssh.com";
  386|      0|        case SSH_DIGEST_SHA512:
  ------------------
  |  Branch (386:9): [True: 0, False: 0]
  ------------------
  387|      0|            return "rsa-sha2-512-cert-v01@openssh.com";
  388|      0|        case SSH_DIGEST_SHA1:
  ------------------
  |  Branch (388:9): [True: 0, False: 0]
  ------------------
  389|      0|        case SSH_DIGEST_AUTO:
  ------------------
  |  Branch (389:9): [True: 0, False: 0]
  ------------------
  390|      0|            return "ssh-rsa-cert-v01@openssh.com";
  391|      0|        default:
  ------------------
  |  Branch (391:9): [True: 0, False: 0]
  ------------------
  392|      0|            return NULL;
  393|      0|        }
  394|      0|        break;
  395|      0|    default:
  ------------------
  |  Branch (395:5): [True: 0, False: 185]
  ------------------
  396|      0|        return ssh_key_type_to_char(type);
  397|    185|    }
  398|       |
  399|       |    /* We should never reach this */
  400|      0|    return NULL;
  401|    185|}
ssh_key_type_to_char:
  410|  3.33k|const char *ssh_key_type_to_char(enum ssh_keytypes_e type) {
  411|  3.33k|  switch (type) {
  ------------------
  |  Branch (411:11): [True: 3.33k, False: 0]
  ------------------
  412|  2.06k|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (412:5): [True: 2.06k, False: 1.26k]
  ------------------
  413|  2.06k|      return "ssh-rsa";
  414|      0|    case SSH_KEYTYPE_ECDSA:
  ------------------
  |  Branch (414:5): [True: 0, False: 3.33k]
  ------------------
  415|      0|      return "ssh-ecdsa"; /* deprecated. invalid value */
  416|      0|    case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (416:5): [True: 0, False: 3.33k]
  ------------------
  417|      0|      return "ecdsa-sha2-nistp256";
  418|      0|    case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (418:5): [True: 0, False: 3.33k]
  ------------------
  419|      0|      return "ecdsa-sha2-nistp384";
  420|      0|    case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (420:5): [True: 0, False: 3.33k]
  ------------------
  421|      0|      return "ecdsa-sha2-nistp521";
  422|      0|    case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (422:5): [True: 0, False: 3.33k]
  ------------------
  423|      0|      return "ssh-ed25519";
  424|  1.26k|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (424:5): [True: 1.26k, False: 2.06k]
  ------------------
  425|  1.26k|      return "ssh-rsa-cert-v01@openssh.com";
  426|      0|    case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (426:5): [True: 0, False: 3.33k]
  ------------------
  427|      0|      return "ecdsa-sha2-nistp256-cert-v01@openssh.com";
  428|      0|    case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (428:5): [True: 0, False: 3.33k]
  ------------------
  429|      0|      return "ecdsa-sha2-nistp384-cert-v01@openssh.com";
  430|      0|    case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (430:5): [True: 0, False: 3.33k]
  ------------------
  431|      0|      return "ecdsa-sha2-nistp521-cert-v01@openssh.com";
  432|      0|    case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (432:5): [True: 0, False: 3.33k]
  ------------------
  433|      0|      return "ssh-ed25519-cert-v01@openssh.com";
  434|      1|    case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (434:5): [True: 1, False: 3.33k]
  ------------------
  435|      1|      return "sk-ecdsa-sha2-nistp256@openssh.com";
  436|      0|    case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (436:5): [True: 0, False: 3.33k]
  ------------------
  437|      0|      return "sk-ssh-ed25519@openssh.com";
  438|      0|    case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (438:5): [True: 0, False: 3.33k]
  ------------------
  439|      0|      return "sk-ecdsa-sha2-nistp256-cert-v01@openssh.com";
  440|      0|    case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (440:5): [True: 0, False: 3.33k]
  ------------------
  441|      0|      return "sk-ssh-ed25519-cert-v01@openssh.com";
  442|      0|    case SSH_KEYTYPE_DSS:   /* deprecated */
  ------------------
  |  Branch (442:5): [True: 0, False: 3.33k]
  ------------------
  443|      0|    case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (443:5): [True: 0, False: 3.33k]
  ------------------
  444|      0|    case SSH_KEYTYPE_DSS_CERT01:    /* deprecated */
  ------------------
  |  Branch (444:5): [True: 0, False: 3.33k]
  ------------------
  445|      0|    case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (445:5): [True: 0, False: 3.33k]
  ------------------
  446|      0|      return NULL;
  447|  3.33k|  }
  448|       |
  449|       |  /* We should never reach this */
  450|      0|  return NULL;
  451|  3.33k|}
ssh_key_type_and_hash_from_signature_name:
  472|    218|{
  473|    218|    size_t len;
  474|       |
  475|    218|    if (name == NULL || type == NULL || hash_type == NULL) {
  ------------------
  |  Branch (475:9): [True: 0, False: 218]
  |  Branch (475:25): [True: 0, False: 218]
  |  Branch (475:41): [True: 0, False: 218]
  ------------------
  476|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  477|      0|    }
  478|       |
  479|    218|    len = strlen(name);
  480|       |
  481|    218|    if (len == 7 && strcmp(name, "ssh-rsa") == 0) {
  ------------------
  |  Branch (481:9): [True: 0, False: 218]
  |  Branch (481:21): [True: 0, False: 0]
  ------------------
  482|      0|        *type = SSH_KEYTYPE_RSA;
  483|      0|        *hash_type = SSH_DIGEST_SHA1;
  484|      0|        return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  485|      0|    }
  486|       |
  487|    218|    if (len == 11 && strcmp(name, "ssh-ed25519") == 0) {
  ------------------
  |  Branch (487:9): [True: 0, False: 218]
  |  Branch (487:22): [True: 0, False: 0]
  ------------------
  488|      0|        *type = SSH_KEYTYPE_ED25519;
  489|      0|        *hash_type = SSH_DIGEST_AUTO;
  490|      0|        return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  491|      0|    }
  492|       |
  493|    218|    if (len == 12) {
  ------------------
  |  Branch (493:9): [True: 218, False: 0]
  ------------------
  494|    218|        if (strcmp(name, "rsa-sha2-256") == 0) {
  ------------------
  |  Branch (494:13): [True: 182, False: 36]
  ------------------
  495|    182|            *type = SSH_KEYTYPE_RSA;
  496|    182|            *hash_type = SSH_DIGEST_SHA256;
  497|    182|            return SSH_OK;
  ------------------
  |  |  315|    182|#define SSH_OK 0     /* No error */
  ------------------
  498|    182|        }
  499|     36|        if (strcmp(name, "rsa-sha2-512") == 0) {
  ------------------
  |  Branch (499:13): [True: 36, False: 0]
  ------------------
  500|     36|            *type = SSH_KEYTYPE_RSA;
  501|     36|            *hash_type = SSH_DIGEST_SHA512;
  502|     36|            return SSH_OK;
  ------------------
  |  |  315|     36|#define SSH_OK 0     /* No error */
  ------------------
  503|     36|        }
  504|     36|    }
  505|       |
  506|      0|    if (len == 19) {
  ------------------
  |  Branch (506:9): [True: 0, False: 0]
  ------------------
  507|      0|        if (strcmp(name, "ecdsa-sha2-nistp256") == 0) {
  ------------------
  |  Branch (507:13): [True: 0, False: 0]
  ------------------
  508|      0|            *type = SSH_KEYTYPE_ECDSA_P256;
  509|      0|            *hash_type = SSH_DIGEST_SHA256;
  510|      0|            return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  511|      0|        }
  512|      0|        if (strcmp(name, "ecdsa-sha2-nistp384") == 0) {
  ------------------
  |  Branch (512:13): [True: 0, False: 0]
  ------------------
  513|      0|            *type = SSH_KEYTYPE_ECDSA_P384;
  514|      0|            *hash_type = SSH_DIGEST_SHA384;
  515|      0|            return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  516|      0|        }
  517|       |
  518|      0|        if (strcmp(name, "ecdsa-sha2-nistp521") == 0) {
  ------------------
  |  Branch (518:13): [True: 0, False: 0]
  ------------------
  519|      0|            *type = SSH_KEYTYPE_ECDSA_P521;
  520|      0|            *hash_type = SSH_DIGEST_SHA512;
  521|      0|            return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  522|      0|        }
  523|      0|    }
  524|       |
  525|      0|    if (len == 26 && strcmp(name, "sk-ssh-ed25519@openssh.com") == 0) {
  ------------------
  |  Branch (525:9): [True: 0, False: 0]
  |  Branch (525:22): [True: 0, False: 0]
  ------------------
  526|      0|        *type = SSH_KEYTYPE_SK_ED25519;
  527|      0|        *hash_type = SSH_DIGEST_AUTO;
  528|      0|        return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  529|      0|    }
  530|       |
  531|      0|    if (len == 28 && strcmp(name, "ssh-rsa-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (531:9): [True: 0, False: 0]
  |  Branch (531:22): [True: 0, False: 0]
  ------------------
  532|      0|        *type = SSH_KEYTYPE_RSA_CERT01;
  533|      0|        *hash_type = SSH_DIGEST_SHA1;
  534|      0|        return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  535|      0|    }
  536|       |
  537|      0|    if (len == 32 && strcmp(name, "ssh-ed25519-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (537:9): [True: 0, False: 0]
  |  Branch (537:22): [True: 0, False: 0]
  ------------------
  538|      0|        *type = SSH_KEYTYPE_ED25519_CERT01;
  539|      0|        *hash_type = SSH_DIGEST_AUTO;
  540|      0|        return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  541|      0|    }
  542|       |
  543|      0|    if (len == 33) {
  ------------------
  |  Branch (543:9): [True: 0, False: 0]
  ------------------
  544|      0|        if (strcmp(name, "rsa-sha2-256-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (544:13): [True: 0, False: 0]
  ------------------
  545|      0|            *type = SSH_KEYTYPE_RSA_CERT01;
  546|      0|            *hash_type = SSH_DIGEST_SHA256;
  547|      0|            return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  548|      0|        }
  549|      0|        if (strcmp(name, "rsa-sha2-512-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (549:13): [True: 0, False: 0]
  ------------------
  550|      0|            *type = SSH_KEYTYPE_RSA_CERT01;
  551|      0|            *hash_type = SSH_DIGEST_SHA512;
  552|      0|            return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  553|      0|        }
  554|      0|    }
  555|       |
  556|      0|    if (len == 34 && strcmp(name, "sk-ecdsa-sha2-nistp256@openssh.com") == 0) {
  ------------------
  |  Branch (556:9): [True: 0, False: 0]
  |  Branch (556:22): [True: 0, False: 0]
  ------------------
  557|      0|        *type = SSH_KEYTYPE_SK_ECDSA;
  558|      0|        *hash_type = SSH_DIGEST_SHA256;
  559|      0|        return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  560|      0|    }
  561|       |
  562|      0|    if (len == 40) {
  ------------------
  |  Branch (562:9): [True: 0, False: 0]
  ------------------
  563|      0|        if (strcmp(name, "ecdsa-sha2-nistp256-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (563:13): [True: 0, False: 0]
  ------------------
  564|      0|            *type = SSH_KEYTYPE_ECDSA_P256_CERT01;
  565|      0|            *hash_type = SSH_DIGEST_SHA256;
  566|      0|            return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  567|      0|        }
  568|      0|        if (strcmp(name, "ecdsa-sha2-nistp384-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (568:13): [True: 0, False: 0]
  ------------------
  569|      0|            *type = SSH_KEYTYPE_ECDSA_P384_CERT01;
  570|      0|            *hash_type = SSH_DIGEST_SHA384;
  571|      0|            return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  572|      0|        }
  573|      0|        if (strcmp(name, "ecdsa-sha2-nistp521-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (573:13): [True: 0, False: 0]
  ------------------
  574|      0|            *type = SSH_KEYTYPE_ECDSA_P521_CERT01;
  575|      0|            *hash_type = SSH_DIGEST_SHA512;
  576|      0|            return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  577|      0|        }
  578|      0|    }
  579|       |
  580|      0|    SSH_LOG(SSH_LOG_TRACE, "Unknown signature name %s", name);
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  581|      0|    return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  582|      0|}
ssh_key_size_allowed_rsa:
  624|    504|{
  625|    504|    int key_size = ssh_key_size(key);
  626|       |
  627|    504|    if (min_size < RSA_MIN_KEY_SIZE) {
  ------------------
  |  |   49|    504|#define RSA_MIN_KEY_SIZE      1024
  ------------------
  |  Branch (627:9): [True: 504, False: 0]
  ------------------
  628|    504|        if (ssh_fips_mode()) {
  ------------------
  |  |  117|    504|#define ssh_fips_mode() EVP_default_properties_is_fips_enabled(NULL)
  |  |  ------------------
  |  |  |  Branch (117:25): [True: 0, False: 504]
  |  |  ------------------
  ------------------
  629|      0|            min_size = RSA_MIN_FIPS_KEY_SIZE;
  ------------------
  |  |   50|      0|#define RSA_MIN_FIPS_KEY_SIZE 2048
  ------------------
  630|    504|        } else {
  631|    504|            min_size = RSA_MIN_KEY_SIZE;
  ------------------
  |  |   49|    504|#define RSA_MIN_KEY_SIZE      1024
  ------------------
  632|    504|        }
  633|    504|    }
  634|    504|    return (key_size >= min_size);
  635|    504|}
ssh_key_size_allowed:
  646|    185|{
  647|    185|    int min_size = 0;
  648|       |
  649|    185|    switch (ssh_key_type(key)) {
  650|    185|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (650:5): [True: 185, False: 0]
  ------------------
  651|    185|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (651:5): [True: 0, False: 185]
  ------------------
  652|    185|        min_size = session->opts.rsa_min_size;
  653|    185|        return ssh_key_size_allowed_rsa(min_size, key);
  654|      0|    default:
  ------------------
  |  Branch (654:5): [True: 0, False: 185]
  ------------------
  655|       |        return true;
  656|    185|    }
  657|    185|}
ssh_key_type_from_name:
  808|  1.83k|{
  809|  1.83k|    if (name == NULL) {
  ------------------
  |  Branch (809:9): [True: 0, False: 1.83k]
  ------------------
  810|      0|        return SSH_KEYTYPE_UNKNOWN;
  811|      0|    }
  812|       |
  813|  1.83k|    if (strcmp(name, "rsa") == 0) {
  ------------------
  |  Branch (813:9): [True: 0, False: 1.83k]
  ------------------
  814|      0|        return SSH_KEYTYPE_RSA;
  815|  1.83k|    } else if (strcmp(name, "ssh-rsa") == 0) {
  ------------------
  |  Branch (815:16): [True: 185, False: 1.65k]
  ------------------
  816|    185|        return SSH_KEYTYPE_RSA;
  817|  1.65k|    } else if (strcmp(name, "ssh-ecdsa") == 0
  ------------------
  |  Branch (817:16): [True: 0, False: 1.65k]
  ------------------
  818|  1.65k|            || strcmp(name, "ecdsa") == 0
  ------------------
  |  Branch (818:16): [True: 0, False: 1.65k]
  ------------------
  819|  1.65k|            || strcmp(name, "ecdsa-sha2-nistp256") == 0) {
  ------------------
  |  Branch (819:16): [True: 0, False: 1.65k]
  ------------------
  820|      0|        return SSH_KEYTYPE_ECDSA_P256;
  821|  1.65k|    } else if (strcmp(name, "ecdsa-sha2-nistp384") == 0) {
  ------------------
  |  Branch (821:16): [True: 0, False: 1.65k]
  ------------------
  822|      0|        return SSH_KEYTYPE_ECDSA_P384;
  823|  1.65k|    } else if (strcmp(name, "ecdsa-sha2-nistp521") == 0) {
  ------------------
  |  Branch (823:16): [True: 0, False: 1.65k]
  ------------------
  824|      0|        return SSH_KEYTYPE_ECDSA_P521;
  825|  1.65k|    } else if (strcmp(name, "ssh-ed25519") == 0){
  ------------------
  |  Branch (825:16): [True: 0, False: 1.65k]
  ------------------
  826|      0|        return SSH_KEYTYPE_ED25519;
  827|  1.65k|    } else if (strcmp(name, "ssh-rsa-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (827:16): [True: 1.26k, False: 389]
  ------------------
  828|  1.26k|        return SSH_KEYTYPE_RSA_CERT01;
  829|  1.26k|    } else if (strcmp(name, "ecdsa-sha2-nistp256-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (829:16): [True: 0, False: 389]
  ------------------
  830|      0|        return SSH_KEYTYPE_ECDSA_P256_CERT01;
  831|    389|    } else if (strcmp(name, "ecdsa-sha2-nistp384-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (831:16): [True: 0, False: 389]
  ------------------
  832|      0|        return SSH_KEYTYPE_ECDSA_P384_CERT01;
  833|    389|    } else if (strcmp(name, "ecdsa-sha2-nistp521-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (833:16): [True: 0, False: 389]
  ------------------
  834|      0|        return SSH_KEYTYPE_ECDSA_P521_CERT01;
  835|    389|    } else if (strcmp(name, "ssh-ed25519-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (835:16): [True: 0, False: 389]
  ------------------
  836|      0|        return SSH_KEYTYPE_ED25519_CERT01;
  837|    389|    } else if(strcmp(name, "sk-ecdsa-sha2-nistp256@openssh.com") == 0) {
  ------------------
  |  Branch (837:15): [True: 1, False: 388]
  ------------------
  838|      1|        return SSH_KEYTYPE_SK_ECDSA;
  839|    388|    } else if(strcmp(name, "sk-ecdsa-sha2-nistp256-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (839:15): [True: 0, False: 388]
  ------------------
  840|      0|        return SSH_KEYTYPE_SK_ECDSA_CERT01;
  841|    388|    } else if(strcmp(name, "sk-ssh-ed25519@openssh.com") == 0) {
  ------------------
  |  Branch (841:15): [True: 0, False: 388]
  ------------------
  842|      0|        return SSH_KEYTYPE_SK_ED25519;
  843|    388|    } else if(strcmp(name, "sk-ssh-ed25519-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (843:15): [True: 0, False: 388]
  ------------------
  844|      0|        return SSH_KEYTYPE_SK_ED25519_CERT01;
  845|      0|    }
  846|       |
  847|    388|    return SSH_KEYTYPE_UNKNOWN;
  848|  1.83k|}
ssh_key_is_private:
  902|    555|int ssh_key_is_private(const ssh_key k) {
  903|    555|    if (k == NULL) {
  ------------------
  |  Branch (903:9): [True: 0, False: 555]
  ------------------
  904|      0|        return 0;
  905|      0|    }
  906|       |
  907|    555|    return (k->flags & SSH_KEY_FLAG_PRIVATE) == SSH_KEY_FLAG_PRIVATE;
  ------------------
  |  |   55|    555|#define SSH_KEY_FLAG_PRIVATE 0x0002
  ------------------
                  return (k->flags & SSH_KEY_FLAG_PRIVATE) == SSH_KEY_FLAG_PRIVATE;
  ------------------
  |  |   55|    555|#define SSH_KEY_FLAG_PRIVATE 0x0002
  ------------------
  908|    555|}
ssh_signature_new:
  997|    185|{
  998|    185|    struct ssh_signature_struct *sig = NULL;
  999|       |
 1000|    185|    sig = calloc(1, sizeof(struct ssh_signature_struct));
 1001|    185|    if (sig == NULL) {
  ------------------
  |  Branch (1001:9): [True: 0, False: 185]
  ------------------
 1002|      0|        return NULL;
 1003|      0|    }
 1004|       |
 1005|    185|    return sig;
 1006|    185|}
ssh_signature_free:
 1009|    185|{
 1010|    185|    if (sig == NULL) {
  ------------------
  |  Branch (1010:9): [True: 0, False: 185]
  ------------------
 1011|      0|        return;
 1012|      0|    }
 1013|       |
 1014|    185|    switch(sig->type) {
  ------------------
  |  Branch (1014:12): [True: 185, False: 0]
  ------------------
 1015|    185|        case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (1015:9): [True: 185, False: 0]
  ------------------
 1016|       |#ifdef HAVE_LIBMBEDCRYPTO
 1017|       |            SAFE_FREE(sig->rsa_sig);
 1018|       |#endif /* HAVE_LIBMBEDCRYPTO */
 1019|    185|            break;
 1020|      0|        case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (1020:9): [True: 0, False: 185]
  ------------------
 1021|      0|        case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (1021:9): [True: 0, False: 185]
  ------------------
 1022|      0|        case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (1022:9): [True: 0, False: 185]
  ------------------
 1023|      0|        case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (1023:9): [True: 0, False: 185]
  ------------------
 1024|       |#ifdef HAVE_GCRYPT_ECC
 1025|       |            gcry_sexp_release(sig->ecdsa_sig);
 1026|       |#elif defined HAVE_LIBMBEDCRYPTO
 1027|       |            bignum_safe_free(sig->ecdsa_sig.r);
 1028|       |            bignum_safe_free(sig->ecdsa_sig.s);
 1029|       |#endif /* HAVE_GCRYPT_ECC */
 1030|      0|            break;
 1031|      0|        case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (1031:9): [True: 0, False: 185]
  ------------------
 1032|      0|        case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (1032:9): [True: 0, False: 185]
  ------------------
 1033|       |#ifndef HAVE_LIBCRYPTO
 1034|       |            /* When using OpenSSL, the signature is stored in sig->raw_sig */
 1035|       |            SAFE_FREE(sig->ed25519_sig);
 1036|       |#endif /* HAVE_LIBCRYPTO */
 1037|      0|            break;
 1038|      0|        case SSH_KEYTYPE_DSS:   /* deprecated */
  ------------------
  |  Branch (1038:9): [True: 0, False: 185]
  ------------------
 1039|      0|        case SSH_KEYTYPE_DSS_CERT01:    /* deprecated */
  ------------------
  |  Branch (1039:9): [True: 0, False: 185]
  ------------------
 1040|      0|        case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (1040:9): [True: 0, False: 185]
  ------------------
 1041|      0|        case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (1041:9): [True: 0, False: 185]
  ------------------
 1042|      0|        case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (1042:9): [True: 0, False: 185]
  ------------------
 1043|      0|        case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (1043:9): [True: 0, False: 185]
  ------------------
 1044|      0|        case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (1044:9): [True: 0, False: 185]
  ------------------
 1045|      0|        case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (1045:9): [True: 0, False: 185]
  ------------------
 1046|      0|        case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (1046:9): [True: 0, False: 185]
  ------------------
 1047|      0|        case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (1047:9): [True: 0, False: 185]
  ------------------
 1048|      0|        case SSH_KEYTYPE_ECDSA:
  ------------------
  |  Branch (1048:9): [True: 0, False: 185]
  ------------------
 1049|      0|        case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (1049:9): [True: 0, False: 185]
  ------------------
 1050|      0|            break;
 1051|    185|    }
 1052|       |
 1053|       |    /* Explicitly zero the signature content before free */
 1054|    185|    ssh_string_burn(sig->raw_sig);
 1055|    185|    SSH_STRING_FREE(sig->raw_sig);
  ------------------
  |  |  882|    185|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 185, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 185]
  |  |  ------------------
  ------------------
 1056|       |    SAFE_FREE(sig);
  ------------------
  |  |  375|    185|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 185, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 185]
  |  |  ------------------
  ------------------
 1057|    185|}
ssh_pki_import_privkey_base64:
 1082|    660|{
 1083|    660|    ssh_key key = NULL;
 1084|    660|    const char *openssh_header = NULL;
 1085|       |
 1086|    660|    if (b64_key == NULL || pkey == NULL) {
  ------------------
  |  Branch (1086:9): [True: 0, False: 660]
  |  Branch (1086:28): [True: 0, False: 660]
  ------------------
 1087|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1088|      0|    }
 1089|       |
 1090|    660|    if (b64_key == NULL || !*b64_key) {
  ------------------
  |  Branch (1090:9): [True: 0, False: 660]
  |  Branch (1090:28): [True: 341, False: 319]
  ------------------
 1091|    341|        return SSH_ERROR;
  ------------------
  |  |  316|    341|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1092|    341|    }
 1093|       |
 1094|    319|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  283|    638|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (283:34): [True: 0, False: 319]
  |  |  ------------------
  ------------------
 1095|    319|            "Trying to decode privkey passphrase=%s",
 1096|    319|            passphrase ? "true" : "false");
 1097|       |
 1098|       |    /* Test for OpenSSH key format first */
 1099|    319|    openssh_header = strstr(b64_key, OPENSSH_HEADER_BEGIN);
  ------------------
  |  |   43|    319|#define OPENSSH_HEADER_BEGIN "-----BEGIN OPENSSH PRIVATE KEY-----"
  ------------------
 1100|    319|    if (openssh_header != NULL) {
  ------------------
  |  Branch (1100:9): [True: 0, False: 319]
  ------------------
 1101|      0|        key = ssh_pki_openssh_privkey_import(openssh_header,
 1102|      0|                                             passphrase,
 1103|      0|                                             auth_fn,
 1104|      0|                                             auth_data);
 1105|    319|    } else {
 1106|       |        /* fallback on PEM decoder */
 1107|    319|        key = pki_private_key_from_base64(b64_key,
 1108|    319|                                          passphrase,
 1109|    319|                                          auth_fn,
 1110|    319|                                          auth_data);
 1111|    319|    }
 1112|    319|    if (key == NULL) {
  ------------------
  |  Branch (1112:9): [True: 0, False: 319]
  ------------------
 1113|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1114|      0|    }
 1115|       |
 1116|    319|    *pkey = key;
 1117|       |
 1118|    319|    return SSH_OK;
  ------------------
  |  |  315|    319|#define SSH_OK 0     /* No error */
  ------------------
 1119|    319|}
ssh_pki_import_privkey_file:
 1266|    660|                                ssh_key *pkey) {
 1267|    660|    struct stat sb;
 1268|    660|    char *key_buf = NULL;
 1269|    660|    FILE *file = NULL;
 1270|    660|    off_t size;
 1271|    660|    int rc;
 1272|       |
 1273|    660|    if (pkey == NULL || filename == NULL || *filename == '\0') {
  ------------------
  |  Branch (1273:9): [True: 0, False: 660]
  |  Branch (1273:25): [True: 0, False: 660]
  |  Branch (1273:45): [True: 0, False: 660]
  ------------------
 1274|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1275|      0|    }
 1276|       |
 1277|       |#ifdef WITH_PKCS11_URI
 1278|       |    if (ssh_pki_is_uri(filename)) {
 1279|       |        rc = pki_uri_import(filename, pkey, SSH_KEY_PRIVATE);
 1280|       |        return rc;
 1281|       |    }
 1282|       |#endif /* WITH_PKCS11_URI */
 1283|       |
 1284|    660|    file = fopen(filename, "rb");
 1285|    660|    if (file == NULL) {
  ------------------
  |  Branch (1285:9): [True: 0, False: 660]
  ------------------
 1286|      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]
  |  |  ------------------
  ------------------
 1287|      0|                         errno,
 1288|      0|                         "Error opening %s: %s",
 1289|      0|                         filename);
 1290|      0|        return SSH_EOF;
  ------------------
  |  |  318|      0|#define SSH_EOF -127 /* We have already a eof */
  ------------------
 1291|      0|    }
 1292|       |
 1293|    660|    rc = fstat(fileno(file), &sb);
 1294|    660|    if (rc < 0) {
  ------------------
  |  Branch (1294:9): [True: 0, False: 660]
  ------------------
 1295|      0|        fclose(file);
 1296|      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]
  |  |  ------------------
  ------------------
 1297|      0|                         errno,
 1298|      0|                         "Error getting fstat of %s: %s",
 1299|      0|                         filename);
 1300|      0|        switch (errno) {
  ------------------
  |  Branch (1300:17): [True: 0, False: 0]
  ------------------
 1301|      0|            case ENOENT:
  ------------------
  |  Branch (1301:13): [True: 0, False: 0]
  ------------------
 1302|      0|            case EACCES:
  ------------------
  |  Branch (1302:13): [True: 0, False: 0]
  ------------------
 1303|      0|                return SSH_EOF;
  ------------------
  |  |  318|      0|#define SSH_EOF -127 /* We have already a eof */
  ------------------
 1304|      0|        }
 1305|       |
 1306|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1307|      0|    }
 1308|       |
 1309|    660|    if (sb.st_size > MAX_PRIVKEY_SIZE) {
  ------------------
  |  |   47|    660|#define MAX_PRIVKEY_SIZE 0x400000 /* 4M */
  ------------------
  |  Branch (1309:9): [True: 0, False: 660]
  ------------------
 1310|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1311|      0|                "Private key is bigger than 4M.");
 1312|      0|        fclose(file);
 1313|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1314|      0|    }
 1315|       |
 1316|    660|    key_buf = malloc(sb.st_size + 1);
 1317|    660|    if (key_buf == NULL) {
  ------------------
  |  Branch (1317:9): [True: 0, False: 660]
  ------------------
 1318|      0|        fclose(file);
 1319|      0|        SSH_LOG(SSH_LOG_TRACE, "Out of memory!");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1320|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1321|      0|    }
 1322|       |
 1323|    660|    size = fread(key_buf, 1, sb.st_size, file);
 1324|    660|    fclose(file);
 1325|       |
 1326|    660|    if (size != sb.st_size) {
  ------------------
  |  Branch (1326:9): [True: 0, False: 660]
  ------------------
 1327|      0|        SAFE_FREE(key_buf);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1328|      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]
  |  |  ------------------
  ------------------
 1329|      0|                         errno,
 1330|      0|                         "Error reading %s: %s",
 1331|      0|                         filename);
 1332|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1333|      0|    }
 1334|    660|    key_buf[size] = 0;
 1335|       |
 1336|    660|    rc = ssh_pki_import_privkey_base64(key_buf,
 1337|    660|                                       passphrase,
 1338|    660|                                       auth_fn,
 1339|    660|                                       auth_data,
 1340|    660|                                       pkey);
 1341|       |
 1342|       |    SAFE_FREE(key_buf);
  ------------------
  |  |  375|    660|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 660, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 660]
  |  |  ------------------
  ------------------
 1343|    660|    return rc;
 1344|    660|}
ssh_pki_import_pubkey_blob:
 2027|  1.93k|{
 2028|  1.93k|    ssh_buffer buffer = NULL;
 2029|  1.93k|    ssh_string type_s = NULL;
 2030|  1.93k|    enum ssh_keytypes_e type;
 2031|  1.93k|    int rc;
 2032|       |
 2033|  1.93k|    if (key_blob == NULL || pkey == NULL) {
  ------------------
  |  Branch (2033:9): [True: 0, False: 1.93k]
  |  Branch (2033:29): [True: 0, False: 1.93k]
  ------------------
 2034|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2035|      0|    }
 2036|       |
 2037|  1.93k|    buffer = ssh_buffer_new();
 2038|  1.93k|    if (buffer == NULL) {
  ------------------
  |  Branch (2038:9): [True: 0, False: 1.93k]
  ------------------
 2039|      0|        SSH_LOG(SSH_LOG_TRACE, "Out of memory!");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2040|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2041|      0|    }
 2042|       |
 2043|  1.93k|    rc = ssh_buffer_add_data(buffer,
 2044|  1.93k|                             ssh_string_data(key_blob),
 2045|  1.93k|                             (uint32_t)ssh_string_len(key_blob));
 2046|  1.93k|    if (rc < 0) {
  ------------------
  |  Branch (2046:9): [True: 0, False: 1.93k]
  ------------------
 2047|      0|        SSH_LOG(SSH_LOG_TRACE, "Out of memory!");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2048|      0|        goto fail;
 2049|      0|    }
 2050|       |
 2051|  1.93k|    type_s = ssh_buffer_get_ssh_string(buffer);
 2052|  1.93k|    if (type_s == NULL) {
  ------------------
  |  Branch (2052:9): [True: 96, False: 1.83k]
  ------------------
 2053|     96|        SSH_LOG(SSH_LOG_TRACE, "Out of memory!");
  ------------------
  |  |  283|     96|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2054|     96|        goto fail;
 2055|     96|    }
 2056|       |
 2057|  1.83k|    type = ssh_key_type_from_name(ssh_string_get_char(type_s));
 2058|  1.83k|    if (type == SSH_KEYTYPE_UNKNOWN) {
  ------------------
  |  Branch (2058:9): [True: 388, False: 1.45k]
  ------------------
 2059|    388|        SSH_LOG(SSH_LOG_TRACE, "Unknown key type found!");
  ------------------
  |  |  283|    388|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2060|    388|        goto fail;
 2061|    388|    }
 2062|  1.45k|    SSH_STRING_FREE(type_s);
  ------------------
  |  |  882|  1.45k|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 1.45k, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 1.45k]
  |  |  ------------------
  ------------------
 2063|       |
 2064|  1.45k|    if (is_cert_type(type)) {
  ------------------
  |  |  146|  1.45k|    ((kt) == SSH_KEYTYPE_RSA_CERT01 ||\
  |  |  ------------------
  |  |  |  Branch (146:6): [True: 1.26k, False: 186]
  |  |  ------------------
  |  |  147|  1.45k|     (kt) == SSH_KEYTYPE_SK_ECDSA_CERT01 ||\
  |  |  ------------------
  |  |  |  Branch (147:6): [True: 0, False: 186]
  |  |  ------------------
  |  |  148|  1.45k|     (kt) == SSH_KEYTYPE_SK_ED25519_CERT01 ||\
  |  |  ------------------
  |  |  |  Branch (148:6): [True: 0, False: 186]
  |  |  ------------------
  |  |  149|  1.45k|    ((kt) >= SSH_KEYTYPE_ECDSA_P256_CERT01 &&\
  |  |  ------------------
  |  |  |  Branch (149:6): [True: 1, False: 185]
  |  |  ------------------
  |  |  150|    186|     (kt) <= SSH_KEYTYPE_ED25519_CERT01))
  |  |  ------------------
  |  |  |  Branch (150:6): [True: 0, False: 1]
  |  |  ------------------
  ------------------
 2065|  1.26k|        rc = pki_import_cert_buffer(buffer, type, pkey);
 2066|  1.26k|    } else {
 2067|    186|        rc = pki_import_pubkey_buffer(buffer, type, pkey);
 2068|    186|    }
 2069|       |
 2070|  1.45k|    SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  924|  1.45k|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 1.45k, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 1.45k]
  |  |  ------------------
  ------------------
 2071|       |
 2072|  1.45k|    return rc;
 2073|    484|fail:
 2074|    484|    SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  924|    484|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 484, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 484]
  |  |  ------------------
  ------------------
 2075|    484|    SSH_STRING_FREE(type_s);
  ------------------
  |  |  882|    484|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 388, False: 96]
  |  |  |  Branch (882:69): [Folded, False: 484]
  |  |  ------------------
  ------------------
 2076|       |
 2077|    484|    return SSH_ERROR;
  ------------------
  |  |  316|    484|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2078|  1.83k|}
ssh_pki_export_privkey_to_pubkey:
 2570|    185|{
 2571|    185|    ssh_key pubkey = NULL;
 2572|       |
 2573|    185|    if (privkey == NULL || !ssh_key_is_private(privkey)) {
  ------------------
  |  Branch (2573:9): [True: 0, False: 185]
  |  Branch (2573:28): [True: 0, False: 185]
  ------------------
 2574|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2575|      0|    }
 2576|       |
 2577|    185|    pubkey = pki_key_dup(privkey, 1);
 2578|    185|    if (pubkey == NULL) {
  ------------------
  |  Branch (2578:9): [True: 0, False: 185]
  ------------------
 2579|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2580|      0|    }
 2581|       |
 2582|    185|    *pkey = pubkey;
 2583|    185|    return SSH_OK;
  ------------------
  |  |  315|    185|#define SSH_OK 0     /* No error */
  ------------------
 2584|    185|}
ssh_pki_export_pubkey_blob:
 2666|    555|{
 2667|    555|    ssh_string blob = NULL;
 2668|       |
 2669|    555|    if (key == NULL) {
  ------------------
  |  Branch (2669:9): [True: 0, False: 555]
  ------------------
 2670|      0|        return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
 2671|      0|    }
 2672|       |
 2673|    555|    blob = pki_key_to_blob(key, SSH_KEY_PUBLIC);
 2674|    555|    if (blob == NULL) {
  ------------------
  |  Branch (2674:9): [True: 0, False: 555]
  ------------------
 2675|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2676|      0|    }
 2677|       |
 2678|    555|    *pblob = blob;
 2679|    555|    return SSH_OK;
  ------------------
  |  |  315|    555|#define SSH_OK 0     /* No error */
  ------------------
 2680|    555|}
ssh_pki_export_signature_blob:
 2877|    185|{
 2878|    185|    ssh_buffer buf = NULL;
 2879|    185|    ssh_string str = NULL;
 2880|    185|    int rc;
 2881|       |
 2882|    185|    if (sig == NULL || sig_blob == NULL) {
  ------------------
  |  Branch (2882:9): [True: 0, False: 185]
  |  Branch (2882:24): [True: 0, False: 185]
  ------------------
 2883|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2884|      0|    }
 2885|       |
 2886|    185|    buf = ssh_buffer_new();
 2887|    185|    if (buf == NULL) {
  ------------------
  |  Branch (2887:9): [True: 0, False: 185]
  ------------------
 2888|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2889|      0|    }
 2890|       |
 2891|    185|    str = ssh_string_from_char(sig->type_c);
 2892|    185|    if (str == NULL) {
  ------------------
  |  Branch (2892:9): [True: 0, False: 185]
  ------------------
 2893|      0|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2894|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2895|      0|    }
 2896|       |
 2897|    185|    rc = ssh_buffer_add_ssh_string(buf, str);
 2898|    185|    SSH_STRING_FREE(str);
  ------------------
  |  |  882|    185|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 185, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 185]
  |  |  ------------------
  ------------------
 2899|    185|    if (rc < 0) {
  ------------------
  |  Branch (2899:9): [True: 0, False: 185]
  ------------------
 2900|      0|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2901|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2902|      0|    }
 2903|       |
 2904|    185|    str = pki_signature_to_blob(sig);
 2905|    185|    if (str == NULL) {
  ------------------
  |  Branch (2905:9): [True: 0, False: 185]
  ------------------
 2906|      0|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2907|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2908|      0|    }
 2909|       |
 2910|    185|    rc = ssh_buffer_add_ssh_string(buf, str);
 2911|    185|    SSH_STRING_FREE(str);
  ------------------
  |  |  882|    185|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 185, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 185]
  |  |  ------------------
  ------------------
 2912|    185|    if (rc < 0) {
  ------------------
  |  Branch (2912:9): [True: 0, False: 185]
  ------------------
 2913|      0|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2914|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2915|      0|    }
 2916|       |
 2917|    185|    if (is_sk_key_type(sig->type)) {
  ------------------
  |  |  153|    185|    ((kt) == SSH_KEYTYPE_SK_ECDSA || (kt) == SSH_KEYTYPE_SK_ED25519 || \
  |  |  ------------------
  |  |  |  Branch (153:6): [True: 0, False: 185]
  |  |  |  Branch (153:38): [True: 0, False: 185]
  |  |  ------------------
  |  |  154|    185|     (kt) == SSH_KEYTYPE_SK_ECDSA_CERT01 ||                            \
  |  |  ------------------
  |  |  |  Branch (154:6): [True: 0, False: 185]
  |  |  ------------------
  |  |  155|    185|     (kt) == SSH_KEYTYPE_SK_ED25519_CERT01)
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 185]
  |  |  ------------------
  ------------------
 2918|       |        /* Add flags and counter for SK keys */
 2919|      0|        rc = ssh_buffer_pack(buf, "bd", sig->sk_flags, sig->sk_counter);
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 2920|      0|        if (rc < 0) {
  ------------------
  |  Branch (2920:13): [True: 0, False: 0]
  ------------------
 2921|      0|            SSH_BUFFER_FREE(buf);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2922|      0|            return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2923|      0|        }
 2924|      0|    }
 2925|       |
 2926|    185|    str = ssh_string_new(ssh_buffer_get_len(buf));
 2927|    185|    if (str == NULL) {
  ------------------
  |  Branch (2927:9): [True: 0, False: 185]
  ------------------
 2928|      0|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2929|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2930|      0|    }
 2931|       |
 2932|    185|    rc = ssh_string_fill(str, ssh_buffer_get(buf), ssh_buffer_get_len(buf));
 2933|    185|    SSH_BUFFER_FREE(buf);
  ------------------
  |  |  924|    185|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 185, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 185]
  |  |  ------------------
  ------------------
 2934|    185|    if (rc < 0) {
  ------------------
  |  Branch (2934:9): [True: 0, False: 185]
  ------------------
 2935|      0|        SSH_STRING_FREE(str);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2936|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2937|      0|    }
 2938|       |
 2939|    185|    *sig_blob = str;
 2940|       |
 2941|    185|    return SSH_OK;
  ------------------
  |  |  315|    185|#define SSH_OK 0     /* No error */
  ------------------
 2942|    185|}
pki_key_check_hash_compatible:
 3034|    370|{
 3035|    370|    if (key == NULL) {
  ------------------
  |  Branch (3035:9): [True: 0, False: 370]
  ------------------
 3036|      0|        SSH_LOG(SSH_LOG_TRACE, "Null pointer provided as key to "
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3037|      0|                               "pki_key_check_hash_compatible()");
 3038|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3039|      0|    }
 3040|       |
 3041|    370|    switch(key->type) {
  ------------------
  |  Branch (3041:12): [True: 370, False: 0]
  ------------------
 3042|      0|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (3042:5): [True: 0, False: 370]
  ------------------
 3043|    370|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (3043:5): [True: 370, False: 0]
  ------------------
 3044|    370|        if (hash_type == SSH_DIGEST_SHA1) {
  ------------------
  |  Branch (3044:13): [True: 0, False: 370]
  ------------------
 3045|      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]
  |  |  ------------------
  ------------------
 3046|      0|                SSH_LOG(SSH_LOG_TRACE, "SHA1 is not allowed in FIPS mode");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3047|      0|                return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3048|      0|            } else {
 3049|      0|                return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
 3050|      0|            }
 3051|      0|        }
 3052|       |
 3053|    370|        if (hash_type == SSH_DIGEST_SHA256 ||
  ------------------
  |  Branch (3053:13): [True: 344, False: 26]
  ------------------
 3054|     26|            hash_type == SSH_DIGEST_SHA512)
  ------------------
  |  Branch (3054:13): [True: 26, False: 0]
  ------------------
 3055|    370|        {
 3056|    370|            return SSH_OK;
  ------------------
  |  |  315|    370|#define SSH_OK 0     /* No error */
  ------------------
 3057|    370|        }
 3058|      0|        break;
 3059|      0|    case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (3059:5): [True: 0, False: 370]
  ------------------
 3060|      0|    case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (3060:5): [True: 0, False: 370]
  ------------------
 3061|      0|    case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (3061:5): [True: 0, False: 370]
  ------------------
 3062|      0|    case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (3062:5): [True: 0, False: 370]
  ------------------
 3063|      0|        if (hash_type == SSH_DIGEST_SHA256) {
  ------------------
  |  Branch (3063:13): [True: 0, False: 0]
  ------------------
 3064|      0|            return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
 3065|      0|        }
 3066|      0|        break;
 3067|      0|    case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (3067:5): [True: 0, False: 370]
  ------------------
 3068|      0|    case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (3068:5): [True: 0, False: 370]
  ------------------
 3069|      0|        if (hash_type == SSH_DIGEST_SHA384) {
  ------------------
  |  Branch (3069:13): [True: 0, False: 0]
  ------------------
 3070|      0|            return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
 3071|      0|        }
 3072|      0|        break;
 3073|      0|    case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (3073:5): [True: 0, False: 370]
  ------------------
 3074|      0|    case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (3074:5): [True: 0, False: 370]
  ------------------
 3075|      0|        if (hash_type == SSH_DIGEST_SHA512) {
  ------------------
  |  Branch (3075:13): [True: 0, False: 0]
  ------------------
 3076|      0|            return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
 3077|      0|        }
 3078|      0|        break;
 3079|      0|    case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (3079:5): [True: 0, False: 370]
  ------------------
 3080|      0|    case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (3080:5): [True: 0, False: 370]
  ------------------
 3081|      0|    case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (3081:5): [True: 0, False: 370]
  ------------------
 3082|      0|    case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (3082:5): [True: 0, False: 370]
  ------------------
 3083|      0|        if (hash_type == SSH_DIGEST_AUTO) {
  ------------------
  |  Branch (3083:13): [True: 0, False: 0]
  ------------------
 3084|      0|            return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
 3085|      0|        }
 3086|      0|        break;
 3087|      0|    case SSH_KEYTYPE_DSS:   /* deprecated */
  ------------------
  |  Branch (3087:5): [True: 0, False: 370]
  ------------------
 3088|      0|    case SSH_KEYTYPE_DSS_CERT01:    /* deprecated */
  ------------------
  |  Branch (3088:5): [True: 0, False: 370]
  ------------------
 3089|      0|    case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (3089:5): [True: 0, False: 370]
  ------------------
 3090|      0|    case SSH_KEYTYPE_ECDSA:
  ------------------
  |  Branch (3090:5): [True: 0, False: 370]
  ------------------
 3091|      0|    case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (3091:5): [True: 0, False: 370]
  ------------------
 3092|      0|        SSH_LOG(SSH_LOG_TRACE, "Unknown key type %d", key->type);
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3093|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3094|    370|    }
 3095|       |
 3096|      0|    SSH_LOG(SSH_LOG_TRACE, "Key type %d incompatible with hash type  %d",
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3097|      0|            key->type, hash_type);
 3098|       |
 3099|      0|    return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3100|    370|}
pki_do_sign:
 3255|    185|{
 3256|    185|    int rc;
 3257|       |
 3258|    185|    if (privkey == NULL || input == NULL) {
  ------------------
  |  Branch (3258:9): [True: 0, False: 185]
  |  Branch (3258:28): [True: 0, False: 185]
  ------------------
 3259|      0|        SSH_LOG(SSH_LOG_TRACE, "Bad parameter provided to "
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3260|      0|                               "pki_do_sign()");
 3261|      0|        return NULL;
 3262|      0|    }
 3263|       |
 3264|       |    /* Check if public key and hash type are compatible */
 3265|    185|    rc = pki_key_check_hash_compatible(privkey, hash_type);
 3266|    185|    if (rc != SSH_OK) {
  ------------------
  |  |  315|    185|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (3266:9): [True: 0, False: 185]
  ------------------
 3267|      0|        return NULL;
 3268|      0|    }
 3269|       |
 3270|    185|    return pki_sign_data(privkey, hash_type, input, input_len);
 3271|    185|}
ssh_srv_pki_do_sign_sessionid:
 4027|    185|{
 4028|    185|    struct ssh_crypto_struct *crypto = NULL;
 4029|    185|    bool allowed;
 4030|    185|    ssh_signature sig = NULL;
 4031|    185|    ssh_string sig_blob = NULL;
 4032|       |
 4033|    185|    ssh_buffer sign_input = NULL;
 4034|       |
 4035|    185|    int rc;
 4036|       |
 4037|    185|    if (session == NULL || privkey == NULL || !ssh_key_is_private(privkey)) {
  ------------------
  |  Branch (4037:9): [True: 0, False: 185]
  |  Branch (4037:28): [True: 0, False: 185]
  |  Branch (4037:47): [True: 0, False: 185]
  ------------------
 4038|      0|        return NULL;
 4039|      0|    }
 4040|       |
 4041|    185|    allowed = ssh_key_size_allowed(session, privkey);
 4042|    185|    if (!allowed) {
  ------------------
  |  Branch (4042:9): [True: 0, False: 185]
  ------------------
 4043|      0|        ssh_set_error(session, SSH_FATAL, "The hostkey size too small");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 4044|      0|        return NULL;
 4045|      0|    }
 4046|       |
 4047|    185|    crypto = session->next_crypto ? session->next_crypto :
  ------------------
  |  Branch (4047:14): [True: 185, False: 0]
  ------------------
 4048|    185|                                    session->current_crypto;
 4049|       |
 4050|    185|    if (crypto->secret_hash == NULL){
  ------------------
  |  Branch (4050:9): [True: 0, False: 185]
  ------------------
 4051|      0|        ssh_set_error(session, SSH_FATAL, "Missing secret_hash");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 4052|      0|        return NULL;
 4053|      0|    }
 4054|       |
 4055|       |    /* Fill the input */
 4056|    185|    sign_input = ssh_buffer_new();
 4057|    185|    if (sign_input == NULL) {
  ------------------
  |  Branch (4057:9): [True: 0, False: 185]
  ------------------
 4058|      0|        goto end;
 4059|      0|    }
 4060|    185|    ssh_buffer_set_secure(sign_input);
 4061|       |
 4062|    185|    rc = ssh_buffer_pack(sign_input,
  ------------------
  |  |   50|    185|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|    185|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|    185|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|    185|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|    185|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|    185|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    185|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 4063|    185|                         "P",
 4064|    185|                         crypto->digest_len,
 4065|    185|                         crypto->secret_hash);
 4066|    185|    if (rc != SSH_OK) {
  ------------------
  |  |  315|    185|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (4066:9): [True: 0, False: 185]
  ------------------
 4067|      0|        goto end;
 4068|      0|    }
 4069|       |
 4070|       |    /* Generate the signature */
 4071|    185|    sig = pki_do_sign(privkey,
 4072|    185|                      ssh_buffer_get(sign_input),
 4073|    185|                      ssh_buffer_get_len(sign_input),
 4074|    185|                      digest);
 4075|    185|    if (sig == NULL) {
  ------------------
  |  Branch (4075:9): [True: 0, False: 185]
  ------------------
 4076|      0|        goto end;
 4077|      0|    }
 4078|       |
 4079|       |    /* Convert the signature to blob */
 4080|    185|    rc = ssh_pki_export_signature_blob(sig, &sig_blob);
 4081|    185|    if (rc < 0) {
  ------------------
  |  Branch (4081:9): [True: 0, False: 185]
  ------------------
 4082|      0|        sig_blob = NULL;
 4083|      0|    }
 4084|       |
 4085|    185|end:
 4086|    185|    ssh_signature_free(sig);
 4087|    185|    SSH_BUFFER_FREE(sign_input);
  ------------------
  |  |  924|    185|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 185, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 185]
  |  |  ------------------
  ------------------
 4088|       |
 4089|    185|    return sig_blob;
 4090|    185|}
pki.c:pki_import_cert_buffer:
 1877|  1.26k|{
 1878|  1.26k|    ssh_buffer cert = NULL;
 1879|  1.26k|    ssh_string tmp_s = NULL;
 1880|  1.26k|    const char *type_c = NULL;
 1881|  1.26k|    ssh_key key = NULL;
 1882|  1.26k|    int rc;
 1883|       |
 1884|       |    /*
 1885|       |     * The cert blob starts with the key type as an ssh_string, but this
 1886|       |     * string has been read out of the buffer to identify the key type.
 1887|       |     * Simply add it again as first element before copying the rest.
 1888|       |     */
 1889|  1.26k|    cert = ssh_buffer_new();
 1890|  1.26k|    if (cert == NULL) {
  ------------------
  |  Branch (1890:9): [True: 0, False: 1.26k]
  ------------------
 1891|      0|        goto fail;
 1892|      0|    }
 1893|  1.26k|    type_c = ssh_key_type_to_char(type);
 1894|  1.26k|    tmp_s = ssh_string_from_char(type_c);
 1895|  1.26k|    if (tmp_s == NULL) {
  ------------------
  |  Branch (1895:9): [True: 0, False: 1.26k]
  ------------------
 1896|      0|        goto fail;
 1897|      0|    }
 1898|  1.26k|    rc = ssh_buffer_add_ssh_string(cert, tmp_s);
 1899|  1.26k|    SSH_STRING_FREE(tmp_s);
  ------------------
  |  |  882|  1.26k|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 1.26k, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 1.26k]
  |  |  ------------------
  ------------------
 1900|  1.26k|    if (rc != 0) {
  ------------------
  |  Branch (1900:9): [True: 0, False: 1.26k]
  ------------------
 1901|      0|        goto fail;
 1902|      0|    }
 1903|  1.26k|    rc = ssh_buffer_add_buffer(cert, buffer);
 1904|  1.26k|    if (rc != 0) {
  ------------------
  |  Branch (1904:9): [True: 0, False: 1.26k]
  ------------------
 1905|      0|        goto fail;
 1906|      0|    }
 1907|       |
 1908|       |    /*
 1909|       |     * After the key type, comes an ssh_string nonce. Just after this comes the
 1910|       |     * cert public key, which can be parsed out of the buffer.
 1911|       |     */
 1912|  1.26k|    tmp_s = ssh_buffer_get_ssh_string(buffer);
 1913|  1.26k|    if (tmp_s == NULL) {
  ------------------
  |  Branch (1913:9): [True: 26, False: 1.23k]
  ------------------
 1914|     26|        goto fail;
 1915|     26|    }
 1916|  1.23k|    SSH_STRING_FREE(tmp_s);
  ------------------
  |  |  882|  1.23k|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 1.23k, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 1.23k]
  |  |  ------------------
  ------------------
 1917|       |
 1918|  1.23k|    switch (type) {
 1919|  1.23k|        case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (1919:9): [True: 1.23k, False: 0]
  ------------------
 1920|  1.23k|            rc = pki_import_pubkey_buffer(buffer, SSH_KEYTYPE_RSA, &key);
 1921|  1.23k|            break;
 1922|      0|        case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (1922:9): [True: 0, False: 1.23k]
  ------------------
 1923|      0|            rc = pki_import_pubkey_buffer(buffer, SSH_KEYTYPE_ECDSA_P256, &key);
 1924|      0|            break;
 1925|      0|        case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (1925:9): [True: 0, False: 1.23k]
  ------------------
 1926|      0|            rc = pki_import_pubkey_buffer(buffer, SSH_KEYTYPE_ECDSA_P384, &key);
 1927|      0|            break;
 1928|      0|        case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (1928:9): [True: 0, False: 1.23k]
  ------------------
 1929|      0|            rc = pki_import_pubkey_buffer(buffer, SSH_KEYTYPE_ECDSA_P521, &key);
 1930|      0|            break;
 1931|      0|        case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (1931:9): [True: 0, False: 1.23k]
  ------------------
 1932|      0|            rc = pki_import_pubkey_buffer(buffer, SSH_KEYTYPE_ED25519, &key);
 1933|      0|            break;
 1934|      0|        case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (1934:9): [True: 0, False: 1.23k]
  ------------------
 1935|      0|            rc = pki_import_pubkey_buffer(buffer, SSH_KEYTYPE_SK_ECDSA, &key);
 1936|      0|            break;
 1937|      0|        case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (1937:9): [True: 0, False: 1.23k]
  ------------------
 1938|      0|            rc = pki_import_pubkey_buffer(buffer, SSH_KEYTYPE_SK_ED25519, &key);
 1939|      0|            break;
 1940|      0|        default:
  ------------------
  |  Branch (1940:9): [True: 0, False: 1.23k]
  ------------------
 1941|      0|            key = ssh_key_new();
 1942|  1.23k|    }
 1943|  1.23k|    if (rc != 0 || key == NULL) {
  ------------------
  |  Branch (1943:9): [True: 65, False: 1.17k]
  |  Branch (1943:20): [True: 0, False: 1.17k]
  ------------------
 1944|     65|        goto fail;
 1945|     65|    }
 1946|       |
 1947|  1.17k|    key->type = type;
 1948|  1.17k|    key->type_c = type_c;
 1949|  1.17k|    key->cert = cert;
 1950|       |
 1951|  1.17k|    *pkey = key;
 1952|  1.17k|    return SSH_OK;
  ------------------
  |  |  315|  1.17k|#define SSH_OK 0     /* No error */
  ------------------
 1953|       |
 1954|     91|fail:
 1955|     91|    ssh_key_free(key);
 1956|     91|    SSH_BUFFER_FREE(cert);
  ------------------
  |  |  924|     91|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 91, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 91]
  |  |  ------------------
  ------------------
 1957|     91|    return SSH_ERROR;
  ------------------
  |  |  316|     91|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1958|  1.23k|}
pki.c:pki_import_pubkey_buffer:
 1736|  1.42k|{
 1737|  1.42k|    ssh_key key = NULL;
 1738|  1.42k|    int rc;
 1739|       |
 1740|  1.42k|    key = ssh_key_new();
 1741|  1.42k|    if (key == NULL) {
  ------------------
  |  Branch (1741:9): [True: 0, False: 1.42k]
  ------------------
 1742|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1743|      0|    }
 1744|       |
 1745|  1.42k|    key->type = type;
 1746|  1.42k|    key->type_c = ssh_key_type_to_char(type);
 1747|  1.42k|    key->flags = SSH_KEY_FLAG_PUBLIC;
  ------------------
  |  |   54|  1.42k|#define SSH_KEY_FLAG_PUBLIC  0x0001
  ------------------
 1748|       |
 1749|  1.42k|    switch (type) {
 1750|  1.42k|        case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (1750:9): [True: 1.42k, False: 1]
  ------------------
 1751|  1.42k|            {
 1752|  1.42k|                ssh_string e = NULL;
 1753|  1.42k|                ssh_string n = NULL;
 1754|       |
 1755|  1.42k|                rc = ssh_buffer_unpack(buffer, "SS", &e, &n);
  ------------------
  |  |   60|  1.42k|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|  1.42k|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|  1.42k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|  1.42k|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|  1.42k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|  1.42k|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|  1.42k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1756|  1.42k|                if (rc != SSH_OK) {
  ------------------
  |  |  315|  1.42k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1756:21): [True: 65, False: 1.35k]
  ------------------
 1757|     65|                    SSH_LOG(SSH_LOG_TRACE, "Unpack error");
  ------------------
  |  |  283|     65|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1758|     65|                    goto fail;
 1759|     65|                }
 1760|       |
 1761|  1.35k|                rc = pki_pubkey_build_rsa(key, e, n);
 1762|       |#ifdef DEBUG_CRYPTO
 1763|       |                ssh_log_hexdump("e", ssh_string_data(e), ssh_string_len(e));
 1764|       |                ssh_log_hexdump("n", ssh_string_data(n), ssh_string_len(n));
 1765|       |#endif /* DEBUG_CRYPTO */
 1766|  1.35k|                ssh_string_burn(e);
 1767|  1.35k|                SSH_STRING_FREE(e);
  ------------------
  |  |  882|  1.35k|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 1.35k, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 1.35k]
  |  |  ------------------
  ------------------
 1768|  1.35k|                ssh_string_burn(n);
 1769|  1.35k|                SSH_STRING_FREE(n);
  ------------------
  |  |  882|  1.35k|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 1.35k, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 1.35k]
  |  |  ------------------
  ------------------
 1770|  1.35k|                if (rc == SSH_ERROR) {
  ------------------
  |  |  316|  1.35k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1770:21): [True: 0, False: 1.35k]
  ------------------
 1771|      0|                    SSH_LOG(SSH_LOG_TRACE, "Failed to build RSA public key");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1772|      0|                    goto fail;
 1773|      0|                }
 1774|  1.35k|            }
 1775|  1.35k|            break;
 1776|  1.35k|#ifdef HAVE_ECC
 1777|  1.35k|        case SSH_KEYTYPE_ECDSA: /* deprecated */
  ------------------
  |  Branch (1777:9): [True: 0, False: 1.42k]
  ------------------
 1778|      0|        case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (1778:9): [True: 0, False: 1.42k]
  ------------------
 1779|      0|        case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (1779:9): [True: 0, False: 1.42k]
  ------------------
 1780|      0|        case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (1780:9): [True: 0, False: 1.42k]
  ------------------
 1781|      1|        case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (1781:9): [True: 1, False: 1.42k]
  ------------------
 1782|      1|            {
 1783|      1|                ssh_string e = NULL;
 1784|      1|                ssh_string i = NULL;
 1785|      1|                int nid;
 1786|       |
 1787|      1|                rc = ssh_buffer_unpack(buffer, "SS", &i, &e);
  ------------------
  |  |   60|      1|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      1|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      1|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      1|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      1|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      1|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      1|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1788|      1|                if (rc != SSH_OK) {
  ------------------
  |  |  315|      1|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1788:21): [True: 0, False: 1]
  ------------------
 1789|      0|                    SSH_LOG(SSH_LOG_TRACE, "Unpack error");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1790|      0|                    goto fail;
 1791|      0|                }
 1792|       |
 1793|      1|                nid = pki_key_ecdsa_nid_from_name(ssh_string_get_char(i));
 1794|      1|                SSH_STRING_FREE(i);
  ------------------
  |  |  882|      1|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 1, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 1]
  |  |  ------------------
  ------------------
 1795|      1|                if (nid == -1) {
  ------------------
  |  Branch (1795:21): [True: 1, False: 0]
  ------------------
 1796|      1|                    ssh_string_burn(e);
 1797|      1|                    SSH_STRING_FREE(e);
  ------------------
  |  |  882|      1|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 1, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 1]
  |  |  ------------------
  ------------------
 1798|      1|                    goto fail;
 1799|      1|                }
 1800|       |
 1801|      0|                rc = pki_pubkey_build_ecdsa(key, nid, e);
 1802|      0|                ssh_string_burn(e);
 1803|      0|                SSH_STRING_FREE(e);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1804|      0|                if (rc < 0) {
  ------------------
  |  Branch (1804:21): [True: 0, False: 0]
  ------------------
 1805|      0|                    SSH_LOG(SSH_LOG_TRACE, "Failed to build ECDSA public key");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1806|      0|                    goto fail;
 1807|      0|                }
 1808|       |
 1809|       |                /* Unpack SK specific parameters */
 1810|      0|                if (type == SSH_KEYTYPE_SK_ECDSA) {
  ------------------
  |  Branch (1810:21): [True: 0, False: 0]
  ------------------
 1811|      0|                    ssh_string application = ssh_buffer_get_ssh_string(buffer);
 1812|      0|                    if (application == NULL) {
  ------------------
  |  Branch (1812:25): [True: 0, False: 0]
  ------------------
 1813|      0|                        SSH_LOG(SSH_LOG_TRACE, "SK Unpack error");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1814|      0|                        goto fail;
 1815|      0|                    }
 1816|      0|                    key->sk_application = application;
 1817|      0|                    key->type_c = ssh_key_type_to_char(key->type);
 1818|      0|                }
 1819|      0|            }
 1820|      0|            break;
 1821|      0|#endif /* HAVE_ECC */
 1822|      0|        case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (1822:9): [True: 0, False: 1.42k]
  ------------------
 1823|      0|        case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (1823:9): [True: 0, False: 1.42k]
  ------------------
 1824|      0|        {
 1825|      0|            ssh_string pubkey = ssh_buffer_get_ssh_string(buffer);
 1826|       |
 1827|      0|            if (ssh_string_len(pubkey) != ED25519_KEY_LEN) {
  ------------------
  |  |   44|      0|#define ED25519_KEY_LEN 32
  ------------------
  |  Branch (1827:17): [True: 0, False: 0]
  ------------------
 1828|      0|                SSH_LOG(SSH_LOG_TRACE, "Invalid public key length");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1829|      0|                ssh_string_burn(pubkey);
 1830|      0|                SSH_STRING_FREE(pubkey);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1831|      0|                goto fail;
 1832|      0|            }
 1833|       |
 1834|      0|            rc = pki_pubkey_build_ed25519(key, pubkey);
 1835|      0|            ssh_string_burn(pubkey);
 1836|      0|            SSH_STRING_FREE(pubkey);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1837|      0|            if (rc < 0) {
  ------------------
  |  Branch (1837:17): [True: 0, False: 0]
  ------------------
 1838|      0|                SSH_LOG(SSH_LOG_TRACE, "Failed to build ED25519 public key");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1839|      0|                goto fail;
 1840|      0|            }
 1841|       |
 1842|      0|            if (type == SSH_KEYTYPE_SK_ED25519) {
  ------------------
  |  Branch (1842:17): [True: 0, False: 0]
  ------------------
 1843|      0|                ssh_string application = ssh_buffer_get_ssh_string(buffer);
 1844|      0|                if (application == NULL) {
  ------------------
  |  Branch (1844:21): [True: 0, False: 0]
  ------------------
 1845|      0|                    SSH_LOG(SSH_LOG_TRACE, "SK Unpack error");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1846|      0|                    goto fail;
 1847|      0|                }
 1848|      0|                key->sk_application = application;
 1849|      0|            }
 1850|      0|        }
 1851|      0|        break;
 1852|      0|        case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (1852:9): [True: 0, False: 1.42k]
  ------------------
 1853|      0|        case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (1853:9): [True: 0, False: 1.42k]
  ------------------
 1854|      0|        case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (1854:9): [True: 0, False: 1.42k]
  ------------------
 1855|      0|        case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (1855:9): [True: 0, False: 1.42k]
  ------------------
 1856|      0|        case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (1856:9): [True: 0, False: 1.42k]
  ------------------
 1857|      0|        case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (1857:9): [True: 0, False: 1.42k]
  ------------------
 1858|      0|        case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (1858:9): [True: 0, False: 1.42k]
  ------------------
 1859|      0|        case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (1859:9): [True: 0, False: 1.42k]
  ------------------
 1860|      0|        case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (1860:9): [True: 0, False: 1.42k]
  ------------------
 1861|      0|        default:
  ------------------
  |  Branch (1861:9): [True: 0, False: 1.42k]
  ------------------
 1862|      0|            SSH_LOG(SSH_LOG_TRACE, "Unknown public key type %d", type);
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1863|      0|            goto fail;
 1864|  1.42k|    }
 1865|       |
 1866|  1.35k|    *pkey = key;
 1867|  1.35k|    return SSH_OK;
  ------------------
  |  |  315|  1.35k|#define SSH_OK 0     /* No error */
  ------------------
 1868|     66|fail:
 1869|     66|    ssh_key_free(key);
 1870|       |
 1871|     66|    return SSH_ERROR;
  ------------------
  |  |  316|     66|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1872|  1.42k|}

ssh_pki_ctx_new:
   49|    660|{
   50|    660|    struct ssh_pki_ctx_struct *ctx = NULL;
   51|       |
   52|    660|    ctx = calloc(1, sizeof(struct ssh_pki_ctx_struct));
   53|    660|    if (ctx == NULL) {
  ------------------
  |  Branch (53:9): [True: 0, False: 660]
  ------------------
   54|      0|        return NULL;
   55|      0|    }
   56|       |
   57|       |#ifdef WITH_FIDO2
   58|       |    /* Initialize SK fields with default, if available. */
   59|       |    ctx->sk_callbacks = ssh_sk_get_default_callbacks();
   60|       |
   61|       |    /*
   62|       |     * Both OpenSSH security key enrollment and server authentication require
   63|       |     * user presence by default, so we replicate that for consistency.
   64|       |     */
   65|       |    ctx->sk_flags = SSH_SK_USER_PRESENCE_REQD;
   66|       |
   67|       |    ctx->sk_application = strdup("ssh:");
   68|       |    if (ctx->sk_application == NULL) {
   69|       |        SSH_LOG(SSH_LOG_WARN,
   70|       |                "Failed to allocate memory for default application");
   71|       |        SAFE_FREE(ctx);
   72|       |        return NULL;
   73|       |    }
   74|       |#endif /* WITH_FIDO2 */
   75|       |
   76|    660|    return ctx;
   77|    660|}
ssh_pki_ctx_free:
   86|    660|{
   87|    660|    if (context == NULL) {
  ------------------
  |  Branch (87:9): [True: 0, False: 660]
  ------------------
   88|      0|        return;
   89|      0|    }
   90|       |
   91|       |#ifdef WITH_FIDO2
   92|       |    SAFE_FREE(context->sk_application);
   93|       |    SSH_BUFFER_FREE(context->sk_challenge_buffer);
   94|       |    SSH_BUFFER_FREE(context->sk_attestation_buffer);
   95|       |    SK_OPTIONS_FREE(context->sk_callbacks_options);
   96|       |#endif /* WITH_FIDO2 */
   97|       |
   98|    660|    SAFE_FREE(context);
  ------------------
  |  |  375|    660|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 660, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 660]
  |  |  ------------------
  ------------------
   99|    660|}

pki_key_clean:
   96|  2.24k|{
   97|  2.24k|    if (key == NULL)
  ------------------
  |  Branch (97:9): [True: 0, False: 2.24k]
  ------------------
   98|      0|        return;
   99|  2.24k|    EVP_PKEY_free(key->key);
  100|       |    key->key = NULL;
  101|  2.24k|}
pki_key_ecdsa_nid_from_name:
  194|      1|{
  195|      1|    if (strcmp(name, "nistp256") == 0) {
  ------------------
  |  Branch (195:9): [True: 0, False: 1]
  ------------------
  196|      0|        return NID_X9_62_prime256v1;
  197|      1|    } else if (strcmp(name, "nistp384") == 0) {
  ------------------
  |  Branch (197:16): [True: 0, False: 1]
  ------------------
  198|      0|        return NID_secp384r1;
  199|      1|    } else if (strcmp(name, "nistp521") == 0) {
  ------------------
  |  Branch (199:16): [True: 0, False: 1]
  ------------------
  200|      0|        return NID_secp521r1;
  201|      0|    }
  202|       |
  203|      1|    return -1;
  204|      1|}
pki_key_dup:
  484|    504|{
  485|    504|    ssh_key new = NULL;
  486|    504|    int rc;
  487|       |
  488|    504|    new = pki_key_dup_common_init(key, demote);
  489|    504|    if (new == NULL) {
  ------------------
  |  Branch (489:9): [True: 0, False: 504]
  ------------------
  490|      0|        return NULL;
  491|      0|    }
  492|       |
  493|    504|    switch (key->type) {
  494|    504|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (494:5): [True: 504, False: 0]
  ------------------
  495|    504|    case SSH_KEYTYPE_RSA1: {
  ------------------
  |  Branch (495:5): [True: 0, False: 504]
  ------------------
  496|       |#if OPENSSL_VERSION_NUMBER < 0x30000000L
  497|       |        const BIGNUM *n = NULL, *e = NULL, *d = NULL;
  498|       |        BIGNUM *nn, *ne, *nd;
  499|       |        RSA *new_rsa = NULL;
  500|       |        const RSA *key_rsa = EVP_PKEY_get0_RSA(key->key);
  501|       |#endif /* OPENSSL_VERSION_NUMBER < 0x30000000L */
  502|       |#ifdef WITH_PKCS11_URI
  503|       |        /* Take the PKCS#11 keys as they are */
  504|       |        if (key->flags & SSH_KEY_FLAG_PKCS11_URI && !demote) {
  505|       |            rc = EVP_PKEY_up_ref(key->key);
  506|       |            if (rc != 1) {
  507|       |                goto fail;
  508|       |            }
  509|       |            new->key = key->key;
  510|       |            return new;
  511|       |        }
  512|       |#endif /* WITH_PKCS11_URI */
  513|       |#if OPENSSL_VERSION_NUMBER < 0x30000000L
  514|       |        new_rsa = RSA_new();
  515|       |        if (new_rsa == NULL) {
  516|       |            goto fail;
  517|       |        }
  518|       |
  519|       |        /*
  520|       |         * n    = public modulus
  521|       |         * e    = public exponent
  522|       |         * d    = private exponent
  523|       |         * p    = secret prime factor
  524|       |         * q    = secret prime factor
  525|       |         * dmp1 = d mod (p-1)
  526|       |         * dmq1 = d mod (q-1)
  527|       |         * iqmp = q^-1 mod p
  528|       |         */
  529|       |        RSA_get0_key(key_rsa, &n, &e, &d);
  530|       |        nn = BN_dup(n);
  531|       |        ne = BN_dup(e);
  532|       |        if (nn == NULL || ne == NULL) {
  533|       |            RSA_free(new_rsa);
  534|       |            BN_free(nn);
  535|       |            BN_free(ne);
  536|       |            goto fail;
  537|       |        }
  538|       |
  539|       |        /* Memory management of nn and ne is transferred to RSA object */
  540|       |        rc = RSA_set0_key(new_rsa, nn, ne, NULL);
  541|       |        if (rc == 0) {
  542|       |            RSA_free(new_rsa);
  543|       |            BN_free(nn);
  544|       |            BN_free(ne);
  545|       |            goto fail;
  546|       |        }
  547|       |
  548|       |        if (!demote && (key->flags & SSH_KEY_FLAG_PRIVATE)) {
  549|       |            const BIGNUM *p = NULL, *q = NULL, *dmp1 = NULL,
  550|       |              *dmq1 = NULL, *iqmp = NULL;
  551|       |            BIGNUM *np, *nq, *ndmp1, *ndmq1, *niqmp;
  552|       |
  553|       |            nd = BN_dup(d);
  554|       |            if (nd == NULL) {
  555|       |                RSA_free(new_rsa);
  556|       |                goto fail;
  557|       |            }
  558|       |
  559|       |            /* Memory management of nd is transferred to RSA object */
  560|       |            rc = RSA_set0_key(new_rsa, NULL, NULL, nd);
  561|       |            if (rc == 0) {
  562|       |                RSA_free(new_rsa);
  563|       |                goto fail;
  564|       |            }
  565|       |
  566|       |            /* p, q, dmp1, dmq1 and iqmp may be NULL in private keys, but the
  567|       |             * RSA operations are much faster when these values are available.
  568|       |             */
  569|       |            RSA_get0_factors(key_rsa, &p, &q);
  570|       |            if (p != NULL && q != NULL) { /* need to set both of them */
  571|       |                np = BN_dup(p);
  572|       |                nq = BN_dup(q);
  573|       |                if (np == NULL || nq == NULL) {
  574|       |                    RSA_free(new_rsa);
  575|       |                    BN_free(np);
  576|       |                    BN_free(nq);
  577|       |                    goto fail;
  578|       |                }
  579|       |
  580|       |                /* Memory management of np and nq is transferred to RSA object */
  581|       |                rc = RSA_set0_factors(new_rsa, np, nq);
  582|       |                if (rc == 0) {
  583|       |                    RSA_free(new_rsa);
  584|       |                    BN_free(np);
  585|       |                    BN_free(nq);
  586|       |                    goto fail;
  587|       |                }
  588|       |            }
  589|       |
  590|       |            RSA_get0_crt_params(key_rsa, &dmp1, &dmq1, &iqmp);
  591|       |            if (dmp1 != NULL || dmq1 != NULL || iqmp != NULL) {
  592|       |                ndmp1 = BN_dup(dmp1);
  593|       |                ndmq1 = BN_dup(dmq1);
  594|       |                niqmp = BN_dup(iqmp);
  595|       |                if (ndmp1 == NULL || ndmq1 == NULL || niqmp == NULL) {
  596|       |                    RSA_free(new_rsa);
  597|       |                    BN_free(ndmp1);
  598|       |                    BN_free(ndmq1);
  599|       |                    BN_free(niqmp);
  600|       |                    goto fail;
  601|       |                }
  602|       |
  603|       |                /* Memory management of ndmp1, ndmq1 and niqmp is transferred
  604|       |                 * to RSA object */
  605|       |                rc = RSA_set0_crt_params(new_rsa, ndmp1, ndmq1, niqmp);
  606|       |                if (rc == 0) {
  607|       |                    RSA_free(new_rsa);
  608|       |                    BN_free(ndmp1);
  609|       |                    BN_free(ndmq1);
  610|       |                    BN_free(niqmp);
  611|       |                    goto fail;
  612|       |                }
  613|       |            }
  614|       |        }
  615|       |
  616|       |        new->key = EVP_PKEY_new();
  617|       |        if (new->key == NULL) {
  618|       |            RSA_free(new_rsa);
  619|       |            goto fail;
  620|       |        }
  621|       |
  622|       |        rc = EVP_PKEY_assign_RSA(new->key, new_rsa);
  623|       |        if (rc != 1) {
  624|       |            RSA_free(new_rsa);
  625|       |            goto fail;
  626|       |        }
  627|       |
  628|       |        new_rsa = NULL;
  629|       |#else
  630|    504|        rc = evp_dup_rsa_pkey(key, new, demote);
  631|    504|        if (rc != SSH_OK) {
  ------------------
  |  |  315|    504|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (631:13): [True: 0, False: 504]
  ------------------
  632|      0|            goto fail;
  633|      0|        }
  634|    504|#endif /* OPENSSL_VERSION_NUMBER */
  635|    504|        break;
  636|    504|    }
  637|    504|    case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (637:5): [True: 0, False: 504]
  ------------------
  638|      0|    case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (638:5): [True: 0, False: 504]
  ------------------
  639|      0|    case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (639:5): [True: 0, False: 504]
  ------------------
  640|      0|    case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (640:5): [True: 0, False: 504]
  ------------------
  641|      0|#ifdef HAVE_OPENSSL_ECC
  642|      0|        new->ecdsa_nid = key->ecdsa_nid;
  643|       |#ifdef WITH_PKCS11_URI
  644|       |        /* Take the PKCS#11 keys as they are */
  645|       |        if (key->flags & SSH_KEY_FLAG_PKCS11_URI && !demote) {
  646|       |            rc = EVP_PKEY_up_ref(key->key);
  647|       |            if (rc != 1) {
  648|       |                goto fail;
  649|       |            }
  650|       |            new->key = key->key;
  651|       |            return new;
  652|       |        }
  653|       |#endif /* WITH_PKCS11_URI */
  654|       |#if OPENSSL_VERSION_NUMBER < 0x30000000L
  655|       |        /* privkey -> pubkey */
  656|       |        if (demote && ssh_key_is_private(key)) {
  657|       |            const EC_POINT *p = NULL;
  658|       |            EC_KEY *new_ecdsa = NULL, *old_ecdsa = NULL;
  659|       |            int ok;
  660|       |
  661|       |            new_ecdsa = EC_KEY_new_by_curve_name(key->ecdsa_nid);
  662|       |            if (new_ecdsa == NULL) {
  663|       |                goto fail;
  664|       |            }
  665|       |
  666|       |            old_ecdsa = EVP_PKEY_get0_EC_KEY(key->key);
  667|       |            if (old_ecdsa == NULL) {
  668|       |                EC_KEY_free(new_ecdsa);
  669|       |                goto fail;
  670|       |            }
  671|       |
  672|       |            p = EC_KEY_get0_public_key(old_ecdsa);
  673|       |            if (p == NULL) {
  674|       |                EC_KEY_free(new_ecdsa);
  675|       |                goto fail;
  676|       |            }
  677|       |
  678|       |            ok = EC_KEY_set_public_key(new_ecdsa, p);
  679|       |            if (ok != 1) {
  680|       |                EC_KEY_free(new_ecdsa);
  681|       |                goto fail;
  682|       |            }
  683|       |
  684|       |            new->key = EVP_PKEY_new();
  685|       |            if (new->key == NULL) {
  686|       |                EC_KEY_free(new_ecdsa);
  687|       |                goto fail;
  688|       |            }
  689|       |
  690|       |            ok = EVP_PKEY_assign_EC_KEY(new->key, new_ecdsa);
  691|       |            if (ok != 1) {
  692|       |                EC_KEY_free(new_ecdsa);
  693|       |                goto fail;
  694|       |            }
  695|       |        } else {
  696|       |            rc = EVP_PKEY_up_ref(key->key);
  697|       |            if (rc != 1) {
  698|       |                goto fail;
  699|       |            }
  700|       |            new->key = key->key;
  701|       |        }
  702|       |#else
  703|      0|        rc = evp_dup_ecdsa_pkey(key, new, demote);
  704|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (704:13): [True: 0, False: 0]
  ------------------
  705|      0|            goto fail;
  706|      0|        }
  707|      0|#endif /* OPENSSL_VERSION_NUMBER */
  708|      0|        break;
  709|      0|#endif /* HAVE_OPENSSL_ECC */
  710|      0|    case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (710:5): [True: 0, False: 504]
  ------------------
  711|      0|    case SSH_KEYTYPE_SK_ED25519: {
  ------------------
  |  Branch (711:5): [True: 0, False: 504]
  ------------------
  712|       |#if OPENSSL_VERSION_NUMBER < 0x30000000L
  713|       |        /* Take the PKCS#11 keys as they are */
  714|       |        if (key->flags & SSH_KEY_FLAG_PKCS11_URI && !demote) {
  715|       |            rc = EVP_PKEY_up_ref(key->key);
  716|       |            if (rc != 1) {
  717|       |                goto fail;
  718|       |            }
  719|       |            new->key = key->key;
  720|       |            return new;
  721|       |        }
  722|       |
  723|       |        if (!demote && (key->flags & SSH_KEY_FLAG_PRIVATE) &&
  724|       |            key->type == SSH_KEYTYPE_ED25519) {
  725|       |            rc = EVP_PKEY_up_ref(key->key);
  726|       |            if (rc != 1) {
  727|       |                goto fail;
  728|       |            }
  729|       |            new->key = key->key;
  730|       |        } else {
  731|       |            unsigned char *ed25519_pubkey = NULL;
  732|       |            size_t key_len = 0;
  733|       |
  734|       |            rc = EVP_PKEY_get_raw_public_key(key->key, NULL, &key_len);
  735|       |            if (rc != 1) {
  736|       |                SSH_LOG(SSH_LOG_TRACE,
  737|       |                        "Failed to get ed25519 raw public key length: %s",
  738|       |                        ERR_error_string(ERR_get_error(), NULL));
  739|       |                goto fail;
  740|       |            }
  741|       |
  742|       |            if (key_len != ED25519_KEY_LEN) {
  743|       |                SSH_LOG(SSH_LOG_TRACE,
  744|       |                        "Unexpected length of public key %zu. Expected %d.",
  745|       |                        key_len,
  746|       |                        ED25519_KEY_LEN);
  747|       |                goto fail;
  748|       |            }
  749|       |
  750|       |            ed25519_pubkey = malloc(key_len);
  751|       |            if (ed25519_pubkey == NULL) {
  752|       |                SSH_LOG(SSH_LOG_TRACE, "Out of memory");
  753|       |                goto fail;
  754|       |            }
  755|       |
  756|       |            rc = EVP_PKEY_get_raw_public_key(key->key,
  757|       |                                             ed25519_pubkey,
  758|       |                                             &key_len);
  759|       |            if (rc != 1) {
  760|       |                SSH_LOG(SSH_LOG_TRACE,
  761|       |                        "Failed to get ed25519 raw public key: %s",
  762|       |                        ERR_error_string(ERR_get_error(), NULL));
  763|       |                free(ed25519_pubkey);
  764|       |                goto fail;
  765|       |            }
  766|       |
  767|       |            new->key = EVP_PKEY_new_raw_public_key(EVP_PKEY_ED25519,
  768|       |                                                   NULL,
  769|       |                                                   ed25519_pubkey,
  770|       |                                                   key_len);
  771|       |            free(ed25519_pubkey);
  772|       |        }
  773|       |
  774|       |#else
  775|      0|        rc = evp_dup_ed25519_pkey(key, new, demote);
  776|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (776:13): [True: 0, False: 0]
  ------------------
  777|      0|            goto fail;
  778|      0|        }
  779|      0|#endif /* OPENSSL_VERSION_NUMBER < 0x30000000L */
  780|      0|        break;
  781|      0|    }
  782|      0|    case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (782:5): [True: 0, False: 504]
  ------------------
  783|      0|    default:
  ------------------
  |  Branch (783:5): [True: 0, False: 504]
  ------------------
  784|      0|        ssh_key_free(new);
  785|      0|        return NULL;
  786|    504|    }
  787|       |
  788|    504|    return new;
  789|      0|fail:
  790|      0|    ssh_key_free(new);
  791|       |    return NULL;
  792|    504|}
pki_private_key_from_base64:
 1135|    319|{
 1136|    319|    BIO *mem = NULL;
 1137|       |#if OPENSSL_VERSION_NUMBER < 0x30000000L
 1138|       |    EC_KEY *ecdsa = NULL;
 1139|       |#endif /* OPENSSL_VERSION_NUMBER */
 1140|    319|    ssh_key key = NULL;
 1141|    319|    enum ssh_keytypes_e type = SSH_KEYTYPE_UNKNOWN;
 1142|    319|    EVP_PKEY *pkey = NULL;
 1143|       |
 1144|    319|    mem = BIO_new_mem_buf((void*)b64_key, -1);
 1145|       |
 1146|    319|    if (passphrase == NULL) {
  ------------------
  |  Branch (1146:9): [True: 319, False: 0]
  ------------------
 1147|    319|        if (auth_fn) {
  ------------------
  |  Branch (1147:13): [True: 0, False: 319]
  ------------------
 1148|      0|            struct pem_get_password_struct pgp = { auth_fn, auth_data };
 1149|       |
 1150|      0|            pkey = PEM_read_bio_PrivateKey(mem, NULL, pem_get_password, &pgp);
 1151|    319|        } else {
 1152|       |            /* openssl uses its own callback to get the passphrase here */
 1153|    319|            pkey = PEM_read_bio_PrivateKey(mem, NULL, NULL, NULL);
 1154|    319|        }
 1155|    319|    } else {
 1156|      0|        pkey = PEM_read_bio_PrivateKey(mem, NULL, NULL, (void *) passphrase);
 1157|      0|    }
 1158|       |
 1159|    319|    BIO_free(mem);
 1160|       |
 1161|    319|    if (pkey == NULL) {
  ------------------
  |  Branch (1161:9): [True: 0, False: 319]
  ------------------
 1162|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1163|      0|                "Error parsing private key: %s",
 1164|      0|                ERR_error_string(ERR_get_error(), NULL));
 1165|      0|        return NULL;
 1166|      0|    }
 1167|    319|    switch (EVP_PKEY_base_id(pkey)) {
 1168|    319|    case EVP_PKEY_RSA:
  ------------------
  |  Branch (1168:5): [True: 319, False: 0]
  ------------------
 1169|    319|        type = SSH_KEYTYPE_RSA;
 1170|    319|        break;
 1171|      0|    case EVP_PKEY_EC:
  ------------------
  |  Branch (1171:5): [True: 0, False: 319]
  ------------------
 1172|      0|#ifdef HAVE_OPENSSL_ECC
 1173|       |#if OPENSSL_VERSION_NUMBER < 0x30000000L
 1174|       |        ecdsa = EVP_PKEY_get0_EC_KEY(pkey);
 1175|       |        if (ecdsa == NULL) {
 1176|       |            SSH_LOG(SSH_LOG_TRACE,
 1177|       |                    "Error parsing private key: %s",
 1178|       |                    ERR_error_string(ERR_get_error(), NULL));
 1179|       |            goto fail;
 1180|       |        }
 1181|       |#endif /* OPENSSL_VERSION_NUMBER */
 1182|       |
 1183|       |        /* pki_privatekey_type_from_string always returns P256 for ECDSA
 1184|       |         * keys, so we need to figure out the correct type here */
 1185|       |#if OPENSSL_VERSION_NUMBER < 0x30000000L
 1186|       |        type = pki_key_ecdsa_to_key_type(ecdsa);
 1187|       |#else
 1188|      0|        type = pki_key_ecdsa_to_key_type(pkey);
 1189|      0|#endif /* OPENSSL_VERSION_NUMBER */
 1190|      0|        if (type == SSH_KEYTYPE_UNKNOWN) {
  ------------------
  |  Branch (1190:13): [True: 0, False: 0]
  ------------------
 1191|      0|            SSH_LOG(SSH_LOG_TRACE, "Invalid private key.");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1192|      0|            goto fail;
 1193|      0|        }
 1194|       |
 1195|      0|        break;
 1196|      0|#endif /* HAVE_OPENSSL_ECC */
 1197|      0|    case EVP_PKEY_ED25519:
  ------------------
  |  Branch (1197:5): [True: 0, False: 319]
  ------------------
 1198|      0|        type = SSH_KEYTYPE_ED25519;
 1199|      0|        break;
 1200|      0|    default:
  ------------------
  |  Branch (1200:5): [True: 0, False: 319]
  ------------------
 1201|      0|        SSH_LOG(SSH_LOG_TRACE, "Unknown or invalid private key type %d",
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1202|      0|                EVP_PKEY_base_id(pkey));
 1203|      0|        EVP_PKEY_free(pkey);
 1204|      0|        return NULL;
 1205|    319|    }
 1206|       |
 1207|    319|    key = ssh_key_new();
 1208|    319|    if (key == NULL) {
  ------------------
  |  Branch (1208:9): [True: 0, False: 319]
  ------------------
 1209|      0|        goto fail;
 1210|      0|    }
 1211|       |
 1212|    319|    key->type = type;
 1213|    319|    key->type_c = ssh_key_type_to_char(type);
 1214|    319|    key->flags = SSH_KEY_FLAG_PRIVATE | SSH_KEY_FLAG_PUBLIC;
  ------------------
  |  |   55|    319|#define SSH_KEY_FLAG_PRIVATE 0x0002
  ------------------
                  key->flags = SSH_KEY_FLAG_PRIVATE | SSH_KEY_FLAG_PUBLIC;
  ------------------
  |  |   54|    319|#define SSH_KEY_FLAG_PUBLIC  0x0001
  ------------------
 1215|    319|    key->key = pkey;
 1216|    319|#ifdef HAVE_OPENSSL_ECC
 1217|    319|    if (is_ecdsa_key_type(key->type)) {
  ------------------
  |  |  143|    319|    ((t) >= SSH_KEYTYPE_ECDSA_P256 && (t) <= SSH_KEYTYPE_ECDSA_P521)
  |  |  ------------------
  |  |  |  Branch (143:6): [True: 0, False: 319]
  |  |  |  Branch (143:39): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1218|       |#if OPENSSL_VERSION_NUMBER < 0x30000000L
 1219|       |        key->ecdsa_nid = pki_key_ecdsa_to_nid(ecdsa);
 1220|       |#else
 1221|      0|        key->ecdsa_nid = pki_key_ecdsa_to_nid(key->key);
 1222|      0|#endif /* OPENSSL_VERSION_NUMBER */
 1223|      0|    }
 1224|    319|#endif /* HAVE_OPENSSL_ECC */
 1225|       |
 1226|    319|    return key;
 1227|      0|fail:
 1228|      0|    EVP_PKEY_free(pkey);
 1229|      0|    ssh_key_free(key);
 1230|       |    return NULL;
 1231|    319|}
pki_pubkey_build_rsa:
 1415|  1.35k|                         ssh_string n) {
 1416|  1.35k|    int rc;
 1417|  1.35k|    BIGNUM *be = NULL, *bn = NULL;
 1418|  1.35k|#if OPENSSL_VERSION_NUMBER >= 0x30000000L
 1419|  1.35k|    OSSL_PARAM_BLD *param_bld = OSSL_PARAM_BLD_new();
 1420|  1.35k|    if (param_bld == NULL) {
  ------------------
  |  Branch (1420:9): [True: 0, False: 1.35k]
  ------------------
 1421|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1422|      0|    }
 1423|       |#else
 1424|       |    RSA *key_rsa = RSA_new();
 1425|       |    if (key_rsa == NULL) {
 1426|       |        return SSH_ERROR;
 1427|       |    }
 1428|       |#endif /* OPENSSL_VERSION_NUMBER */
 1429|       |
 1430|  1.35k|    be = ssh_make_string_bn(e);
 1431|  1.35k|    if (be == NULL) {
  ------------------
  |  Branch (1431:9): [True: 0, False: 1.35k]
  ------------------
 1432|      0|        rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1433|      0|        goto fail;
 1434|      0|    }
 1435|  1.35k|    bn = ssh_make_string_bn(n);
 1436|  1.35k|    if (bn == NULL) {
  ------------------
  |  Branch (1436:9): [True: 0, False: 1.35k]
  ------------------
 1437|      0|        rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1438|      0|        goto fail;
 1439|      0|    }
 1440|       |
 1441|       |#if OPENSSL_VERSION_NUMBER < 0x30000000L
 1442|       |    rc = RSA_set0_key(key_rsa, bn, be, NULL);
 1443|       |    if (rc == 0) {
 1444|       |        goto fail;
 1445|       |    }
 1446|       |    /* Memory management of bn and be is transferred to RSA object */
 1447|       |    bn = NULL;
 1448|       |    be = NULL;
 1449|       |
 1450|       |    key->key = EVP_PKEY_new();
 1451|       |    if (key->key == NULL) {
 1452|       |        goto fail;
 1453|       |    }
 1454|       |
 1455|       |    rc = EVP_PKEY_assign_RSA(key->key, key_rsa);
 1456|       |    if (rc != 1) {
 1457|       |        goto fail;
 1458|       |    }
 1459|       |
 1460|       |    return SSH_OK;
 1461|       |#else
 1462|  1.35k|    rc = OSSL_PARAM_BLD_push_BN(param_bld, OSSL_PKEY_PARAM_RSA_N, bn);
 1463|  1.35k|    if (rc != 1) {
  ------------------
  |  Branch (1463:9): [True: 0, False: 1.35k]
  ------------------
 1464|      0|        rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1465|      0|        goto fail;
 1466|      0|    }
 1467|  1.35k|    rc = OSSL_PARAM_BLD_push_BN(param_bld, OSSL_PKEY_PARAM_RSA_E, be);
 1468|  1.35k|    if (rc != 1) {
  ------------------
  |  Branch (1468:9): [True: 0, False: 1.35k]
  ------------------
 1469|      0|        rc = SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1470|      0|        goto fail;
 1471|      0|    }
 1472|       |
 1473|  1.35k|    rc = evp_build_pkey("RSA", param_bld, &(key->key), EVP_PKEY_PUBLIC_KEY);
 1474|  1.35k|#endif /* OPENSSL_VERSION_NUMBER */
 1475|       |
 1476|  1.35k|fail:
 1477|  1.35k|    bignum_safe_free(bn);
  ------------------
  |  |   71|  1.35k|#define bignum_safe_free(num) do { \
  |  |   72|  1.35k|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 1.35k, False: 0]
  |  |  ------------------
  |  |   73|  1.35k|        BN_clear_free((num)); \
  |  |   74|  1.35k|        (num)=NULL; \
  |  |   75|  1.35k|    } \
  |  |   76|  1.35k|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 1.35k]
  |  |  ------------------
  ------------------
 1478|  1.35k|    bignum_safe_free(be);
  ------------------
  |  |   71|  1.35k|#define bignum_safe_free(num) do { \
  |  |   72|  1.35k|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 1.35k, False: 0]
  |  |  ------------------
  |  |   73|  1.35k|        BN_clear_free((num)); \
  |  |   74|  1.35k|        (num)=NULL; \
  |  |   75|  1.35k|    } \
  |  |   76|  1.35k|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 1.35k]
  |  |  ------------------
  ------------------
 1479|       |#if OPENSSL_VERSION_NUMBER < 0x30000000L
 1480|       |    RSA_free(key_rsa);
 1481|       |
 1482|       |    return SSH_ERROR;
 1483|       |#else
 1484|  1.35k|    OSSL_PARAM_BLD_free(param_bld);
 1485|       |
 1486|  1.35k|    return rc;
 1487|  1.35k|#endif /* OPENSSL_VERSION_NUMBER */
 1488|  1.35k|}
pki_key_to_blob:
 1491|    555|{
 1492|    555|    ssh_buffer buffer = NULL;
 1493|    555|    ssh_string type_s = NULL;
 1494|    555|    ssh_string str = NULL;
 1495|    555|    ssh_string e = NULL;
 1496|    555|    ssh_string n = NULL;
 1497|    555|    ssh_string p = NULL;
 1498|    555|    ssh_string g = NULL;
 1499|    555|    ssh_string q = NULL;
 1500|    555|    ssh_string d = NULL;
 1501|    555|    ssh_string iqmp = NULL;
 1502|    555|    int rc;
 1503|    555|#if OPENSSL_VERSION_NUMBER >= 0x30000000L
 1504|    555|    BIGNUM *bp = NULL, *bq = NULL, *bg = NULL, *bpub_key = NULL,
 1505|    555|           *bn = NULL, *be = NULL,
 1506|    555|           *bd = NULL, *biqmp = NULL;
 1507|    555|    OSSL_PARAM *params = NULL;
 1508|    555|#endif /* OPENSSL_VERSION_NUMBER */
 1509|    555|    uint8_t *ed25519_pubkey = NULL;
 1510|    555|    uint8_t *ed25519_privkey = NULL;
 1511|    555|    size_t key_len = 0;
 1512|       |
 1513|    555|    buffer = ssh_buffer_new();
 1514|    555|    if (buffer == NULL) {
  ------------------
  |  Branch (1514:9): [True: 0, False: 555]
  ------------------
 1515|      0|        return NULL;
 1516|      0|    }
 1517|       |    /* The buffer will contain sensitive information. Make sure it is erased */
 1518|    555|    ssh_buffer_set_secure(buffer);
 1519|       |
 1520|    555|    if (key->cert != NULL) {
  ------------------
  |  Branch (1520:9): [True: 0, False: 555]
  ------------------
 1521|      0|        rc = ssh_buffer_add_buffer(buffer, key->cert);
 1522|      0|        if (rc < 0) {
  ------------------
  |  Branch (1522:13): [True: 0, False: 0]
  ------------------
 1523|      0|            SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1524|      0|            return NULL;
 1525|      0|        }
 1526|      0|        goto makestring;
 1527|      0|    }
 1528|       |
 1529|    555|    type_s = ssh_string_from_char(key->type_c);
 1530|    555|    if (type_s == NULL) {
  ------------------
  |  Branch (1530:9): [True: 0, False: 555]
  ------------------
 1531|      0|        SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1532|      0|        return NULL;
 1533|      0|    }
 1534|       |
 1535|    555|    rc = ssh_buffer_add_ssh_string(buffer, type_s);
 1536|    555|    SSH_STRING_FREE(type_s);
  ------------------
  |  |  882|    555|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 555, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 555]
  |  |  ------------------
  ------------------
 1537|    555|    if (rc < 0) {
  ------------------
  |  Branch (1537:9): [True: 0, False: 555]
  ------------------
 1538|      0|        SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1539|      0|        return NULL;
 1540|      0|    }
 1541|       |
 1542|    555|    switch (key->type) {
 1543|    555|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (1543:5): [True: 555, False: 0]
  ------------------
 1544|    555|    case SSH_KEYTYPE_RSA1: {
  ------------------
  |  Branch (1544:5): [True: 0, False: 555]
  ------------------
 1545|       |#if OPENSSL_VERSION_NUMBER < 0x30000000L
 1546|       |        const BIGNUM *be = NULL, *bn = NULL;
 1547|       |        const RSA *key_rsa = EVP_PKEY_get0_RSA(key->key);
 1548|       |        RSA_get0_key(key_rsa, &bn, &be, NULL);
 1549|       |#else
 1550|    555|        const OSSL_PARAM *out_param = NULL;
 1551|    555|        rc = EVP_PKEY_todata(key->key, EVP_PKEY_PUBLIC_KEY, &params);
 1552|    555|        if (rc != 1) {
  ------------------
  |  Branch (1552:13): [True: 0, False: 555]
  ------------------
 1553|      0|            goto fail;
 1554|      0|        }
 1555|    555|        out_param = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_E);
 1556|    555|        if (out_param == NULL) {
  ------------------
  |  Branch (1556:13): [True: 0, False: 555]
  ------------------
 1557|      0|            SSH_LOG(SSH_LOG_TRACE, "RSA: No param E has been found");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1558|      0|            goto fail;
 1559|      0|        }
 1560|    555|        rc = OSSL_PARAM_get_BN(out_param, &be);
 1561|    555|        if (rc != 1) {
  ------------------
  |  Branch (1561:13): [True: 0, False: 555]
  ------------------
 1562|      0|            goto fail;
 1563|      0|        }
 1564|    555|        out_param = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_N);
 1565|    555|        if (out_param == NULL) {
  ------------------
  |  Branch (1565:13): [True: 0, False: 555]
  ------------------
 1566|      0|            SSH_LOG(SSH_LOG_TRACE, "RSA: No param N has been found");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1567|      0|            goto fail;
 1568|      0|        }
 1569|    555|        rc = OSSL_PARAM_get_BN(out_param, &bn);
 1570|    555|        if (rc != 1) {
  ------------------
  |  Branch (1570:13): [True: 0, False: 555]
  ------------------
 1571|      0|            goto fail;
 1572|      0|        }
 1573|    555|#endif /* OPENSSL_VERSION_NUMBER */
 1574|    555|        e = ssh_make_bignum_string((BIGNUM *)be);
 1575|    555|        if (e == NULL) {
  ------------------
  |  Branch (1575:13): [True: 0, False: 555]
  ------------------
 1576|      0|            goto fail;
 1577|      0|        }
 1578|       |
 1579|    555|        n = ssh_make_bignum_string((BIGNUM *)bn);
 1580|    555|        if (n == NULL) {
  ------------------
  |  Branch (1580:13): [True: 0, False: 555]
  ------------------
 1581|      0|            goto fail;
 1582|      0|        }
 1583|       |
 1584|    555|        if (type == SSH_KEY_PUBLIC) {
  ------------------
  |  Branch (1584:13): [True: 555, False: 0]
  ------------------
 1585|       |            /* The N and E parts are swapped in the public key export ! */
 1586|    555|            rc = ssh_buffer_add_ssh_string(buffer, e);
 1587|    555|            if (rc < 0) {
  ------------------
  |  Branch (1587:17): [True: 0, False: 555]
  ------------------
 1588|      0|                goto fail;
 1589|      0|            }
 1590|    555|            rc = ssh_buffer_add_ssh_string(buffer, n);
 1591|    555|            if (rc < 0) {
  ------------------
  |  Branch (1591:17): [True: 0, False: 555]
  ------------------
 1592|      0|                goto fail;
 1593|      0|            }
 1594|    555|        } else if (type == SSH_KEY_PRIVATE) {
  ------------------
  |  Branch (1594:20): [True: 0, False: 0]
  ------------------
 1595|       |#if OPENSSL_VERSION_NUMBER < 0x30000000L
 1596|       |            const BIGNUM *bd, *biqmp, *bp, *bq;
 1597|       |            RSA_get0_key(key_rsa, NULL, NULL, &bd);
 1598|       |            RSA_get0_factors(key_rsa, &bp, &bq);
 1599|       |            RSA_get0_crt_params(key_rsa, NULL, NULL, &biqmp);
 1600|       |#else
 1601|      0|            OSSL_PARAM_free(params);
 1602|      0|            rc = EVP_PKEY_todata(key->key, EVP_PKEY_KEYPAIR, &params);
 1603|      0|            if (rc != 1) {
  ------------------
  |  Branch (1603:17): [True: 0, False: 0]
  ------------------
 1604|      0|                goto fail;
 1605|      0|            }
 1606|       |
 1607|      0|            out_param = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_D);
 1608|      0|            if (out_param == NULL) {
  ------------------
  |  Branch (1608:17): [True: 0, False: 0]
  ------------------
 1609|      0|                SSH_LOG(SSH_LOG_TRACE, "RSA: No param D has been found");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1610|      0|                goto fail;
 1611|      0|            }
 1612|      0|            rc = OSSL_PARAM_get_BN(out_param, &bd);
 1613|      0|            if (rc != 1) {
  ------------------
  |  Branch (1613:17): [True: 0, False: 0]
  ------------------
 1614|      0|                goto fail;
 1615|      0|            }
 1616|       |
 1617|      0|            out_param = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_FACTOR1);
 1618|      0|            if (out_param == NULL) {
  ------------------
  |  Branch (1618:17): [True: 0, False: 0]
  ------------------
 1619|      0|                SSH_LOG(SSH_LOG_TRACE, "RSA: No param P has been found");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1620|      0|                goto fail;
 1621|      0|            }
 1622|      0|            rc = OSSL_PARAM_get_BN(out_param, &bp);
 1623|      0|            if (rc != 1) {
  ------------------
  |  Branch (1623:17): [True: 0, False: 0]
  ------------------
 1624|      0|                goto fail;
 1625|      0|            }
 1626|       |
 1627|      0|            out_param = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_FACTOR2);
 1628|      0|            if (out_param == NULL) {
  ------------------
  |  Branch (1628:17): [True: 0, False: 0]
  ------------------
 1629|      0|                SSH_LOG(SSH_LOG_TRACE, "RSA: No param Q has been found");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1630|      0|                goto fail;
 1631|      0|            }
 1632|      0|            rc = OSSL_PARAM_get_BN(out_param, &bq);
 1633|      0|            if (rc != 1) {
  ------------------
  |  Branch (1633:17): [True: 0, False: 0]
  ------------------
 1634|      0|                goto fail;
 1635|      0|            }
 1636|       |
 1637|      0|            out_param = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_COEFFICIENT1);
 1638|      0|            if (out_param == NULL) {
  ------------------
  |  Branch (1638:17): [True: 0, False: 0]
  ------------------
 1639|      0|                SSH_LOG(SSH_LOG_TRACE, "RSA: No param IQMP has been found");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1640|      0|                goto fail;
 1641|      0|            }
 1642|      0|            rc = OSSL_PARAM_get_BN(out_param, &biqmp);
 1643|      0|            if (rc != 1) {
  ------------------
  |  Branch (1643:17): [True: 0, False: 0]
  ------------------
 1644|      0|                goto fail;
 1645|      0|            }
 1646|      0|#endif /* OPENSSL_VERSION_NUMBER */
 1647|      0|            rc = ssh_buffer_add_ssh_string(buffer, n);
 1648|      0|            if (rc < 0) {
  ------------------
  |  Branch (1648:17): [True: 0, False: 0]
  ------------------
 1649|      0|                goto fail;
 1650|      0|            }
 1651|      0|            rc = ssh_buffer_add_ssh_string(buffer, e);
 1652|      0|            if (rc < 0) {
  ------------------
  |  Branch (1652:17): [True: 0, False: 0]
  ------------------
 1653|      0|                goto fail;
 1654|      0|            }
 1655|       |
 1656|      0|            d = ssh_make_bignum_string((BIGNUM *)bd);
 1657|      0|            if (d == NULL) {
  ------------------
  |  Branch (1657:17): [True: 0, False: 0]
  ------------------
 1658|      0|                goto fail;
 1659|      0|            }
 1660|       |
 1661|      0|            iqmp = ssh_make_bignum_string((BIGNUM *)biqmp);
 1662|      0|            if (iqmp == NULL) {
  ------------------
  |  Branch (1662:17): [True: 0, False: 0]
  ------------------
 1663|      0|                goto fail;
 1664|      0|            }
 1665|       |
 1666|      0|            p = ssh_make_bignum_string((BIGNUM *)bp);
 1667|      0|            if (p == NULL) {
  ------------------
  |  Branch (1667:17): [True: 0, False: 0]
  ------------------
 1668|      0|                goto fail;
 1669|      0|            }
 1670|       |
 1671|      0|            q = ssh_make_bignum_string((BIGNUM *)bq);
 1672|      0|            if (q == NULL) {
  ------------------
  |  Branch (1672:17): [True: 0, False: 0]
  ------------------
 1673|      0|                goto fail;
 1674|      0|            }
 1675|       |
 1676|      0|            rc = ssh_buffer_add_ssh_string(buffer, d);
 1677|      0|            if (rc < 0) {
  ------------------
  |  Branch (1677:17): [True: 0, False: 0]
  ------------------
 1678|      0|                goto fail;
 1679|      0|            }
 1680|      0|            rc = ssh_buffer_add_ssh_string(buffer, iqmp);
 1681|      0|            if (rc < 0) {
  ------------------
  |  Branch (1681:17): [True: 0, False: 0]
  ------------------
 1682|      0|                goto fail;
 1683|      0|            }
 1684|      0|            rc = ssh_buffer_add_ssh_string(buffer, p);
 1685|      0|            if (rc < 0) {
  ------------------
  |  Branch (1685:17): [True: 0, False: 0]
  ------------------
 1686|      0|                goto fail;
 1687|      0|            }
 1688|      0|            rc = ssh_buffer_add_ssh_string(buffer, q);
 1689|      0|            if (rc < 0) {
  ------------------
  |  Branch (1689:17): [True: 0, False: 0]
  ------------------
 1690|      0|                goto fail;
 1691|      0|            }
 1692|       |
 1693|      0|            ssh_string_burn(d);
 1694|      0|            SSH_STRING_FREE(d);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1695|      0|            ssh_string_burn(iqmp);
 1696|      0|            SSH_STRING_FREE(iqmp);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1697|      0|            ssh_string_burn(p);
 1698|      0|            SSH_STRING_FREE(p);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1699|      0|            ssh_string_burn(q);
 1700|      0|            SSH_STRING_FREE(q);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1701|      0|#if OPENSSL_VERSION_NUMBER >= 0x30000000L
 1702|      0|            bignum_safe_free(bd);
  ------------------
  |  |   71|      0|#define bignum_safe_free(num) do { \
  |  |   72|      0|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 0]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1703|      0|            bignum_safe_free(biqmp);
  ------------------
  |  |   71|      0|#define bignum_safe_free(num) do { \
  |  |   72|      0|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 0]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1704|      0|            bignum_safe_free(bp);
  ------------------
  |  |   71|      0|#define bignum_safe_free(num) do { \
  |  |   72|      0|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 0]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1705|      0|            bignum_safe_free(bq);
  ------------------
  |  |   71|      0|#define bignum_safe_free(num) do { \
  |  |   72|      0|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 0]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1706|      0|#endif /* OPENSSL_VERSION_NUMBER */
 1707|      0|        }
 1708|    555|        ssh_string_burn(e);
 1709|    555|        SSH_STRING_FREE(e);
  ------------------
  |  |  882|    555|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 555, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 555]
  |  |  ------------------
  ------------------
 1710|    555|        ssh_string_burn(n);
 1711|    555|        SSH_STRING_FREE(n);
  ------------------
  |  |  882|    555|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 555, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 555]
  |  |  ------------------
  ------------------
 1712|    555|#if OPENSSL_VERSION_NUMBER >= 0x30000000L
 1713|    555|        bignum_safe_free(bn);
  ------------------
  |  |   71|    555|#define bignum_safe_free(num) do { \
  |  |   72|    555|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 555, False: 0]
  |  |  ------------------
  |  |   73|    555|        BN_clear_free((num)); \
  |  |   74|    555|        (num)=NULL; \
  |  |   75|    555|    } \
  |  |   76|    555|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 555]
  |  |  ------------------
  ------------------
 1714|    555|        bignum_safe_free(be);
  ------------------
  |  |   71|    555|#define bignum_safe_free(num) do { \
  |  |   72|    555|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 555, False: 0]
  |  |  ------------------
  |  |   73|    555|        BN_clear_free((num)); \
  |  |   74|    555|        (num)=NULL; \
  |  |   75|    555|    } \
  |  |   76|    555|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 555]
  |  |  ------------------
  ------------------
 1715|    555|        OSSL_PARAM_free(params);
 1716|    555|        params = NULL;
 1717|    555|#endif /* OPENSSL_VERSION_NUMBER */
 1718|    555|        break;
 1719|    555|    }
 1720|      0|    case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (1720:5): [True: 0, False: 555]
  ------------------
 1721|      0|    case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (1721:5): [True: 0, False: 555]
  ------------------
 1722|      0|        rc = EVP_PKEY_get_raw_public_key(key->key, NULL, &key_len);
 1723|      0|        if (rc != 1) {
  ------------------
  |  Branch (1723:13): [True: 0, False: 0]
  ------------------
 1724|      0|            SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1725|      0|                    "Failed to get ed25519 raw public key length: %s",
 1726|      0|                    ERR_error_string(ERR_get_error(), NULL));
 1727|      0|            goto fail;
 1728|      0|        }
 1729|       |
 1730|      0|        if (key_len != ED25519_KEY_LEN) {
  ------------------
  |  |   44|      0|#define ED25519_KEY_LEN 32
  ------------------
  |  Branch (1730:13): [True: 0, False: 0]
  ------------------
 1731|      0|            SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1732|      0|                    "Unexpected length of private key %zu. Expected %d.",
 1733|      0|                    key_len,
 1734|      0|                    ED25519_KEY_LEN);
 1735|      0|            goto fail;
 1736|      0|        }
 1737|       |
 1738|      0|        ed25519_pubkey = malloc(key_len);
 1739|      0|        if (ed25519_pubkey == NULL) {
  ------------------
  |  Branch (1739:13): [True: 0, False: 0]
  ------------------
 1740|      0|            SSH_LOG(SSH_LOG_TRACE, "Out of memory");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1741|      0|            goto fail;
 1742|      0|        }
 1743|       |
 1744|      0|        rc = EVP_PKEY_get_raw_public_key(key->key,
 1745|      0|                                         (uint8_t *)ed25519_pubkey,
 1746|      0|                                         &key_len);
 1747|      0|        if (rc != 1) {
  ------------------
  |  Branch (1747:13): [True: 0, False: 0]
  ------------------
 1748|      0|            SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1749|      0|                    "Failed to get ed25519 raw public key:  %s",
 1750|      0|                    ERR_error_string(ERR_get_error(), NULL));
 1751|      0|            goto fail;
 1752|      0|        }
 1753|       |
 1754|      0|        rc = ssh_buffer_pack(buffer,
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1755|      0|                             "dP",
 1756|      0|                             (uint32_t)ED25519_KEY_LEN,
 1757|      0|                             (size_t)ED25519_KEY_LEN,
 1758|      0|                             ed25519_pubkey);
 1759|      0|        if (rc == SSH_ERROR) {
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1759:13): [True: 0, False: 0]
  ------------------
 1760|      0|            goto fail;
 1761|      0|        }
 1762|       |
 1763|      0|        if (type == SSH_KEY_PRIVATE && key->type == SSH_KEYTYPE_ED25519) {
  ------------------
  |  Branch (1763:13): [True: 0, False: 0]
  |  Branch (1763:40): [True: 0, False: 0]
  ------------------
 1764|      0|            key_len = 0;
 1765|      0|            rc = EVP_PKEY_get_raw_private_key(key->key, NULL, &key_len);
 1766|      0|            if (rc != 1) {
  ------------------
  |  Branch (1766:17): [True: 0, False: 0]
  ------------------
 1767|      0|                SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1768|      0|                        "Failed to get ed25519 raw private key length: %s",
 1769|      0|                        ERR_error_string(ERR_get_error(), NULL));
 1770|      0|                goto fail;
 1771|      0|            }
 1772|       |
 1773|      0|            if (key_len != ED25519_KEY_LEN) {
  ------------------
  |  |   44|      0|#define ED25519_KEY_LEN 32
  ------------------
  |  Branch (1773:17): [True: 0, False: 0]
  ------------------
 1774|      0|                SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1775|      0|                        "Unexpected length of private key %zu. Expected %d.",
 1776|      0|                        key_len,
 1777|      0|                        ED25519_KEY_LEN);
 1778|      0|                goto fail;
 1779|      0|            }
 1780|       |
 1781|      0|            ed25519_privkey = malloc(key_len);
 1782|      0|            if (ed25519_privkey == NULL) {
  ------------------
  |  Branch (1782:17): [True: 0, False: 0]
  ------------------
 1783|      0|                SSH_LOG(SSH_LOG_TRACE, "Out of memory");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1784|      0|                goto fail;
 1785|      0|            }
 1786|       |
 1787|      0|            rc = EVP_PKEY_get_raw_private_key(key->key,
 1788|      0|                                              ed25519_privkey,
 1789|      0|                                              &key_len);
 1790|      0|            if (rc != 1) {
  ------------------
  |  Branch (1790:17): [True: 0, False: 0]
  ------------------
 1791|      0|                SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1792|      0|                        "Failed to get ed25519 raw private key: %s",
 1793|      0|                        ERR_error_string(ERR_get_error(), NULL));
 1794|      0|                goto fail;
 1795|      0|            }
 1796|       |
 1797|      0|            rc = ssh_buffer_pack(buffer,
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1798|      0|                                 "dPP",
 1799|      0|                                 (uint32_t)(2 * ED25519_KEY_LEN),
 1800|      0|                                 (size_t)ED25519_KEY_LEN,
 1801|      0|                                 ed25519_privkey,
 1802|      0|                                 (size_t)ED25519_KEY_LEN,
 1803|      0|                                 ed25519_pubkey);
 1804|      0|            if (rc == SSH_ERROR) {
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1804:17): [True: 0, False: 0]
  ------------------
 1805|      0|                goto fail;
 1806|      0|            }
 1807|      0|            ssh_burn(ed25519_privkey, ED25519_KEY_LEN);
  ------------------
  |  |  390|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
 1808|      0|            SAFE_FREE(ed25519_privkey);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1809|      0|        } else if (type == SSH_KEY_PRIVATE &&
  ------------------
  |  Branch (1809:20): [True: 0, False: 0]
  ------------------
 1810|      0|                   key->type == SSH_KEYTYPE_SK_ED25519) {
  ------------------
  |  Branch (1810:20): [True: 0, False: 0]
  ------------------
 1811|       |
 1812|      0|            rc = pki_buffer_pack_sk_priv_data(buffer, key);
 1813|      0|            if (rc == SSH_ERROR) {
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1813:17): [True: 0, False: 0]
  ------------------
 1814|      0|                goto fail;
 1815|      0|            }
 1816|      0|        } else if (type == SSH_KEY_PUBLIC &&
  ------------------
  |  Branch (1816:20): [True: 0, False: 0]
  ------------------
 1817|      0|                   key->type == SSH_KEYTYPE_SK_ED25519) {
  ------------------
  |  Branch (1817:20): [True: 0, False: 0]
  ------------------
 1818|       |            /* public key can contain certificate sk information */
 1819|      0|            rc = ssh_buffer_add_ssh_string(buffer, key->sk_application);
 1820|      0|            if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1820:17): [True: 0, False: 0]
  ------------------
 1821|      0|                goto fail;
 1822|      0|            }
 1823|      0|        }
 1824|       |
 1825|      0|        SAFE_FREE(ed25519_pubkey);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1826|      0|        break;
 1827|      0|    case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (1827:5): [True: 0, False: 555]
  ------------------
 1828|      0|    case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (1828:5): [True: 0, False: 555]
  ------------------
 1829|      0|    case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (1829:5): [True: 0, False: 555]
  ------------------
 1830|      0|    case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (1830:5): [True: 0, False: 555]
  ------------------
 1831|      0|#ifdef HAVE_OPENSSL_ECC
 1832|      0|    {
 1833|      0|#if OPENSSL_VERSION_NUMBER >= 0x30000000L
 1834|      0|        EC_GROUP *group = NULL;
 1835|      0|        EC_POINT *point = NULL;
 1836|      0|        const void *pubkey = NULL;
 1837|      0|        size_t pubkey_len;
 1838|      0|        OSSL_PARAM *locate_param = NULL;
 1839|       |#else
 1840|       |        const EC_GROUP *group = NULL;
 1841|       |        const EC_POINT *point = NULL;
 1842|       |        const BIGNUM *exp = NULL;
 1843|       |        EC_KEY *ec = NULL;
 1844|       |#endif /* OPENSSL_VERSION_NUMBER */
 1845|       |
 1846|      0|        type_s = ssh_string_from_char(pki_key_ecdsa_nid_to_char(key->ecdsa_nid));
 1847|      0|        if (type_s == NULL) {
  ------------------
  |  Branch (1847:13): [True: 0, False: 0]
  ------------------
 1848|      0|            SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1849|      0|            return NULL;
 1850|      0|        }
 1851|       |
 1852|      0|        rc = ssh_buffer_add_ssh_string(buffer, type_s);
 1853|      0|        SSH_STRING_FREE(type_s);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1854|      0|        if (rc < 0) {
  ------------------
  |  Branch (1854:13): [True: 0, False: 0]
  ------------------
 1855|      0|            SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1856|      0|            return NULL;
 1857|      0|        }
 1858|       |
 1859|       |#if OPENSSL_VERSION_NUMBER < 0x30000000L
 1860|       |        ec = EVP_PKEY_get0_EC_KEY(key->key);
 1861|       |        if (ec == NULL) {
 1862|       |            goto fail;
 1863|       |        }
 1864|       |#ifdef WITH_PKCS11_URI
 1865|       |        if (ssh_key_is_private(key) && !EC_KEY_get0_public_key(ec)) {
 1866|       |            SSH_LOG(SSH_LOG_TRACE,
 1867|       |                    "It is mandatory to have separate"
 1868|       |                    " public ECDSA key objects in the PKCS #11 device."
 1869|       |                    " Unlike RSA, ECDSA public keys cannot be derived"
 1870|       |                    " from their private keys.");
 1871|       |            goto fail;
 1872|       |        }
 1873|       |#endif /* WITH_PKCS11_URI */
 1874|       |        group = EC_KEY_get0_group(ec);
 1875|       |        point = EC_KEY_get0_public_key(ec);
 1876|       |        if (group == NULL || point == NULL) {
 1877|       |            goto fail;
 1878|       |        }
 1879|       |        e = pki_key_make_ecpoint_string(group, point);
 1880|       |#else
 1881|      0|        rc = EVP_PKEY_todata(key->key, EVP_PKEY_PUBLIC_KEY, &params);
 1882|      0|        if (rc < 0) {
  ------------------
  |  Branch (1882:13): [True: 0, False: 0]
  ------------------
 1883|      0|            goto fail;
 1884|      0|        }
 1885|       |
 1886|      0|        locate_param = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_PUB_KEY);
 1887|       |#ifdef WITH_PKCS11_URI
 1888|       |        if (ssh_key_is_private(key) && !locate_param) {
 1889|       |            SSH_LOG(SSH_LOG_TRACE,
 1890|       |                    "It is mandatory to have separate"
 1891|       |                    " public ECDSA key objects in the PKCS #11 device."
 1892|       |                    " Unlike RSA, ECDSA public keys cannot be derived"
 1893|       |                    " from their private keys.");
 1894|       |            goto fail;
 1895|       |        }
 1896|       |#endif /* WITH_PKCS11_URI */
 1897|       |
 1898|      0|        rc = OSSL_PARAM_get_octet_string_ptr(locate_param, &pubkey, &pubkey_len);
 1899|      0|        if (rc != 1) {
  ------------------
  |  Branch (1899:13): [True: 0, False: 0]
  ------------------
 1900|      0|            goto fail;
 1901|      0|        }
 1902|       |        /* Convert the data to low-level representation */
 1903|      0|        group = EC_GROUP_new_by_curve_name_ex(NULL, NULL, key->ecdsa_nid);
 1904|      0|        point = EC_POINT_new(group);
 1905|      0|        rc = EC_POINT_oct2point(group, point, pubkey, pubkey_len, NULL);
 1906|      0|        if (group == NULL || point == NULL || rc != 1) {
  ------------------
  |  Branch (1906:13): [True: 0, False: 0]
  |  Branch (1906:30): [True: 0, False: 0]
  |  Branch (1906:47): [True: 0, False: 0]
  ------------------
 1907|      0|            EC_GROUP_free(group);
 1908|      0|            EC_POINT_free(point);
 1909|      0|            goto fail;
 1910|      0|        }
 1911|       |
 1912|      0|        e = pki_key_make_ecpoint_string(group, point);
 1913|      0|        EC_GROUP_free(group);
 1914|      0|        EC_POINT_free(point);
 1915|      0|#endif /* OPENSSL_VERSION_NUMBER */
 1916|      0|        if (e == NULL) {
  ------------------
  |  Branch (1916:13): [True: 0, False: 0]
  ------------------
 1917|      0|            SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1918|      0|            return NULL;
 1919|      0|        }
 1920|       |
 1921|      0|        rc = ssh_buffer_add_ssh_string(buffer, e);
 1922|      0|        if (rc < 0) {
  ------------------
  |  Branch (1922:13): [True: 0, False: 0]
  ------------------
 1923|      0|            goto fail;
 1924|      0|        }
 1925|       |
 1926|      0|        ssh_string_burn(e);
 1927|      0|        SSH_STRING_FREE(e);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1928|      0|        e = NULL;
 1929|       |
 1930|      0|        if (type == SSH_KEY_PRIVATE && key->type != SSH_KEYTYPE_SK_ECDSA) {
  ------------------
  |  Branch (1930:13): [True: 0, False: 0]
  |  Branch (1930:40): [True: 0, False: 0]
  ------------------
 1931|      0|#if OPENSSL_VERSION_NUMBER >= 0x30000000L
 1932|      0|            OSSL_PARAM_free(params);
 1933|      0|            rc = EVP_PKEY_todata(key->key, EVP_PKEY_KEYPAIR, &params);
 1934|      0|            if (rc < 0) {
  ------------------
  |  Branch (1934:17): [True: 0, False: 0]
  ------------------
 1935|      0|                goto fail;
 1936|      0|            }
 1937|       |
 1938|      0|            locate_param = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_PRIV_KEY);
 1939|      0|            rc = OSSL_PARAM_get_BN(locate_param, &bd);
 1940|      0|            if (rc != 1) {
  ------------------
  |  Branch (1940:17): [True: 0, False: 0]
  ------------------
 1941|      0|                goto fail;
 1942|      0|            }
 1943|      0|            d = ssh_make_bignum_string((BIGNUM *)bd);
 1944|      0|            if (d == NULL) {
  ------------------
  |  Branch (1944:17): [True: 0, False: 0]
  ------------------
 1945|      0|                goto fail;
 1946|      0|            }
 1947|      0|            if (ssh_buffer_add_ssh_string(buffer, d) < 0) {
  ------------------
  |  Branch (1947:17): [True: 0, False: 0]
  ------------------
 1948|      0|                goto fail;
 1949|      0|            }
 1950|       |#else
 1951|       |            exp = EC_KEY_get0_private_key(ec);
 1952|       |            if (exp == NULL) {
 1953|       |                goto fail;
 1954|       |            }
 1955|       |            d = ssh_make_bignum_string((BIGNUM *)exp);
 1956|       |            if (d == NULL) {
 1957|       |                goto fail;
 1958|       |            }
 1959|       |            rc = ssh_buffer_add_ssh_string(buffer, d);
 1960|       |            if (rc < 0) {
 1961|       |                goto fail;
 1962|       |            }
 1963|       |#endif /* OPENSSL_VERSION_NUMBER */
 1964|      0|            ssh_string_burn(d);
 1965|      0|            SSH_STRING_FREE(d);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1966|      0|            d = NULL;
 1967|      0|        } else if (type == SSH_KEY_PRIVATE &&
  ------------------
  |  Branch (1967:20): [True: 0, False: 0]
  ------------------
 1968|      0|                   key->type == SSH_KEYTYPE_SK_ECDSA) {
  ------------------
  |  Branch (1968:20): [True: 0, False: 0]
  ------------------
 1969|       |
 1970|      0|            rc = pki_buffer_pack_sk_priv_data(buffer, key);
 1971|      0|            if (rc == SSH_ERROR) {
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1971:17): [True: 0, False: 0]
  ------------------
 1972|      0|                goto fail;
 1973|      0|            }
 1974|      0|        } else if (type == SSH_KEY_PUBLIC &&
  ------------------
  |  Branch (1974:20): [True: 0, False: 0]
  ------------------
 1975|      0|                   key->type == SSH_KEYTYPE_SK_ECDSA) {
  ------------------
  |  Branch (1975:20): [True: 0, False: 0]
  ------------------
 1976|       |            /* public key can contain certificate sk information */
 1977|      0|            rc = ssh_buffer_add_ssh_string(buffer, key->sk_application);
 1978|      0|            if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1978:17): [True: 0, False: 0]
  ------------------
 1979|      0|                goto fail;
 1980|      0|            }
 1981|      0|        }
 1982|      0|#if OPENSSL_VERSION_NUMBER >= 0x30000000L
 1983|      0|        bignum_safe_free(bd);
  ------------------
  |  |   71|      0|#define bignum_safe_free(num) do { \
  |  |   72|      0|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 0]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1984|      0|        OSSL_PARAM_free(params);
 1985|      0|        params = NULL;
 1986|      0|#endif /* OPENSSL_VERSION_NUMBER */
 1987|      0|        break;
 1988|      0|    }
 1989|      0|#endif /* HAVE_OPENSSL_ECC */
 1990|      0|    case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (1990:5): [True: 0, False: 555]
  ------------------
 1991|      0|    default:
  ------------------
  |  Branch (1991:5): [True: 0, False: 555]
  ------------------
 1992|      0|        goto fail;
 1993|    555|    }
 1994|       |
 1995|    555|makestring:
 1996|    555|    str = ssh_string_new(ssh_buffer_get_len(buffer));
 1997|    555|    if (str == NULL) {
  ------------------
  |  Branch (1997:9): [True: 0, False: 555]
  ------------------
 1998|      0|        goto fail;
 1999|      0|    }
 2000|       |
 2001|    555|    rc = ssh_string_fill(str, ssh_buffer_get(buffer), ssh_buffer_get_len(buffer));
 2002|    555|    if (rc < 0) {
  ------------------
  |  Branch (2002:9): [True: 0, False: 555]
  ------------------
 2003|      0|        goto fail;
 2004|      0|    }
 2005|    555|    SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  924|    555|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 555, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 555]
  |  |  ------------------
  ------------------
 2006|       |
 2007|    555|    return str;
 2008|      0|fail:
 2009|      0|    SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2010|      0|    ssh_string_burn(str);
 2011|      0|    SSH_STRING_FREE(str);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2012|      0|    ssh_string_burn(e);
 2013|      0|    SSH_STRING_FREE(e);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2014|      0|    ssh_string_burn(p);
 2015|      0|    SSH_STRING_FREE(p);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2016|      0|    ssh_string_burn(g);
 2017|      0|    SSH_STRING_FREE(g);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2018|      0|    ssh_string_burn(q);
 2019|      0|    SSH_STRING_FREE(q);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2020|      0|    ssh_string_burn(n);
 2021|      0|    SSH_STRING_FREE(n);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2022|      0|    ssh_string_burn(d);
 2023|      0|    SSH_STRING_FREE(d);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2024|      0|    ssh_string_burn(iqmp);
 2025|      0|    SSH_STRING_FREE(iqmp);
  ------------------
  |  |  882|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 0, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2026|      0|#if OPENSSL_VERSION_NUMBER >= 0x30000000L
 2027|      0|    bignum_safe_free(bp);
  ------------------
  |  |   71|      0|#define bignum_safe_free(num) do { \
  |  |   72|      0|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 0]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2028|      0|    bignum_safe_free(bq);
  ------------------
  |  |   71|      0|#define bignum_safe_free(num) do { \
  |  |   72|      0|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 0]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2029|      0|    bignum_safe_free(bg);
  ------------------
  |  |   71|      0|#define bignum_safe_free(num) do { \
  |  |   72|      0|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 0]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2030|      0|    bignum_safe_free(bpub_key);
  ------------------
  |  |   71|      0|#define bignum_safe_free(num) do { \
  |  |   72|      0|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 0]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2031|      0|    bignum_safe_free(bn);
  ------------------
  |  |   71|      0|#define bignum_safe_free(num) do { \
  |  |   72|      0|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 0]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2032|      0|    bignum_safe_free(be);
  ------------------
  |  |   71|      0|#define bignum_safe_free(num) do { \
  |  |   72|      0|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 0]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2033|      0|    bignum_safe_free(bd);
  ------------------
  |  |   71|      0|#define bignum_safe_free(num) do { \
  |  |   72|      0|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 0]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2034|      0|    bignum_safe_free(biqmp);
  ------------------
  |  |   71|      0|#define bignum_safe_free(num) do { \
  |  |   72|      0|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 0]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2035|      0|    OSSL_PARAM_free(params);
 2036|      0|#endif /* OPENSSL_VERSION_NUMBER */
 2037|      0|    free(ed25519_pubkey);
 2038|      0|    if (ed25519_privkey) {
  ------------------
  |  Branch (2038:9): [True: 0, False: 0]
  ------------------
 2039|      0|        ssh_burn(ed25519_privkey, ED25519_KEY_LEN);
  ------------------
  |  |  390|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
 2040|      0|        free(ed25519_privkey);
 2041|      0|    }
 2042|       |
 2043|       |    return NULL;
 2044|    555|}
pki_signature_to_blob:
 2134|    185|{
 2135|    185|    ssh_string sig_blob = NULL;
 2136|       |
 2137|    185|    switch(sig->type) {
 2138|    185|        case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (2138:9): [True: 185, False: 0]
  ------------------
 2139|    185|        case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (2139:9): [True: 0, False: 185]
  ------------------
 2140|    185|            sig_blob = ssh_string_copy(sig->raw_sig);
 2141|    185|            break;
 2142|      0|        case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (2142:9): [True: 0, False: 185]
  ------------------
 2143|      0|            sig_blob = pki_ed25519_signature_to_blob(sig);
 2144|      0|            break;
 2145|      0|        case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (2145:9): [True: 0, False: 185]
  ------------------
 2146|      0|        case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (2146:9): [True: 0, False: 185]
  ------------------
 2147|      0|        case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (2147:9): [True: 0, False: 185]
  ------------------
 2148|      0|#ifdef HAVE_OPENSSL_ECC
 2149|      0|            sig_blob = pki_ecdsa_signature_to_blob(sig);
 2150|      0|            break;
 2151|      0|#endif /* HAVE_OPENSSL_ECC */
 2152|      0|        case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (2152:9): [True: 0, False: 185]
  ------------------
 2153|      0|        case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (2153:9): [True: 0, False: 185]
  ------------------
 2154|       |            /* For SK keys, signature data is already in raw_sig */
 2155|      0|            sig_blob = ssh_string_copy(sig->raw_sig);
 2156|      0|            break;
 2157|      0|        default:
  ------------------
  |  Branch (2157:9): [True: 0, False: 185]
  ------------------
 2158|      0|        case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (2158:9): [True: 0, False: 185]
  ------------------
 2159|      0|            SSH_LOG(SSH_LOG_TRACE, "Unknown signature key type: %s", sig->type_c);
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2160|      0|            return NULL;
 2161|    185|    }
 2162|       |
 2163|    185|    return sig_blob;
 2164|    185|}
pki_sign_data:
 2547|    185|{
 2548|    185|    const EVP_MD *md = NULL;
 2549|    185|    EVP_MD_CTX *ctx = NULL;
 2550|    185|    EVP_PKEY *pkey = NULL;
 2551|       |
 2552|    185|    unsigned char *raw_sig_data = NULL;
 2553|    185|    size_t raw_sig_len;
 2554|       |
 2555|    185|    ssh_signature sig = NULL;
 2556|       |
 2557|    185|    int rc;
 2558|       |
 2559|    185|    if (privkey == NULL || !ssh_key_is_private(privkey) || input == NULL) {
  ------------------
  |  Branch (2559:9): [True: 0, False: 185]
  |  Branch (2559:28): [True: 0, False: 185]
  |  Branch (2559:60): [True: 0, False: 185]
  ------------------
 2560|      0|        SSH_LOG(SSH_LOG_TRACE, "Bad parameter provided to "
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2561|      0|                               "pki_sign_data()");
 2562|      0|        return NULL;
 2563|      0|    }
 2564|       |
 2565|       |    /* Check if public key and hash type are compatible */
 2566|    185|    rc = pki_key_check_hash_compatible(privkey, hash_type);
 2567|    185|    if (rc != SSH_OK) {
  ------------------
  |  |  315|    185|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2567:9): [True: 0, False: 185]
  ------------------
 2568|      0|        return NULL;
 2569|      0|    }
 2570|       |
 2571|       |    /* Set hash algorithm to be used */
 2572|    185|    md = pki_digest_to_md(hash_type);
 2573|    185|    if (md == NULL) {
  ------------------
  |  Branch (2573:9): [True: 0, False: 185]
  ------------------
 2574|      0|        if (hash_type != SSH_DIGEST_AUTO) {
  ------------------
  |  Branch (2574:13): [True: 0, False: 0]
  ------------------
 2575|      0|            return NULL;
 2576|      0|        }
 2577|      0|    }
 2578|       |
 2579|       |    /* Setup private key EVP_PKEY */
 2580|    185|    pkey = pki_key_to_pkey(privkey);
 2581|    185|    if (pkey == NULL) {
  ------------------
  |  Branch (2581:9): [True: 0, False: 185]
  ------------------
 2582|      0|        return NULL;
 2583|      0|    }
 2584|       |
 2585|       |    /* Allocate buffer for signature */
 2586|    185|    raw_sig_len = (size_t)EVP_PKEY_size(pkey);
 2587|    185|    raw_sig_data = (unsigned char *)malloc(raw_sig_len);
 2588|    185|    if (raw_sig_data == NULL) {
  ------------------
  |  Branch (2588:9): [True: 0, False: 185]
  ------------------
 2589|      0|        SSH_LOG(SSH_LOG_TRACE, "Out of memory");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2590|      0|        goto out;
 2591|      0|    }
 2592|       |
 2593|       |    /* Create the context */
 2594|    185|    ctx = EVP_MD_CTX_new();
 2595|    185|    if (ctx == NULL) {
  ------------------
  |  Branch (2595:9): [True: 0, False: 185]
  ------------------
 2596|      0|        SSH_LOG(SSH_LOG_TRACE, "Out of memory");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2597|      0|        goto out;
 2598|      0|    }
 2599|       |
 2600|       |    /* Sign the data */
 2601|    185|    rc = EVP_DigestSignInit(ctx, NULL, md, NULL, pkey);
 2602|    185|    if (rc != 1){
  ------------------
  |  Branch (2602:9): [True: 0, False: 185]
  ------------------
 2603|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2604|      0|                "EVP_DigestSignInit() failed: %s",
 2605|      0|                ERR_error_string(ERR_get_error(), NULL));
 2606|      0|        goto out;
 2607|      0|    }
 2608|       |
 2609|    185|    rc = EVP_DigestSign(ctx, raw_sig_data, &raw_sig_len, input, input_len);
 2610|    185|    if (rc != 1) {
  ------------------
  |  Branch (2610:9): [True: 0, False: 185]
  ------------------
 2611|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2612|      0|                "EVP_DigestSign() failed: %s",
 2613|      0|                ERR_error_string(ERR_get_error(), NULL));
 2614|      0|        goto out;
 2615|      0|    }
 2616|       |
 2617|       |#ifdef DEBUG_CRYPTO
 2618|       |        ssh_log_hexdump("Generated signature", raw_sig_data, raw_sig_len);
 2619|       |#endif
 2620|       |
 2621|       |    /* Allocate and fill output signature */
 2622|    185|    sig = ssh_signature_new();
 2623|    185|    if (sig == NULL) {
  ------------------
  |  Branch (2623:9): [True: 0, False: 185]
  ------------------
 2624|      0|        goto out;
 2625|      0|    }
 2626|       |
 2627|    185|    sig->raw_sig = ssh_string_new(raw_sig_len);
 2628|    185|    if (sig->raw_sig == NULL) {
  ------------------
  |  Branch (2628:9): [True: 0, False: 185]
  ------------------
 2629|      0|        ssh_signature_free(sig);
 2630|      0|        sig = NULL;
 2631|      0|        goto out;
 2632|      0|    }
 2633|       |
 2634|    185|    rc = ssh_string_fill(sig->raw_sig, raw_sig_data, raw_sig_len);
 2635|    185|    if (rc < 0) {
  ------------------
  |  Branch (2635:9): [True: 0, False: 185]
  ------------------
 2636|      0|        ssh_signature_free(sig);
 2637|      0|        sig = NULL;
 2638|      0|        goto out;
 2639|      0|    }
 2640|       |
 2641|    185|    sig->type = privkey->type;
 2642|    185|    sig->hash_type = hash_type;
 2643|    185|    sig->type_c = ssh_key_signature_to_char(privkey->type, hash_type);
 2644|       |
 2645|    185|out:
 2646|    185|    if (ctx != NULL) {
  ------------------
  |  Branch (2646:9): [True: 185, False: 0]
  ------------------
 2647|    185|        EVP_MD_CTX_free(ctx);
 2648|    185|    }
 2649|    185|    if (raw_sig_data != NULL) {
  ------------------
  |  Branch (2649:9): [True: 185, False: 0]
  ------------------
 2650|    185|        ssh_burn(raw_sig_data, raw_sig_len);
  ------------------
  |  |  390|    185|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
 2651|    185|    }
 2652|       |    SAFE_FREE(raw_sig_data);
  ------------------
  |  |  375|    185|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 185, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 185]
  |  |  ------------------
  ------------------
 2653|    185|    EVP_PKEY_free(pkey);
 2654|    185|    return sig;
 2655|    185|}
ssh_key_size:
 2760|    504|{
 2761|    504|    int bits = 0;
 2762|    504|    EVP_PKEY *pkey = NULL;
 2763|       |
 2764|    504|    switch (key->type) {
 2765|    504|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (2765:5): [True: 504, False: 0]
  ------------------
 2766|    504|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (2766:5): [True: 0, False: 504]
  ------------------
 2767|    504|    case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (2767:5): [True: 0, False: 504]
  ------------------
 2768|    504|    case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (2768:5): [True: 0, False: 504]
  ------------------
 2769|    504|    case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (2769:5): [True: 0, False: 504]
  ------------------
 2770|    504|    case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (2770:5): [True: 0, False: 504]
  ------------------
 2771|    504|    case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (2771:5): [True: 0, False: 504]
  ------------------
 2772|    504|    case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (2772:5): [True: 0, False: 504]
  ------------------
 2773|    504|    case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (2773:5): [True: 0, False: 504]
  ------------------
 2774|    504|    case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (2774:5): [True: 0, False: 504]
  ------------------
 2775|    504|    case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (2775:5): [True: 0, False: 504]
  ------------------
 2776|    504|        pkey = pki_key_to_pkey(key);
 2777|    504|        if (pkey == NULL) {
  ------------------
  |  Branch (2777:13): [True: 0, False: 504]
  ------------------
 2778|      0|            return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2779|      0|        }
 2780|    504|        bits = EVP_PKEY_bits(pkey);
 2781|    504|        EVP_PKEY_free(pkey);
 2782|    504|        return bits;
 2783|      0|    case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (2783:5): [True: 0, False: 504]
  ------------------
 2784|      0|    case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (2784:5): [True: 0, False: 504]
  ------------------
 2785|      0|    case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (2785:5): [True: 0, False: 504]
  ------------------
 2786|      0|    case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (2786:5): [True: 0, False: 504]
  ------------------
 2787|       |        /* ed25519 keys have fixed size */
 2788|      0|        return 255;
 2789|      0|    case SSH_KEYTYPE_DSS:   /* deprecated */
  ------------------
  |  Branch (2789:5): [True: 0, False: 504]
  ------------------
 2790|      0|    case SSH_KEYTYPE_DSS_CERT01:    /* deprecated */
  ------------------
  |  Branch (2790:5): [True: 0, False: 504]
  ------------------
 2791|      0|    case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (2791:5): [True: 0, False: 504]
  ------------------
 2792|      0|    default:
  ------------------
  |  Branch (2792:5): [True: 0, False: 504]
  ------------------
 2793|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2794|    504|    }
 2795|    504|}
pki_crypto.c:pki_digest_to_md:
 2456|    185|{
 2457|    185|    const EVP_MD *md = NULL;
 2458|       |
 2459|    185|    switch (hash_type) {
 2460|    172|    case SSH_DIGEST_SHA256:
  ------------------
  |  Branch (2460:5): [True: 172, False: 13]
  ------------------
 2461|    172|        md = EVP_sha256();
 2462|    172|        break;
 2463|      0|    case SSH_DIGEST_SHA384:
  ------------------
  |  Branch (2463:5): [True: 0, False: 185]
  ------------------
 2464|      0|        md = EVP_sha384();
 2465|      0|        break;
 2466|     13|    case SSH_DIGEST_SHA512:
  ------------------
  |  Branch (2466:5): [True: 13, False: 172]
  ------------------
 2467|     13|        md = EVP_sha512();
 2468|     13|        break;
 2469|      0|    case SSH_DIGEST_SHA1:
  ------------------
  |  Branch (2469:5): [True: 0, False: 185]
  ------------------
 2470|      0|        md = EVP_sha1();
 2471|      0|        break;
 2472|      0|    case SSH_DIGEST_AUTO:
  ------------------
  |  Branch (2472:5): [True: 0, False: 185]
  ------------------
 2473|      0|        md = NULL;
 2474|      0|        break;
 2475|      0|    default:
  ------------------
  |  Branch (2475:5): [True: 0, False: 185]
  ------------------
 2476|      0|        SSH_LOG(SSH_LOG_TRACE, "Unknown hash algorithm for type: %d",
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2477|      0|                hash_type);
 2478|      0|        return NULL;
 2479|    185|    }
 2480|       |
 2481|    185|    return md;
 2482|    185|}
pki_crypto.c:pki_key_to_pkey:
 2485|    689|{
 2486|    689|    EVP_PKEY *pkey = NULL;
 2487|    689|    int rc = 0;
 2488|       |
 2489|    689|    switch (key->type) {
 2490|    689|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (2490:5): [True: 689, False: 0]
  ------------------
 2491|    689|    case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (2491:5): [True: 0, False: 689]
  ------------------
 2492|    689|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (2492:5): [True: 0, False: 689]
  ------------------
 2493|    689|    case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (2493:5): [True: 0, False: 689]
  ------------------
 2494|    689|    case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (2494:5): [True: 0, False: 689]
  ------------------
 2495|    689|    case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (2495:5): [True: 0, False: 689]
  ------------------
 2496|    689|    case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (2496:5): [True: 0, False: 689]
  ------------------
 2497|    689|    case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (2497:5): [True: 0, False: 689]
  ------------------
 2498|    689|    case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (2498:5): [True: 0, False: 689]
  ------------------
 2499|    689|    case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (2499:5): [True: 0, False: 689]
  ------------------
 2500|    689|    case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (2500:5): [True: 0, False: 689]
  ------------------
 2501|    689|    case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (2501:5): [True: 0, False: 689]
  ------------------
 2502|    689|    case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (2502:5): [True: 0, False: 689]
  ------------------
 2503|    689|    case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (2503:5): [True: 0, False: 689]
  ------------------
 2504|    689|    case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (2504:5): [True: 0, False: 689]
  ------------------
 2505|    689|        if (key->key == NULL) {
  ------------------
  |  Branch (2505:13): [True: 0, False: 689]
  ------------------
 2506|      0|            SSH_LOG(SSH_LOG_TRACE, "NULL key->key");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2507|      0|            goto error;
 2508|      0|        }
 2509|    689|        rc = EVP_PKEY_up_ref(key->key);
 2510|    689|        if (rc != 1) {
  ------------------
  |  Branch (2510:13): [True: 0, False: 689]
  ------------------
 2511|      0|            SSH_LOG(SSH_LOG_TRACE, "Failed to reference EVP_PKEY");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2512|      0|            return NULL;
 2513|      0|        }
 2514|    689|        pkey = key->key;
 2515|    689|        break;
 2516|      0|    case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (2516:5): [True: 0, False: 689]
  ------------------
 2517|      0|    default:
  ------------------
  |  Branch (2517:5): [True: 0, False: 689]
  ------------------
 2518|      0|        SSH_LOG(SSH_LOG_TRACE, "Unknown private key algorithm for type: %d",
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2519|      0|                key->type);
 2520|      0|        goto error;
 2521|    689|    }
 2522|       |
 2523|    689|    return pkey;
 2524|       |
 2525|      0|error:
 2526|      0|    EVP_PKEY_free(pkey);
 2527|       |    return NULL;
 2528|    689|}

ssh_poll_init:
   91|      2|{
   92|      2|    return;
   93|      2|}
ssh_poll:
  115|  1.66k|{
  116|  1.66k|    return poll((struct pollfd *)fds, nfds, timeout);
  117|  1.66k|}
ssh_poll_new:
  396|    319|{
  397|    319|    ssh_poll_handle p = NULL;
  398|       |
  399|    319|    p = malloc(sizeof(struct ssh_poll_handle_struct));
  400|    319|    if (p == NULL) {
  ------------------
  |  Branch (400:9): [True: 0, False: 319]
  ------------------
  401|      0|        return NULL;
  402|      0|    }
  403|    319|    ZERO_STRUCTP(p);
  ------------------
  |  |  381|    319|#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((x), 0, sizeof(*(x))); } while(0)
  |  |  ------------------
  |  |  |  Branch (381:34): [True: 319, False: 0]
  |  |  |  Branch (381:85): [Folded, False: 319]
  |  |  ------------------
  ------------------
  404|       |
  405|    319|    p->x.fd = fd;
  406|    319|    p->events = events;
  407|    319|    p->cb = cb;
  408|    319|    p->cb_data = userdata;
  409|       |
  410|    319|    return p;
  411|    319|}
ssh_poll_free:
  420|    319|{
  421|    319|    if (p->ctx != NULL) {
  ------------------
  |  Branch (421:9): [True: 319, False: 0]
  ------------------
  422|    319|        ssh_poll_ctx_remove(p->ctx, p);
  423|    319|        p->ctx = NULL;
  424|    319|    }
  425|       |    SAFE_FREE(p);
  ------------------
  |  |  375|    319|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 319, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 319]
  |  |  ------------------
  ------------------
  426|    319|}
ssh_poll_get_ctx:
  436|    837|{
  437|    837|    return p->ctx;
  438|    837|}
ssh_poll_get_events:
  448|  17.0k|{
  449|  17.0k|    return p->events;
  450|  17.0k|}
ssh_poll_set_events:
  461|  17.7k|{
  462|  17.7k|    p->events = events;
  463|  17.7k|    if (p->ctx != NULL) {
  ------------------
  |  Branch (463:9): [True: 16.4k, False: 1.27k]
  ------------------
  464|  16.4k|        if (!ssh_poll_is_locked(p)) {
  ------------------
  |  Branch (464:13): [True: 679, False: 15.7k]
  ------------------
  465|    679|            p->ctx->pollfds[p->x.idx].events = events;
  466|  15.7k|        } else if (!(p->ctx->pollfds[p->x.idx].events & POLLOUT)) {
  ------------------
  |  Branch (466:20): [True: 847, False: 14.9k]
  ------------------
  467|       |            /* if locked, allow only setting POLLOUT to prevent recursive
  468|       |             * callbacks */
  469|       |            p->ctx->pollfds[p->x.idx].events = events & POLLOUT;
  470|    847|        }
  471|  16.4k|    }
  472|  17.7k|}
ssh_poll_add_events:
  498|  16.9k|{
  499|  16.9k|    ssh_poll_set_events(p, ssh_poll_get_events(p) | events);
  500|  16.9k|}
ssh_poll_remove_events:
  510|    114|{
  511|    114|    ssh_poll_set_events(p, ssh_poll_get_events(p) & ~events);
  512|    114|}
ssh_poll_ctx_new:
  560|    638|{
  561|    638|    ssh_poll_ctx ctx;
  562|       |
  563|    638|    ctx = malloc(sizeof(struct ssh_poll_ctx_struct));
  564|    638|    if (ctx == NULL) {
  ------------------
  |  Branch (564:9): [True: 0, False: 638]
  ------------------
  565|      0|        return NULL;
  566|      0|    }
  567|    638|    ZERO_STRUCTP(ctx);
  ------------------
  |  |  381|    638|#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((x), 0, sizeof(*(x))); } while(0)
  |  |  ------------------
  |  |  |  Branch (381:34): [True: 638, False: 0]
  |  |  |  Branch (381:85): [Folded, False: 638]
  |  |  ------------------
  ------------------
  568|       |
  569|    638|    if (chunk_size == 0) {
  ------------------
  |  Branch (569:9): [True: 0, False: 638]
  ------------------
  570|      0|        chunk_size = SSH_POLL_CTX_CHUNK;
  ------------------
  |  |   43|      0|#define SSH_POLL_CTX_CHUNK			5
  ------------------
  571|      0|    }
  572|       |
  573|    638|    ctx->chunk_size = chunk_size;
  574|       |
  575|    638|    return ctx;
  576|    638|}
ssh_poll_ctx_free:
  584|    638|{
  585|    638|    if (ctx->polls_allocated > 0) {
  ------------------
  |  Branch (585:9): [True: 396, False: 242]
  ------------------
  586|    396|        while (ctx->polls_used > 0) {
  ------------------
  |  Branch (586:16): [True: 0, False: 396]
  ------------------
  587|      0|            ssh_poll_handle p = ctx->pollptrs[0];
  588|       |            /*
  589|       |             * The free function calls ssh_poll_ctx_remove() and decrements
  590|       |             * ctx->polls_used
  591|       |             */
  592|      0|            ssh_poll_free(p);
  593|      0|        }
  594|       |
  595|    396|        SAFE_FREE(ctx->pollptrs);
  ------------------
  |  |  375|    396|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 396, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 396]
  |  |  ------------------
  ------------------
  596|    396|        SAFE_FREE(ctx->pollfds);
  ------------------
  |  |  375|    396|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 396, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 396]
  |  |  ------------------
  ------------------
  597|    396|    }
  598|       |
  599|       |    SAFE_FREE(ctx);
  ------------------
  |  |  375|    638|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 638, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 638]
  |  |  ------------------
  ------------------
  600|    638|}
ssh_poll_ctx_add:
  647|    473|{
  648|    473|    socket_t fd;
  649|       |
  650|    473|    if (p->ctx != NULL) {
  ------------------
  |  Branch (650:9): [True: 0, False: 473]
  ------------------
  651|       |        /* already attached to a context */
  652|      0|        return -1;
  653|      0|    }
  654|       |
  655|    473|    if (ctx->polls_used == ctx->polls_allocated &&
  ------------------
  |  Branch (655:9): [True: 396, False: 77]
  ------------------
  656|    396|        ssh_poll_ctx_resize(ctx, ctx->polls_allocated + ctx->chunk_size) < 0) {
  ------------------
  |  Branch (656:9): [True: 0, False: 396]
  ------------------
  657|      0|        return -1;
  658|      0|    }
  659|       |
  660|    473|    fd = p->x.fd;
  661|    473|    p->x.idx = ctx->polls_used++;
  662|    473|    ctx->pollptrs[p->x.idx] = p;
  663|    473|    ctx->pollfds[p->x.idx].fd = fd;
  664|    473|    ctx->pollfds[p->x.idx].events = p->events;
  665|    473|    ctx->pollfds[p->x.idx].revents = 0;
  666|    473|    p->ctx = ctx;
  667|       |
  668|    473|    return 0;
  669|    473|}
ssh_poll_ctx_remove:
  697|    473|{
  698|    473|    size_t i;
  699|       |
  700|    473|    i = p->x.idx;
  701|    473|    p->x.fd = ctx->pollfds[i].fd;
  702|    473|    p->ctx = NULL;
  703|       |
  704|    473|    ctx->polls_used--;
  705|       |
  706|       |    /* fill the empty poll slot with the last one */
  707|    473|    if (ctx->polls_used > 0 && ctx->polls_used != i) {
  ------------------
  |  Branch (707:9): [True: 0, False: 473]
  |  Branch (707:32): [True: 0, False: 0]
  ------------------
  708|      0|        ctx->pollfds[i] = ctx->pollfds[ctx->polls_used];
  709|      0|        ctx->pollptrs[i] = ctx->pollptrs[ctx->polls_used];
  710|      0|        ctx->pollptrs[i]->x.idx = i;
  711|      0|    }
  712|       |
  713|       |    /* this will always leave at least chunk_size polls allocated */
  714|    473|    if (ctx->polls_allocated - ctx->polls_used > ctx->chunk_size) {
  ------------------
  |  Branch (714:9): [True: 0, False: 473]
  ------------------
  715|      0|        ssh_poll_ctx_resize(ctx, ctx->polls_allocated - ctx->chunk_size);
  716|      0|    }
  717|    473|}
ssh_poll_is_locked:
  726|  18.4k|{
  727|  18.4k|    if (p == NULL) {
  ------------------
  |  Branch (727:9): [True: 0, False: 18.4k]
  ------------------
  728|      0|        return false;
  729|      0|    }
  730|  18.4k|    return p->lock_cnt > 0;
  731|  18.4k|}
ssh_poll_ctx_dopoll:
  750|  1.66k|{
  751|  1.66k|    int rc;
  752|  1.66k|    size_t i, used;
  753|  1.66k|    ssh_poll_handle p = NULL;
  754|  1.66k|    socket_t fd;
  755|  1.66k|    int revents;
  756|  1.66k|    struct ssh_timestamp ts;
  757|       |
  758|  1.66k|    if (ctx->polls_used == 0) {
  ------------------
  |  Branch (758:9): [True: 0, False: 1.66k]
  ------------------
  759|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  760|      0|    }
  761|       |
  762|       |    /* Allow only POLLOUT events on locked sockets as that means we are called
  763|       |     * recursively and we only want process the POLLOUT events here to flush
  764|       |     * output buffer */
  765|  3.32k|    for (i = 0; i < ctx->polls_used; i++) {
  ------------------
  |  Branch (765:17): [True: 1.66k, False: 1.66k]
  ------------------
  766|       |        /* The lock allows only POLLOUT events: drop the rest */
  767|  1.66k|        if (ssh_poll_is_locked(ctx->pollptrs[i])) {
  ------------------
  |  Branch (767:13): [True: 0, False: 1.66k]
  ------------------
  768|      0|            ctx->pollfds[i].events &= POLLOUT;
  769|      0|        }
  770|  1.66k|    }
  771|  1.66k|    ssh_timestamp_init(&ts);
  772|  1.66k|    do {
  773|  1.66k|        int tm = ssh_timeout_update(&ts, timeout);
  774|  1.66k|        rc = ssh_poll(ctx->pollfds, ctx->polls_used, tm);
  775|  1.66k|    } while (rc == -1 && errno == EINTR);
  ------------------
  |  Branch (775:14): [True: 0, False: 1.66k]
  |  Branch (775:26): [True: 0, False: 0]
  ------------------
  776|       |
  777|  1.66k|    if (rc < 0) {
  ------------------
  |  Branch (777:9): [True: 0, False: 1.66k]
  ------------------
  778|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  779|      0|    }
  780|  1.66k|    if (rc == 0) {
  ------------------
  |  Branch (780:9): [True: 0, False: 1.66k]
  ------------------
  781|      0|        return SSH_AGAIN;
  ------------------
  |  |  317|      0|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  782|      0|    }
  783|       |
  784|  1.66k|    used = ctx->polls_used;
  785|  3.20k|    for (i = 0; i < used && rc > 0; ) {
  ------------------
  |  Branch (785:17): [True: 1.66k, False: 1.54k]
  |  Branch (785:29): [True: 1.66k, False: 0]
  ------------------
  786|  1.66k|        revents = ctx->pollfds[i].revents;
  787|       |        /* Do not pass any other events except for POLLOUT to callback when
  788|       |         * called recursively more than 2 times. On s390x the poll will be
  789|       |         * spammed with POLLHUP events causing infinite recursion when the user
  790|       |         * callback issues some write/flush/poll calls. */
  791|  1.66k|        if (ctx->pollptrs[i]->lock_cnt > 2) {
  ------------------
  |  Branch (791:13): [True: 0, False: 1.66k]
  ------------------
  792|      0|            revents &= POLLOUT;
  793|      0|        }
  794|  1.66k|        if (revents == 0) {
  ------------------
  |  Branch (794:13): [True: 0, False: 1.66k]
  ------------------
  795|      0|            i++;
  796|  1.66k|        } else {
  797|  1.66k|            int ret;
  798|       |
  799|  1.66k|            p = ctx->pollptrs[i];
  800|  1.66k|            fd = ctx->pollfds[i].fd;
  801|       |            /* avoid having any event caught during callback */
  802|  1.66k|            ctx->pollfds[i].events = 0;
  803|  1.66k|            p->lock_cnt++;
  804|  1.66k|            if (p->cb && (ret = p->cb(p, fd, revents, p->cb_data)) < 0) {
  ------------------
  |  Branch (804:17): [True: 1.66k, False: 0]
  |  Branch (804:26): [True: 114, False: 1.54k]
  ------------------
  805|    114|                if (ret == -2) {
  ------------------
  |  Branch (805:21): [True: 114, False: 0]
  ------------------
  806|    114|                    return -1;
  807|    114|                }
  808|       |                /* the poll was removed, reload the used counter and start again
  809|       |                 */
  810|      0|                used = ctx->polls_used;
  811|      0|                i = 0;
  812|  1.54k|            } else {
  813|  1.54k|                ctx->pollfds[i].revents = 0;
  814|  1.54k|                ctx->pollfds[i].events = p->events;
  815|  1.54k|                p->lock_cnt--;
  816|  1.54k|                i++;
  817|  1.54k|            }
  818|       |
  819|  1.54k|            rc--;
  820|  1.54k|        }
  821|  1.66k|    }
  822|       |
  823|  1.54k|    return rc;
  824|  1.66k|}
ssh_poll_get_default_ctx:
  834|    319|{
  835|    319|    if (session->default_poll_ctx != NULL) {
  ------------------
  |  Branch (835:9): [True: 0, False: 319]
  ------------------
  836|      0|        return session->default_poll_ctx;
  837|      0|    }
  838|       |    /* 2 is enough for the default one */
  839|    319|    session->default_poll_ctx = ssh_poll_ctx_new(2);
  840|    319|    return session->default_poll_ctx;
  841|    319|}
ssh_event_new:
  866|    319|{
  867|    319|    ssh_event event;
  868|       |
  869|    319|    event = malloc(sizeof(struct ssh_event_struct));
  870|    319|    if (event == NULL) {
  ------------------
  |  Branch (870:9): [True: 0, False: 319]
  ------------------
  871|      0|        return NULL;
  872|      0|    }
  873|    319|    ZERO_STRUCTP(event);
  ------------------
  |  |  381|    319|#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((x), 0, sizeof(*(x))); } while(0)
  |  |  ------------------
  |  |  |  Branch (381:34): [True: 319, False: 0]
  |  |  |  Branch (381:85): [Folded, False: 319]
  |  |  ------------------
  ------------------
  874|       |
  875|    319|    event->ctx = ssh_poll_ctx_new(2);
  876|    319|    if (event->ctx == NULL) {
  ------------------
  |  Branch (876:9): [True: 0, False: 319]
  ------------------
  877|      0|        free(event);
  878|      0|        return NULL;
  879|      0|    }
  880|       |
  881|    319|#ifdef WITH_SERVER
  882|    319|    event->sessions = ssh_list_new();
  883|    319|    if (event->sessions == NULL) {
  ------------------
  |  Branch (883:9): [True: 0, False: 319]
  ------------------
  884|      0|        ssh_poll_ctx_free(event->ctx);
  885|      0|        free(event);
  886|      0|        return NULL;
  887|      0|    }
  888|    319|#endif
  889|       |
  890|    319|    return event;
  891|    319|}
ssh_event_add_session:
 1000|     77|{
 1001|     77|    ssh_poll_handle p = NULL;
 1002|     77|#ifdef WITH_SERVER
 1003|     77|    struct ssh_iterator *iterator = NULL;
 1004|     77|#endif
 1005|     77|    int rc;
 1006|       |
 1007|     77|    if (event == NULL || event->ctx == NULL || session == NULL) {
  ------------------
  |  Branch (1007:9): [True: 0, False: 77]
  |  Branch (1007:26): [True: 0, False: 77]
  |  Branch (1007:48): [True: 0, False: 77]
  ------------------
 1008|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1009|      0|    }
 1010|     77|    if (session->default_poll_ctx == NULL) {
  ------------------
  |  Branch (1010:9): [True: 0, False: 77]
  ------------------
 1011|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1012|      0|    }
 1013|    154|    while (session->default_poll_ctx->polls_used > 0) {
  ------------------
  |  Branch (1013:12): [True: 77, False: 77]
  ------------------
 1014|     77|        p = session->default_poll_ctx->pollptrs[0];
 1015|       |        /*
 1016|       |         * ssh_poll_ctx_remove() decrements
 1017|       |         * session->default_poll_ctx->polls_used
 1018|       |         */
 1019|     77|        ssh_poll_ctx_remove(session->default_poll_ctx, p);
 1020|     77|        rc = ssh_poll_ctx_add(event->ctx, p);
 1021|     77|        if (rc != SSH_OK) {
  ------------------
  |  |  315|     77|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1021:13): [True: 0, False: 77]
  ------------------
 1022|      0|            return rc;
 1023|      0|        }
 1024|       |        /* associate the pollhandler with a session so we can put it back
 1025|       |         * at ssh_event_free()
 1026|       |         */
 1027|     77|        p->session = session;
 1028|     77|    }
 1029|     77|#ifdef WITH_SERVER
 1030|     77|    iterator = ssh_list_get_iterator(event->sessions);
 1031|     77|    while (iterator != NULL) {
  ------------------
  |  Branch (1031:12): [True: 0, False: 77]
  ------------------
 1032|      0|        if (ssh_iterator_value(ssh_session, iterator) == session) {
  ------------------
  |  |  122|      0|  ((type)((iterator)->data))
  ------------------
  |  Branch (1032:13): [True: 0, False: 0]
  ------------------
 1033|       |            /* allow only one instance of this session */
 1034|      0|            return SSH_OK;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
 1035|      0|        }
 1036|      0|        iterator = iterator->next;
 1037|      0|    }
 1038|     77|    if (ssh_list_append(event->sessions, session) == SSH_ERROR) {
  ------------------
  |  |  316|     77|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1038:9): [True: 0, False: 77]
  ------------------
 1039|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1040|      0|    }
 1041|     77|#endif
 1042|     77|    return SSH_OK;
  ------------------
  |  |  315|     77|#define SSH_OK 0     /* No error */
  ------------------
 1043|     77|}
ssh_event_dopoll:
 1082|    824|{
 1083|    824|    int rc;
 1084|       |
 1085|    824|    if (event == NULL || event->ctx == NULL) {
  ------------------
  |  Branch (1085:9): [True: 0, False: 824]
  |  Branch (1085:26): [True: 0, False: 824]
  ------------------
 1086|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1087|      0|    }
 1088|    824|    rc = ssh_poll_ctx_dopoll(event->ctx, timeout);
 1089|    824|    return rc;
 1090|    824|}
ssh_event_free:
 1220|  1.29k|{
 1221|  1.29k|    size_t used, i;
 1222|  1.29k|    ssh_poll_handle p = NULL;
 1223|       |
 1224|  1.29k|    if (event == NULL) {
  ------------------
  |  Branch (1224:9): [True: 980, False: 319]
  ------------------
 1225|    980|        return;
 1226|    980|    }
 1227|       |
 1228|    319|    if (event->ctx != NULL) {
  ------------------
  |  Branch (1228:9): [True: 319, False: 0]
  ------------------
 1229|    319|        used = event->ctx->polls_used;
 1230|    396|        for (i = 0; i < used; i++) {
  ------------------
  |  Branch (1230:21): [True: 77, False: 319]
  ------------------
 1231|     77|            p = event->ctx->pollptrs[i];
 1232|     77|            if (p->session != NULL) {
  ------------------
  |  Branch (1232:17): [True: 77, False: 0]
  ------------------
 1233|     77|                ssh_poll_ctx_remove(event->ctx, p);
 1234|     77|                ssh_poll_ctx_add(p->session->default_poll_ctx, p);
 1235|     77|                p->session = NULL;
 1236|     77|                used = 0;
 1237|     77|            }
 1238|     77|        }
 1239|       |
 1240|    319|        ssh_poll_ctx_free(event->ctx);
 1241|    319|    }
 1242|    319|#ifdef WITH_SERVER
 1243|    319|    if (event->sessions != NULL) {
  ------------------
  |  Branch (1243:9): [True: 319, False: 0]
  ------------------
 1244|    319|        ssh_list_free(event->sessions);
 1245|    319|    }
 1246|    319|#endif
 1247|    319|    free(event);
 1248|    319|}
poll.c:ssh_poll_ctx_resize:
  603|    396|{
  604|    396|    ssh_poll_handle *pollptrs = NULL;
  605|    396|    ssh_pollfd_t *pollfds = NULL;
  606|       |
  607|    396|    pollptrs = realloc(ctx->pollptrs, sizeof(ssh_poll_handle) * new_size);
  608|    396|    if (pollptrs == NULL) {
  ------------------
  |  Branch (608:9): [True: 0, False: 396]
  ------------------
  609|       |        /* Fail, but keep the old value to be freed later */
  610|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  611|      0|    }
  612|    396|    ctx->pollptrs = pollptrs;
  613|       |
  614|    396|    pollfds = realloc(ctx->pollfds, sizeof(ssh_pollfd_t) * new_size);
  615|    396|    if (pollfds == NULL) {
  ------------------
  |  Branch (615:9): [True: 0, False: 396]
  ------------------
  616|      0|        if (ctx->polls_allocated == 0) {
  ------------------
  |  Branch (616:13): [True: 0, False: 0]
  ------------------
  617|       |            /* This was initial allocation -- just free what we allocated above
  618|       |             * and fail */
  619|      0|            SAFE_FREE(ctx->pollptrs);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  620|      0|            return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  621|      0|        }
  622|       |        /* Try to realloc the pollptrs back to the original size */
  623|      0|        pollptrs = realloc(ctx->pollptrs,
  624|      0|                           sizeof(ssh_poll_handle) * ctx->polls_allocated);
  625|      0|        if (pollptrs == NULL) {
  ------------------
  |  Branch (625:13): [True: 0, False: 0]
  ------------------
  626|      0|            return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  627|      0|        }
  628|      0|        ctx->pollptrs = pollptrs;
  629|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  630|      0|    }
  631|       |
  632|    396|    ctx->pollfds = pollfds;
  633|    396|    ctx->polls_allocated = new_size;
  634|       |
  635|    396|    return SSH_OK;
  ------------------
  |  |  315|    396|#define SSH_OK 0     /* No error */
  ------------------
  636|    396|}

server_set_kex:
   93|    583|{
   94|    583|    struct ssh_kex_struct *server = &session->next_crypto->server_kex;
   95|    583|    int i, j, rc;
   96|    583|    const char *wanted = NULL, *allowed = NULL;
   97|    583|    char *kept = NULL;
   98|    583|    char hostkeys[128] = {0};
   99|    583|    enum ssh_keytypes_e keytype;
  100|    583|    size_t len;
  101|    583|    int ok;
  102|       |#ifdef WITH_GSSAPI
  103|       |    char *gssapi_algs = NULL;
  104|       |#endif /* WITH_GSSAPI */
  105|       |
  106|       |    /* Skip if already set, for example for the rekey or when we do the guessing
  107|       |     * it could have been already used to make some protocol decisions. */
  108|    583|    if (server->methods[0] != NULL) {
  ------------------
  |  Branch (108:9): [True: 260, False: 323]
  ------------------
  109|    260|        return SSH_OK;
  ------------------
  |  |  315|    260|#define SSH_OK 0     /* No error */
  ------------------
  110|    260|    }
  111|       |
  112|    323|    ok = ssh_get_random(server->cookie, 16, 0);
  113|    323|    if (!ok) {
  ------------------
  |  Branch (113:9): [True: 0, False: 323]
  ------------------
  114|      0|        ssh_set_error(session, SSH_FATAL, "PRNG error");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  115|      0|        return -1;
  116|      0|    }
  117|       |
  118|    323|    if (session->srv.ed25519_key != NULL) {
  ------------------
  |  Branch (118:9): [True: 0, False: 323]
  ------------------
  119|      0|        snprintf(hostkeys,
  120|      0|                 sizeof(hostkeys),
  121|      0|                 "%s",
  122|      0|                 ssh_key_type_to_char(ssh_key_type(session->srv.ed25519_key)));
  123|      0|    }
  124|    323|#ifdef HAVE_ECC
  125|    323|    if (session->srv.ecdsa_key != NULL) {
  ------------------
  |  Branch (125:9): [True: 0, False: 323]
  ------------------
  126|      0|        len = strlen(hostkeys);
  127|      0|        snprintf(hostkeys + len, sizeof(hostkeys) - len,
  128|      0|                 ",%s", session->srv.ecdsa_key->type_c);
  129|      0|    }
  130|    323|#endif
  131|    323|    if (session->srv.rsa_key != NULL) {
  ------------------
  |  Branch (131:9): [True: 323, False: 0]
  ------------------
  132|       |        /* We support also the SHA2 variants */
  133|    323|        len = strlen(hostkeys);
  134|    323|        snprintf(hostkeys + len, sizeof(hostkeys) - len,
  135|    323|                 ",rsa-sha2-512,rsa-sha2-256");
  136|       |
  137|    323|        len = strlen(hostkeys);
  138|    323|        keytype = ssh_key_type(session->srv.rsa_key);
  139|       |
  140|    323|        snprintf(hostkeys + len, sizeof(hostkeys) - len,
  141|    323|                 ",%s", ssh_key_type_to_char(keytype));
  142|    323|    }
  143|       |
  144|    323|    if (session->opts.wanted_methods[SSH_HOSTKEYS]) {
  ------------------
  |  Branch (144:9): [True: 4, False: 319]
  ------------------
  145|      4|        allowed = session->opts.wanted_methods[SSH_HOSTKEYS];
  146|    319|    } else {
  147|    319|        if (ssh_fips_mode()) {
  ------------------
  |  |  117|    319|#define ssh_fips_mode() EVP_default_properties_is_fips_enabled(NULL)
  |  |  ------------------
  |  |  |  Branch (117:25): [True: 0, False: 319]
  |  |  ------------------
  ------------------
  148|      0|            allowed = ssh_kex_get_fips_methods(SSH_HOSTKEYS);
  149|    319|        } else {
  150|    319|            allowed = ssh_kex_get_default_methods(SSH_HOSTKEYS);
  151|    319|        }
  152|    319|    }
  153|       |
  154|    323|    if (strlen(hostkeys) != 0) {
  ------------------
  |  Branch (154:9): [True: 323, False: 0]
  ------------------
  155|       |        /* It is expected for the list of allowed hostkeys to be ordered by
  156|       |         * preference */
  157|    323|        kept =
  158|    323|            ssh_find_all_matching(hostkeys[0] == ',' ? hostkeys + 1 : hostkeys,
  ------------------
  |  Branch (158:35): [True: 323, False: 0]
  ------------------
  159|    323|                                  allowed);
  160|    323|        if (kept == NULL) {
  ------------------
  |  Branch (160:13): [True: 0, False: 323]
  ------------------
  161|       |            /* Nothing was allowed */
  162|      0|            return -1;
  163|      0|        }
  164|       |
  165|    323|        rc = ssh_options_set_algo(session,
  166|    323|                                  SSH_HOSTKEYS,
  167|    323|                                  kept,
  168|    323|                                  &session->opts.wanted_methods[SSH_HOSTKEYS]);
  169|    323|        SAFE_FREE(kept);
  ------------------
  |  |  375|    323|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 323, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 323]
  |  |  ------------------
  ------------------
  170|    323|        if (rc < 0) {
  ------------------
  |  Branch (170:13): [True: 0, False: 323]
  ------------------
  171|      0|            return -1;
  172|      0|        }
  173|    323|    }
  174|       |#ifdef WITH_GSSAPI
  175|       |    if (session->opts.gssapi_key_exchange) {
  176|       |        ok = ssh_gssapi_init(session);
  177|       |        if (ok != SSH_OK) {
  178|       |            ssh_set_error_oom(session);
  179|       |            return SSH_ERROR;
  180|       |        }
  181|       |
  182|       |        gssapi_algs = ssh_gssapi_kex_mechs(session);
  183|       |        if (gssapi_algs == NULL) {
  184|       |            return SSH_ERROR;
  185|       |        }
  186|       |        ssh_gssapi_free(session);
  187|       |
  188|       |        /* Prefix the default algorithms with gsskex algs */
  189|       |        session->opts.wanted_methods[SSH_KEX] =
  190|       |            ssh_prefix_without_duplicates(ssh_kex_get_default_methods(SSH_KEX),
  191|       |                                          gssapi_algs);
  192|       |
  193|       |        if (strlen(hostkeys) == 0) {
  194|       |            session->opts.wanted_methods[SSH_HOSTKEYS] = strdup("null");
  195|       |        }
  196|       |
  197|       |        SAFE_FREE(gssapi_algs);
  198|       |    }
  199|       |#endif /* WITH_GSSAPI */
  200|       |
  201|  3.55k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  3.55k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (201:17): [True: 3.23k, False: 323]
  ------------------
  202|  3.23k|        wanted = session->opts.wanted_methods[i];
  203|  3.23k|        if (wanted == NULL) {
  ------------------
  |  Branch (203:13): [True: 1.61k, False: 1.61k]
  ------------------
  204|  1.61k|            if (ssh_fips_mode()) {
  ------------------
  |  |  117|  1.61k|#define ssh_fips_mode() EVP_default_properties_is_fips_enabled(NULL)
  |  |  ------------------
  |  |  |  Branch (117:25): [True: 0, False: 1.61k]
  |  |  ------------------
  ------------------
  205|      0|                wanted = ssh_kex_get_fips_methods(i);
  206|  1.61k|            } else {
  207|  1.61k|                wanted = ssh_kex_get_default_methods(i);
  208|  1.61k|            }
  209|  1.61k|        }
  210|  3.23k|        if (wanted == NULL) {
  ------------------
  |  Branch (210:13): [True: 0, False: 3.23k]
  ------------------
  211|      0|            for (j = 0; j < i; j++) {
  ------------------
  |  Branch (211:25): [True: 0, False: 0]
  ------------------
  212|      0|                SAFE_FREE(server->methods[j]);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  213|      0|            }
  214|      0|            return -1;
  215|      0|        }
  216|       |
  217|  3.23k|        server->methods[i] = strdup(wanted);
  218|  3.23k|        if (server->methods[i] == NULL) {
  ------------------
  |  Branch (218:13): [True: 0, False: 3.23k]
  ------------------
  219|      0|            for (j = 0; j < i; j++) {
  ------------------
  |  Branch (219:25): [True: 0, False: 0]
  ------------------
  220|      0|                SAFE_FREE(server->methods[j]);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  221|      0|            }
  222|      0|            return -1;
  223|      0|        }
  224|  3.23k|    }
  225|       |
  226|       |    /* Do not append the extensions during rekey */
  227|    323|    if (session->flags & SSH_SESSION_FLAG_AUTHENTICATED) {
  ------------------
  |  |   78|    323|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (227:9): [True: 4, False: 319]
  ------------------
  228|      4|        return SSH_OK;
  ------------------
  |  |  315|      4|#define SSH_OK 0     /* No error */
  ------------------
  229|      4|    }
  230|       |
  231|    319|    rc = ssh_kex_append_extensions(session, server);
  232|    319|    return rc;
  233|    323|}
ssh_packet_kexdh_init:
  310|    186|SSH_PACKET_CALLBACK(ssh_packet_kexdh_init){
  311|    186|  (void)packet;
  312|    186|  (void)type;
  313|    186|  (void)user;
  314|       |
  315|    186|  SSH_LOG(SSH_LOG_PACKET,"Received SSH_MSG_KEXDH_INIT");
  ------------------
  |  |  283|    186|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  316|    186|  if(session->dh_handshake_state != DH_STATE_INIT){
  ------------------
  |  Branch (316:6): [True: 0, False: 186]
  ------------------
  317|      0|    SSH_LOG(SSH_LOG_RARE,"Invalid state for SSH_MSG_KEXDH_INIT");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  318|      0|    session->session_state = SSH_SESSION_STATE_ERROR;
  319|      0|    return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  320|      0|  }
  321|       |
  322|       |  /* If first_kex_packet_follows guess was wrong, ignore this message. */
  323|    186|  if (session->first_kex_follows_guess_wrong != 0) {
  ------------------
  |  Branch (323:7): [True: 0, False: 186]
  ------------------
  324|      0|    SSH_LOG(SSH_LOG_RARE, "first_kex_packet_follows guess was wrong, "
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  325|      0|                          "ignoring first SSH_MSG_KEXDH_INIT message");
  326|      0|    session->first_kex_follows_guess_wrong = 0;
  327|       |
  328|      0|    return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  329|      0|  }
  330|    186|  SSH_LOG(SSH_LOG_DEBUG, "Calling next KEXDH handler");
  ------------------
  |  |  283|    186|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  331|    186|  return SSH_PACKET_NOT_USED;
  ------------------
  |  |  641|    186|#define SSH_PACKET_NOT_USED 2
  ------------------
  332|    186|}
ssh_get_key_params:
  354|    185|{
  355|    185|    ssh_key pubkey = NULL;
  356|    185|    ssh_string pubkey_blob = NULL;
  357|    185|    int rc;
  358|       |
  359|    185|    switch(session->srv.hostkey) {
  360|    185|      case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (360:7): [True: 185, False: 0]
  ------------------
  361|    185|        *privkey = session->srv.rsa_key;
  362|    185|        break;
  363|      0|      case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (363:7): [True: 0, False: 185]
  ------------------
  364|      0|      case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (364:7): [True: 0, False: 185]
  ------------------
  365|      0|      case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (365:7): [True: 0, False: 185]
  ------------------
  366|      0|        *privkey = session->srv.ecdsa_key;
  367|      0|        break;
  368|      0|      case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (368:7): [True: 0, False: 185]
  ------------------
  369|      0|        *privkey = session->srv.ed25519_key;
  370|      0|        break;
  371|      0|      case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (371:7): [True: 0, False: 185]
  ------------------
  372|      0|      case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (372:7): [True: 0, False: 185]
  ------------------
  373|      0|      default:
  ------------------
  |  Branch (373:7): [True: 0, False: 185]
  ------------------
  374|      0|        *privkey = NULL;
  375|    185|    }
  376|       |
  377|    185|    *digest = session->srv.hostkey_digest;
  378|    185|    rc = ssh_pki_export_privkey_to_pubkey(*privkey, &pubkey);
  379|    185|    if (rc < 0) {
  ------------------
  |  Branch (379:9): [True: 0, False: 185]
  ------------------
  380|      0|      ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  381|      0|          "Could not get the public key from the private key");
  382|       |
  383|      0|      return -1;
  384|      0|    }
  385|       |
  386|    185|    rc = ssh_pki_export_pubkey_blob(pubkey, &pubkey_blob);
  387|    185|    ssh_key_free(pubkey);
  388|    185|    if (rc < 0) {
  ------------------
  |  Branch (388:9): [True: 0, False: 185]
  ------------------
  389|      0|      ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  390|      0|      return -1;
  391|      0|    }
  392|       |
  393|    185|    rc = ssh_dh_import_next_pubkey_blob(session, pubkey_blob);
  394|    185|    SSH_STRING_FREE(pubkey_blob);
  ------------------
  |  |  882|    185|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 185, False: 0]
  |  |  |  Branch (882:69): [Folded, False: 185]
  |  |  ------------------
  ------------------
  395|    185|    if (rc != 0) {
  ------------------
  |  Branch (395:9): [True: 0, False: 185]
  ------------------
  396|      0|        ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  397|      0|                      SSH_FATAL,
  398|      0|                      "Could not import server public key");
  399|      0|        return -1;
  400|      0|    }
  401|       |
  402|    185|    return SSH_OK;
  ------------------
  |  |  315|    185|#define SSH_OK 0     /* No error */
  ------------------
  403|    185|}
ssh_set_auth_methods:
  613|    319|{
  614|       |    /* accept only methods in range */
  615|    319|    session->auth.supported_methods = (uint32_t)auth_methods & 0x3fU;
  616|    319|}
ssh_handle_key_exchange:
  645|    319|{
  646|    319|    int rc;
  647|       |
  648|    319|    if (session->session_state != SSH_SESSION_STATE_NONE) {
  ------------------
  |  Branch (648:9): [True: 0, False: 319]
  ------------------
  649|      0|        goto pending;
  650|      0|    }
  651|       |
  652|    319|    rc = ssh_send_banner(session, 1);
  653|    319|    if (rc < 0) {
  ------------------
  |  Branch (653:9): [True: 0, False: 319]
  ------------------
  654|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  655|      0|    }
  656|       |
  657|    319|    session->alive = 1;
  658|       |
  659|    319|    session->ssh_connection_callback = ssh_server_connection_callback;
  660|    319|    session->session_state = SSH_SESSION_STATE_SOCKET_CONNECTED;
  661|    319|    ssh_socket_set_callbacks(session->socket,&session->socket_callbacks);
  662|    319|    session->socket_callbacks.data = callback_receive_banner;
  663|    319|    session->socket_callbacks.exception = ssh_socket_exception_callback;
  664|    319|    session->socket_callbacks.userdata = session;
  665|       |
  666|    319|    rc = server_set_kex(session);
  667|    319|    if (rc < 0) {
  ------------------
  |  Branch (667:9): [True: 0, False: 319]
  ------------------
  668|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  669|      0|    }
  670|    319|pending:
  671|    319|    rc = ssh_handle_packets_termination(session, SSH_TIMEOUT_USER,
  ------------------
  |  |  101|    319|#define SSH_TIMEOUT_USER -2
  ------------------
  672|    319|                                        ssh_server_kex_termination,session);
  673|    319|    SSH_LOG(SSH_LOG_PACKET, "ssh_handle_key_exchange: current state : %d",
  ------------------
  |  |  283|    319|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  674|    319|            session->session_state);
  675|    319|    if (rc != SSH_OK) {
  ------------------
  |  |  315|    319|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (675:9): [True: 40, False: 279]
  ------------------
  676|     40|        return rc;
  677|     40|    }
  678|    279|    if (session->session_state == SSH_SESSION_STATE_ERROR ||
  ------------------
  |  Branch (678:9): [True: 202, False: 77]
  ------------------
  679|    202|        session->session_state == SSH_SESSION_STATE_DISCONNECTED) {
  ------------------
  |  Branch (679:9): [True: 0, False: 77]
  ------------------
  680|    202|        return SSH_ERROR;
  ------------------
  |  |  316|    202|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  681|    202|    }
  682|       |
  683|     77|    return SSH_OK;
  ------------------
  |  |  315|     77|#define SSH_OK 0     /* No error */
  ------------------
  684|    279|}
ssh_auth_reply_default:
  691|    366|int ssh_auth_reply_default(ssh_session session,int partial) {
  692|    366|  char methods_c[128] = {0};
  693|    366|  int rc = SSH_ERROR;
  ------------------
  |  |  316|    366|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  694|       |
  695|       |
  696|    366|  if (session->auth.supported_methods == 0) {
  ------------------
  |  Branch (696:7): [True: 0, False: 366]
  ------------------
  697|      0|    session->auth.supported_methods = SSH_AUTH_METHOD_PUBLICKEY | SSH_AUTH_METHOD_PASSWORD;
  ------------------
  |  |  157|      0|#define SSH_AUTH_METHOD_PUBLICKEY    0x0004u
  ------------------
                  session->auth.supported_methods = SSH_AUTH_METHOD_PUBLICKEY | SSH_AUTH_METHOD_PASSWORD;
  ------------------
  |  |  156|      0|#define SSH_AUTH_METHOD_PASSWORD     0x0002u
  ------------------
  698|      0|  }
  699|    366|  if (session->auth.supported_methods & SSH_AUTH_METHOD_PUBLICKEY) {
  ------------------
  |  |  157|    366|#define SSH_AUTH_METHOD_PUBLICKEY    0x0004u
  ------------------
  |  Branch (699:7): [True: 0, False: 366]
  ------------------
  700|      0|      strlcat(methods_c, "publickey,", sizeof(methods_c));
  701|      0|  }
  702|    366|  if (session->auth.supported_methods & SSH_AUTH_METHOD_GSSAPI_MIC){
  ------------------
  |  |  160|    366|#define SSH_AUTH_METHOD_GSSAPI_MIC   0x0020u
  ------------------
  |  Branch (702:7): [True: 0, False: 366]
  ------------------
  703|      0|      strlcat(methods_c, "gssapi-with-mic,", sizeof(methods_c));
  704|      0|  }
  705|       |  /* Check if GSSAPI Key exchange was performed */
  706|    366|  if (session->auth.supported_methods & SSH_AUTH_METHOD_GSSAPI_KEYEX) {
  ------------------
  |  |  161|    366|#define SSH_AUTH_METHOD_GSSAPI_KEYEX 0x0040u
  ------------------
  |  Branch (706:7): [True: 0, False: 366]
  ------------------
  707|      0|      if (ssh_session_kex_is_gss(session)) {
  ------------------
  |  Branch (707:11): [True: 0, False: 0]
  ------------------
  708|      0|          strlcat(methods_c, "gssapi-keyex,", sizeof(methods_c));
  709|      0|      }
  710|      0|  }
  711|    366|  if (session->auth.supported_methods & SSH_AUTH_METHOD_INTERACTIVE) {
  ------------------
  |  |  159|    366|#define SSH_AUTH_METHOD_INTERACTIVE  0x0010u
  ------------------
  |  Branch (711:7): [True: 0, False: 366]
  ------------------
  712|      0|      strlcat(methods_c, "keyboard-interactive,", sizeof(methods_c));
  713|      0|  }
  714|    366|  if (session->auth.supported_methods & SSH_AUTH_METHOD_PASSWORD) {
  ------------------
  |  |  156|    366|#define SSH_AUTH_METHOD_PASSWORD     0x0002u
  ------------------
  |  Branch (714:7): [True: 0, False: 366]
  ------------------
  715|      0|      strlcat(methods_c, "password,", sizeof(methods_c));
  716|      0|  }
  717|    366|  if (session->auth.supported_methods & SSH_AUTH_METHOD_HOSTBASED) {
  ------------------
  |  |  158|    366|#define SSH_AUTH_METHOD_HOSTBASED    0x0008u
  ------------------
  |  Branch (717:7): [True: 0, False: 366]
  ------------------
  718|      0|      strlcat(methods_c, "hostbased,", sizeof(methods_c));
  719|      0|  }
  720|       |
  721|    366|  if (methods_c[0] == '\0' || methods_c[strlen(methods_c)-1] != ',') {
  ------------------
  |  Branch (721:7): [True: 366, False: 0]
  |  Branch (721:31): [True: 0, False: 0]
  ------------------
  722|    366|      return SSH_ERROR;
  ------------------
  |  |  316|    366|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  723|    366|  }
  724|       |
  725|       |  /* Strip the comma. */
  726|      0|  methods_c[strlen(methods_c) - 1] = '\0'; // strip the comma. We are sure there is at
  727|       |
  728|      0|  SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  729|      0|      "Sending a auth failure. methods that can continue: %s", methods_c);
  730|       |
  731|      0|  rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  |  |  |  Branch (50:68): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  732|      0|                       "bsb",
  733|      0|                       SSH2_MSG_USERAUTH_FAILURE,
  734|      0|                       methods_c,
  735|      0|                       partial ? 1 : 0);
  736|      0|  if (rc != SSH_OK){
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (736:7): [True: 0, False: 0]
  ------------------
  737|      0|      ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  738|      0|      return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  739|      0|  }
  740|      0|  rc = ssh_packet_send(session);
  741|      0|  return rc;
  742|      0|}
ssh_message_service_reply_success:
  834|      1|{
  835|      1|    ssh_session session = NULL;
  836|      1|    int rc;
  837|       |
  838|      1|    if (msg == NULL) {
  ------------------
  |  Branch (838:9): [True: 0, False: 1]
  ------------------
  839|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  840|      0|    }
  841|      1|    session = msg->session;
  842|       |
  843|      1|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|      1|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  844|      1|            "Sending a SERVICE_ACCEPT for service %s", msg->service_request.service);
  845|       |
  846|      1|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|      1|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      1|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      1|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      1|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      1|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      1|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      1|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  847|      1|                         "bs",
  848|      1|                         SSH2_MSG_SERVICE_ACCEPT,
  849|      1|                         msg->service_request.service);
  850|      1|    if (rc != SSH_OK){
  ------------------
  |  |  315|      1|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (850:9): [True: 0, False: 1]
  ------------------
  851|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  852|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  853|      0|    }
  854|      1|    rc = ssh_packet_send(msg->session);
  855|      1|    return rc;
  856|      1|}
ssh_message_reply_default:
  933|    356|int ssh_message_reply_default(ssh_message msg) {
  934|    356|  if (msg == NULL) {
  ------------------
  |  Branch (934:7): [True: 0, False: 356]
  ------------------
  935|      0|    return -1;
  936|      0|  }
  937|       |
  938|    356|  switch(msg->type) {
  939|    330|    case SSH_REQUEST_AUTH:
  ------------------
  |  Branch (939:5): [True: 330, False: 26]
  ------------------
  940|    330|      return ssh_auth_reply_default(msg->session, 0);
  941|     25|    case SSH_REQUEST_CHANNEL_OPEN:
  ------------------
  |  Branch (941:5): [True: 25, False: 331]
  ------------------
  942|     25|      return ssh_message_channel_request_open_reply_default(msg);
  943|      0|    case SSH_REQUEST_CHANNEL:
  ------------------
  |  Branch (943:5): [True: 0, False: 356]
  ------------------
  944|      0|      return ssh_message_channel_request_reply_default(msg);
  945|      1|    case SSH_REQUEST_SERVICE:
  ------------------
  |  Branch (945:5): [True: 1, False: 355]
  ------------------
  946|      1|      return ssh_message_service_request_reply_default(msg);
  947|      0|    case SSH_REQUEST_GLOBAL:
  ------------------
  |  Branch (947:5): [True: 0, False: 356]
  ------------------
  948|      0|      return ssh_message_global_request_reply_default(msg);
  949|      0|    default:
  ------------------
  |  Branch (949:5): [True: 0, False: 356]
  ------------------
  950|      0|      SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  951|      0|          "Don't know what to default reply to %d type",
  952|      0|          msg->type);
  953|      0|      break;
  954|    356|  }
  955|       |
  956|      0|  return -1;
  957|    356|}
ssh_auth_reply_success:
 1192|     69|{
 1193|     69|    struct ssh_crypto_struct *crypto = NULL;
 1194|     69|    int r;
 1195|       |
 1196|     69|    if (session == NULL) {
  ------------------
  |  Branch (1196:9): [True: 0, False: 69]
  ------------------
 1197|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1198|      0|    }
 1199|       |
 1200|     69|    if (partial) {
  ------------------
  |  Branch (1200:9): [True: 36, False: 33]
  ------------------
 1201|     36|        return ssh_auth_reply_default(session, partial);
 1202|     36|    }
 1203|       |
 1204|     33|    r = ssh_buffer_add_u8(session->out_buffer,SSH2_MSG_USERAUTH_SUCCESS);
  ------------------
  |  |   38|     33|#define SSH2_MSG_USERAUTH_SUCCESS 52
  ------------------
 1205|     33|    if (r < 0) {
  ------------------
  |  Branch (1205:9): [True: 0, False: 33]
  ------------------
 1206|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1207|      0|    }
 1208|       |
 1209|     33|    r = ssh_packet_send(session);
 1210|       |
 1211|       |    /*
 1212|       |     * Consider the session as having been authenticated only after sending
 1213|       |     * the `USERAUTH_SUCCESS` message.  Setting these flags after
 1214|       |     * ssh_packet_send ensures that a rekey is not triggered prematurely,
 1215|       |     * causing the message to be queued.
 1216|       |     */
 1217|     33|    session->session_state = SSH_SESSION_STATE_AUTHENTICATED;
 1218|     33|    session->flags |= SSH_SESSION_FLAG_AUTHENTICATED;
  ------------------
  |  |   78|     33|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
 1219|       |
 1220|     33|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_OUT);
 1221|     33|    if (crypto != NULL && crypto->delayed_compress_out) {
  ------------------
  |  Branch (1221:9): [True: 33, False: 0]
  |  Branch (1221:27): [True: 0, False: 33]
  ------------------
 1222|      0|        SSH_LOG(SSH_LOG_DEBUG, "Enabling delayed compression OUT");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1223|      0|        crypto->do_compress_out = 1;
 1224|      0|    }
 1225|       |
 1226|     33|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_IN);
 1227|     33|    if (crypto != NULL && crypto->delayed_compress_in) {
  ------------------
  |  Branch (1227:9): [True: 33, False: 0]
  |  Branch (1227:27): [True: 0, False: 33]
  ------------------
 1228|      0|        SSH_LOG(SSH_LOG_DEBUG, "Enabling delayed compression IN");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1229|      0|        crypto->do_compress_in = 1;
 1230|      0|    }
 1231|     33|    return r;
 1232|     33|}
ssh_message_auth_reply_success:
 1246|     69|int ssh_message_auth_reply_success(ssh_message msg, int partial) {
 1247|     69|	if(msg == NULL)
  ------------------
  |  Branch (1247:5): [True: 0, False: 69]
  ------------------
 1248|      0|		return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1249|     69|	return ssh_auth_reply_success(msg->session, partial);
 1250|     69|}
server.c:ssh_server_connection_callback:
  412|    908|{
  413|    908|    int rc;
  414|       |
  415|    908|    switch (session->session_state) {
  416|      0|    case SSH_SESSION_STATE_NONE:
  ------------------
  |  Branch (416:5): [True: 0, False: 908]
  ------------------
  417|      0|    case SSH_SESSION_STATE_CONNECTING:
  ------------------
  |  Branch (417:5): [True: 0, False: 908]
  ------------------
  418|      0|    case SSH_SESSION_STATE_SOCKET_CONNECTED:
  ------------------
  |  Branch (418:5): [True: 0, False: 908]
  ------------------
  419|      0|        break;
  420|    307|    case SSH_SESSION_STATE_BANNER_RECEIVED:
  ------------------
  |  Branch (420:5): [True: 307, False: 601]
  ------------------
  421|    307|        if (session->clientbanner == NULL) {
  ------------------
  |  Branch (421:13): [True: 0, False: 307]
  ------------------
  422|      0|            goto error;
  423|      0|        }
  424|    307|        set_status(session, 0.4f);
  ------------------
  |  |   65|    307|#define set_status(session, status) do {\
  |  |   66|    307|        if (session->common.callbacks && session->common.callbacks->connect_status_function) \
  |  |  ------------------
  |  |  |  Branch (66:13): [True: 0, False: 307]
  |  |  |  Branch (66:42): [True: 0, False: 0]
  |  |  ------------------
  |  |   67|    307|            session->common.callbacks->connect_status_function(session->common.callbacks->userdata, status); \
  |  |   68|    307|    } while (0)
  |  |  ------------------
  |  |  |  Branch (68:14): [Folded, False: 307]
  |  |  ------------------
  ------------------
  425|    307|        SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  283|    307|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  426|    307|                "SSH client banner: %s", session->clientbanner);
  427|       |
  428|       |        /* Here we analyze the different protocols the server allows. */
  429|    307|        rc = ssh_analyze_banner(session, 1);
  430|    307|        if (rc < 0) {
  ------------------
  |  Branch (430:13): [True: 13, False: 294]
  ------------------
  431|     13|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  313|     13|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  432|     13|                    "No version of SSH protocol usable (banner: %s)",
  433|     13|                    session->clientbanner);
  434|     13|            goto error;
  435|     13|        }
  436|       |
  437|       |        /* from now, the packet layer is handling incoming packets */
  438|    294|        ssh_packet_register_socket_callback(session, session->socket);
  439|       |
  440|    294|        ssh_packet_set_default_callbacks(session);
  441|    294|        set_status(session, 0.5f);
  ------------------
  |  |   65|    294|#define set_status(session, status) do {\
  |  |   66|    294|        if (session->common.callbacks && session->common.callbacks->connect_status_function) \
  |  |  ------------------
  |  |  |  Branch (66:13): [True: 0, False: 294]
  |  |  |  Branch (66:42): [True: 0, False: 0]
  |  |  ------------------
  |  |   67|    294|            session->common.callbacks->connect_status_function(session->common.callbacks->userdata, status); \
  |  |   68|    294|    } while (0)
  |  |  ------------------
  |  |  |  Branch (68:14): [Folded, False: 294]
  |  |  ------------------
  ------------------
  442|    294|        session->session_state = SSH_SESSION_STATE_INITIAL_KEX;
  443|    294|        rc = ssh_send_kex(session);
  444|    294|        if (rc < 0) {
  ------------------
  |  Branch (444:13): [True: 0, False: 294]
  ------------------
  445|      0|            goto error;
  446|      0|        }
  447|    294|        break;
  448|    294|    case SSH_SESSION_STATE_INITIAL_KEX:
  ------------------
  |  Branch (448:5): [True: 0, False: 908]
  ------------------
  449|       |        /* TODO: This state should disappear in favor of get_key handle */
  450|      0|        break;
  451|    249|    case SSH_SESSION_STATE_KEXINIT_RECEIVED:
  ------------------
  |  Branch (451:5): [True: 249, False: 659]
  ------------------
  452|    249|        set_status(session, 0.6f);
  ------------------
  |  |   65|    249|#define set_status(session, status) do {\
  |  |   66|    249|        if (session->common.callbacks && session->common.callbacks->connect_status_function) \
  |  |  ------------------
  |  |  |  Branch (66:13): [True: 0, False: 249]
  |  |  |  Branch (66:42): [True: 0, False: 0]
  |  |  ------------------
  |  |   67|    249|            session->common.callbacks->connect_status_function(session->common.callbacks->userdata, status); \
  |  |   68|    249|    } while (0)
  |  |  ------------------
  |  |  |  Branch (68:14): [Folded, False: 249]
  |  |  ------------------
  ------------------
  453|    249|        if ((session->flags & SSH_SESSION_FLAG_KEXINIT_SENT) == 0) {
  ------------------
  |  |   86|    249|#define SSH_SESSION_FLAG_KEXINIT_SENT 0x0008
  ------------------
  |  Branch (453:13): [True: 4, False: 245]
  ------------------
  454|      4|            rc = server_set_kex(session);
  455|      4|            if (rc == SSH_ERROR) {
  ------------------
  |  |  316|      4|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (455:17): [True: 0, False: 4]
  ------------------
  456|      0|                goto error;
  457|      0|            }
  458|       |            /* We are in a rekeying, so we need to send the server kex */
  459|      4|            rc = ssh_send_kex(session);
  460|      4|            if (rc < 0) {
  ------------------
  |  Branch (460:17): [True: 0, False: 4]
  ------------------
  461|      0|                goto error;
  462|      0|            }
  463|      4|        }
  464|    249|        ssh_list_kex(&session->next_crypto->client_kex); // log client kex
  465|    249|        rc = ssh_kex_select_methods(session);
  466|    249|        if (rc < 0) {
  ------------------
  |  Branch (466:13): [True: 31, False: 218]
  ------------------
  467|     31|            goto error;
  468|     31|        }
  469|    218|        rc = crypt_set_algorithms_server(session);
  470|    218|        if (rc == SSH_ERROR) {
  ------------------
  |  |  316|    218|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (470:13): [True: 0, False: 218]
  ------------------
  471|      0|            goto error;
  472|      0|        }
  473|    218|        set_status(session, 0.8f);
  ------------------
  |  |   65|    218|#define set_status(session, status) do {\
  |  |   66|    218|        if (session->common.callbacks && session->common.callbacks->connect_status_function) \
  |  |  ------------------
  |  |  |  Branch (66:13): [True: 0, False: 218]
  |  |  |  Branch (66:42): [True: 0, False: 0]
  |  |  ------------------
  |  |   67|    218|            session->common.callbacks->connect_status_function(session->common.callbacks->userdata, status); \
  |  |   68|    218|    } while (0)
  |  |  ------------------
  |  |  |  Branch (68:14): [Folded, False: 218]
  |  |  ------------------
  ------------------
  474|    218|        session->session_state = SSH_SESSION_STATE_DH;
  475|    218|        break;
  476|    180|    case SSH_SESSION_STATE_DH:
  ------------------
  |  Branch (476:5): [True: 180, False: 728]
  ------------------
  477|    180|        if (session->dh_handshake_state == DH_STATE_FINISHED) {
  ------------------
  |  Branch (477:13): [True: 180, False: 0]
  ------------------
  478|       |
  479|    180|            rc = ssh_packet_set_newkeys(session, SSH_DIRECTION_IN);
  480|    180|            if (rc != SSH_OK) {
  ------------------
  |  |  315|    180|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (480:17): [True: 0, False: 180]
  ------------------
  481|      0|                goto error;
  482|      0|            }
  483|       |
  484|       |            /*
  485|       |             * If the client supports extension negotiation, we will send
  486|       |             * our supported extensions now. This is the first message after
  487|       |             * sending NEWKEYS message and after turning on crypto.
  488|       |             */
  489|    180|            if (session->extensions & SSH_EXT_NEGOTIATION &&
  ------------------
  |  |  124|    360|#define SSH_EXT_NEGOTIATION     0x01
  ------------------
  |  Branch (489:17): [True: 0, False: 180]
  ------------------
  490|      0|                session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (490:17): [True: 0, False: 0]
  ------------------
  491|       |                /*
  492|       |                 * Only send an SSH_MSG_EXT_INFO message the first time the
  493|       |                 * client undergoes NEWKEYS.  It is unexpected for this message
  494|       |                 * to be sent upon rekey, and may cause clients to log error
  495|       |                 * messages.
  496|       |                 *
  497|       |                 * The session_state can not be used for this purpose because it
  498|       |                 * is re-set to SSH_SESSION_STATE_KEXINIT_RECEIVED during rekey.
  499|       |                 * So, use the connected flag which transitions from non-zero
  500|       |                 * below.
  501|       |                 *
  502|       |                 * See also:
  503|       |                 * - https://bugzilla.mindrot.org/show_bug.cgi?id=2929
  504|       |                 */
  505|      0|                if (session->connected == 0) {
  ------------------
  |  Branch (505:21): [True: 0, False: 0]
  ------------------
  506|      0|                    ssh_server_send_extensions(session);
  507|      0|                }
  508|      0|            }
  509|       |
  510|    180|            set_status(session, 1.0f);
  ------------------
  |  |   65|    180|#define set_status(session, status) do {\
  |  |   66|    180|        if (session->common.callbacks && session->common.callbacks->connect_status_function) \
  |  |  ------------------
  |  |  |  Branch (66:13): [True: 0, False: 180]
  |  |  |  Branch (66:42): [True: 0, False: 0]
  |  |  ------------------
  |  |   67|    180|            session->common.callbacks->connect_status_function(session->common.callbacks->userdata, status); \
  |  |   68|    180|    } while (0)
  |  |  ------------------
  |  |  |  Branch (68:14): [Folded, False: 180]
  |  |  ------------------
  ------------------
  511|    180|            session->connected = 1;
  512|    180|            session->session_state = SSH_SESSION_STATE_AUTHENTICATING;
  513|    180|            if (session->flags & SSH_SESSION_FLAG_AUTHENTICATED)
  ------------------
  |  |   78|    180|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (513:17): [True: 0, False: 180]
  ------------------
  514|      0|                session->session_state = SSH_SESSION_STATE_AUTHENTICATED;
  515|       |
  516|    180|        }
  517|    180|        break;
  518|    180|    case SSH_SESSION_STATE_AUTHENTICATING:
  ------------------
  |  Branch (518:5): [True: 0, False: 908]
  ------------------
  519|      0|        break;
  520|    172|    case SSH_SESSION_STATE_ERROR:
  ------------------
  |  Branch (520:5): [True: 172, False: 736]
  ------------------
  521|    172|        goto error;
  522|      0|    default:
  ------------------
  |  Branch (522:5): [True: 0, False: 908]
  ------------------
  523|      0|        ssh_set_error(session, SSH_FATAL, "Invalid state %d",
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  524|    908|                      session->session_state);
  525|    908|    }
  526|       |
  527|    692|    return;
  528|    692|error:
  529|    216|    ssh_socket_close(session->socket);
  530|    216|    session->alive = 0;
  531|    216|    session->session_state = SSH_SESSION_STATE_ERROR;
  532|    216|}
server.c:callback_receive_banner:
  546|    319|{
  547|    319|    char *buffer = (char *)data;
  548|    319|    ssh_session session = (ssh_session)user;
  549|    319|    char *str = NULL;
  550|    319|    size_t i;
  551|    319|    size_t processed = 0;
  552|       |
  553|  15.3k|    for (i = 0; i < len; i++) {
  ------------------
  |  Branch (553:17): [True: 15.3k, False: 11]
  ------------------
  554|  15.3k|#ifdef WITH_PCAP
  555|  15.3k|        if (session->pcap_ctx && buffer[i] == '\n') {
  ------------------
  |  Branch (555:13): [True: 0, False: 15.3k]
  |  Branch (555:34): [True: 0, False: 0]
  ------------------
  556|      0|            ssh_pcap_context_write(session->pcap_ctx,
  557|      0|                                   SSH_PCAP_DIR_IN,
  558|      0|                                   buffer,
  559|      0|                                   (uint32_t)(i + 1),
  560|      0|                                   (uint32_t)(i + 1));
  561|      0|        }
  562|  15.3k|#endif
  563|  15.3k|        if (buffer[i] == '\r') {
  ------------------
  |  Branch (563:13): [True: 44, False: 15.2k]
  ------------------
  564|     44|            buffer[i] = '\0';
  565|     44|        }
  566|       |
  567|  15.3k|        if (buffer[i] == '\n') {
  ------------------
  |  Branch (567:13): [True: 307, False: 15.0k]
  ------------------
  568|    307|            buffer[i] = '\0';
  569|       |
  570|    307|            str = strdup(buffer);
  571|    307|            if (str == NULL) {
  ------------------
  |  Branch (571:17): [True: 0, False: 307]
  ------------------
  572|      0|                session->session_state = SSH_SESSION_STATE_ERROR;
  573|      0|                ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  574|      0|                return 0;
  575|      0|            }
  576|       |            /* number of bytes read */
  577|    307|            processed = i + 1;
  578|    307|            session->clientbanner = str;
  579|    307|            session->session_state = SSH_SESSION_STATE_BANNER_RECEIVED;
  580|    307|            SSH_LOG(SSH_LOG_PACKET, "Received banner: %s", str);
  ------------------
  |  |  283|    307|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  581|    307|            session->ssh_connection_callback(session);
  582|       |
  583|    307|            return processed;
  584|    307|        }
  585|       |
  586|  15.0k|        if (i > 127) {
  ------------------
  |  Branch (586:13): [True: 1, False: 14.9k]
  ------------------
  587|       |            /* Too big banner */
  588|      1|            session->session_state = SSH_SESSION_STATE_ERROR;
  589|      1|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  313|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  590|      1|                          "Receiving banner: too large banner");
  591|       |
  592|      1|            return 0;
  593|      1|        }
  594|  15.0k|    }
  595|       |
  596|     11|    return processed;
  597|    319|}
server.c:ssh_server_kex_termination:
  600|  1.11k|static int ssh_server_kex_termination(void *s){
  601|  1.11k|  ssh_session session = s;
  602|  1.11k|  if (session->session_state != SSH_SESSION_STATE_ERROR &&
  ------------------
  |  Branch (602:7): [True: 914, False: 202]
  ------------------
  603|    914|      session->session_state != SSH_SESSION_STATE_AUTHENTICATING &&
  ------------------
  |  Branch (603:7): [True: 843, False: 71]
  ------------------
  604|    843|      session->session_state != SSH_SESSION_STATE_AUTHENTICATED &&
  ------------------
  |  Branch (604:7): [True: 837, False: 6]
  ------------------
  605|    837|      session->session_state != SSH_SESSION_STATE_DISCONNECTED)
  ------------------
  |  Branch (605:7): [True: 837, False: 0]
  ------------------
  606|    837|    return 0;
  607|    279|  else
  608|    279|    return 1;
  609|  1.11k|}
server.c:ssh_message_channel_request_open_reply_default:
  758|     25|static int ssh_message_channel_request_open_reply_default(ssh_message msg) {
  759|     25|    int rc;
  760|       |
  761|     25|    SSH_LOG(SSH_LOG_FUNCTIONS, "Refusing a channel");
  ------------------
  |  |  283|     25|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  762|       |
  763|     25|    rc = ssh_buffer_pack(msg->session->out_buffer,
  ------------------
  |  |   50|     25|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|     25|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|     25|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|     25|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|     25|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|     25|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     25|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  764|     25|                         "bdddd",
  765|     25|                         SSH2_MSG_CHANNEL_OPEN_FAILURE,
  766|     25|                         msg->channel_request_open.sender,
  767|     25|                         SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED,
  768|     25|                         0,    /* reason is empty string */
  769|     25|                         0);   /* language string */
  770|     25|    if (rc != SSH_OK){
  ------------------
  |  |  315|     25|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (770:9): [True: 0, False: 25]
  ------------------
  771|      0|        ssh_set_error_oom(msg->session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  772|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  773|      0|    }
  774|       |
  775|     25|    rc = ssh_packet_send(msg->session);
  776|     25|    return rc;
  777|     25|}
server.c:ssh_message_service_request_reply_default:
  821|      1|static int ssh_message_service_request_reply_default(ssh_message msg) {
  822|       |  /* The only return code accepted by specifications are success or disconnect */
  823|      1|  return ssh_message_service_reply_success(msg);
  824|      1|}

ssh_new:
   66|    996|{
   67|    996|    ssh_session session = NULL;
   68|    996|    char *id = NULL;
   69|    996|    int rc;
   70|       |
   71|    996|    session = calloc(1, sizeof (struct ssh_session_struct));
   72|    996|    if (session == NULL) {
  ------------------
  |  Branch (72:9): [True: 165, False: 831]
  ------------------
   73|    165|        return NULL;
   74|    165|    }
   75|       |
   76|    831|    session->next_crypto = crypto_new();
   77|    831|    if (session->next_crypto == NULL) {
  ------------------
  |  Branch (77:9): [True: 84, False: 747]
  ------------------
   78|     84|        goto err;
   79|     84|    }
   80|       |
   81|    747|    session->socket = ssh_socket_new(session);
   82|    747|    if (session->socket == NULL) {
  ------------------
  |  Branch (82:9): [True: 86, False: 661]
  ------------------
   83|     86|        goto err;
   84|     86|    }
   85|       |
   86|    661|    session->out_buffer = ssh_buffer_new();
   87|    661|    if (session->out_buffer == NULL) {
  ------------------
  |  Branch (87:9): [True: 0, False: 661]
  ------------------
   88|      0|        goto err;
   89|      0|    }
   90|       |
   91|    661|    session->in_buffer = ssh_buffer_new();
   92|    661|    if (session->in_buffer == NULL) {
  ------------------
  |  Branch (92:9): [True: 0, False: 661]
  ------------------
   93|      0|        goto err;
   94|      0|    }
   95|       |
   96|    661|    session->out_queue = ssh_list_new();
   97|    661|    if (session->out_queue == NULL) {
  ------------------
  |  Branch (97:9): [True: 0, False: 661]
  ------------------
   98|      0|        goto err;
   99|      0|    }
  100|       |
  101|    661|    session->alive = 0;
  102|    661|    session->auth.supported_methods = 0;
  103|    661|    ssh_set_blocking(session, 1);
  104|    661|    session->maxchannel = FIRST_CHANNEL;
  ------------------
  |  |   49|    661|#define FIRST_CHANNEL 42 // why not ? it helps to find bugs.
  ------------------
  105|    661|    session->proxy_root = true;
  106|       |
  107|    661|    session->agent = ssh_agent_new(session);
  108|    661|    if (session->agent == NULL) {
  ------------------
  |  Branch (108:9): [True: 1, False: 660]
  ------------------
  109|      1|        goto err;
  110|      1|    }
  111|       |
  112|       |    /* Initialise a default PKI context */
  113|    660|    session->pki_context = ssh_pki_ctx_new();
  114|    660|    if (session->pki_context == NULL) {
  ------------------
  |  Branch (114:9): [True: 0, False: 660]
  ------------------
  115|      0|        goto err;
  116|      0|    }
  117|       |
  118|       |    /* OPTIONS */
  119|    660|    session->opts.StrictHostKeyChecking = SSH_STRICT_HOSTKEY_ASK;
  120|    660|    session->opts.port = 22;
  121|    660|    session->opts.fd = -1;
  122|    660|    session->opts.compressionlevel = 7;
  123|    660|    session->opts.nodelay = 0;
  124|    660|    session->opts.identities_only = false;
  125|    660|    session->opts.server_alive_interval = 0;
  126|    660|    session->opts.server_alive_count_max = 3;
  127|    660|    session->opts.batch_mode = false;
  128|    660|    session->opts.gateway_ports = false;
  129|    660|    session->opts.control_master = SSH_CONTROL_MASTER_NO;
  130|       |
  131|    660|    session->opts.flags = SSH_OPT_FLAG_PASSWORD_AUTH |
  ------------------
  |  |  109|    660|#define SSH_OPT_FLAG_PASSWORD_AUTH 0x1
  ------------------
  132|    660|                          SSH_OPT_FLAG_PUBKEY_AUTH |
  ------------------
  |  |  110|    660|#define SSH_OPT_FLAG_PUBKEY_AUTH 0x2
  ------------------
  133|    660|                          SSH_OPT_FLAG_KBDINT_AUTH |
  ------------------
  |  |  111|    660|#define SSH_OPT_FLAG_KBDINT_AUTH 0x4
  ------------------
  134|    660|                          SSH_OPT_FLAG_GSSAPI_AUTH;
  ------------------
  |  |  112|    660|#define SSH_OPT_FLAG_GSSAPI_AUTH 0x8
  ------------------
  135|    660|    session->opts.pubkey_auth = SSH_PUBKEY_AUTH_ALL;
  136|       |
  137|    660|    session->opts.exp_flags = 0;
  138|       |
  139|       |#ifdef WITH_GSSAPI
  140|       |    session->opts.gssapi_key_exchange_algs =
  141|       |        strdup(GSSAPI_KEY_EXCHANGE_SUPPORTED);
  142|       |    if (session->opts.gssapi_key_exchange_algs == NULL) {
  143|       |        goto err;
  144|       |    }
  145|       |#endif /* WITH_GSSAPI */
  146|       |
  147|       |    /* Lazy allocation for identity_non_exp before populating the defaults */
  148|    660|    if (session->opts.identity_non_exp == NULL) {
  ------------------
  |  Branch (148:9): [True: 660, False: 0]
  ------------------
  149|    660|        session->opts.identity_non_exp = ssh_list_new();
  150|    660|        if (session->opts.identity_non_exp == NULL) {
  ------------------
  |  Branch (150:13): [True: 0, False: 660]
  ------------------
  151|      0|            goto err;
  152|      0|        }
  153|    660|    }
  154|       |
  155|    660|    id = strdup("%d/.ssh/id_ed25519");
  156|    660|    if (id == NULL) {
  ------------------
  |  Branch (156:9): [True: 0, False: 660]
  ------------------
  157|      0|        goto err;
  158|      0|    }
  159|       |
  160|    660|    rc = ssh_list_append(session->opts.identity_non_exp, id);
  161|    660|    if (rc == SSH_ERROR) {
  ------------------
  |  |  316|    660|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (161:9): [True: 0, False: 660]
  ------------------
  162|      0|        goto err;
  163|      0|    }
  164|       |
  165|    660|#ifdef HAVE_ECC
  166|    660|    id = strdup("%d/.ssh/id_ecdsa");
  167|    660|    if (id == NULL) {
  ------------------
  |  Branch (167:9): [True: 0, False: 660]
  ------------------
  168|      0|        goto err;
  169|      0|    }
  170|    660|    rc = ssh_list_append(session->opts.identity_non_exp, id);
  171|    660|    if (rc == SSH_ERROR) {
  ------------------
  |  |  316|    660|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (171:9): [True: 0, False: 660]
  ------------------
  172|      0|        goto err;
  173|      0|    }
  174|    660|#endif
  175|       |
  176|    660|    id = strdup("%d/.ssh/id_rsa");
  177|    660|    if (id == NULL) {
  ------------------
  |  Branch (177:9): [True: 0, False: 660]
  ------------------
  178|      0|        goto err;
  179|      0|    }
  180|    660|    rc = ssh_list_append(session->opts.identity_non_exp, id);
  181|    660|    if (rc == SSH_ERROR) {
  ------------------
  |  |  316|    660|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (181:9): [True: 0, False: 660]
  ------------------
  182|      0|        goto err;
  183|      0|    }
  184|       |
  185|       |#ifdef WITH_FIDO2
  186|       |    /* Add security key identities */
  187|       |    id = strdup("%d/.ssh/id_ed25519_sk");
  188|       |    if (id == NULL) {
  189|       |        goto err;
  190|       |    }
  191|       |    rc = ssh_list_append(session->opts.identity_non_exp, id);
  192|       |    if (rc == SSH_ERROR) {
  193|       |        goto err;
  194|       |    }
  195|       |
  196|       |#ifdef HAVE_ECC
  197|       |    id = strdup("%d/.ssh/id_ecdsa_sk");
  198|       |    if (id == NULL) {
  199|       |        goto err;
  200|       |    }
  201|       |    rc = ssh_list_append(session->opts.identity_non_exp, id);
  202|       |    if (rc == SSH_ERROR) {
  203|       |        goto err;
  204|       |    }
  205|       |#endif /* HAVE_ECC */
  206|       |#endif /* WITH_FIDO2 */
  207|       |
  208|       |    /* Explicitly initialize states */
  209|    660|    session->session_state = SSH_SESSION_STATE_NONE;
  210|    660|    session->pending_call_state = SSH_PENDING_CALL_NONE;
  211|    660|    session->packet_state = PACKET_STATE_INIT;
  212|    660|    session->dh_handshake_state = DH_STATE_INIT;
  213|    660|    session->global_req_state = SSH_CHANNEL_REQ_STATE_NONE;
  214|       |
  215|    660|    session->auth.state = SSH_AUTH_STATE_NONE;
  216|    660|    session->auth.service_state = SSH_AUTH_SERVICE_NONE;
  217|       |
  218|    660|    return session;
  219|       |
  220|    171|err:
  221|    171|    free(id);
  222|    171|    ssh_free(session);
  223|       |    return NULL;
  224|    660|}
ssh_free:
  235|  1.47k|{
  236|  1.47k|  int i;
  237|  1.47k|  struct ssh_iterator *it = NULL;
  238|  1.47k|  struct ssh_buffer_struct *b = NULL;
  239|       |
  240|  1.47k|  if (session == NULL) {
  ------------------
  |  Branch (240:7): [True: 639, False: 831]
  ------------------
  241|    639|    return;
  242|    639|  }
  243|       |
  244|       |  /*
  245|       |   * Delete all channels
  246|       |   *
  247|       |   * This needs the first thing we clean up cause if there is still an open
  248|       |   * channel we call ssh_channel_close() first. So we need a working socket
  249|       |   * and poll context for it.
  250|       |   */
  251|    831|  for (it = ssh_list_get_iterator(session->channels);
  252|    831|       it != NULL;
  ------------------
  |  Branch (252:8): [True: 0, False: 831]
  ------------------
  253|    831|       it = ssh_list_get_iterator(session->channels)) {
  254|      0|      ssh_channel_do_free(ssh_iterator_value(ssh_channel,it));
  ------------------
  |  |  122|      0|  ((type)((iterator)->data))
  ------------------
  255|      0|      ssh_list_remove(session->channels, it);
  256|      0|  }
  257|    831|  ssh_list_free(session->channels);
  258|    831|  session->channels = NULL;
  259|       |
  260|    831|#ifdef WITH_PCAP
  261|    831|  if (session->pcap_ctx) {
  ------------------
  |  Branch (261:7): [True: 0, False: 831]
  ------------------
  262|      0|      ssh_pcap_context_free(session->pcap_ctx);
  263|      0|      session->pcap_ctx = NULL;
  264|      0|  }
  265|    831|#endif
  266|       |
  267|    831|  ssh_socket_free(session->socket);
  268|    831|  session->socket = NULL;
  269|       |
  270|    831|  if (session->default_poll_ctx) {
  ------------------
  |  Branch (270:7): [True: 319, False: 512]
  ------------------
  271|    319|      ssh_poll_ctx_free(session->default_poll_ctx);
  272|    319|  }
  273|       |
  274|    831|  SSH_BUFFER_FREE(session->in_buffer);
  ------------------
  |  |  924|    831|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 661, False: 170]
  |  |  |  Branch (924:69): [Folded, False: 831]
  |  |  ------------------
  ------------------
  275|    831|  SSH_BUFFER_FREE(session->out_buffer);
  ------------------
  |  |  924|    831|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 661, False: 170]
  |  |  |  Branch (924:69): [Folded, False: 831]
  |  |  ------------------
  ------------------
  276|    831|  session->in_buffer = session->out_buffer = NULL;
  277|       |
  278|    831|  if (session->in_hashbuf != NULL) {
  ------------------
  |  Branch (278:7): [True: 75, False: 756]
  ------------------
  279|     75|      SSH_BUFFER_FREE(session->in_hashbuf);
  ------------------
  |  |  924|     75|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 75, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 75]
  |  |  ------------------
  ------------------
  280|     75|  }
  281|    831|  if (session->out_hashbuf != NULL) {
  ------------------
  |  Branch (281:7): [True: 113, False: 718]
  ------------------
  282|    113|      SSH_BUFFER_FREE(session->out_hashbuf);
  ------------------
  |  |  924|    113|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 113, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 113]
  |  |  ------------------
  ------------------
  283|    113|  }
  284|       |
  285|    831|  crypto_free(session->current_crypto);
  286|    831|  crypto_free(session->next_crypto);
  287|       |
  288|    831|  ssh_agent_free(session->agent);
  289|       |
  290|    831|  SSH_PKI_CTX_FREE(session->pki_context);
  ------------------
  |  | 1017|    831|    do {                         \
  |  | 1018|    831|        if ((x) != NULL) {       \
  |  |  ------------------
  |  |  |  Branch (1018:13): [True: 660, False: 171]
  |  |  ------------------
  |  | 1019|    660|            ssh_pki_ctx_free(x); \
  |  | 1020|    660|            x = NULL;            \
  |  | 1021|    660|        }                        \
  |  | 1022|    831|    } while (0)
  |  |  ------------------
  |  |  |  Branch (1022:14): [Folded, False: 831]
  |  |  ------------------
  ------------------
  291|       |
  292|    831|  ssh_key_free(session->srv.rsa_key);
  293|    831|  session->srv.rsa_key = NULL;
  294|    831|  ssh_key_free(session->srv.ecdsa_key);
  295|    831|  session->srv.ecdsa_key = NULL;
  296|    831|  ssh_key_free(session->srv.ed25519_key);
  297|    831|  session->srv.ed25519_key = NULL;
  298|       |
  299|    831|  if (session->ssh_message_list) {
  ------------------
  |  Branch (299:7): [True: 0, False: 831]
  ------------------
  300|      0|      ssh_message msg;
  301|       |
  302|      0|      for (msg = ssh_list_pop_head(ssh_message, session->ssh_message_list);
  ------------------
  |  |  130|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  303|      0|           msg != NULL;
  ------------------
  |  Branch (303:12): [True: 0, False: 0]
  ------------------
  304|      0|           msg = ssh_list_pop_head(ssh_message, session->ssh_message_list)) {
  ------------------
  |  |  130|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  305|      0|          ssh_message_free(msg);
  306|      0|      }
  307|      0|      ssh_list_free(session->ssh_message_list);
  308|      0|  }
  309|       |
  310|    831|  if (session->kbdint != NULL) {
  ------------------
  |  Branch (310:7): [True: 0, False: 831]
  ------------------
  311|      0|    ssh_kbdint_free(session->kbdint);
  312|      0|  }
  313|       |
  314|    831|  if (session->packet_callbacks) {
  ------------------
  |  Branch (314:7): [True: 0, False: 831]
  ------------------
  315|      0|    ssh_list_free(session->packet_callbacks);
  316|      0|  }
  317|       |
  318|       |#ifdef WITH_GSSAPI
  319|       |    ssh_gssapi_free(session);
  320|       |    SAFE_FREE(session->opts.gssapi_key_exchange_algs);
  321|       |#endif
  322|       |
  323|       |  /* options */
  324|    831|  if (session->opts.identity) {
  ------------------
  |  Branch (324:7): [True: 0, False: 831]
  ------------------
  325|      0|      char *id = NULL;
  326|       |
  327|      0|      for (id = ssh_list_pop_head(char *, session->opts.identity);
  ------------------
  |  |  130|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  328|      0|           id != NULL;
  ------------------
  |  Branch (328:12): [True: 0, False: 0]
  ------------------
  329|      0|           id = ssh_list_pop_head(char *, session->opts.identity)) {
  ------------------
  |  |  130|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  330|      0|          SAFE_FREE(id);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  331|      0|      }
  332|      0|      ssh_list_free(session->opts.identity);
  333|      0|  }
  334|       |
  335|    831|  if (session->opts.identity_non_exp) {
  ------------------
  |  Branch (335:7): [True: 660, False: 171]
  ------------------
  336|    660|      char *id = NULL;
  337|       |
  338|    660|      for (id = ssh_list_pop_head(char *, session->opts.identity_non_exp);
  ------------------
  |  |  130|    660|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  339|  2.64k|           id != NULL;
  ------------------
  |  Branch (339:12): [True: 1.98k, False: 660]
  ------------------
  340|  1.98k|           id = ssh_list_pop_head(char *, session->opts.identity_non_exp)) {
  ------------------
  |  |  130|  1.98k|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  341|  1.98k|          SAFE_FREE(id);
  ------------------
  |  |  375|  1.98k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 1.98k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 1.98k]
  |  |  ------------------
  ------------------
  342|  1.98k|      }
  343|    660|      ssh_list_free(session->opts.identity_non_exp);
  344|    660|  }
  345|       |
  346|    831|    if (session->opts.certificate) {
  ------------------
  |  Branch (346:9): [True: 0, False: 831]
  ------------------
  347|      0|        char *cert = NULL;
  348|       |
  349|      0|        for (cert = ssh_list_pop_head(char *, session->opts.certificate);
  ------------------
  |  |  130|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  350|      0|             cert != NULL;
  ------------------
  |  Branch (350:14): [True: 0, False: 0]
  ------------------
  351|      0|             cert = ssh_list_pop_head(char *, session->opts.certificate)) {
  ------------------
  |  |  130|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  352|      0|            SAFE_FREE(cert);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  353|      0|        }
  354|      0|        ssh_list_free(session->opts.certificate);
  355|      0|    }
  356|       |
  357|    831|    if (session->opts.certificate_non_exp) {
  ------------------
  |  Branch (357:9): [True: 0, False: 831]
  ------------------
  358|      0|        char *cert = NULL;
  359|       |
  360|      0|        for (cert = ssh_list_pop_head(char *, session->opts.certificate_non_exp);
  ------------------
  |  |  130|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  361|      0|             cert != NULL;
  ------------------
  |  Branch (361:14): [True: 0, False: 0]
  ------------------
  362|      0|             cert = ssh_list_pop_head(char *, session->opts.certificate_non_exp)) {
  ------------------
  |  |  130|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  363|      0|            SAFE_FREE(cert);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  364|      0|        }
  365|      0|        ssh_list_free(session->opts.certificate_non_exp);
  366|      0|    }
  367|       |
  368|    831|    ssh_proxyjumps_free(session->opts.proxy_jumps);
  369|    831|    SSH_LIST_FREE(session->opts.proxy_jumps);
  ------------------
  |  |  133|    831|    do { if ((x) != NULL) { ssh_list_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (133:14): [True: 0, False: 831]
  |  |  |  Branch (133:69): [Folded, False: 831]
  |  |  ------------------
  ------------------
  370|    831|    SSH_LIST_FREE(session->opts.proxy_jumps_user_cb);
  ------------------
  |  |  133|    831|    do { if ((x) != NULL) { ssh_list_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (133:14): [True: 0, False: 831]
  |  |  |  Branch (133:69): [Folded, False: 831]
  |  |  ------------------
  ------------------
  371|    831|    SAFE_FREE(session->opts.proxy_jumps_str);
  ------------------
  |  |  375|    831|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 831]
  |  |  |  Branch (375:71): [Folded, False: 831]
  |  |  ------------------
  ------------------
  372|       |
  373|    831|    if (session->opts.send_env) {
  ------------------
  |  Branch (373:9): [True: 0, False: 831]
  ------------------
  374|      0|        char *pattern = NULL;
  375|       |
  376|      0|        for (pattern = ssh_list_pop_head(char *, session->opts.send_env);
  ------------------
  |  |  130|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  377|      0|             pattern != NULL;
  ------------------
  |  Branch (377:14): [True: 0, False: 0]
  ------------------
  378|      0|             pattern = ssh_list_pop_head(char *, session->opts.send_env)) {
  ------------------
  |  |  130|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  379|      0|            SAFE_FREE(pattern);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  380|      0|        }
  381|      0|        ssh_list_free(session->opts.send_env);
  382|      0|    }
  383|       |
  384|    831|    while ((b = ssh_list_pop_head(struct ssh_buffer_struct *,
  ------------------
  |  |  130|    831|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  |  Branch (384:12): [True: 0, False: 831]
  ------------------
  385|    831|                                  session->out_queue)) != NULL) {
  386|      0|        SSH_BUFFER_FREE(b);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  387|      0|    }
  388|    831|    ssh_list_free(session->out_queue);
  389|       |
  390|    831|  ssh_agent_state_free(session->agent_state);
  391|    831|  session->agent_state = NULL;
  392|       |
  393|    831|  SAFE_FREE(session->auth.auto_state);
  ------------------
  |  |  375|    831|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 831]
  |  |  |  Branch (375:71): [Folded, False: 831]
  |  |  ------------------
  ------------------
  394|    831|  SAFE_FREE(session->serverbanner);
  ------------------
  |  |  375|    831|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 831]
  |  |  |  Branch (375:71): [Folded, False: 831]
  |  |  ------------------
  ------------------
  395|    831|  SAFE_FREE(session->clientbanner);
  ------------------
  |  |  375|    831|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 831]
  |  |  |  Branch (375:71): [Folded, False: 831]
  |  |  ------------------
  ------------------
  396|    831|  SAFE_FREE(session->banner);
  ------------------
  |  |  375|    831|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 18, False: 813]
  |  |  |  Branch (375:71): [Folded, False: 831]
  |  |  ------------------
  ------------------
  397|    831|  SAFE_FREE(session->disconnect_message);
  ------------------
  |  |  375|    831|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 831]
  |  |  |  Branch (375:71): [Folded, False: 831]
  |  |  ------------------
  ------------------
  398|    831|  SAFE_FREE(session->peer_discon_msg);
  ------------------
  |  |  375|    831|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 831]
  |  |  |  Branch (375:71): [Folded, False: 831]
  |  |  ------------------
  ------------------
  399|       |
  400|    831|  SAFE_FREE(session->opts.agent_socket);
  ------------------
  |  |  375|    831|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 831]
  |  |  |  Branch (375:71): [Folded, False: 831]
  |  |  ------------------
  ------------------
  401|    831|  SAFE_FREE(session->opts.bindaddr);
  ------------------
  |  |  375|    831|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 831]
  |  |  |  Branch (375:71): [Folded, False: 831]
  |  |  ------------------
  ------------------
  402|    831|  SAFE_FREE(session->opts.username);
  ------------------
  |  |  375|    831|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 831]
  |  |  |  Branch (375:71): [Folded, False: 831]
  |  |  ------------------
  ------------------
  403|    831|  SAFE_FREE(session->opts.host);
  ------------------
  |  |  375|    831|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 831]
  |  |  |  Branch (375:71): [Folded, False: 831]
  |  |  ------------------
  ------------------
  404|    831|  SAFE_FREE(session->opts.originalhost);
  ------------------
  |  |  375|    831|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 831]
  |  |  |  Branch (375:71): [Folded, False: 831]
  |  |  ------------------
  ------------------
  405|    831|  SAFE_FREE(session->opts.config_hostname);
  ------------------
  |  |  375|    831|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 831]
  |  |  |  Branch (375:71): [Folded, False: 831]
  |  |  ------------------
  ------------------
  406|    831|  SAFE_FREE(session->opts.tag);
  ------------------
  |  |  375|    831|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 831]
  |  |  |  Branch (375:71): [Folded, False: 831]
  |  |  ------------------
  ------------------
  407|    831|  SAFE_FREE(session->opts.homedir);
  ------------------
  |  |  375|    831|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 831]
  |  |  |  Branch (375:71): [Folded, False: 831]
  |  |  ------------------
  ------------------
  408|    831|  SAFE_FREE(session->opts.sshdir);
  ------------------
  |  |  375|    831|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 831]
  |  |  |  Branch (375:71): [Folded, False: 831]
  |  |  ------------------
  ------------------
  409|    831|  SAFE_FREE(session->opts.knownhosts);
  ------------------
  |  |  375|    831|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 831]
  |  |  |  Branch (375:71): [Folded, False: 831]
  |  |  ------------------
  ------------------
  410|    831|  SAFE_FREE(session->opts.global_knownhosts);
  ------------------
  |  |  375|    831|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 831]
  |  |  |  Branch (375:71): [Folded, False: 831]
  |  |  ------------------
  ------------------
  411|    831|  SAFE_FREE(session->opts.ProxyCommand);
  ------------------
  |  |  375|    831|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 831]
  |  |  |  Branch (375:71): [Folded, False: 831]
  |  |  ------------------
  ------------------
  412|    831|  SAFE_FREE(session->opts.gss_server_identity);
  ------------------
  |  |  375|    831|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 831]
  |  |  |  Branch (375:71): [Folded, False: 831]
  |  |  ------------------
  ------------------
  413|    831|  SAFE_FREE(session->opts.gss_client_identity);
  ------------------
  |  |  375|    831|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 831]
  |  |  |  Branch (375:71): [Folded, False: 831]
  |  |  ------------------
  ------------------
  414|    831|  SAFE_FREE(session->opts.pubkey_accepted_types);
  ------------------
  |  |  375|    831|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 831]
  |  |  |  Branch (375:71): [Folded, False: 831]
  |  |  ------------------
  ------------------
  415|    831|  SAFE_FREE(session->opts.control_path);
  ------------------
  |  |  375|    831|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 831]
  |  |  |  Branch (375:71): [Folded, False: 831]
  |  |  ------------------
  ------------------
  416|    831|  SAFE_FREE(session->opts.preferred_authentications);
  ------------------
  |  |  375|    831|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 831]
  |  |  |  Branch (375:71): [Folded, False: 831]
  |  |  ------------------
  ------------------
  417|    831|  SAFE_FREE(session->opts.forward_agent_sock_path);
  ------------------
  |  |  375|    831|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 831]
  |  |  |  Branch (375:71): [Folded, False: 831]
  |  |  ------------------
  ------------------
  418|       |
  419|    831|  if (session->opts.local_forward) {
  ------------------
  |  Branch (419:7): [True: 0, False: 831]
  ------------------
  420|      0|      char *entry = NULL;
  421|       |
  422|      0|      for (entry = ssh_list_pop_head(char *, session->opts.local_forward);
  ------------------
  |  |  130|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  423|      0|           entry != NULL;
  ------------------
  |  Branch (423:12): [True: 0, False: 0]
  ------------------
  424|      0|           entry = ssh_list_pop_head(char *, session->opts.local_forward)) {
  ------------------
  |  |  130|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  425|      0|          SAFE_FREE(entry);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  426|      0|      }
  427|      0|      ssh_list_free(session->opts.local_forward);
  428|      0|  }
  429|       |
  430|    831|  if (session->opts.remote_forward) {
  ------------------
  |  Branch (430:7): [True: 0, False: 831]
  ------------------
  431|      0|      char *entry = NULL;
  432|       |
  433|      0|      for (entry = ssh_list_pop_head(char *, session->opts.remote_forward);
  ------------------
  |  |  130|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  434|      0|           entry != NULL;
  ------------------
  |  Branch (434:12): [True: 0, False: 0]
  ------------------
  435|      0|           entry = ssh_list_pop_head(char *, session->opts.remote_forward)) {
  ------------------
  |  |  130|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  436|      0|          SAFE_FREE(entry);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  437|      0|      }
  438|      0|      ssh_list_free(session->opts.remote_forward);
  439|      0|  }
  440|       |
  441|  9.14k|  for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  9.14k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (441:15): [True: 8.31k, False: 831]
  ------------------
  442|  8.31k|      if (session->opts.wanted_methods[i]) {
  ------------------
  |  Branch (442:11): [True: 1.59k, False: 6.71k]
  ------------------
  443|  1.59k|          SAFE_FREE(session->opts.wanted_methods[i]);
  ------------------
  |  |  375|  1.59k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 1.59k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 1.59k]
  |  |  ------------------
  ------------------
  444|  1.59k|      }
  445|  8.31k|  }
  446|       |
  447|    831|  SAFE_FREE(session->server_opts.custombanner);
  ------------------
  |  |  375|    831|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 831]
  |  |  |  Branch (375:71): [Folded, False: 831]
  |  |  ------------------
  ------------------
  448|    831|  SAFE_FREE(session->server_opts.moduli_file);
  ------------------
  |  |  375|    831|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 831]
  |  |  |  Branch (375:71): [Folded, False: 831]
  |  |  ------------------
  ------------------
  449|       |
  450|    831|  _ssh_remove_legacy_log_cb();
  451|       |
  452|       |  /* burn connection, it could contain sensitive data */
  453|    831|  ssh_burn(session, sizeof(struct ssh_session_struct));
  ------------------
  |  |  390|    831|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  454|       |  SAFE_FREE(session);
  ------------------
  |  |  375|    831|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 831, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 831]
  |  |  ------------------
  ------------------
  455|    831|}
ssh_session_socket_close:
  635|    161|{
  636|    161|    if (session->opts.fd == SSH_INVALID_SOCKET) {
  ------------------
  |  |  123|    161|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  |  Branch (636:9): [True: 161, False: 0]
  ------------------
  637|    161|        ssh_socket_close(session->socket);
  638|    161|    }
  639|    161|    session->alive = 0;
  640|    161|    session->session_state = SSH_SESSION_STATE_ERROR;
  641|    161|}
ssh_set_blocking:
  669|    661|{
  670|    661|    if (session == NULL) {
  ------------------
  |  Branch (670:9): [True: 0, False: 661]
  ------------------
  671|      0|        return;
  672|      0|    }
  673|    661|    session->flags &= ~SSH_SESSION_FLAG_BLOCKING;
  ------------------
  |  |   75|    661|#define SSH_SESSION_FLAG_BLOCKING 0x0001
  ------------------
  674|    661|    session->flags |= blocking ? SSH_SESSION_FLAG_BLOCKING : 0;
  ------------------
  |  |   75|    661|#define SSH_SESSION_FLAG_BLOCKING 0x0001
  ------------------
  |  Branch (674:23): [True: 661, False: 0]
  ------------------
  675|    661|}
ssh_is_blocking:
  684|    319|{
  685|    319|    return (session->flags & SSH_SESSION_FLAG_BLOCKING) ? 1 : 0;
  ------------------
  |  |   75|    319|#define SSH_SESSION_FLAG_BLOCKING 0x0001
  ------------------
  |  Branch (685:12): [True: 319, False: 0]
  ------------------
  686|    319|}
ssh_handle_packets:
  821|    837|{
  822|    837|    ssh_poll_handle spoll = NULL;
  823|    837|    ssh_poll_ctx ctx = NULL;
  824|    837|    int tm = timeout;
  825|    837|    int rc;
  826|       |
  827|    837|    if (session == NULL || session->socket == NULL) {
  ------------------
  |  Branch (827:9): [True: 0, False: 837]
  |  Branch (827:28): [True: 0, False: 837]
  ------------------
  828|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  829|      0|    }
  830|       |
  831|    837|    spoll = ssh_socket_get_poll_handle(session->socket);
  832|    837|    if (spoll == NULL) {
  ------------------
  |  Branch (832:9): [True: 0, False: 837]
  ------------------
  833|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  834|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  835|      0|    }
  836|    837|    ssh_poll_add_events(spoll, POLLIN);
  837|    837|    ctx = ssh_poll_get_ctx(spoll);
  838|       |
  839|    837|    if (ctx == NULL) {
  ------------------
  |  Branch (839:9): [True: 319, False: 518]
  ------------------
  840|    319|        ctx = ssh_poll_get_default_ctx(session);
  841|    319|        if (ctx == NULL) {
  ------------------
  |  Branch (841:13): [True: 0, False: 319]
  ------------------
  842|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  843|      0|            return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  844|      0|        }
  845|    319|        rc = ssh_poll_ctx_add(ctx, spoll);
  846|    319|        if (rc != SSH_OK) {
  ------------------
  |  |  315|    319|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (846:13): [True: 0, False: 319]
  ------------------
  847|      0|            return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  848|      0|        }
  849|    319|    }
  850|       |
  851|    837|    if (timeout == SSH_TIMEOUT_USER) {
  ------------------
  |  |  101|    837|#define SSH_TIMEOUT_USER -2
  ------------------
  |  Branch (851:9): [True: 0, False: 837]
  ------------------
  852|      0|        if (ssh_is_blocking(session)) {
  ------------------
  |  Branch (852:13): [True: 0, False: 0]
  ------------------
  853|      0|            tm = ssh_make_milliseconds(session->opts.timeout,
  854|      0|                                       session->opts.timeout_usec);
  855|      0|        } else {
  856|      0|            tm = 0;
  857|      0|        }
  858|      0|    }
  859|    837|    rc = ssh_poll_ctx_dopoll(ctx, tm);
  860|    837|    if (rc == SSH_ERROR) {
  ------------------
  |  |  316|    837|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (860:9): [True: 40, False: 797]
  ------------------
  861|     40|        session->session_state = SSH_SESSION_STATE_ERROR;
  862|     40|    }
  863|       |
  864|    837|    return rc;
  865|    837|}
ssh_handle_packets_termination:
  898|    319|{
  899|    319|    struct ssh_timestamp ts;
  900|    319|    int timeout_ms = SSH_TIMEOUT_INFINITE;
  ------------------
  |  |   99|    319|#define SSH_TIMEOUT_INFINITE -1
  ------------------
  901|    319|    int tm;
  902|    319|    int ret = SSH_OK;
  ------------------
  |  |  315|    319|#define SSH_OK 0     /* No error */
  ------------------
  903|       |
  904|       |    /* If a timeout has been provided, use it */
  905|    319|    if (timeout >= 0) {
  ------------------
  |  Branch (905:9): [True: 0, False: 319]
  ------------------
  906|      0|        timeout_ms = timeout;
  907|    319|    } else {
  908|    319|        if (ssh_is_blocking(session)) {
  ------------------
  |  Branch (908:13): [True: 319, False: 0]
  ------------------
  909|    319|            if (timeout == SSH_TIMEOUT_USER || timeout == SSH_TIMEOUT_DEFAULT) {
  ------------------
  |  |  101|    638|#define SSH_TIMEOUT_USER -2
  ------------------
                          if (timeout == SSH_TIMEOUT_USER || timeout == SSH_TIMEOUT_DEFAULT) {
  ------------------
  |  |  103|      0|#define SSH_TIMEOUT_DEFAULT -3
  ------------------
  |  Branch (909:17): [True: 319, False: 0]
  |  Branch (909:48): [True: 0, False: 0]
  ------------------
  910|    319|                if (session->opts.timeout > 0 ||
  ------------------
  |  Branch (910:21): [True: 0, False: 319]
  ------------------
  911|    319|                    session->opts.timeout_usec > 0) {
  ------------------
  |  Branch (911:21): [True: 0, False: 319]
  ------------------
  912|      0|                    timeout_ms =
  913|      0|                        ssh_make_milliseconds(session->opts.timeout,
  914|      0|                                              session->opts.timeout_usec);
  915|      0|                }
  916|    319|            }
  917|    319|        } else {
  918|      0|            timeout_ms = SSH_TIMEOUT_NONBLOCKING;
  ------------------
  |  |  105|      0|#define SSH_TIMEOUT_NONBLOCKING 0
  ------------------
  919|      0|        }
  920|    319|    }
  921|       |
  922|       |    /* avoid unnecessary syscall for the SSH_TIMEOUT_NONBLOCKING case */
  923|    319|    if (timeout_ms != SSH_TIMEOUT_NONBLOCKING) {
  ------------------
  |  |  105|    319|#define SSH_TIMEOUT_NONBLOCKING 0
  ------------------
  |  Branch (923:9): [True: 319, False: 0]
  ------------------
  924|    319|        ssh_timestamp_init(&ts);
  925|    319|    }
  926|       |
  927|    319|    tm = timeout_ms;
  928|  1.11k|    while(!fct(user)) {
  ------------------
  |  Branch (928:11): [True: 837, False: 279]
  ------------------
  929|    837|        ret = ssh_handle_packets(session, tm);
  930|    837|        if (ret == SSH_ERROR) {
  ------------------
  |  |  316|    837|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (930:13): [True: 40, False: 797]
  ------------------
  931|     40|            break;
  932|     40|        }
  933|    797|        if (ssh_timeout_elapsed(&ts, timeout_ms)) {
  ------------------
  |  Branch (933:13): [True: 0, False: 797]
  ------------------
  934|      0|            ret = fct(user) ? SSH_OK : SSH_AGAIN;
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
                          ret = fct(user) ? SSH_OK : SSH_AGAIN;
  ------------------
  |  |  317|      0|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  |  Branch (934:19): [True: 0, False: 0]
  ------------------
  935|      0|            break;
  936|      0|        }
  937|       |
  938|    797|        tm = ssh_timeout_update(&ts, timeout_ms);
  939|    797|    }
  940|       |
  941|    319|    return ret;
  942|    319|}
ssh_socket_exception_callback:
 1053|    172|void ssh_socket_exception_callback(int code, int errno_code, void *user){
 1054|    172|    ssh_session session = (ssh_session)user;
 1055|       |
 1056|    172|    SSH_LOG(SSH_LOG_RARE,
  ------------------
  |  |  283|    172|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1057|    172|            "Socket exception callback: %d (%d)",
 1058|    172|            code,
 1059|    172|            errno_code);
 1060|    172|    session->session_state = SSH_SESSION_STATE_ERROR;
 1061|    172|    if (errno_code == 0 && code == SSH_SOCKET_EXCEPTION_EOF) {
  ------------------
  |  |  521|    158|#define SSH_SOCKET_EXCEPTION_EOF 	     1
  ------------------
  |  Branch (1061:9): [True: 158, False: 14]
  |  Branch (1061:28): [True: 114, False: 44]
  ------------------
 1062|    114|        ssh_set_error(session, SSH_FATAL, "Socket error: disconnected");
  ------------------
  |  |  313|    114|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1063|       |#ifdef _WIN32
 1064|       |    } else if (errno_code == WSAENETDOWN) {
 1065|       |        ssh_set_error(session, SSH_FATAL, "Socket error: network down");
 1066|       |    } else if (errno_code == WSAENETUNREACH) {
 1067|       |        ssh_set_error(session, SSH_FATAL, "Socket error: network unreachable");
 1068|       |    } else if (errno_code == WSAENETRESET) {
 1069|       |        ssh_set_error(session, SSH_FATAL, "Socket error: network reset");
 1070|       |    } else if (errno_code == WSAECONNABORTED) {
 1071|       |        ssh_set_error(session, SSH_FATAL, "Socket error: connection aborted");
 1072|       |    } else if (errno_code == WSAECONNRESET) {
 1073|       |        ssh_set_error(session,
 1074|       |                      SSH_FATAL,
 1075|       |                      "Socket error: connection reset by peer");
 1076|       |    } else if (errno_code == WSAETIMEDOUT) {
 1077|       |        ssh_set_error(session, SSH_FATAL, "Socket error: connection timed out");
 1078|       |    } else if (errno_code == WSAECONNREFUSED) {
 1079|       |        ssh_set_error(session, SSH_FATAL, "Socket error: connection refused");
 1080|       |    } else if (errno_code == WSAEHOSTUNREACH) {
 1081|       |        ssh_set_error(session, SSH_FATAL, "Socket error: host unreachable");
 1082|       |#endif
 1083|    114|    } else {
 1084|     58|        char err_msg[SSH_ERRNO_MSG_MAX] = {0};
 1085|     58|        ssh_set_error(session,
  ------------------
  |  |  313|     58|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1086|     58|                      SSH_FATAL,
 1087|     58|                      "Socket error: %s",
 1088|     58|                      ssh_strerror(errno_code, err_msg, SSH_ERRNO_MSG_MAX));
 1089|     58|    }
 1090|       |
 1091|    172|    session->ssh_connection_callback(session);
 1092|    172|}

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_socket_new:
  182|  1.72k|{
  183|  1.72k|    ssh_socket s;
  184|       |
  185|  1.72k|    s = calloc(1, sizeof(struct ssh_socket_struct));
  186|  1.72k|    if (s == NULL) {
  ------------------
  |  Branch (186:9): [True: 42, False: 1.68k]
  ------------------
  187|     42|        ssh_set_error_oom(session);
  ------------------
  |  |  320|     42|    _ssh_set_error_oom(error, __func__)
  ------------------
  188|     42|        return NULL;
  189|     42|    }
  190|  1.68k|    s->fd = SSH_INVALID_SOCKET;
  ------------------
  |  |  123|  1.68k|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  191|  1.68k|    s->last_errno = -1;
  192|  1.68k|    s->fd_is_socket = 1;
  193|  1.68k|    s->session = session;
  194|  1.68k|    s->in_buffer = ssh_buffer_new();
  195|  1.68k|    if (s->in_buffer == NULL) {
  ------------------
  |  Branch (195:9): [True: 39, False: 1.64k]
  ------------------
  196|     39|        ssh_set_error_oom(session);
  ------------------
  |  |  320|     39|    _ssh_set_error_oom(error, __func__)
  ------------------
  197|     39|        SAFE_FREE(s);
  ------------------
  |  |  375|     39|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 39, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 39]
  |  |  ------------------
  ------------------
  198|     39|        return NULL;
  199|     39|    }
  200|  1.64k|    s->out_buffer=ssh_buffer_new();
  201|  1.64k|    if (s->out_buffer == NULL) {
  ------------------
  |  Branch (201:9): [True: 6, False: 1.64k]
  ------------------
  202|      6|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      6|    _ssh_set_error_oom(error, __func__)
  ------------------
  203|      6|        SSH_BUFFER_FREE(s->in_buffer);
  ------------------
  |  |  924|      6|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 6, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 6]
  |  |  ------------------
  ------------------
  204|      6|        SAFE_FREE(s);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  205|      6|        return NULL;
  206|      6|    }
  207|  1.64k|    s->read_wontblock = 0;
  208|  1.64k|    s->write_wontblock = 0;
  209|  1.64k|    s->data_except = 0;
  210|       |    s->poll_handle = NULL;
  211|  1.64k|    s->state=SSH_SOCKET_NONE;
  212|  1.64k|    return s;
  213|  1.64k|}
ssh_socket_reset:
  226|    660|{
  227|    660|    s->fd = SSH_INVALID_SOCKET;
  ------------------
  |  |  123|    660|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  228|    660|    s->last_errno = -1;
  229|    660|    s->fd_is_socket = 1;
  230|    660|    ssh_buffer_reinit(s->in_buffer);
  231|    660|    ssh_buffer_reinit(s->out_buffer);
  232|    660|    s->read_wontblock = 0;
  233|    660|    s->write_wontblock = 0;
  234|    660|    s->data_except = 0;
  235|    660|    if (s->poll_handle != NULL) {
  ------------------
  |  Branch (235:9): [True: 158, False: 502]
  ------------------
  236|    158|        ssh_poll_free(s->poll_handle);
  237|       |        s->poll_handle = NULL;
  238|    158|    }
  239|    660|    s->state=SSH_SOCKET_NONE;
  240|    660|#ifndef _WIN32
  241|    660|    s->proxy_pid = 0;
  242|    660|#endif
  243|    660|}
ssh_socket_set_callbacks:
  253|    613|{
  254|    613|    s->callbacks = callbacks;
  255|    613|}
ssh_socket_set_connected:
  269|    319|{
  270|    319|    s->state = SSH_SOCKET_CONNECTED;
  271|       |    /* `POLLOUT` is the event to wait for in a non-blocking connect */
  272|    319|    if (p != NULL) {
  ------------------
  |  Branch (272:9): [True: 319, False: 0]
  ------------------
  273|    319|        ssh_poll_set_events(p, POLLIN | POLLOUT);
  274|    319|    }
  275|    319|}
ssh_socket_pollcallback:
  296|  1.66k|{
  297|  1.66k|    ssh_socket s = (ssh_socket)v_s;
  298|  1.66k|    void *buffer = NULL;
  299|  1.66k|    ssize_t nread = 0;
  300|  1.66k|    int rc;
  301|  1.66k|    int err = 0;
  302|  1.66k|    socklen_t errlen = sizeof(err);
  303|       |
  304|       |    /* Do not do anything if this socket was already closed */
  305|  1.66k|    if (!ssh_socket_is_open(s)) {
  ------------------
  |  Branch (305:9): [True: 0, False: 1.66k]
  ------------------
  306|      0|        return -1;
  307|      0|    }
  308|  1.66k|    SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|  9.96k|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (283:34): [True: 1.66k, False: 0]
  |  |  |  Branch (283:34): [True: 1.62k, False: 38]
  |  |  |  Branch (283:34): [True: 0, False: 1.66k]
  |  |  ------------------
  ------------------
  309|  1.66k|            "Poll callback on socket %d (%s%s%s), out buffer %" PRIu32, fd,
  310|  1.66k|            (revents & POLLIN) ? "POLLIN ":"",
  311|  1.66k|            (revents & POLLOUT) ? "POLLOUT ":"",
  312|  1.66k|            (revents & POLLERR) ? "POLLERR":"",
  313|  1.66k|            ssh_buffer_get_len(s->out_buffer));
  314|  1.66k|    if ((revents & POLLERR) || (revents & POLLHUP)) {
  ------------------
  |  Branch (314:9): [True: 0, False: 1.66k]
  |  Branch (314:32): [True: 0, False: 1.66k]
  ------------------
  315|       |        /* Check if we are in a connecting state */
  316|      0|        if (s->state == SSH_SOCKET_CONNECTING) {
  ------------------
  |  Branch (316:13): [True: 0, False: 0]
  ------------------
  317|      0|            s->state = SSH_SOCKET_ERROR;
  318|      0|            rc = getsockopt(fd, SOL_SOCKET, SO_ERROR, (char *)&err, &errlen);
  319|      0|            if (rc < 0) {
  ------------------
  |  Branch (319:17): [True: 0, False: 0]
  ------------------
  320|      0|                err = errno;
  321|      0|            }
  322|      0|            ssh_socket_close(s);
  323|       |            /* Overwrite ssh_socket_close() error with the real socket error */
  324|      0|            s->last_errno = err;
  325|      0|            errno = err;
  326|       |
  327|      0|            if (s->callbacks != NULL && s->callbacks->connected != NULL) {
  ------------------
  |  Branch (327:17): [True: 0, False: 0]
  |  Branch (327:41): [True: 0, False: 0]
  ------------------
  328|      0|                s->callbacks->connected(SSH_SOCKET_CONNECTED_ERROR,
  ------------------
  |  |  525|      0|#define SSH_SOCKET_CONNECTED_ERROR 		2
  ------------------
  329|      0|                                        err,
  330|      0|                                        s->callbacks->userdata);
  331|      0|            }
  332|       |
  333|      0|            return -1;
  334|      0|        }
  335|       |        /* Then we are in a more standard kind of error */
  336|       |        /* force a read to get an explanation */
  337|      0|        revents |= POLLIN;
  338|      0|    }
  339|  1.66k|    if ((revents & POLLIN) && s->state == SSH_SOCKET_CONNECTED) {
  ------------------
  |  Branch (339:9): [True: 1.66k, False: 0]
  |  Branch (339:31): [True: 1.66k, False: 0]
  ------------------
  340|  1.66k|        s->read_wontblock = 1;
  341|  1.66k|        buffer = ssh_buffer_allocate(s->in_buffer, MAX_BUF_SIZE);
  ------------------
  |  |  230|  1.66k|#define MAX_BUF_SIZE 4096
  ------------------
  342|  1.66k|        if (buffer) {
  ------------------
  |  Branch (342:13): [True: 1.66k, False: 0]
  ------------------
  343|  1.66k|            nread = ssh_socket_unbuffered_read(s, buffer, MAX_BUF_SIZE);
  ------------------
  |  |  230|  1.66k|#define MAX_BUF_SIZE 4096
  ------------------
  344|  1.66k|        }
  345|  1.66k|        if (nread < 0) {
  ------------------
  |  Branch (345:13): [True: 0, False: 1.66k]
  ------------------
  346|      0|            ssh_buffer_pass_bytes_end(s->in_buffer, MAX_BUF_SIZE);
  ------------------
  |  |  230|      0|#define MAX_BUF_SIZE 4096
  ------------------
  347|      0|            if (p != NULL) {
  ------------------
  |  Branch (347:17): [True: 0, False: 0]
  ------------------
  348|      0|                ssh_poll_remove_events(p, POLLIN);
  349|      0|            }
  350|       |
  351|      0|            if (s->callbacks != NULL && s->callbacks->exception != NULL) {
  ------------------
  |  Branch (351:17): [True: 0, False: 0]
  |  Branch (351:41): [True: 0, False: 0]
  ------------------
  352|      0|                s->callbacks->exception(SSH_SOCKET_EXCEPTION_ERROR,
  ------------------
  |  |  522|      0|#define SSH_SOCKET_EXCEPTION_ERROR     2
  ------------------
  353|      0|                                        s->last_errno,
  354|      0|                                        s->callbacks->userdata);
  355|      0|            }
  356|      0|            return -2;
  357|      0|        }
  358|       |
  359|       |        /* Rollback the unused space */
  360|  1.66k|        ssh_buffer_pass_bytes_end(s->in_buffer,
  361|  1.66k|                                  (uint32_t)(MAX_BUF_SIZE - nread));
  ------------------
  |  |  230|  1.66k|#define MAX_BUF_SIZE 4096
  ------------------
  362|       |
  363|  1.66k|        if (nread == 0) {
  ------------------
  |  Branch (363:13): [True: 114, False: 1.54k]
  ------------------
  364|    114|            if (p != NULL) {
  ------------------
  |  Branch (364:17): [True: 114, False: 0]
  ------------------
  365|    114|                ssh_poll_remove_events(p, POLLIN);
  366|    114|            }
  367|    114|            if (s->callbacks != NULL && s->callbacks->exception != NULL) {
  ------------------
  |  Branch (367:17): [True: 114, False: 0]
  |  Branch (367:41): [True: 114, False: 0]
  ------------------
  368|    114|                s->callbacks->exception(SSH_SOCKET_EXCEPTION_EOF,
  ------------------
  |  |  521|    114|#define SSH_SOCKET_EXCEPTION_EOF 	     1
  ------------------
  369|    114|                                        0,
  370|    114|                                        s->callbacks->userdata);
  371|    114|            }
  372|    114|            return -2;
  373|    114|        }
  374|       |
  375|  1.54k|        if (s->session->socket_counter != NULL) {
  ------------------
  |  Branch (375:13): [True: 0, False: 1.54k]
  ------------------
  376|      0|            s->session->socket_counter->in_bytes += nread;
  377|      0|        }
  378|       |
  379|       |        /* Call the callback */
  380|  1.54k|        if (s->callbacks != NULL && s->callbacks->data != NULL) {
  ------------------
  |  Branch (380:13): [True: 1.54k, False: 0]
  |  Branch (380:37): [True: 1.54k, False: 0]
  ------------------
  381|  1.54k|            size_t processed;
  382|  51.4k|            do {
  383|  51.4k|                processed = s->callbacks->data(ssh_buffer_get(s->in_buffer),
  384|  51.4k|                                               ssh_buffer_get_len(s->in_buffer),
  385|  51.4k|                                               s->callbacks->userdata);
  386|  51.4k|                ssh_buffer_pass_bytes(s->in_buffer, (uint32_t)processed);
  387|  51.4k|            } while ((processed > 0) && (s->state == SSH_SOCKET_CONNECTED));
  ------------------
  |  Branch (387:22): [True: 49.9k, False: 1.50k]
  |  Branch (387:41): [True: 49.8k, False: 44]
  ------------------
  388|       |
  389|       |            /* p may have been freed, so don't use it
  390|       |             * anymore in this function */
  391|  1.54k|            p = NULL;
  392|  1.54k|        }
  393|  1.54k|    }
  394|       |#ifdef _WIN32
  395|       |    if (revents & POLLOUT || revents & POLLWRNORM) {
  396|       |#else
  397|  1.54k|    if (revents & POLLOUT) {
  ------------------
  |  Branch (397:9): [True: 1.51k, False: 37]
  ------------------
  398|  1.51k|#endif
  399|  1.51k|        uint32_t len;
  400|       |
  401|       |        /* First, POLLOUT is a sign we may be connected */
  402|  1.51k|        if (s->state == SSH_SOCKET_CONNECTING) {
  ------------------
  |  Branch (402:13): [True: 0, False: 1.51k]
  ------------------
  403|      0|            SSH_LOG(SSH_LOG_PACKET, "Received POLLOUT in connecting state");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  404|      0|            ssh_socket_set_connected(s, p);
  405|       |
  406|      0|            rc = ssh_socket_set_blocking(ssh_socket_get_fd(s));
  407|      0|            if (rc < 0) {
  ------------------
  |  Branch (407:17): [True: 0, False: 0]
  ------------------
  408|      0|                return -1;
  409|      0|            }
  410|       |
  411|      0|            if (s->callbacks != NULL && s->callbacks->connected != NULL) {
  ------------------
  |  Branch (411:17): [True: 0, False: 0]
  |  Branch (411:41): [True: 0, False: 0]
  ------------------
  412|      0|                s->callbacks->connected(SSH_SOCKET_CONNECTED_OK,
  ------------------
  |  |  524|      0|#define SSH_SOCKET_CONNECTED_OK 			1
  ------------------
  413|      0|                                        0,
  414|      0|                                        s->callbacks->userdata);
  415|      0|            }
  416|       |
  417|      0|            return 0;
  418|      0|        }
  419|       |
  420|       |        /* So, we can write data */
  421|  1.51k|        s->write_wontblock = 1;
  422|  1.51k|        if (p != NULL) {
  ------------------
  |  Branch (422:13): [True: 0, False: 1.51k]
  ------------------
  423|      0|            ssh_poll_remove_events(p, POLLOUT);
  424|      0|        }
  425|       |
  426|       |        /* If buffered data is pending, write it */
  427|  1.51k|        len = ssh_buffer_get_len(s->out_buffer);
  428|  1.51k|        if (len > 0) {
  ------------------
  |  Branch (428:13): [True: 693, False: 817]
  ------------------
  429|    693|            ssh_socket_nonblocking_flush(s);
  430|    817|        } else if (s->callbacks != NULL && s->callbacks->controlflow != NULL) {
  ------------------
  |  Branch (430:20): [True: 817, False: 0]
  |  Branch (430:44): [True: 817, False: 0]
  ------------------
  431|       |            /* Otherwise advertise the upper level that write can be done */
  432|    817|            SSH_LOG(SSH_LOG_TRACE, "sending control flow event");
  ------------------
  |  |  283|    817|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  433|    817|            s->callbacks->controlflow(SSH_SOCKET_FLOW_WRITEWONTBLOCK,
  ------------------
  |  |  519|    817|#define SSH_SOCKET_FLOW_WRITEWONTBLOCK 2
  ------------------
  434|    817|                                      s->callbacks->userdata);
  435|    817|        }
  436|       |        /* TODO: Find a way to put back POLLOUT when buffering occurs */
  437|  1.51k|    }
  438|       |
  439|       |    /* Return -1 if the poll handler disappeared */
  440|  1.54k|    if (s->poll_handle == NULL) {
  ------------------
  |  Branch (440:9): [True: 0, False: 1.54k]
  ------------------
  441|      0|        return -1;
  442|      0|    }
  443|       |
  444|  1.54k|    return 0;
  445|  1.54k|}
ssh_socket_get_poll_handle:
  454|  1.47k|{
  455|  1.47k|    if (s->poll_handle) {
  ------------------
  |  Branch (455:9): [True: 1.15k, False: 319]
  ------------------
  456|  1.15k|        return s->poll_handle;
  457|  1.15k|    }
  458|    319|    s->poll_handle = ssh_poll_new(s->fd, 0, ssh_socket_pollcallback, s);
  459|    319|    return s->poll_handle;
  460|  1.47k|}
ssh_socket_free:
  473|  1.81k|{
  474|  1.81k|    if (s == NULL) {
  ------------------
  |  Branch (474:9): [True: 170, False: 1.64k]
  ------------------
  475|    170|        return;
  476|    170|    }
  477|  1.64k|    ssh_socket_close(s);
  478|  1.64k|    SSH_BUFFER_FREE(s->in_buffer);
  ------------------
  |  |  924|  1.64k|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 1.64k, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 1.64k]
  |  |  ------------------
  ------------------
  479|  1.64k|    SSH_BUFFER_FREE(s->out_buffer);
  ------------------
  |  |  924|  1.64k|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 1.64k, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 1.64k]
  |  |  ------------------
  ------------------
  480|       |    SAFE_FREE(s);
  ------------------
  |  |  375|  1.64k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 1.64k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 1.64k]
  |  |  ------------------
  ------------------
  481|  1.64k|}
ssh_socket_close:
  546|  2.69k|{
  547|  2.69k|    if (ssh_socket_is_open(s)) {
  ------------------
  |  Branch (547:9): [True: 319, False: 2.37k]
  ------------------
  548|       |#ifdef _WIN32
  549|       |        CLOSE_SOCKET(s->fd);
  550|       |        s->last_errno = WSAGetLastError();
  551|       |#else
  552|    319|        CLOSE_SOCKET(s->fd);
  ------------------
  |  |  474|    319|#define CLOSE_SOCKET(s) do { if ((s) != SSH_INVALID_SOCKET) { _XCLOSESOCKET(s); (s) = SSH_INVALID_SOCKET;} } while(0)
  |  |  ------------------
  |  |  |  |  123|    319|#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|    319|#define _XCLOSESOCKET close
  |  |  ------------------
  |  |               #define CLOSE_SOCKET(s) do { if ((s) != SSH_INVALID_SOCKET) { _XCLOSESOCKET(s); (s) = SSH_INVALID_SOCKET;} } while(0)
  |  |  ------------------
  |  |  |  |  123|    319|#define SSH_INVALID_SOCKET ((socket_t) -1)
  |  |  ------------------
  |  |  |  Branch (474:34): [True: 319, False: 0]
  |  |  |  Branch (474:116): [Folded, False: 319]
  |  |  ------------------
  ------------------
  553|    319|        s->last_errno = errno;
  554|    319|#endif
  555|    319|    }
  556|       |
  557|  2.69k|    if (s->poll_handle != NULL && !ssh_poll_is_locked(s->poll_handle)) {
  ------------------
  |  Branch (557:9): [True: 363, False: 2.32k]
  |  Branch (557:35): [True: 161, False: 202]
  ------------------
  558|    161|        ssh_poll_free(s->poll_handle);
  559|    161|        s->poll_handle = NULL;
  560|    161|    }
  561|       |
  562|  2.69k|    s->state = SSH_SOCKET_CLOSED;
  563|       |
  564|  2.69k|#ifndef _WIN32
  565|       |    /* If the proxy command still runs try to kill it */
  566|  2.69k|    if (s->proxy_pid != 0) {
  ------------------
  |  Branch (566:9): [True: 0, False: 2.69k]
  ------------------
  567|      0|        int status;
  568|      0|        pid_t pid = s->proxy_pid;
  569|       |
  570|      0|        s->proxy_pid = 0;
  571|      0|        kill(pid, SIGTERM);
  572|      0|        while (waitpid(pid, &status, 0) == -1) {
  ------------------
  |  Branch (572:16): [True: 0, False: 0]
  ------------------
  573|      0|            if (errno != EINTR) {
  ------------------
  |  Branch (573:17): [True: 0, False: 0]
  ------------------
  574|      0|                SSH_LOG_STRERROR(SSH_LOG_TRACE, errno, "waitpid failed: %s");
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  575|      0|                return;
  576|      0|            }
  577|      0|        }
  578|      0|        if (!WIFEXITED(status)) {
  ------------------
  |  Branch (578:13): [True: 0, False: 0]
  ------------------
  579|      0|            SSH_LOG(SSH_LOG_TRACE, "Proxy command exited abnormally");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  580|      0|            return;
  581|      0|        }
  582|      0|        SSH_LOG(SSH_LOG_TRACE, "Proxy command returned %d", WEXITSTATUS(status));
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  583|      0|    }
  584|  2.69k|#endif
  585|  2.69k|}
ssh_socket_set_fd:
  596|    319|{
  597|    319|    ssh_poll_handle h = NULL;
  598|       |
  599|    319|    s->fd = fd;
  600|       |
  601|    319|    if (s->poll_handle) {
  ------------------
  |  Branch (601:9): [True: 0, False: 319]
  ------------------
  602|      0|        ssh_poll_set_fd(s->poll_handle,fd);
  603|    319|    } else {
  604|    319|        s->state = SSH_SOCKET_CONNECTING;
  605|    319|        h = ssh_socket_get_poll_handle(s);
  606|    319|        if (h == NULL) {
  ------------------
  |  Branch (606:13): [True: 0, False: 319]
  ------------------
  607|      0|            return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  608|      0|        }
  609|       |
  610|       |        /* POLLOUT is the event to wait for in a nonblocking connect */
  611|    319|        ssh_poll_set_events(h, POLLOUT);
  612|       |#ifdef _WIN32
  613|       |        ssh_poll_add_events(h, POLLWRNORM);
  614|       |#endif
  615|    319|    }
  616|    319|    return SSH_OK;
  ------------------
  |  |  315|    319|#define SSH_OK 0     /* No error */
  ------------------
  617|    319|}
ssh_socket_is_open:
  643|  36.3k|{
  644|  36.3k|    return s->fd != SSH_INVALID_SOCKET;
  ------------------
  |  |  123|  36.3k|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  645|  36.3k|}
ssh_socket_write:
  811|  15.4k|{
  812|  15.4k|    if (len > 0) {
  ------------------
  |  Branch (812:9): [True: 15.4k, False: 0]
  ------------------
  813|  15.4k|        if (ssh_buffer_add_data(s->out_buffer, buffer, len) < 0) {
  ------------------
  |  Branch (813:13): [True: 0, False: 15.4k]
  ------------------
  814|      0|            ssh_set_error_oom(s->session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  815|      0|            return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  816|      0|        }
  817|  15.4k|        ssh_socket_nonblocking_flush(s);
  818|  15.4k|    }
  819|       |
  820|  15.4k|    return SSH_OK;
  ------------------
  |  |  315|  15.4k|#define SSH_OK 0     /* No error */
  ------------------
  821|  15.4k|}
ssh_socket_nonblocking_flush:
  841|  16.1k|{
  842|  16.1k|    ssh_session session = s->session;
  843|  16.1k|    uint32_t len;
  844|       |
  845|  16.1k|    if (!ssh_socket_is_open(s)) {
  ------------------
  |  Branch (845:9): [True: 44, False: 16.1k]
  ------------------
  846|     44|        session->alive = 0;
  847|     44|        if (s->callbacks && s->callbacks->exception) {
  ------------------
  |  Branch (847:13): [True: 44, False: 0]
  |  Branch (847:29): [True: 44, False: 0]
  ------------------
  848|     44|            s->callbacks->exception(SSH_SOCKET_EXCEPTION_ERROR,
  ------------------
  |  |  522|     44|#define SSH_SOCKET_EXCEPTION_ERROR     2
  ------------------
  849|     44|                                    s->last_errno,
  850|     44|                                    s->callbacks->userdata);
  851|     44|        } else {
  852|      0|            char err_msg[SSH_ERRNO_MSG_MAX] = {0};
  853|      0|            ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  854|      0|                          SSH_FATAL,
  855|      0|                          "Writing packet: error on socket (or connection "
  856|      0|                          "closed): %s",
  857|      0|                          ssh_strerror(errno, err_msg, SSH_ERRNO_MSG_MAX));
  858|      0|        }
  859|       |
  860|     44|        return SSH_ERROR;
  ------------------
  |  |  316|     44|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  861|     44|    }
  862|       |
  863|  16.1k|    len = ssh_buffer_get_len(s->out_buffer);
  864|  16.1k|    if (!s->write_wontblock && s->poll_handle && len > 0) {
  ------------------
  |  Branch (864:9): [True: 15.4k, False: 708]
  |  Branch (864:32): [True: 15.4k, False: 0]
  |  Branch (864:50): [True: 15.4k, False: 0]
  ------------------
  865|       |        /* force the poll system to catch pollout events */
  866|  15.4k|        ssh_poll_add_events(s->poll_handle, POLLOUT);
  867|       |
  868|  15.4k|        return SSH_AGAIN;
  ------------------
  |  |  317|  15.4k|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  869|  15.4k|    }
  870|       |
  871|    708|    if (s->write_wontblock && len > 0) {
  ------------------
  |  Branch (871:9): [True: 708, False: 0]
  |  Branch (871:31): [True: 708, False: 0]
  ------------------
  872|    708|        ssize_t bwritten;
  873|       |
  874|    708|        bwritten = ssh_socket_unbuffered_write(s,
  875|    708|                                               ssh_buffer_get(s->out_buffer),
  876|    708|                                               len);
  877|    708|        if (bwritten < 0) {
  ------------------
  |  Branch (877:13): [True: 14, False: 694]
  ------------------
  878|     14|            session->alive = 0;
  879|     14|            ssh_socket_close(s);
  880|       |
  881|     14|            if (s->callbacks && s->callbacks->exception) {
  ------------------
  |  Branch (881:17): [True: 14, False: 0]
  |  Branch (881:33): [True: 14, False: 0]
  ------------------
  882|     14|                s->callbacks->exception(SSH_SOCKET_EXCEPTION_ERROR,
  ------------------
  |  |  522|     14|#define SSH_SOCKET_EXCEPTION_ERROR     2
  ------------------
  883|     14|                                        s->last_errno,
  884|     14|                                        s->callbacks->userdata);
  885|     14|            } else {
  886|      0|                char err_msg[SSH_ERRNO_MSG_MAX] = {0};
  887|      0|                ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  888|      0|                              SSH_FATAL,
  889|      0|                              "Writing packet: error on socket (or connection "
  890|      0|                              "closed): %s",
  891|      0|                              ssh_strerror(errno, err_msg, SSH_ERRNO_MSG_MAX));
  892|      0|            }
  893|       |
  894|     14|            return SSH_ERROR;
  ------------------
  |  |  316|     14|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  895|     14|        }
  896|       |
  897|    694|        ssh_buffer_pass_bytes(s->out_buffer, (uint32_t)bwritten);
  898|    694|        if (s->session->socket_counter != NULL) {
  ------------------
  |  Branch (898:13): [True: 0, False: 694]
  ------------------
  899|      0|            s->session->socket_counter->out_bytes += bwritten;
  900|      0|        }
  901|    694|    }
  902|       |
  903|       |    /* Is there some data pending? */
  904|    694|    len = ssh_buffer_get_len(s->out_buffer);
  905|    694|    if (s->poll_handle && len > 0) {
  ------------------
  |  Branch (905:9): [True: 694, False: 0]
  |  Branch (905:27): [True: 0, False: 694]
  ------------------
  906|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  907|      0|                "did not send all the data, queuing pollout event");
  908|       |        /* force the poll system to catch pollout events */
  909|      0|        ssh_poll_add_events(s->poll_handle, POLLOUT);
  910|       |
  911|      0|        return SSH_AGAIN;
  ------------------
  |  |  317|      0|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  912|      0|    }
  913|       |
  914|       |    /* all data written */
  915|    694|    return SSH_OK;
  ------------------
  |  |  315|    694|#define SSH_OK 0     /* No error */
  ------------------
  916|    694|}
socket.c:ssh_socket_unbuffered_read:
  665|  1.66k|{
  666|  1.66k|    ssize_t rc = -1;
  667|       |
  668|  1.66k|    if (s->data_except) {
  ------------------
  |  Branch (668:9): [True: 0, False: 1.66k]
  ------------------
  669|      0|        return -1;
  670|      0|    }
  671|  1.66k|    if (s->fd_is_socket) {
  ------------------
  |  Branch (671:9): [True: 1.66k, False: 0]
  ------------------
  672|  1.66k|        rc = recv(s->fd, buffer, len, 0);
  673|  1.66k|    } else {
  674|      0|        rc = read(s->fd, buffer, len);
  675|      0|    }
  676|       |#ifdef _WIN32
  677|       |    s->last_errno = WSAGetLastError();
  678|       |#else
  679|  1.66k|    s->last_errno = errno;
  680|  1.66k|#endif
  681|  1.66k|    s->read_wontblock = 0;
  682|       |
  683|  1.66k|    if (rc < 0) {
  ------------------
  |  Branch (683:9): [True: 0, False: 1.66k]
  ------------------
  684|      0|        s->data_except = 1;
  685|  1.66k|    } else {
  686|  1.66k|        SSH_LOG(SSH_LOG_TRACE, "read %zd", rc);
  ------------------
  |  |  283|  1.66k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  687|  1.66k|    }
  688|       |
  689|  1.66k|    return rc;
  690|  1.66k|}
socket.c:ssh_socket_unbuffered_write:
  711|    708|{
  712|    708|    ssize_t w = -1;
  713|    708|    int flags = 0;
  714|       |
  715|    708|#ifdef MSG_NOSIGNAL
  716|    708|    flags |= MSG_NOSIGNAL;
  717|    708|#endif
  718|       |
  719|    708|    if (s->data_except) {
  ------------------
  |  Branch (719:9): [True: 0, False: 708]
  ------------------
  720|      0|        return -1;
  721|      0|    }
  722|       |
  723|    708|    if (s->fd_is_socket) {
  ------------------
  |  Branch (723:9): [True: 708, False: 0]
  ------------------
  724|    708|        w = send(s->fd, buffer, len, flags);
  725|    708|    } else {
  726|      0|        w = write(s->fd, buffer, len);
  727|      0|    }
  728|       |#ifdef _WIN32
  729|       |    s->last_errno = WSAGetLastError();
  730|       |#else
  731|    708|    s->last_errno = errno;
  732|    708|#endif
  733|    708|    s->write_wontblock = 0;
  734|       |    /* Reactive the POLLOUT detector in the poll multiplexer system */
  735|    708|    if (s->poll_handle) {
  ------------------
  |  Branch (735:9): [True: 708, False: 0]
  ------------------
  736|    708|        SSH_LOG(SSH_LOG_PACKET, "Enabling POLLOUT for socket");
  ------------------
  |  |  283|    708|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  737|    708|        ssh_poll_add_events(s->poll_handle, POLLOUT);
  738|    708|    }
  739|    708|    if (w < 0) {
  ------------------
  |  Branch (739:9): [True: 14, False: 694]
  ------------------
  740|     14|        s->data_except = 1;
  741|     14|    }
  742|       |
  743|    708|    SSH_LOG(SSH_LOG_TRACE, "wrote %zd", w);
  ------------------
  |  |  283|    708|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  744|    708|    return w;
  745|    708|}

ssh_string_new:
   57|  20.0k|{
   58|  20.0k|    struct ssh_string_struct *str = NULL;
   59|       |
   60|  20.0k|    if (size > STRING_SIZE_MAX) {
  ------------------
  |  |   38|  20.0k|#define STRING_SIZE_MAX 0x10000000
  ------------------
  |  Branch (60:9): [True: 0, False: 20.0k]
  ------------------
   61|      0|        errno = EINVAL;
   62|      0|        return NULL;
   63|      0|    }
   64|       |
   65|  20.0k|    str = calloc(1, sizeof(struct ssh_string_struct) + size);
   66|  20.0k|    if (str == NULL) {
  ------------------
  |  Branch (66:9): [True: 0, False: 20.0k]
  ------------------
   67|      0|        return NULL;
   68|      0|    }
   69|       |
   70|  20.0k|    str->size = htonl((uint32_t)size);
   71|       |
   72|  20.0k|    return str;
   73|  20.0k|}
ssh_string_fill:
   87|  1.10k|{
   88|  1.10k|    if ((s == NULL) || (data == NULL) || (len == 0) ||
  ------------------
  |  Branch (88:9): [True: 0, False: 1.10k]
  |  Branch (88:24): [True: 0, False: 1.10k]
  |  Branch (88:42): [True: 0, False: 1.10k]
  ------------------
   89|  1.10k|        (len > ssh_string_len(s))) {
  ------------------
  |  Branch (89:9): [True: 0, False: 1.10k]
  ------------------
   90|      0|        return -1;
   91|      0|    }
   92|       |
   93|  1.10k|    memcpy(s->data, data, len);
   94|       |
   95|  1.10k|    return 0;
   96|  1.10k|}
ssh_string_from_char:
  109|  4.98k|{
  110|  4.98k|    struct ssh_string_struct *ptr = NULL;
  111|  4.98k|    size_t len;
  112|       |
  113|  4.98k|    if (what == NULL) {
  ------------------
  |  Branch (113:9): [True: 0, False: 4.98k]
  ------------------
  114|      0|        errno = EINVAL;
  115|      0|        return NULL;
  116|      0|    }
  117|       |
  118|  4.98k|    len = strlen(what);
  119|       |
  120|  4.98k|    ptr = ssh_string_new(len);
  121|  4.98k|    if (ptr == NULL) {
  ------------------
  |  Branch (121:9): [True: 0, False: 4.98k]
  ------------------
  122|      0|        return NULL;
  123|      0|    }
  124|       |
  125|  4.98k|    memcpy(ptr->data, what, len);
  126|       |
  127|  4.98k|    return ptr;
  128|  4.98k|}
ssh_string_len:
  177|  26.6k|{
  178|  26.6k|    size_t size;
  179|       |
  180|  26.6k|    if (s == NULL) {
  ------------------
  |  Branch (180:9): [True: 0, False: 26.6k]
  ------------------
  181|      0|        return 0;
  182|      0|    }
  183|       |
  184|  26.6k|    size = ntohl(s->size);
  185|  26.6k|    if (size > 0 && size <= STRING_SIZE_MAX) {
  ------------------
  |  |   38|  21.1k|#define STRING_SIZE_MAX 0x10000000
  ------------------
  |  Branch (185:9): [True: 21.1k, False: 5.51k]
  |  Branch (185:21): [True: 21.1k, False: 0]
  ------------------
  186|  21.1k|        return size;
  187|  21.1k|    }
  188|       |
  189|  5.51k|    return 0;
  190|  26.6k|}
ssh_string_get_char:
  202|  3.01k|{
  203|  3.01k|    if (s == NULL) {
  ------------------
  |  Branch (203:9): [True: 0, False: 3.01k]
  ------------------
  204|      0|        return NULL;
  205|      0|    }
  206|  3.01k|    s->data[ssh_string_len(s)] = '\0';
  207|       |
  208|  3.01k|    return (const char *)s->data;
  209|  3.01k|}
ssh_string_to_char:
  223|  2.54k|{
  224|  2.54k|    size_t len;
  225|  2.54k|    char *new = NULL;
  226|       |
  227|  2.54k|    if (s == NULL) {
  ------------------
  |  Branch (227:9): [True: 0, False: 2.54k]
  ------------------
  228|      0|        return NULL;
  229|      0|    }
  230|       |
  231|  2.54k|    len = ssh_string_len(s);
  232|  2.54k|    if (len + 1 < len) {
  ------------------
  |  Branch (232:9): [True: 0, False: 2.54k]
  ------------------
  233|      0|        return NULL;
  234|      0|    }
  235|       |
  236|  2.54k|    new = malloc(len + 1);
  237|  2.54k|    if (new == NULL) {
  ------------------
  |  Branch (237:9): [True: 0, False: 2.54k]
  ------------------
  238|      0|        return NULL;
  239|      0|    }
  240|  2.54k|    memcpy(new, s->data, len);
  241|  2.54k|    new[len] = '\0';
  242|       |
  243|  2.54k|    return new;
  244|  2.54k|}
ssh_string_copy:
  265|    185|{
  266|    185|    struct ssh_string_struct *new = NULL;
  267|    185|    size_t len;
  268|       |
  269|    185|    if (s == NULL) {
  ------------------
  |  Branch (269:9): [True: 0, False: 185]
  ------------------
  270|      0|        return NULL;
  271|      0|    }
  272|       |
  273|    185|    len = ssh_string_len(s);
  274|       |
  275|    185|    new = ssh_string_new(len);
  276|    185|    if (new == NULL) {
  ------------------
  |  Branch (276:9): [True: 0, False: 185]
  ------------------
  277|      0|        return NULL;
  278|      0|    }
  279|       |
  280|    185|    memcpy(new->data, s->data, len);
  281|       |
  282|    185|    return new;
  283|    185|}
ssh_string_burn:
  341|  5.79k|{
  342|  5.79k|    if (s == NULL || s->size == 0) {
  ------------------
  |  Branch (342:9): [True: 1.59k, False: 4.20k]
  |  Branch (342:22): [True: 2.34k, False: 1.85k]
  ------------------
  343|  3.94k|        return;
  344|  3.94k|    }
  345|       |
  346|  1.85k|    ssh_burn(s->data, ssh_string_len(s));
  ------------------
  |  |  390|  1.85k|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  347|  1.85k|}
ssh_string_data:
  357|  14.4k|{
  358|  14.4k|    if (s == NULL) {
  ------------------
  |  Branch (358:9): [True: 0, False: 14.4k]
  ------------------
  359|      0|        return NULL;
  360|      0|    }
  361|       |
  362|  14.4k|    return s->data;
  363|  14.4k|}
ssh_string_free:
  371|  27.6k|{
  372|       |    SAFE_FREE(s);
  ------------------
  |  |  375|  27.6k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 19.7k, False: 7.93k]
  |  |  |  Branch (375:71): [Folded, False: 27.6k]
  |  |  ------------------
  ------------------
  373|  27.6k|}

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|  8.28k|{
   44|  8.28k|    int i;
   45|  8.28k|    if (tokens == NULL) {
  ------------------
  |  Branch (45:9): [True: 0, False: 8.28k]
  ------------------
   46|      0|        return;
   47|      0|    }
   48|       |
   49|  8.28k|    if (tokens->tokens != NULL) {
  ------------------
  |  Branch (49:9): [True: 8.28k, False: 0]
  ------------------
   50|  42.2k|        for (i = 0; tokens->tokens[i] != NULL; i++) {
  ------------------
  |  Branch (50:21): [True: 33.9k, False: 8.28k]
  ------------------
   51|  33.9k|            ssh_burn(tokens->tokens[i], strlen(tokens->tokens[i]));
  ------------------
  |  |  390|  33.9k|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
   52|  33.9k|        }
   53|  8.28k|    }
   54|       |
   55|  8.28k|    SAFE_FREE(tokens->buffer);
  ------------------
  |  |  375|  8.28k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 8.28k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 8.28k]
  |  |  ------------------
  ------------------
   56|  8.28k|    SAFE_FREE(tokens->tokens);
  ------------------
  |  |  375|  8.28k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 8.28k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 8.28k]
  |  |  ------------------
  ------------------
   57|       |    SAFE_FREE(tokens);
  ------------------
  |  |  375|  8.28k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 8.28k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 8.28k]
  |  |  ------------------
  ------------------
   58|  8.28k|}
ssh_tokenize:
   74|  8.28k|{
   75|       |
   76|  8.28k|    struct ssh_tokens_st *tokens = NULL;
   77|  8.28k|    size_t num_tokens = 1, i = 1;
   78|       |
   79|  8.28k|    char *found, *c;
   80|       |
   81|  8.28k|    if (chain == NULL) {
  ------------------
  |  Branch (81:9): [True: 0, False: 8.28k]
  ------------------
   82|      0|        return NULL;
   83|      0|    }
   84|       |
   85|  8.28k|    tokens = calloc(1, sizeof(struct ssh_tokens_st));
   86|  8.28k|    if (tokens == NULL) {
  ------------------
  |  Branch (86:9): [True: 0, False: 8.28k]
  ------------------
   87|      0|        return NULL;
   88|      0|    }
   89|       |
   90|  8.28k|    tokens->buffer = strdup(chain);
   91|  8.28k|    if (tokens->buffer == NULL) {
  ------------------
  |  Branch (91:9): [True: 0, False: 8.28k]
  ------------------
   92|      0|        goto error;
   93|      0|    }
   94|       |
   95|  8.28k|    c = tokens->buffer;
   96|  33.9k|    do {
   97|  33.9k|        found = strchr(c, separator);
   98|  33.9k|        if (found != NULL) {
  ------------------
  |  Branch (98:13): [True: 25.6k, False: 8.28k]
  ------------------
   99|  25.6k|            c = found + 1;
  100|  25.6k|            num_tokens++;
  101|  25.6k|        }
  102|  33.9k|    } while(found != NULL);
  ------------------
  |  Branch (102:13): [True: 25.6k, False: 8.28k]
  ------------------
  103|       |
  104|       |    /* Allocate tokens list */
  105|  8.28k|    tokens->tokens = calloc(num_tokens + 1, sizeof(char *));
  106|  8.28k|    if (tokens->tokens == NULL) {
  ------------------
  |  Branch (106:9): [True: 0, False: 8.28k]
  ------------------
  107|      0|        goto error;
  108|      0|    }
  109|       |
  110|       |    /* First token starts in the beginning of the chain */
  111|  8.28k|    tokens->tokens[0] = tokens->buffer;
  112|  8.28k|    c = tokens->buffer;
  113|       |
  114|  33.9k|    for (i = 1; i < num_tokens; i++) {
  ------------------
  |  Branch (114:17): [True: 25.6k, False: 8.27k]
  ------------------
  115|       |        /* Find next separator */
  116|  25.6k|        found = strchr(c, separator);
  117|  25.6k|        if (found == NULL) {
  ------------------
  |  Branch (117:13): [True: 0, False: 25.6k]
  ------------------
  118|      0|            break;
  119|      0|        }
  120|       |
  121|       |        /* Replace it with a string terminator */
  122|  25.6k|        *found = '\0';
  123|       |
  124|       |        /* The next token starts in the next byte */
  125|  25.6k|        c = found + 1;
  126|       |
  127|       |        /* If we did not reach the end of the chain yet, set the next token */
  128|  25.6k|        if (*c != '\0') {
  ------------------
  |  Branch (128:13): [True: 25.6k, False: 1]
  ------------------
  129|  25.6k|            tokens->tokens[i] = c;
  130|  25.6k|        } else {
  131|      1|            break;
  132|      1|        }
  133|  25.6k|    }
  134|       |
  135|  8.28k|    return tokens;
  136|       |
  137|      0|error:
  138|      0|    ssh_tokens_free(tokens);
  139|       |    return NULL;
  140|  8.28k|}
ssh_find_matching:
  157|  2.21k|{
  158|  2.21k|    struct ssh_tokens_st *a_tok = NULL, *p_tok = NULL;
  159|       |
  160|  2.21k|    int i, j;
  161|  2.21k|    char *ret = NULL;
  162|       |
  163|  2.21k|    if ((available_list == NULL) || (preferred_list == NULL)) {
  ------------------
  |  Branch (163:9): [True: 0, False: 2.21k]
  |  Branch (163:37): [True: 0, False: 2.21k]
  ------------------
  164|      0|        return NULL;
  165|      0|    }
  166|       |
  167|  2.21k|    a_tok = ssh_tokenize(available_list, ',');
  168|  2.21k|    if (a_tok == NULL) {
  ------------------
  |  Branch (168:9): [True: 0, False: 2.21k]
  ------------------
  169|      0|        return NULL;
  170|      0|    }
  171|       |
  172|  2.21k|    p_tok = ssh_tokenize(preferred_list, ',');
  173|  2.21k|    if (p_tok == NULL) {
  ------------------
  |  Branch (173:9): [True: 0, False: 2.21k]
  ------------------
  174|      0|        goto out;
  175|      0|    }
  176|       |
  177|  2.97k|    for (i = 0; p_tok->tokens[i]; i++) {
  ------------------
  |  Branch (177:17): [True: 2.74k, False: 223]
  ------------------
  178|  8.45k|        for (j = 0; a_tok->tokens[j]; j++) {
  ------------------
  |  Branch (178:21): [True: 7.69k, False: 753]
  ------------------
  179|  7.69k|            if (strcmp(a_tok->tokens[j], p_tok->tokens[i]) == 0) {
  ------------------
  |  Branch (179:17): [True: 1.99k, False: 5.70k]
  ------------------
  180|  1.99k|                ret = strdup(a_tok->tokens[j]);
  181|  1.99k|                goto out;
  182|  1.99k|            }
  183|  7.69k|        }
  184|  2.74k|    }
  185|       |
  186|  2.21k|out:
  187|  2.21k|    ssh_tokens_free(a_tok);
  188|  2.21k|    ssh_tokens_free(p_tok);
  189|  2.21k|    return ret;
  190|  2.21k|}
ssh_find_all_matching:
  208|  1.92k|{
  209|  1.92k|    struct ssh_tokens_st *a_tok = NULL, *p_tok = NULL;
  210|  1.92k|    int i, j;
  211|  1.92k|    char *ret = NULL;
  212|  1.92k|    size_t max, len, pos = 0;
  213|  1.92k|    int match;
  214|       |
  215|  1.92k|    if ((available_list == NULL) || (preferred_list == NULL)) {
  ------------------
  |  Branch (215:9): [True: 0, False: 1.92k]
  |  Branch (215:37): [True: 0, False: 1.92k]
  ------------------
  216|      0|        return NULL;
  217|      0|    }
  218|       |
  219|  1.92k|    max = MAX(strlen(available_list), strlen(preferred_list));
  ------------------
  |  |  371|  1.92k|#define MAX(a,b) ((a) > (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (371:19): [True: 1.60k, False: 319]
  |  |  ------------------
  ------------------
  220|       |
  221|  1.92k|    ret = calloc(1, max + 1);
  222|  1.92k|    if (ret == NULL) {
  ------------------
  |  Branch (222:9): [True: 0, False: 1.92k]
  ------------------
  223|      0|        return NULL;
  224|      0|    }
  225|       |
  226|  1.92k|    a_tok = ssh_tokenize(available_list, ',');
  227|  1.92k|    if (a_tok == NULL) {
  ------------------
  |  Branch (227:9): [True: 0, False: 1.92k]
  ------------------
  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|  1.92k|    p_tok = ssh_tokenize(preferred_list, ',');
  233|  1.92k|    if (p_tok == NULL) {
  ------------------
  |  Branch (233:9): [True: 0, False: 1.92k]
  ------------------
  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|  8.63k|    for (i = 0; p_tok->tokens[i] ; i++) {
  ------------------
  |  Branch (238:17): [True: 6.71k, False: 1.92k]
  ------------------
  239|  44.2k|        for (j = 0; a_tok->tokens[j]; j++) {
  ------------------
  |  Branch (239:21): [True: 37.4k, False: 6.71k]
  ------------------
  240|  37.4k|            match = !strcmp(a_tok->tokens[j], p_tok->tokens[i]);
  241|  37.4k|            if (match) {
  ------------------
  |  Branch (241:17): [True: 2.56k, False: 34.9k]
  ------------------
  242|  2.56k|                if (pos != 0) {
  ------------------
  |  Branch (242:21): [True: 646, False: 1.92k]
  ------------------
  243|    646|                    ret[pos] = ',';
  244|    646|                    pos++;
  245|    646|                }
  246|       |
  247|  2.56k|                len = strlen(a_tok->tokens[j]);
  248|  2.56k|                memcpy(&ret[pos], a_tok->tokens[j], len);
  249|  2.56k|                pos += len;
  250|  2.56k|                ret[pos] = '\0';
  251|  2.56k|            }
  252|  37.4k|        }
  253|  6.71k|    }
  254|       |
  255|  1.92k|    if (ret[0] == '\0') {
  ------------------
  |  Branch (255:9): [True: 0, False: 1.92k]
  ------------------
  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|  1.92k|out:
  260|  1.92k|    ssh_tokens_free(a_tok);
  261|  1.92k|    ssh_tokens_free(p_tok);
  262|  1.92k|    return ret;
  263|  1.92k|}

ssh_get_hmactab:
   74|    218|struct ssh_hmac_struct *ssh_get_hmactab(void) {
   75|    218|  return ssh_hmac_tab;
   76|    218|}
hmac_digest_len:
   78|  18.6k|size_t hmac_digest_len(enum ssh_hmac_e type) {
   79|  18.6k|  switch(type) {
   80|      0|    case SSH_HMAC_SHA1:
  ------------------
  |  Branch (80:5): [True: 0, False: 18.6k]
  ------------------
   81|      0|      return SHA_DIGEST_LEN;
  ------------------
  |  |   44|      0|#define SHA_DIGEST_LEN SHA_DIGEST_LENGTH
  ------------------
   82|      0|    case SSH_HMAC_SHA256:
  ------------------
  |  Branch (82:5): [True: 0, False: 18.6k]
  ------------------
   83|      0|      return SHA256_DIGEST_LEN;
  ------------------
  |  |   45|      0|#define SHA256_DIGEST_LEN SHA256_DIGEST_LENGTH
  ------------------
   84|      0|    case SSH_HMAC_SHA512:
  ------------------
  |  Branch (84:5): [True: 0, False: 18.6k]
  ------------------
   85|      0|      return SHA512_DIGEST_LEN;
  ------------------
  |  |   47|      0|#define SHA512_DIGEST_LEN SHA512_DIGEST_LENGTH
  ------------------
   86|      0|    case SSH_HMAC_MD5:
  ------------------
  |  Branch (86:5): [True: 0, False: 18.6k]
  ------------------
   87|      0|      return MD5_DIGEST_LEN;
  ------------------
  |  |   51|      0|#define MD5_DIGEST_LEN MD5_DIGEST_LENGTH
  ------------------
   88|      0|    case SSH_HMAC_AEAD_POLY1305:
  ------------------
  |  Branch (88:5): [True: 0, False: 18.6k]
  ------------------
   89|      0|      return POLY1305_TAGLEN;
  ------------------
  |  |   37|      0|#define POLY1305_TAGLEN 16
  ------------------
   90|      0|    case SSH_HMAC_AEAD_GCM:
  ------------------
  |  Branch (90:5): [True: 0, False: 18.6k]
  ------------------
   91|      0|      return AES_GCM_TAGLEN;
  ------------------
  |  |   58|      0|#define AES_GCM_TAGLEN 16
  ------------------
   92|  18.6k|    default:
  ------------------
  |  Branch (92:5): [True: 18.6k, False: 0]
  ------------------
   93|  18.6k|      return 0;
   94|  18.6k|  }
   95|  18.6k|}
ssh_cipher_clear:
  124|  3.17k|void ssh_cipher_clear(struct ssh_cipher_struct *cipher){
  125|       |#ifdef HAVE_LIBGCRYPT
  126|       |    unsigned int i;
  127|       |#endif
  128|       |
  129|  3.17k|    if (cipher == NULL) {
  ------------------
  |  Branch (129:9): [True: 2.73k, False: 436]
  ------------------
  130|  2.73k|        return;
  131|  2.73k|    }
  132|       |
  133|       |#ifdef HAVE_LIBGCRYPT
  134|       |    if (cipher->key) {
  135|       |        for (i = 0; i < (cipher->keylen / sizeof(gcry_cipher_hd_t)); i++) {
  136|       |            gcry_cipher_close(cipher->key[i]);
  137|       |        }
  138|       |        SAFE_FREE(cipher->key);
  139|       |    }
  140|       |#endif
  141|       |
  142|    436|    if (cipher->cleanup != NULL) {
  ------------------
  |  Branch (142:9): [True: 0, False: 436]
  ------------------
  143|      0|        cipher->cleanup(cipher);
  144|      0|    }
  145|    436|}
crypto_new:
  153|  1.67k|{
  154|  1.67k|    struct ssh_crypto_struct *crypto = NULL;
  155|       |
  156|  1.67k|    crypto = calloc(1, sizeof(struct ssh_crypto_struct));
  157|  1.67k|    if (crypto == NULL) {
  ------------------
  |  Branch (157:9): [True: 84, False: 1.58k]
  ------------------
  158|     84|        return NULL;
  159|     84|    }
  160|  1.58k|    return crypto;
  161|  1.67k|}
crypto_free:
  164|  2.50k|{
  165|  2.50k|    size_t i;
  166|       |
  167|  2.50k|    if (crypto == NULL) {
  ------------------
  |  Branch (167:9): [True: 915, False: 1.58k]
  ------------------
  168|    915|        return;
  169|    915|    }
  170|       |
  171|  1.58k|    ssh_key_free(crypto->server_pubkey);
  172|       |
  173|  1.58k|    ssh_dh_cleanup(crypto);
  174|  1.58k|    bignum_safe_free(crypto->shared_secret);
  ------------------
  |  |   71|  1.58k|#define bignum_safe_free(num) do { \
  |  |   72|  1.58k|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 185, False: 1.40k]
  |  |  ------------------
  |  |   73|    185|        BN_clear_free((num)); \
  |  |   74|    185|        (num)=NULL; \
  |  |   75|    185|    } \
  |  |   76|  1.58k|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 1.58k]
  |  |  ------------------
  ------------------
  175|  1.58k|#ifdef HAVE_ECDH
  176|  1.58k|    SAFE_FREE(crypto->ecdh_client_pubkey);
  ------------------
  |  |  375|  1.58k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 1.58k]
  |  |  |  Branch (375:71): [Folded, False: 1.58k]
  |  |  ------------------
  ------------------
  177|  1.58k|    SAFE_FREE(crypto->ecdh_server_pubkey);
  ------------------
  |  |  375|  1.58k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 1.58k]
  |  |  |  Branch (375:71): [Folded, False: 1.58k]
  |  |  ------------------
  ------------------
  178|  1.58k|    if (crypto->ecdh_privkey != NULL) {
  ------------------
  |  Branch (178:9): [True: 0, False: 1.58k]
  ------------------
  179|      0|#ifdef HAVE_OPENSSL_ECC
  180|       |#if OPENSSL_VERSION_NUMBER < 0x30000000L
  181|       |        EC_KEY_free(crypto->ecdh_privkey);
  182|       |#else
  183|      0|        EVP_PKEY_free(crypto->ecdh_privkey);
  184|      0|#endif /* OPENSSL_VERSION_NUMBER */
  185|       |#elif defined HAVE_GCRYPT_ECC
  186|       |        gcry_sexp_release(crypto->ecdh_privkey);
  187|       |#elif defined HAVE_LIBMBEDCRYPTO
  188|       |        mbedtls_ecp_keypair_free(crypto->ecdh_privkey);
  189|       |        SAFE_FREE(crypto->ecdh_privkey);
  190|       |#endif /* HAVE_LIBGCRYPT */
  191|      0|        crypto->ecdh_privkey = NULL;
  192|      0|    }
  193|  1.58k|#endif
  194|  1.58k|#ifdef HAVE_LIBCRYPTO
  195|  1.58k|    EVP_PKEY_free(crypto->curve25519_privkey);
  196|       |#elif defined(HAVE_GCRYPT_CURVE25519)
  197|       |    gcry_sexp_release(crypto->curve25519_privkey);
  198|       |#endif
  199|  1.58k|    SAFE_FREE(crypto->dh_server_signature);
  ------------------
  |  |  375|  1.58k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 1.58k]
  |  |  |  Branch (375:71): [Folded, False: 1.58k]
  |  |  ------------------
  ------------------
  200|  1.58k|    if (crypto->session_id != NULL) {
  ------------------
  |  Branch (200:9): [True: 365, False: 1.22k]
  ------------------
  201|    365|        ssh_burn(crypto->session_id, crypto->session_id_len);
  ------------------
  |  |  390|    365|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  202|    365|        SAFE_FREE(crypto->session_id);
  ------------------
  |  |  375|    365|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 365, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 365]
  |  |  ------------------
  ------------------
  203|    365|    }
  204|  1.58k|    if (crypto->secret_hash != NULL) {
  ------------------
  |  Branch (204:9): [True: 185, False: 1.40k]
  ------------------
  205|    185|        ssh_burn(crypto->secret_hash, crypto->digest_len);
  ------------------
  |  |  390|    185|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  206|    185|        SAFE_FREE(crypto->secret_hash);
  ------------------
  |  |  375|    185|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 185, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 185]
  |  |  ------------------
  ------------------
  207|    185|    }
  208|  1.58k|    compress_cleanup(crypto);
  209|  1.58k|    BURN_FREE(crypto->encryptIV, crypto->digest_len);
  ------------------
  |  |  414|  1.58k|    do {                           \
  |  |  415|  1.58k|        if ((x) != NULL) {         \
  |  |  ------------------
  |  |  |  Branch (415:13): [True: 185, False: 1.40k]
  |  |  ------------------
  |  |  416|    185|            burn_free((x), (len)); \
  |  |  417|    185|            (x) = NULL;            \
  |  |  418|    185|        }                          \
  |  |  419|  1.58k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (419:14): [Folded, False: 1.58k]
  |  |  ------------------
  ------------------
  210|  1.58k|    BURN_FREE(crypto->decryptIV, crypto->digest_len);
  ------------------
  |  |  414|  1.58k|    do {                           \
  |  |  415|  1.58k|        if ((x) != NULL) {         \
  |  |  ------------------
  |  |  |  Branch (415:13): [True: 185, False: 1.40k]
  |  |  ------------------
  |  |  416|    185|            burn_free((x), (len)); \
  |  |  417|    185|            (x) = NULL;            \
  |  |  418|    185|        }                          \
  |  |  419|  1.58k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (419:14): [Folded, False: 1.58k]
  |  |  ------------------
  ------------------
  211|  1.58k|    BURN_FREE(crypto->encryptMAC, hmac_digest_len(crypto->out_hmac));
  ------------------
  |  |  414|  1.58k|    do {                           \
  |  |  415|  1.58k|        if ((x) != NULL) {         \
  |  |  ------------------
  |  |  |  Branch (415:13): [True: 185, False: 1.40k]
  |  |  ------------------
  |  |  416|    185|            burn_free((x), (len)); \
  |  |  417|    185|            (x) = NULL;            \
  |  |  418|    185|        }                          \
  |  |  419|  1.58k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (419:14): [Folded, False: 1.58k]
  |  |  ------------------
  ------------------
  212|  1.58k|    BURN_FREE(crypto->decryptMAC, hmac_digest_len(crypto->in_hmac));
  ------------------
  |  |  414|  1.58k|    do {                           \
  |  |  415|  1.58k|        if ((x) != NULL) {         \
  |  |  ------------------
  |  |  |  Branch (415:13): [True: 185, False: 1.40k]
  |  |  ------------------
  |  |  416|    185|            burn_free((x), (len)); \
  |  |  417|    185|            (x) = NULL;            \
  |  |  418|    185|        }                          \
  |  |  419|  1.58k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (419:14): [Folded, False: 1.58k]
  |  |  ------------------
  ------------------
  213|  1.58k|    if (crypto->encryptkey != NULL) {
  ------------------
  |  Branch (213:9): [True: 185, False: 1.40k]
  ------------------
  214|    185|        ssh_burn(crypto->encryptkey, crypto->out_cipher->keysize / 8);
  ------------------
  |  |  390|    185|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  215|    185|        SAFE_FREE(crypto->encryptkey);
  ------------------
  |  |  375|    185|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 185, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 185]
  |  |  ------------------
  ------------------
  216|    185|    }
  217|  1.58k|    if (crypto->decryptkey != NULL) {
  ------------------
  |  Branch (217:9): [True: 185, False: 1.40k]
  ------------------
  218|    185|        ssh_burn(crypto->decryptkey, crypto->in_cipher->keysize / 8);
  ------------------
  |  |  390|    185|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  219|    185|        SAFE_FREE(crypto->decryptkey);
  ------------------
  |  |  375|    185|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 185, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 185]
  |  |  ------------------
  ------------------
  220|    185|    }
  221|       |
  222|  1.58k|    cipher_free(crypto->in_cipher);
  223|  1.58k|    cipher_free(crypto->out_cipher);
  224|       |
  225|  17.4k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  17.4k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (225:17): [True: 15.8k, False: 1.58k]
  ------------------
  226|  15.8k|        SAFE_FREE(crypto->client_kex.methods[i]);
  ------------------
  |  |  375|  15.8k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 2.49k, False: 13.3k]
  |  |  |  Branch (375:71): [Folded, False: 15.8k]
  |  |  ------------------
  ------------------
  227|  15.8k|        SAFE_FREE(crypto->server_kex.methods[i]);
  ------------------
  |  |  375|  15.8k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 3.23k, False: 12.6k]
  |  |  |  Branch (375:71): [Folded, False: 15.8k]
  |  |  ------------------
  ------------------
  228|  15.8k|        SAFE_FREE(crypto->kex_methods[i]);
  ------------------
  |  |  375|  15.8k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 2.18k, False: 13.6k]
  |  |  |  Branch (375:71): [Folded, False: 15.8k]
  |  |  ------------------
  ------------------
  229|  15.8k|    }
  230|       |
  231|       |#ifdef HAVE_OPENSSL_MLKEM
  232|       |    EVP_PKEY_free(crypto->mlkem_privkey);
  233|       |#else
  234|  1.58k|    if (crypto->mlkem_privkey != NULL) {
  ------------------
  |  Branch (234:9): [True: 0, False: 1.58k]
  ------------------
  235|      0|        ssh_burn(crypto->mlkem_privkey, crypto->mlkem_privkey_len);
  ------------------
  |  |  390|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  236|      0|        SAFE_FREE(crypto->mlkem_privkey);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  237|      0|        crypto->mlkem_privkey_len = 0;
  238|      0|    }
  239|  1.58k|#endif
  240|  1.58k|    ssh_string_burn(crypto->hybrid_shared_secret);
  241|  1.58k|    ssh_string_free(crypto->mlkem_client_pubkey);
  242|  1.58k|    ssh_string_free(crypto->mlkem_ciphertext);
  243|  1.58k|    ssh_string_free(crypto->hybrid_client_init);
  244|  1.58k|    ssh_string_free(crypto->hybrid_server_reply);
  245|  1.58k|    ssh_string_free(crypto->hybrid_shared_secret);
  246|       |
  247|  1.58k|    ssh_burn(crypto, sizeof(struct ssh_crypto_struct));
  ------------------
  |  |  390|  1.58k|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  248|       |
  249|       |    SAFE_FREE(crypto);
  ------------------
  |  |  375|  1.58k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 1.58k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 1.58k]
  |  |  ------------------
  ------------------
  250|  1.58k|}
crypt_set_algorithms_server:
  434|    218|int crypt_set_algorithms_server(ssh_session session){
  435|    218|    const char *method = NULL;
  436|    218|    uint8_t i = 0;
  437|    218|    struct ssh_cipher_struct *ssh_ciphertab=ssh_get_ciphertab();
  438|    218|    struct ssh_hmac_struct   *ssh_hmactab=ssh_get_hmactab();
  439|    218|    int cmp;
  440|    218|    int rc;
  441|       |
  442|    218|    if (session == NULL) {
  ------------------
  |  Branch (442:9): [True: 0, False: 218]
  ------------------
  443|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  444|      0|    }
  445|       |
  446|       |    /*
  447|       |     * We must scan the kex entries to find crypto algorithms and set their
  448|       |     * appropriate structure
  449|       |     */
  450|       |    /* out */
  451|    218|    method = session->next_crypto->kex_methods[SSH_CRYPT_S_C];
  452|       |
  453|  2.39k|    for (i = 0; ssh_ciphertab[i].name != NULL; i++) {
  ------------------
  |  Branch (453:17): [True: 2.39k, False: 0]
  ------------------
  454|  2.39k|        cmp = strcmp(method, ssh_ciphertab[i].name);
  455|  2.39k|        if (cmp == 0) {
  ------------------
  |  Branch (455:13): [True: 218, False: 2.18k]
  ------------------
  456|    218|          break;
  457|    218|        }
  458|  2.39k|    }
  459|       |
  460|    218|    if (ssh_ciphertab[i].name == NULL) {
  ------------------
  |  Branch (460:9): [True: 0, False: 218]
  ------------------
  461|      0|        ssh_set_error(session,SSH_FATAL,"crypt_set_algorithms_server : "
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  462|      0|                "no crypto algorithm function found for %s",method);
  463|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  464|      0|    }
  465|    218|    SSH_LOG(SSH_LOG_PACKET,"Set output algorithm %s",method);
  ------------------
  |  |  283|    218|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  466|       |
  467|    218|    session->next_crypto->out_cipher = cipher_new(i);
  468|    218|    if (session->next_crypto->out_cipher == NULL) {
  ------------------
  |  Branch (468:9): [True: 0, False: 218]
  ------------------
  469|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  470|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  471|      0|    }
  472|       |
  473|    218|    if (session->next_crypto->out_cipher->aead_encrypt != NULL){
  ------------------
  |  Branch (473:9): [True: 0, False: 218]
  ------------------
  474|       |        /* this cipher has integrated MAC */
  475|      0|        if (session->next_crypto->out_cipher->ciphertype == SSH_AEAD_CHACHA20_POLY1305) {
  ------------------
  |  Branch (475:13): [True: 0, False: 0]
  ------------------
  476|      0|            method = "aead-poly1305";
  477|      0|        } else {
  478|      0|            method = "aead-gcm";
  479|      0|        }
  480|    218|    } else {
  481|       |        /* we must scan the kex entries to find hmac algorithms and set their appropriate structure */
  482|       |        /* out */
  483|    218|        method = session->next_crypto->kex_methods[SSH_MAC_S_C];
  484|    218|    }
  485|       |    /* HMAC algorithm selection */
  486|       |
  487|  2.39k|    for (i = 0; ssh_hmactab[i].name != NULL; i++) {
  ------------------
  |  Branch (487:17): [True: 2.39k, False: 0]
  ------------------
  488|  2.39k|        cmp = strcmp(method, ssh_hmactab[i].name);
  489|  2.39k|        if (cmp == 0) {
  ------------------
  |  Branch (489:13): [True: 218, False: 2.18k]
  ------------------
  490|    218|            break;
  491|    218|        }
  492|  2.39k|    }
  493|       |
  494|    218|    if (ssh_hmactab[i].name == NULL) {
  ------------------
  |  Branch (494:9): [True: 0, False: 218]
  ------------------
  495|      0|      ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  496|      0|          "crypt_set_algorithms_server: no hmac algorithm function found for %s",
  497|      0|          method);
  498|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  499|      0|    }
  500|    218|    SSH_LOG(SSH_LOG_PACKET, "Set HMAC output algorithm to %s", method);
  ------------------
  |  |  283|    218|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  501|       |
  502|    218|    session->next_crypto->out_hmac = ssh_hmactab[i].hmac_type;
  503|    218|    session->next_crypto->out_hmac_etm = ssh_hmactab[i].etm;
  504|       |
  505|       |    /* in */
  506|    218|    method = session->next_crypto->kex_methods[SSH_CRYPT_C_S];
  507|       |
  508|  2.39k|    for (i = 0; ssh_ciphertab[i].name; i++) {
  ------------------
  |  Branch (508:17): [True: 2.39k, False: 0]
  ------------------
  509|  2.39k|        cmp = strcmp(method, ssh_ciphertab[i].name);
  510|  2.39k|        if (cmp == 0) {
  ------------------
  |  Branch (510:13): [True: 218, False: 2.18k]
  ------------------
  511|    218|            break;
  512|    218|        }
  513|  2.39k|    }
  514|       |
  515|    218|    if (ssh_ciphertab[i].name == NULL) {
  ------------------
  |  Branch (515:9): [True: 0, False: 218]
  ------------------
  516|      0|        ssh_set_error(session,SSH_FATAL,"Crypt_set_algorithms_server :"
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  517|      0|                "no crypto algorithm function found for %s",method);
  518|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  519|      0|    }
  520|    218|    SSH_LOG(SSH_LOG_PACKET,"Set input algorithm %s",method);
  ------------------
  |  |  283|    218|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  521|       |
  522|    218|    session->next_crypto->in_cipher = cipher_new(i);
  523|    218|    if (session->next_crypto->in_cipher == NULL) {
  ------------------
  |  Branch (523:9): [True: 0, False: 218]
  ------------------
  524|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  525|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  526|      0|    }
  527|       |
  528|    218|    if (session->next_crypto->in_cipher->aead_encrypt != NULL){
  ------------------
  |  Branch (528:9): [True: 0, False: 218]
  ------------------
  529|       |        /* this cipher has integrated MAC */
  530|      0|        if (session->next_crypto->in_cipher->ciphertype == SSH_AEAD_CHACHA20_POLY1305) {
  ------------------
  |  Branch (530:13): [True: 0, False: 0]
  ------------------
  531|      0|            method = "aead-poly1305";
  532|      0|        } else {
  533|      0|            method = "aead-gcm";
  534|      0|        }
  535|    218|    } else {
  536|       |        /* we must scan the kex entries to find hmac algorithms and set their appropriate structure */
  537|    218|        method = session->next_crypto->kex_methods[SSH_MAC_C_S];
  538|    218|    }
  539|       |
  540|  2.39k|    for (i = 0; ssh_hmactab[i].name != NULL; i++) {
  ------------------
  |  Branch (540:17): [True: 2.39k, False: 0]
  ------------------
  541|  2.39k|        cmp = strcmp(method, ssh_hmactab[i].name);
  542|  2.39k|        if (cmp == 0) {
  ------------------
  |  Branch (542:13): [True: 218, False: 2.18k]
  ------------------
  543|    218|            break;
  544|    218|        }
  545|  2.39k|    }
  546|       |
  547|    218|    if (ssh_hmactab[i].name == NULL) {
  ------------------
  |  Branch (547:9): [True: 0, False: 218]
  ------------------
  548|      0|      ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  549|      0|          "crypt_set_algorithms_server: no hmac algorithm function found for %s",
  550|      0|          method);
  551|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  552|      0|    }
  553|    218|    SSH_LOG(SSH_LOG_PACKET, "Set HMAC input algorithm to %s", method);
  ------------------
  |  |  283|    218|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  554|       |
  555|    218|    session->next_crypto->in_hmac = ssh_hmactab[i].hmac_type;
  556|    218|    session->next_crypto->in_hmac_etm = ssh_hmactab[i].etm;
  557|       |
  558|       |    /* compression */
  559|    218|    method = session->next_crypto->kex_methods[SSH_COMP_C_S];
  560|    218|    cmp = strcmp(method, "zlib");
  561|    218|    if (cmp == 0) {
  ------------------
  |  Branch (561:9): [True: 0, False: 218]
  ------------------
  562|      0|        SSH_LOG(SSH_LOG_PACKET, "enabling C->S compression");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  563|      0|        compression_enable(session, SSH_DIRECTION_IN, false);
  564|      0|    }
  565|    218|    cmp = strcmp(method, "zlib@openssh.com");
  566|    218|    if (cmp == 0) {
  ------------------
  |  Branch (566:9): [True: 0, False: 218]
  ------------------
  567|      0|        SSH_LOG(SSH_LOG_PACKET, "enabling C->S delayed compression");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  568|      0|        compression_enable(session, SSH_DIRECTION_IN, true);
  569|      0|    }
  570|       |
  571|    218|    method = session->next_crypto->kex_methods[SSH_COMP_S_C];
  572|    218|    cmp = strcmp(method, "zlib");
  573|    218|    if (cmp == 0) {
  ------------------
  |  Branch (573:9): [True: 0, False: 218]
  ------------------
  574|      0|        SSH_LOG(SSH_LOG_PACKET, "enabling S->C compression");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  575|      0|        compression_enable(session, SSH_DIRECTION_OUT, false);
  576|      0|    }
  577|    218|    cmp = strcmp(method, "zlib@openssh.com");
  578|    218|    if (cmp == 0) {
  ------------------
  |  Branch (578:9): [True: 0, False: 218]
  ------------------
  579|      0|        SSH_LOG(SSH_LOG_PACKET, "enabling S->C delayed compression");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  580|      0|        compression_enable(session, SSH_DIRECTION_OUT, true);
  581|      0|    }
  582|       |
  583|    218|    method = session->next_crypto->kex_methods[SSH_HOSTKEYS];
  584|       |
  585|       |    /* For GSSAPI key exchange, hostkey algorithm may be "null" */
  586|    218|    if (strcmp(method, "null") == 0) {
  ------------------
  |  Branch (586:9): [True: 0, False: 218]
  ------------------
  587|      0|        session->srv.hostkey = SSH_KEYTYPE_UNKNOWN;
  588|      0|        session->srv.hostkey_digest = SSH_DIGEST_AUTO;
  589|    218|    } else {
  590|    218|        rc = ssh_key_type_and_hash_from_signature_name(
  591|    218|            method,
  592|    218|            &session->srv.hostkey,
  593|    218|            &session->srv.hostkey_digest);
  594|    218|        if (rc != SSH_OK) {
  ------------------
  |  |  315|    218|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (594:13): [True: 0, False: 218]
  ------------------
  595|      0|            ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  596|      0|                          SSH_FATAL,
  597|      0|                          "unknown hostkey algorithm %s",
  598|      0|                          method);
  599|      0|            return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  600|      0|        }
  601|    218|    }
  602|       |
  603|       |    /* setup DH key exchange type */
  604|    218|    switch (session->next_crypto->kex_type) {
  605|      0|    case SSH_KEX_DH_GROUP1_SHA1:
  ------------------
  |  Branch (605:5): [True: 0, False: 218]
  ------------------
  606|      0|    case SSH_KEX_DH_GROUP14_SHA1:
  ------------------
  |  Branch (606:5): [True: 0, False: 218]
  ------------------
  607|      3|    case SSH_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (607:5): [True: 3, False: 215]
  ------------------
  608|      3|    case SSH_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (608:5): [True: 0, False: 218]
  ------------------
  609|      3|    case SSH_KEX_DH_GROUP18_SHA512:
  ------------------
  |  Branch (609:5): [True: 0, False: 218]
  ------------------
  610|      3|      ssh_server_dh_init(session);
  611|      3|      break;
  612|       |#ifdef WITH_GSSAPI
  613|       |    case SSH_GSS_KEX_DH_GROUP14_SHA256:
  614|       |    case SSH_GSS_KEX_DH_GROUP16_SHA512:
  615|       |    case SSH_GSS_KEX_ECDH_NISTP256_SHA256:
  616|       |    case SSH_GSS_KEX_CURVE25519_SHA256:
  617|       |        ssh_server_gss_kex_init(session);
  618|       |        break;
  619|       |#endif /* WITH_GSSAPI */
  620|      0|#ifdef WITH_GEX
  621|      0|    case SSH_KEX_DH_GEX_SHA1:
  ------------------
  |  Branch (621:5): [True: 0, False: 218]
  ------------------
  622|     23|    case SSH_KEX_DH_GEX_SHA256:
  ------------------
  |  Branch (622:5): [True: 23, False: 195]
  ------------------
  623|     23|      ssh_server_dhgex_init(session);
  624|     23|      break;
  625|      0|#endif /* WITH_GEX */
  626|      0|#ifdef HAVE_ECDH
  627|      0|    case SSH_KEX_ECDH_SHA2_NISTP256:
  ------------------
  |  Branch (627:5): [True: 0, False: 218]
  ------------------
  628|      0|    case SSH_KEX_ECDH_SHA2_NISTP384:
  ------------------
  |  Branch (628:5): [True: 0, False: 218]
  ------------------
  629|      0|    case SSH_KEX_ECDH_SHA2_NISTP521:
  ------------------
  |  Branch (629:5): [True: 0, False: 218]
  ------------------
  630|      0|      ssh_server_ecdh_init(session);
  631|      0|      break;
  632|      0|#endif
  633|      0|#ifdef HAVE_CURVE25519
  634|    192|    case SSH_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (634:5): [True: 192, False: 26]
  ------------------
  635|    192|    case SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG:
  ------------------
  |  Branch (635:5): [True: 0, False: 218]
  ------------------
  636|    192|        ssh_server_curve25519_init(session);
  637|    192|        break;
  638|      0|#endif
  639|      0|#ifdef HAVE_SNTRUP761
  640|      0|    case SSH_KEX_SNTRUP761X25519_SHA512:
  ------------------
  |  Branch (640:5): [True: 0, False: 218]
  ------------------
  641|      0|    case SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM:
  ------------------
  |  Branch (641:5): [True: 0, False: 218]
  ------------------
  642|      0|        ssh_server_sntrup761x25519_init(session);
  643|      0|        break;
  644|      0|#endif
  645|      0|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (645:5): [True: 0, False: 218]
  ------------------
  646|      0|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (646:5): [True: 0, False: 218]
  ------------------
  647|       |#ifdef HAVE_MLKEM1024
  648|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
  649|       |#endif
  650|      0|        ssh_server_hybrid_mlkem_init(session);
  651|      0|        break;
  652|      0|    default:
  ------------------
  |  Branch (652:5): [True: 0, False: 218]
  ------------------
  653|      0|        ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  654|      0|                      SSH_FATAL,
  655|      0|                      "crypt_set_algorithms_server: could not find init "
  656|      0|                      "handler for kex type %d",
  657|      0|                      session->next_crypto->kex_type);
  658|      0|        return SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  659|    218|    }
  660|    218|    return SSH_OK;
  ------------------
  |  |  315|    218|#define SSH_OK 0     /* No error */
  ------------------
  661|    218|}
wrapper.c:cipher_free:
  147|  3.17k|static void cipher_free(struct ssh_cipher_struct *cipher) {
  148|  3.17k|  ssh_cipher_clear(cipher);
  149|       |  SAFE_FREE(cipher);
  ------------------
  |  |  375|  3.17k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 436, False: 2.73k]
  |  |  |  Branch (375:71): [Folded, False: 3.17k]
  |  |  ------------------
  ------------------
  150|  3.17k|}
wrapper.c:cipher_new:
  110|    436|static struct ssh_cipher_struct *cipher_new(uint8_t offset) {
  111|    436|  struct ssh_cipher_struct *cipher = NULL;
  112|       |
  113|    436|  cipher = malloc(sizeof(struct ssh_cipher_struct));
  114|    436|  if (cipher == NULL) {
  ------------------
  |  Branch (114:7): [True: 0, False: 436]
  ------------------
  115|      0|    return NULL;
  116|      0|  }
  117|       |
  118|       |  /* note the memcpy will copy the pointers : so, you shouldn't free them */
  119|    436|  memcpy(cipher, &ssh_get_ciphertab()[offset], sizeof(*cipher));
  120|       |
  121|    436|  return cipher;
  122|    436|}

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|}
recv:
  289|  1.66k|{
  290|  1.66k|    if (nalloc_fail(count, "recv")) {
  ------------------
  |  Branch (290:9): [True: 0, False: 1.66k]
  ------------------
  291|      0|        errno = EIO;
  292|      0|        return -1;
  293|      0|    }
  294|  1.66k|    return nalloc_recv(fd, buf, count, flags);
  ------------------
  |  |  265|  1.66k|#define nalloc_recv(f, b, s, x) __recv(f, b, s, x)
  ------------------
  295|  1.66k|}
send:
  298|  2.00k|{
  299|  2.00k|    if (nalloc_fail(count, "send")) {
  ------------------
  |  Branch (299:9): [True: 0, False: 2.00k]
  ------------------
  300|      0|        errno = EIO;
  301|      0|        return -1;
  302|      0|    }
  303|  2.00k|    return nalloc_send(fd, buf, count, flags);
  ------------------
  |  |  266|  2.00k|#define nalloc_send(f, b, s, x) __send(f, b, s, x)
  ------------------
  304|  2.00k|}
calloc:
  307|  65.9k|{
  308|  65.9k|    if (nalloc_fail(size, "calloc")) {
  ------------------
  |  Branch (308:9): [True: 624, False: 65.3k]
  ------------------
  309|    624|        errno = ENOMEM;
  310|    624|        return NULL;
  311|    624|    }
  312|  65.3k|    return nalloc_calloc(nmemb, size);
  ------------------
  |  |  259|  65.3k|#define nalloc_calloc(s, n)          __libc_calloc(s, n)
  ------------------
  313|  65.9k|}
malloc:
  316|  1.01M|{
  317|  1.01M|    if (nalloc_fail(size, "malloc")) {
  ------------------
  |  Branch (317:9): [True: 0, False: 1.01M]
  ------------------
  318|      0|        errno = ENOMEM;
  319|      0|        return NULL;
  320|      0|    }
  321|  1.01M|    return nalloc_malloc(size);
  ------------------
  |  |  258|  1.01M|#define nalloc_malloc(s)             __libc_malloc(s)
  ------------------
  322|  1.01M|}
realloc:
  325|  22.8k|{
  326|  22.8k|    if (nalloc_fail(size, "realloc")) {
  ------------------
  |  Branch (326:9): [True: 15, False: 22.8k]
  ------------------
  327|     15|        errno = ENOMEM;
  328|     15|        return NULL;
  329|     15|    }
  330|  22.8k|    return nalloc_realloc(ptr, size);
  ------------------
  |  |  260|  22.8k|#define nalloc_realloc(p, s)         __libc_realloc(p, s)
  ------------------
  331|  22.8k|}
ssh_server_fuzzer.c:nalloc_fail:
  194|  1.11M|{
  195|       |    // do not fail before thread init
  196|  1.11M|    if (nalloc_runs == 0) {
  ------------------
  |  Branch (196:9): [True: 11.9k, False: 1.09M]
  ------------------
  197|  11.9k|        return false;
  198|  11.9k|    }
  199|  1.09M|    if (__sync_fetch_and_add(&nalloc_running, 1) != 1) {
  ------------------
  |  Branch (199:9): [True: 11.8k, False: 1.08M]
  ------------------
  200|       |        // do not fail allocations outside of fuzzer input
  201|       |        // and do not fail inside of this function
  202|  11.8k|        __sync_fetch_and_sub(&nalloc_running, 1);
  203|  11.8k|        return false;
  204|  11.8k|    }
  205|  1.08M|    nalloc_random_update((uint8_t)size);
  206|  1.08M|    if (size >= 0x100) {
  ------------------
  |  Branch (206:9): [True: 46.4k, False: 1.04M]
  ------------------
  207|  46.4k|        nalloc_random_update((uint8_t)(size >> 8));
  208|  46.4k|        if (size >= 0x10000) {
  ------------------
  |  Branch (208:13): [True: 87, False: 46.3k]
  ------------------
  209|     87|            nalloc_random_update((uint8_t)(size >> 16));
  210|       |            // bigger may already fail or oom
  211|     87|        }
  212|  46.4k|    }
  213|  1.08M|    if (((nalloc_random_state ^ nalloc_magic) & nalloc_bitmask) == 0) {
  ------------------
  |  Branch (213:9): [True: 639, False: 1.08M]
  ------------------
  214|    639|        if (nalloc_backtrace_exclude(size, op)) {
  ------------------
  |  Branch (214:13): [True: 0, False: 639]
  ------------------
  215|      0|            __sync_fetch_and_sub(&nalloc_running, 1);
  216|      0|            return false;
  217|      0|        }
  218|    639|        __sync_fetch_and_sub(&nalloc_running, 1);
  219|    639|        return true;
  220|    639|    }
  221|  1.08M|    __sync_fetch_and_sub(&nalloc_running, 1);
  222|       |    return false;
  223|  1.08M|}
ssh_server_fuzzer.c:nalloc_random_update:
  143|  15.4M|{
  144|  15.4M|    nalloc_random_state =
  145|  15.4M|        ((uint32_t)((uint32_t)nalloc_random_state << 8)) ^
  146|  15.4M|        nalloc_crc32_table[((nalloc_random_state >> 24) ^ b) & 0xFF];
  147|  15.4M|}
ssh_server_fuzzer.c:nalloc_backtrace_exclude:
  181|    639|{
  182|    639|    if (nalloc_verbose) {
  ------------------
  |  Branch (182:9): [True: 0, False: 639]
  ------------------
  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|    639|}
ssh_server_fuzzer.c:nalloc_start:
  151|  1.29k|{
  152|  1.29k|    if (nalloc_random_bitmask) {
  ------------------
  |  Branch (152:9): [True: 1.29k, False: 0]
  ------------------
  153|  1.29k|        if (nalloc_random_state & 0x10) {
  ------------------
  |  Branch (153:13): [True: 660, False: 639]
  ------------------
  154|    660|            nalloc_bitmask = 0xFFFFFFFF;
  155|    660|        } else {
  156|    639|            nalloc_bitmask = 1 << (5 + (nalloc_random_state & 0xF));
  157|    639|        }
  158|  1.29k|    } else if (nalloc_bitmask == 0) {
  ------------------
  |  Branch (158:16): [True: 0, False: 0]
  ------------------
  159|       |        // nalloc disabled
  160|      0|        return 2;
  161|      0|    }
  162|  1.29k|    nalloc_random_state = 0;
  163|  14.3M|    for (size_t i = 0; i < size; i++) {
  ------------------
  |  Branch (163:24): [True: 14.3M, False: 1.29k]
  ------------------
  164|  14.3M|        nalloc_random_update(data[i]);
  165|  14.3M|    }
  166|  1.29k|    if (__sync_fetch_and_add(&nalloc_running, 1)) {
  ------------------
  |  Branch (166:9): [True: 0, False: 1.29k]
  ------------------
  167|      0|        __sync_fetch_and_sub(&nalloc_running, 1);
  168|      0|        return 0;
  169|      0|    }
  170|  1.29k|    nalloc_runs++;
  171|  1.29k|    return 1;
  172|  1.29k|}
ssh_server_fuzzer.c:nalloc_end:
  176|  1.29k|{
  177|  1.29k|    __sync_fetch_and_sub(&nalloc_running, 1);
  178|  1.29k|}

LLVMFuzzerInitialize:
   79|      2|{
   80|      2|    (void)argc;
   81|       |
   82|      2|    nalloc_init(*argv[0]);
   83|       |
   84|      2|    ssh_init();
   85|       |
   86|      2|    atexit(_fuzz_finalize);
   87|       |
   88|      2|    return 0;
   89|      2|}
LLVMFuzzerTestOneInput:
  142|  1.30k|{
  143|  1.30k|    int socket_fds[2] = {-1, -1};
  144|  1.30k|    ssize_t nwritten;
  145|  1.30k|    bool no = false;
  146|  1.30k|    const char *env = NULL;
  147|  1.30k|    int rc;
  148|  1.30k|    ssh_bind sshbind = NULL;
  149|  1.30k|    ssh_session session = NULL;
  150|  1.30k|    ssh_event event = NULL;
  151|       |
  152|       |    /* Our struct holding information about the session. */
  153|  1.30k|    struct session_data_struct sdata = {
  154|  1.30k|        .channel       = NULL,
  155|  1.30k|        .auth_attempts = 0,
  156|  1.30k|        .authenticated = false,
  157|  1.30k|    };
  158|       |
  159|  1.30k|    struct ssh_server_callbacks_struct server_cb = {
  160|  1.30k|        .userdata = &sdata,
  161|  1.30k|        .auth_none_function = auth_none,
  162|  1.30k|        .channel_open_request_session_function = channel_open,
  163|  1.30k|    };
  164|       |
  165|       |    /* This is the maximum that can be handled by the socket buffer before the
  166|       |     * other side will read some data. Other option would be feeding the socket
  167|       |     * from different thread which would not mind if it would be blocked, but I
  168|       |     * believe all the important inputs should fit into this size */
  169|  1.30k|    if (size > 219264) {
  ------------------
  |  Branch (169:9): [True: 3, False: 1.29k]
  ------------------
  170|      3|        return -1;
  171|      3|    }
  172|       |
  173|       |    /* Write SSH RSA host key to disk */
  174|  1.29k|    rc = write_rsa_hostkey("/tmp/libssh_fuzzer_private_key");
  175|  1.29k|    assert(rc == 0);
  ------------------
  |  Branch (175:5): [True: 0, False: 1.29k]
  |  Branch (175:5): [True: 1.29k, False: 0]
  ------------------
  176|       |
  177|       |    /* Set up the socket to send data */
  178|  1.29k|    rc = socketpair(AF_UNIX, SOCK_STREAM, 0, socket_fds);
  179|  1.29k|    assert(rc == 0);
  ------------------
  |  Branch (179:5): [True: 0, False: 1.29k]
  |  Branch (179:5): [True: 1.29k, False: 0]
  ------------------
  180|       |
  181|  1.29k|    nwritten = send(socket_fds[1], data, size, 0);
  182|  1.29k|    assert((size_t)nwritten == size);
  ------------------
  |  Branch (182:5): [True: 0, False: 1.29k]
  |  Branch (182:5): [True: 1.29k, False: 0]
  ------------------
  183|       |
  184|  1.29k|    rc = shutdown(socket_fds[1], SHUT_WR);
  185|  1.29k|    assert(rc == 0);
  ------------------
  |  Branch (185:5): [True: 0, False: 1.29k]
  |  Branch (185:5): [True: 1.29k, False: 0]
  ------------------
  186|       |
  187|  1.29k|    assert(nalloc_start(data, size) > 0);
  ------------------
  |  Branch (187:5): [True: 0, False: 1.29k]
  |  Branch (187:5): [True: 1.29k, False: 0]
  ------------------
  188|       |
  189|       |    /* Set up the libssh server */
  190|  1.29k|    sshbind = ssh_bind_new();
  191|  1.29k|    if (sshbind == NULL) {
  ------------------
  |  Branch (191:9): [True: 303, False: 996]
  ------------------
  192|    303|        goto out;
  193|    303|    }
  194|       |
  195|    996|    session = ssh_new();
  196|    996|    if (session == NULL) {
  ------------------
  |  Branch (196:9): [True: 336, False: 660]
  ------------------
  197|    336|        goto out;
  198|    336|    }
  199|       |
  200|    660|    env = getenv("LIBSSH_VERBOSITY");
  201|    660|    if (env != NULL && strlen(env) > 0) {
  ------------------
  |  Branch (201:9): [True: 0, False: 660]
  |  Branch (201:24): [True: 0, False: 0]
  ------------------
  202|      0|        rc = ssh_bind_options_set(sshbind,
  203|      0|                                  SSH_BIND_OPTIONS_LOG_VERBOSITY_STR,
  204|      0|                                  env);
  205|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  315|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (205:13): [True: 0, False: 0]
  ------------------
  206|      0|            goto out;
  207|      0|        }
  208|      0|    }
  209|    660|    rc = ssh_bind_options_set(sshbind,
  210|    660|                              SSH_BIND_OPTIONS_HOSTKEY,
  211|    660|                              "/tmp/libssh_fuzzer_private_key");
  212|    660|    if (rc != SSH_OK) {
  ------------------
  |  |  315|    660|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (212:9): [True: 341, False: 319]
  ------------------
  213|    341|        goto out;
  214|    341|    }
  215|    319|    rc = ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_CIPHERS_C_S, "none");
  216|    319|    if (rc != SSH_OK) {
  ------------------
  |  |  315|    319|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (216:9): [True: 0, False: 319]
  ------------------
  217|      0|        goto out;
  218|      0|    }
  219|    319|    rc = ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_CIPHERS_S_C, "none");
  220|    319|    if (rc != SSH_OK) {
  ------------------
  |  |  315|    319|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (220:9): [True: 0, False: 319]
  ------------------
  221|      0|        goto out;
  222|      0|    }
  223|    319|    rc = ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HMAC_C_S, "none");
  224|    319|    if (rc != SSH_OK) {
  ------------------
  |  |  315|    319|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (224:9): [True: 0, False: 319]
  ------------------
  225|      0|        goto out;
  226|      0|    }
  227|    319|    rc = ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HMAC_S_C, "none");
  228|    319|    if (rc != SSH_OK) {
  ------------------
  |  |  315|    319|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (228:9): [True: 0, False: 319]
  ------------------
  229|      0|        goto out;
  230|      0|    }
  231|    319|    rc = ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_PROCESS_CONFIG, &no);
  232|    319|    if (rc != SSH_OK) {
  ------------------
  |  |  315|    319|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (232:9): [True: 0, False: 319]
  ------------------
  233|      0|        goto out;
  234|      0|    }
  235|       |
  236|    319|    ssh_set_auth_methods(session, SSH_AUTH_METHOD_NONE);
  ------------------
  |  |  155|    319|#define SSH_AUTH_METHOD_NONE         0x0001u
  ------------------
  237|       |
  238|    319|    ssh_callbacks_init(&server_cb);
  ------------------
  |  |  535|    319|#define ssh_callbacks_init(p) do {\
  |  |  536|    319|	(p)->size=sizeof(*(p)); \
  |  |  537|    319|} while(0);
  |  |  ------------------
  |  |  |  Branch (537:9): [Folded, False: 319]
  |  |  ------------------
  ------------------
  239|    319|    ssh_set_server_callbacks(session, &server_cb);
  240|       |
  241|    319|    rc = ssh_bind_accept_fd(sshbind, session, socket_fds[0]);
  242|    319|    if (rc != SSH_OK) {
  ------------------
  |  |  315|    319|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (242:9): [True: 0, False: 319]
  ------------------
  243|      0|        goto out;
  244|      0|    }
  245|       |
  246|    319|    event = ssh_event_new();
  247|    319|    if (event == NULL) {
  ------------------
  |  Branch (247:9): [True: 0, False: 319]
  ------------------
  248|      0|        goto out;
  249|      0|    }
  250|       |
  251|    319|    if (ssh_handle_key_exchange(session) == SSH_OK) {
  ------------------
  |  |  315|    319|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (251:9): [True: 77, False: 242]
  ------------------
  252|     77|        ssh_event_add_session(event, session);
  253|       |
  254|     77|        size_t n = 0;
  255|    827|        while (sdata.authenticated == false || sdata.channel == NULL) {
  ------------------
  |  Branch (255:16): [True: 802, False: 25]
  |  Branch (255:48): [True: 22, False: 3]
  ------------------
  256|    824|            if (sdata.auth_attempts >= 3 || n >= 100) {
  ------------------
  |  Branch (256:17): [True: 0, False: 824]
  |  Branch (256:45): [True: 0, False: 824]
  ------------------
  257|      0|                break;
  258|      0|            }
  259|       |
  260|    824|            if (ssh_event_dopoll(event, 100) == SSH_ERROR) {
  ------------------
  |  |  316|    824|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (260:17): [True: 74, False: 750]
  ------------------
  261|     74|                break;
  262|     74|            }
  263|       |
  264|    750|            n++;
  265|    750|        }
  266|     77|    }
  267|       |
  268|  1.29k|out:
  269|  1.29k|    nalloc_end();
  270|       |
  271|  1.29k|    ssh_event_free(event);
  272|       |
  273|  1.29k|    close(socket_fds[0]);
  274|  1.29k|    close(socket_fds[1]);
  275|       |
  276|  1.29k|    ssh_disconnect(session);
  277|  1.29k|    ssh_free(session);
  278|  1.29k|    ssh_bind_free(sshbind);
  279|       |
  280|  1.29k|    return 0;
  281|    319|}
ssh_server_fuzzer.c:_fuzz_finalize:
   74|      2|{
   75|      2|    ssh_finalize();
   76|      2|}
ssh_server_fuzzer.c:auth_none:
   92|     69|{
   93|     69|    struct session_data_struct *sdata =
   94|     69|        (struct session_data_struct *)userdata;
   95|       |
   96|     69|    (void)session;
   97|     69|    (void)user;
   98|       |
   99|     69|    if (sdata->auth_attempts > 0) {
  ------------------
  |  Branch (99:9): [True: 33, False: 36]
  ------------------
  100|     33|        sdata->authenticated = true;
  101|     33|    }
  102|     69|    sdata->auth_attempts++;
  103|       |
  104|     69|    if (!sdata->authenticated) {
  ------------------
  |  Branch (104:9): [True: 36, False: 33]
  ------------------
  105|     36|        return SSH_AUTH_PARTIAL;
  106|     36|    }
  107|       |
  108|     33|    return SSH_AUTH_SUCCESS;
  109|     69|}
ssh_server_fuzzer.c:channel_open:
  112|     17|{
  113|     17|    struct session_data_struct *sdata =
  114|     17|        (struct session_data_struct *)userdata;
  115|       |
  116|     17|    sdata->channel = ssh_channel_new(session);
  117|       |
  118|     17|    return sdata->channel;
  119|     17|}
ssh_server_fuzzer.c:write_rsa_hostkey:
  122|  1.29k|{
  123|  1.29k|    FILE *fp = NULL;
  124|  1.29k|    size_t nwritten;
  125|       |
  126|  1.29k|    fp = fopen(rsakey_path, "wb");
  127|  1.29k|    if (fp == NULL) {
  ------------------
  |  Branch (127:9): [True: 0, False: 1.29k]
  ------------------
  128|      0|        return -1;
  129|      0|    }
  130|       |
  131|  1.29k|    nwritten = fwrite(kRSAPrivateKeyPEM, 1, strlen(kRSAPrivateKeyPEM), fp);
  132|  1.29k|    fclose(fp);
  133|       |
  134|  1.29k|    if (nwritten != strlen(kRSAPrivateKeyPEM)) {
  ------------------
  |  Branch (134:9): [True: 0, False: 1.29k]
  ------------------
  135|      0|        return -1;
  136|      0|    }
  137|       |
  138|  1.29k|    return 0;
  139|  1.29k|}

