ssh_agent_new:
  136|    362|{
  137|    362|    ssh_agent agent = NULL;
  138|       |
  139|    362|    agent = calloc(1, sizeof(struct ssh_agent_struct));
  140|    362|    if (agent == NULL) {
  ------------------
  |  Branch (140:9): [True: 0, False: 362]
  ------------------
  141|      0|        return NULL;
  142|      0|    }
  143|       |
  144|    362|    agent->count = 0;
  145|    362|    agent->sock = ssh_socket_new(session);
  146|    362|    if (agent->sock == NULL) {
  ------------------
  |  Branch (146:9): [True: 0, False: 362]
  ------------------
  147|      0|        SAFE_FREE(agent);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  148|      0|        return NULL;
  149|      0|    }
  150|    362|    agent->channel = NULL;
  151|    362|    return agent;
  152|    362|}
ssh_agent_close:
  221|    362|{
  222|    362|    if (agent == NULL) {
  ------------------
  |  Branch (222:9): [True: 0, False: 362]
  ------------------
  223|      0|        return;
  224|      0|    }
  225|       |
  226|    362|    ssh_socket_close(agent->sock);
  227|    362|}
ssh_agent_free:
  230|    558|{
  231|    558|    if (agent) {
  ------------------
  |  Branch (231:9): [True: 362, False: 196]
  ------------------
  232|    362|        if (agent->ident) {
  ------------------
  |  Branch (232:13): [True: 0, False: 362]
  ------------------
  233|      0|            SSH_BUFFER_FREE(agent->ident);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  234|      0|        }
  235|    362|        if (agent->sock) {
  ------------------
  |  Branch (235:13): [True: 362, False: 0]
  ------------------
  236|    362|            ssh_agent_close(agent);
  237|    362|            ssh_socket_free(agent->sock);
  238|    362|        }
  239|       |        SAFE_FREE(agent);
  ------------------
  |  |  373|    362|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 362, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 362]
  |  |  ------------------
  ------------------
  240|    362|    }
  241|    558|}

ssh_agent_state_free:
 1148|    558|{
 1149|    558|    struct ssh_agent_state_struct *state = data;
 1150|       |
 1151|    558|    if (state) {
  ------------------
  |  Branch (1151:9): [True: 0, False: 558]
  ------------------
 1152|       |        SSH_STRING_FREE_CHAR(state->comment);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_string_free_char(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:74): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1153|      0|        ssh_key_free(state->pubkey);
 1154|      0|        free(state);
 1155|      0|    }
 1156|    558|}

ssh_buffer_new:
  126|  2.61k|{
  127|  2.61k|    struct ssh_buffer_struct *buf = NULL;
  128|  2.61k|    int rc;
  129|       |
  130|  2.61k|    buf = calloc(1, sizeof(struct ssh_buffer_struct));
  131|  2.61k|    if (buf == NULL) {
  ------------------
  |  Branch (131:9): [True: 35, False: 2.57k]
  ------------------
  132|     35|        return NULL;
  133|     35|    }
  134|       |
  135|       |    /*
  136|       |     * Always preallocate 64 bytes.
  137|       |     *
  138|       |     * -1 for realloc_buffer magic.
  139|       |     */
  140|  2.57k|    rc = ssh_buffer_allocate_size(buf, 64 - 1);
  141|  2.57k|    if (rc != 0) {
  ------------------
  |  Branch (141:9): [True: 20, False: 2.55k]
  ------------------
  142|     20|        SAFE_FREE(buf);
  ------------------
  |  |  373|     20|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 20, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 20]
  |  |  ------------------
  ------------------
  143|     20|        return NULL;
  144|     20|    }
  145|  2.55k|    buffer_verify(buf);
  146|       |
  147|  2.55k|    return buf;
  148|  2.57k|}
ssh_buffer_free:
  156|  2.95k|{
  157|  2.95k|    if (buffer == NULL) {
  ------------------
  |  Branch (157:9): [True: 399, False: 2.55k]
  ------------------
  158|    399|        return;
  159|    399|    }
  160|  2.55k|    buffer_verify(buffer);
  161|       |
  162|  2.55k|    if (buffer->secure && buffer->allocated > 0) {
  ------------------
  |  Branch (162:9): [True: 0, False: 2.55k]
  |  Branch (162:27): [True: 0, False: 0]
  ------------------
  163|       |        /* burn the data */
  164|      0|        ssh_burn(buffer->data, buffer->allocated);
  ------------------
  |  |  388|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  165|      0|        SAFE_FREE(buffer->data);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  166|       |
  167|      0|        ssh_burn(buffer, sizeof(struct ssh_buffer_struct));
  ------------------
  |  |  388|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  168|  2.55k|    } else {
  169|  2.55k|        SAFE_FREE(buffer->data);
  ------------------
  |  |  373|  2.55k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 2.55k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 2.55k]
  |  |  ------------------
  ------------------
  170|  2.55k|    }
  171|       |    SAFE_FREE(buffer);
  ------------------
  |  |  373|  2.55k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 2.55k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 2.55k]
  |  |  ------------------
  ------------------
  172|  2.55k|}
ssh_buffer_reinit:
  266|  1.44k|{
  267|  1.44k|    if (buffer == NULL) {
  ------------------
  |  Branch (267:9): [True: 0, False: 1.44k]
  ------------------
  268|      0|        return -1;
  269|      0|    }
  270|       |
  271|  1.44k|    buffer_verify(buffer);
  272|       |
  273|  1.44k|    if (buffer->secure && buffer->allocated > 0) {
  ------------------
  |  Branch (273:9): [True: 0, False: 1.44k]
  |  Branch (273:27): [True: 0, False: 0]
  ------------------
  274|      0|        ssh_burn(buffer->data, buffer->allocated);
  ------------------
  |  |  388|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  275|      0|    }
  276|  1.44k|    buffer->used = 0;
  277|  1.44k|    buffer->pos = 0;
  278|       |
  279|       |    /* If the buffer is bigger then 64K, reset it to 64K */
  280|  1.44k|    if (buffer->allocated > 65536) {
  ------------------
  |  Branch (280:9): [True: 96, False: 1.35k]
  ------------------
  281|     96|        int rc;
  282|       |
  283|       |        /* -1 for realloc_buffer magic */
  284|     96|        rc = realloc_buffer(buffer, 65536 - 1);
  285|     96|        if (rc != 0) {
  ------------------
  |  Branch (285:13): [True: 0, False: 96]
  ------------------
  286|      0|            return -1;
  287|      0|        }
  288|     96|    }
  289|       |
  290|  1.44k|    buffer_verify(buffer);
  291|       |
  292|  1.44k|    return 0;
  293|  1.44k|}
ssh_buffer_add_data:
  307|  1.44k|{
  308|  1.44k|    if (buffer == NULL) {
  ------------------
  |  Branch (308:9): [True: 0, False: 1.44k]
  ------------------
  309|      0|        return -1;
  310|      0|    }
  311|       |
  312|  1.44k|    buffer_verify(buffer);
  313|       |
  314|  1.44k|    if (data == NULL) {
  ------------------
  |  Branch (314:9): [True: 0, False: 1.44k]
  ------------------
  315|      0|        return -1;
  316|      0|    }
  317|       |
  318|  1.44k|    if (buffer->used + len < len) {
  ------------------
  |  Branch (318:9): [True: 0, False: 1.44k]
  ------------------
  319|      0|        return -1;
  320|      0|    }
  321|       |
  322|  1.44k|    if (buffer->allocated < (buffer->used + len)) {
  ------------------
  |  Branch (322:9): [True: 228, False: 1.22k]
  ------------------
  323|    228|        if (buffer->pos > 0) {
  ------------------
  |  Branch (323:13): [True: 0, False: 228]
  ------------------
  324|      0|            buffer_shift(buffer);
  325|      0|        }
  326|    228|        if (realloc_buffer(buffer, buffer->used + len) < 0) {
  ------------------
  |  Branch (326:13): [True: 0, False: 228]
  ------------------
  327|      0|            return -1;
  328|      0|        }
  329|    228|    }
  330|       |
  331|  1.44k|    memcpy(buffer->data + buffer->used, data, len);
  332|  1.44k|    buffer->used += len;
  333|  1.44k|    buffer_verify(buffer);
  334|  1.44k|    return 0;
  335|  1.44k|}
ssh_buffer_allocate_size:
  348|  2.57k|{
  349|  2.57k|    buffer_verify(buffer);
  350|       |
  351|  2.57k|    if (buffer->allocated < len) {
  ------------------
  |  Branch (351:9): [True: 2.57k, False: 0]
  ------------------
  352|  2.57k|        if (buffer->pos > 0) {
  ------------------
  |  Branch (352:13): [True: 0, False: 2.57k]
  ------------------
  353|      0|            buffer_shift(buffer);
  354|      0|        }
  355|  2.57k|        if (realloc_buffer(buffer, len) < 0) {
  ------------------
  |  Branch (355:13): [True: 20, False: 2.55k]
  ------------------
  356|     20|            return -1;
  357|     20|        }
  358|  2.57k|    }
  359|       |
  360|  2.55k|    buffer_verify(buffer);
  361|       |
  362|  2.55k|    return 0;
  363|  2.57k|}
ssh_buffer_get_len:
  620|  42.1k|uint32_t ssh_buffer_get_len(struct ssh_buffer_struct *buffer){
  621|  42.1k|  buffer_verify(buffer);
  622|  42.1k|  return buffer->used - buffer->pos;
  623|  42.1k|}
ssh_buffer_get_data:
  737|   352k|{
  738|   352k|    int rc;
  739|       |
  740|       |    /*
  741|       |     * Check for a integer overflow first, then check if not enough data is in
  742|       |     * the buffer.
  743|       |     */
  744|   352k|    rc = ssh_buffer_validate_length(buffer, len);
  745|   352k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|   352k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (745:9): [True: 644, False: 352k]
  ------------------
  746|    644|        return 0;
  747|    644|    }
  748|   352k|    memcpy(data,buffer->data+buffer->pos,len);
  749|   352k|    buffer->pos+=len;
  750|   352k|    return len;   /* no yet support for partial reads (is it really needed ?? ) */
  751|   352k|}
ssh_buffer_get_u32:
  780|   177k|uint32_t ssh_buffer_get_u32(struct ssh_buffer_struct *buffer, uint32_t *data){
  781|   177k|    return ssh_buffer_get_data(buffer,data,sizeof(uint32_t));
  782|   177k|}
ssh_buffer_get_u64:
  795|    570|uint32_t ssh_buffer_get_u64(struct ssh_buffer_struct *buffer, uint64_t *data){
  796|    570|    return ssh_buffer_get_data(buffer,data,sizeof(uint64_t));
  797|    570|}
ssh_buffer_validate_length:
  809|   527k|{
  810|   527k|    if (buffer == NULL || buffer->pos + len < len ||
  ------------------
  |  Branch (810:9): [True: 0, False: 527k]
  |  Branch (810:27): [True: 0, False: 527k]
  ------------------
  811|   527k|        buffer->pos + len > buffer->used) {
  ------------------
  |  Branch (811:9): [True: 894, False: 526k]
  ------------------
  812|    894|        return SSH_ERROR;
  ------------------
  |  |  317|    894|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  813|    894|    }
  814|       |
  815|   526k|    return SSH_OK;
  ------------------
  |  |  316|   526k|#define SSH_OK 0     /* No error */
  ------------------
  816|   527k|}
ssh_buffer_get_ssh_string:
  829|   174k|{
  830|   174k|    uint32_t stringlen;
  831|   174k|    uint32_t hostlen;
  832|   174k|    struct ssh_string_struct *str = NULL;
  833|   174k|    int rc;
  834|       |
  835|   174k|    rc = ssh_buffer_get_u32(buffer, &stringlen);
  836|   174k|    if (rc == 0) {
  ------------------
  |  Branch (836:9): [True: 270, False: 174k]
  ------------------
  837|    270|        return NULL;
  838|    270|    }
  839|   174k|    hostlen = ntohl(stringlen);
  840|       |    /* verify if there is enough space in buffer to get it */
  841|   174k|    rc = ssh_buffer_validate_length(buffer, hostlen);
  842|   174k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|   174k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (842:9): [True: 236, False: 174k]
  ------------------
  843|    236|      return NULL; /* it is indeed */
  844|    236|    }
  845|   174k|    str = ssh_string_new(hostlen);
  846|   174k|    if (str == NULL) {
  ------------------
  |  Branch (846:9): [True: 0, False: 174k]
  ------------------
  847|      0|        return NULL;
  848|      0|    }
  849|       |
  850|   174k|    stringlen = ssh_buffer_get_data(buffer, ssh_string_data(str), hostlen);
  851|   174k|    if (stringlen != hostlen) {
  ------------------
  |  Branch (851:9): [True: 0, False: 174k]
  ------------------
  852|       |        /* should never happen */
  853|      0|        SAFE_FREE(str);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  854|      0|        return NULL;
  855|      0|    }
  856|       |
  857|   174k|    return str;
  858|   174k|}
ssh_buffer_unpack_va:
 1173|  42.1k|{
 1174|  42.1k|    int rc = SSH_ERROR;
  ------------------
  |  |  317|  42.1k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1175|  42.1k|    const char *p = format, *last = NULL;
 1176|  42.1k|    union {
 1177|  42.1k|        uint8_t *byte;
 1178|  42.1k|        uint16_t *word;
 1179|  42.1k|        uint32_t *dword;
 1180|  42.1k|        uint64_t *qword;
 1181|  42.1k|        ssh_string *string;
 1182|  42.1k|        char **cstring;
 1183|  42.1k|        bignum *bignum;
 1184|  42.1k|        void **data;
 1185|  42.1k|    } o;
 1186|  42.1k|    size_t len;
 1187|  42.1k|    uint32_t rlen, max_len;
 1188|  42.1k|    ssh_string tmp_string = NULL;
 1189|  42.1k|    va_list ap_copy;
 1190|  42.1k|    size_t count;
 1191|       |
 1192|  42.1k|    max_len = ssh_buffer_get_len(buffer);
 1193|       |
 1194|       |    /* copy the argument list in case a rollback is needed */
 1195|  42.1k|    va_copy(ap_copy, ap);
 1196|       |
 1197|  42.1k|    if (argc > 256) {
  ------------------
  |  Branch (1197:9): [True: 0, False: 42.1k]
  ------------------
 1198|      0|        rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1199|      0|        goto cleanup;
 1200|      0|    }
 1201|       |
 1202|   124k|    for (count = 0; *p != '\0'; p++, count++) {
  ------------------
  |  Branch (1202:21): [True: 83.0k, False: 41.5k]
  ------------------
 1203|       |        /* Invalid number of arguments passed */
 1204|  83.0k|        if (count > argc) {
  ------------------
  |  Branch (1204:13): [True: 0, False: 83.0k]
  ------------------
 1205|      0|            rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1206|      0|            goto cleanup;
 1207|      0|        }
 1208|       |
 1209|  83.0k|        rc = SSH_ERROR;
  ------------------
  |  |  317|  83.0k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1210|  83.0k|        switch (*p) {
 1211|      0|        case 'b':
  ------------------
  |  Branch (1211:9): [True: 0, False: 83.0k]
  ------------------
 1212|      0|            o.byte = va_arg(ap, uint8_t *);
 1213|      0|            rlen = ssh_buffer_get_u8(buffer, o.byte);
 1214|      0|            rc = rlen==1 ? SSH_OK : SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
                          rc = rlen==1 ? SSH_OK : SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1214:18): [True: 0, False: 0]
  ------------------
 1215|      0|            break;
 1216|      0|        case 'w':
  ------------------
  |  Branch (1216:9): [True: 0, False: 83.0k]
  ------------------
 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;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 1222|      0|            }
 1223|      0|            break;
 1224|  1.16k|        case 'd':
  ------------------
  |  Branch (1224:9): [True: 1.16k, False: 81.9k]
  ------------------
 1225|  1.16k|            o.dword = va_arg(ap, uint32_t *);
 1226|  1.16k|            rlen = ssh_buffer_get_u32(buffer, o.dword);
 1227|  1.16k|            if (rlen == 4) {
  ------------------
  |  Branch (1227:17): [True: 1.06k, False: 104]
  ------------------
 1228|  1.06k|                *o.dword = ntohl(*o.dword);
 1229|  1.06k|                rc = SSH_OK;
  ------------------
  |  |  316|  1.06k|#define SSH_OK 0     /* No error */
  ------------------
 1230|  1.06k|            }
 1231|  1.16k|            break;
 1232|    106|        case 'q':
  ------------------
  |  Branch (1232:9): [True: 106, False: 82.9k]
  ------------------
 1233|    106|            o.qword = va_arg(ap, uint64_t*);
 1234|    106|            rlen = ssh_buffer_get_u64(buffer, o.qword);
 1235|    106|            if (rlen == 8) {
  ------------------
  |  Branch (1235:17): [True: 92, False: 14]
  ------------------
 1236|     92|                *o.qword = ntohll(*o.qword);
  ------------------
  |  |  488|     92|    (((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32))
  ------------------
 1237|     92|                rc = SSH_OK;
  ------------------
  |  |  316|     92|#define SSH_OK 0     /* No error */
  ------------------
 1238|     92|            }
 1239|    106|            break;
 1240|      0|        case 'B':
  ------------------
  |  Branch (1240:9): [True: 0, False: 83.0k]
  ------------------
 1241|      0|            o.bignum = va_arg(ap, bignum *);
 1242|      0|            *o.bignum = NULL;
 1243|      0|            tmp_string = ssh_buffer_get_ssh_string(buffer);
 1244|      0|            if (tmp_string == NULL) {
  ------------------
  |  Branch (1244:17): [True: 0, False: 0]
  ------------------
 1245|      0|                break;
 1246|      0|            }
 1247|      0|            *o.bignum = ssh_make_string_bn(tmp_string);
 1248|      0|            ssh_string_burn(tmp_string);
 1249|      0|            SSH_STRING_FREE(tmp_string);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1250|      0|            rc = (*o.bignum != NULL) ? SSH_OK : SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
                          rc = (*o.bignum != NULL) ? SSH_OK : SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1250:18): [True: 0, False: 0]
  ------------------
 1251|      0|            break;
 1252|  81.1k|        case 'S':
  ------------------
  |  Branch (1252:9): [True: 81.1k, False: 1.96k]
  ------------------
 1253|  81.1k|            o.string = va_arg(ap, ssh_string *);
 1254|  81.1k|            *o.string = ssh_buffer_get_ssh_string(buffer);
 1255|  81.1k|            rc = *o.string != NULL ? SSH_OK : SSH_ERROR;
  ------------------
  |  |  316|  81.0k|#define SSH_OK 0     /* No error */
  ------------------
                          rc = *o.string != NULL ? SSH_OK : SSH_ERROR;
  ------------------
  |  |  317|  81.2k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1255:18): [True: 81.0k, False: 86]
  ------------------
 1256|  81.1k|            o.string = NULL;
 1257|  81.1k|            break;
 1258|    691|        case 's': {
  ------------------
  |  Branch (1258:9): [True: 691, False: 82.3k]
  ------------------
 1259|    691|            uint32_t u32len = 0;
 1260|       |
 1261|    691|            o.cstring = va_arg(ap, char **);
 1262|    691|            *o.cstring = NULL;
 1263|    691|            rlen = ssh_buffer_get_u32(buffer, &u32len);
 1264|    691|            if (rlen != 4){
  ------------------
  |  Branch (1264:17): [True: 64, False: 627]
  ------------------
 1265|     64|                break;
 1266|     64|            }
 1267|    627|            u32len = ntohl(u32len);
 1268|    627|            if (u32len > max_len - 1) {
  ------------------
  |  Branch (1268:17): [True: 318, False: 309]
  ------------------
 1269|    318|                break;
 1270|    318|            }
 1271|       |
 1272|    309|            rc = ssh_buffer_validate_length(buffer, u32len);
 1273|    309|            if (rc != SSH_OK) {
  ------------------
  |  |  316|    309|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1273:17): [True: 14, False: 295]
  ------------------
 1274|     14|                break;
 1275|     14|            }
 1276|       |
 1277|    295|            *o.cstring = malloc(u32len + 1);
 1278|    295|            if (*o.cstring == NULL){
  ------------------
  |  Branch (1278:17): [True: 0, False: 295]
  ------------------
 1279|      0|                rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1280|      0|                break;
 1281|      0|            }
 1282|    295|            rlen = ssh_buffer_get_data(buffer, *o.cstring, u32len);
 1283|    295|            if (rlen != u32len) {
  ------------------
  |  Branch (1283:17): [True: 0, False: 295]
  ------------------
 1284|      0|                SAFE_FREE(*o.cstring);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1285|      0|                rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1286|      0|                break;
 1287|      0|            }
 1288|    295|            (*o.cstring)[u32len] = '\0';
 1289|    295|            o.cstring = NULL;
 1290|    295|            rc = SSH_OK;
  ------------------
  |  |  316|    295|#define SSH_OK 0     /* No error */
  ------------------
 1291|    295|            break;
 1292|    295|        }
 1293|      0|        case 'P':
  ------------------
  |  Branch (1293:9): [True: 0, False: 83.0k]
  ------------------
 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;
  ------------------
  |  |  317|      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) {
  ------------------
  |  |  316|      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;
  ------------------
  |  |  317|      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);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1316|      0|                rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1317|      0|                break;
 1318|      0|            }
 1319|      0|            o.data = NULL;
 1320|      0|            rc = SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 1321|      0|            break;
 1322|      0|        default:
  ------------------
  |  Branch (1322:9): [True: 0, False: 83.0k]
  ------------------
 1323|      0|            SSH_LOG(SSH_LOG_TRACE, "Invalid buffer format %c", *p);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1324|  83.0k|        }
 1325|  83.0k|        if (rc != SSH_OK) {
  ------------------
  |  |  316|  83.0k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1325:13): [True: 600, False: 82.4k]
  ------------------
 1326|    600|            break;
 1327|    600|        }
 1328|  83.0k|    }
 1329|       |
 1330|  42.1k|    if (argc != count) {
  ------------------
  |  Branch (1330:9): [True: 600, False: 41.5k]
  ------------------
 1331|    600|        rc = SSH_ERROR;
  ------------------
  |  |  317|    600|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1332|    600|    }
 1333|       |
 1334|  42.1k|cleanup:
 1335|  42.1k|    if (rc != SSH_ERROR){
  ------------------
  |  |  317|  42.1k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1335:9): [True: 41.5k, False: 600]
  ------------------
 1336|       |        /* Check if our canary is intact, if not something really bad happened */
 1337|  41.5k|        uint32_t canary = va_arg(ap, uint32_t);
 1338|  41.5k|        if (canary != SSH_BUFFER_PACK_END){
  ------------------
  |  |   28|  41.5k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  ------------------
  |  Branch (1338:13): [True: 0, False: 41.5k]
  ------------------
 1339|      0|            abort();
 1340|      0|        }
 1341|  41.5k|    }
 1342|       |
 1343|  42.1k|    if (rc != SSH_OK){
  ------------------
  |  |  316|  42.1k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1343:9): [True: 600, False: 41.5k]
  ------------------
 1344|       |        /* Reset the format string and erase everything that was allocated */
 1345|    600|        last = p;
 1346|    681|        for(p=format;p<last;++p){
  ------------------
  |  Branch (1346:22): [True: 81, False: 600]
  ------------------
 1347|     81|            switch(*p){
 1348|      0|            case 'b':
  ------------------
  |  Branch (1348:13): [True: 0, False: 81]
  ------------------
 1349|      0|                o.byte = va_arg(ap_copy, uint8_t *);
 1350|      0|                if (buffer->secure) {
  ------------------
  |  Branch (1350:21): [True: 0, False: 0]
  ------------------
 1351|      0|                    ssh_burn(o.byte, sizeof(uint8_t));
  ------------------
  |  |  388|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
 1352|      0|                    break;
 1353|      0|                }
 1354|      0|                break;
 1355|      0|            case 'w':
  ------------------
  |  Branch (1355:13): [True: 0, False: 81]
  ------------------
 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));
  ------------------
  |  |  388|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
 1359|      0|                    break;
 1360|      0|                }
 1361|      0|                break;
 1362|     15|            case 'd':
  ------------------
  |  Branch (1362:13): [True: 15, False: 66]
  ------------------
 1363|     15|                o.dword = va_arg(ap_copy, uint32_t *);
 1364|     15|                if (buffer->secure) {
  ------------------
  |  Branch (1364:21): [True: 0, False: 15]
  ------------------
 1365|      0|                    ssh_burn(o.dword, sizeof(uint32_t));
  ------------------
  |  |  388|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
 1366|      0|                    break;
 1367|      0|                }
 1368|     15|                break;
 1369|     15|            case 'q':
  ------------------
  |  Branch (1369:13): [True: 0, False: 81]
  ------------------
 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));
  ------------------
  |  |  388|      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: 81]
  ------------------
 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|     29|            case 'S':
  ------------------
  |  Branch (1380:13): [True: 29, False: 52]
  ------------------
 1381|     29|                o.string = va_arg(ap_copy, ssh_string *);
 1382|     29|                if (buffer->secure) {
  ------------------
  |  Branch (1382:21): [True: 0, False: 29]
  ------------------
 1383|      0|                    ssh_string_burn(*o.string);
 1384|      0|                }
 1385|     29|                SAFE_FREE(*o.string);
  ------------------
  |  |  373|     29|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 29, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 29]
  |  |  ------------------
  ------------------
 1386|     29|                break;
 1387|     37|            case 's':
  ------------------
  |  Branch (1387:13): [True: 37, False: 44]
  ------------------
 1388|     37|                o.cstring = va_arg(ap_copy, char **);
 1389|     37|                if (buffer->secure) {
  ------------------
  |  Branch (1389:21): [True: 0, False: 37]
  ------------------
 1390|      0|                    ssh_burn(*o.cstring, strlen(*o.cstring));
  ------------------
  |  |  388|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
 1391|      0|                }
 1392|     37|                SAFE_FREE(*o.cstring);
  ------------------
  |  |  373|     37|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 37, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 37]
  |  |  ------------------
  ------------------
 1393|     37|                break;
 1394|      0|            case 'P':
  ------------------
  |  Branch (1394:13): [True: 0, False: 81]
  ------------------
 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);
  ------------------
  |  |  388|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
 1399|      0|                }
 1400|      0|                SAFE_FREE(*o.data);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1401|      0|                break;
 1402|      0|            default:
  ------------------
  |  Branch (1402:13): [True: 0, False: 81]
  ------------------
 1403|      0|                (void)va_arg(ap_copy, void *);
 1404|      0|                break;
 1405|     81|            }
 1406|     81|        }
 1407|    600|    }
 1408|  42.1k|    va_end(ap_copy);
 1409|       |
 1410|  42.1k|    return rc;
 1411|  42.1k|}
_ssh_buffer_unpack:
 1439|  42.1k|{
 1440|  42.1k|    va_list ap;
 1441|  42.1k|    int rc;
 1442|       |
 1443|  42.1k|    va_start(ap, argc);
 1444|  42.1k|    rc = ssh_buffer_unpack_va(buffer, format, argc, ap);
 1445|       |    va_end(ap);
 1446|  42.1k|    return rc;
 1447|  42.1k|}
buffer.c:realloc_buffer:
  188|  2.90k|{
  189|  2.90k|    uint32_t smallest = 1;
  190|  2.90k|    uint8_t *new = NULL;
  191|       |
  192|  2.90k|    buffer_verify(buffer);
  193|       |
  194|       |    /* Find the smallest power of two which is greater or equal to needed */
  195|  23.3k|    while(smallest <= needed) {
  ------------------
  |  Branch (195:11): [True: 20.4k, False: 2.90k]
  ------------------
  196|  20.4k|        if (smallest == 0) {
  ------------------
  |  Branch (196:13): [True: 0, False: 20.4k]
  ------------------
  197|      0|            return -1;
  198|      0|        }
  199|  20.4k|        smallest <<= 1;
  200|  20.4k|    }
  201|  2.90k|    needed = smallest;
  202|       |
  203|  2.90k|    if (needed > BUFFER_SIZE_MAX) {
  ------------------
  |  |   57|  2.90k|#define BUFFER_SIZE_MAX 0x10000000
  ------------------
  |  Branch (203:9): [True: 0, False: 2.90k]
  ------------------
  204|      0|        return -1;
  205|      0|    }
  206|       |
  207|  2.90k|    if (buffer->secure) {
  ------------------
  |  Branch (207:9): [True: 0, False: 2.90k]
  ------------------
  208|      0|        new = malloc(needed);
  209|      0|        if (new == NULL) {
  ------------------
  |  Branch (209:13): [True: 0, False: 0]
  ------------------
  210|      0|            return -1;
  211|      0|        }
  212|      0|        memcpy(new, buffer->data, buffer->used);
  213|      0|        ssh_burn(buffer->data, buffer->used);
  ------------------
  |  |  388|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  214|      0|        SAFE_FREE(buffer->data);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  215|  2.90k|    } else {
  216|  2.90k|        new = realloc(buffer->data, needed);
  217|  2.90k|        if (new == NULL) {
  ------------------
  |  Branch (217:13): [True: 20, False: 2.88k]
  ------------------
  218|     20|            return -1;
  219|     20|        }
  220|  2.90k|    }
  221|  2.88k|    buffer->data = new;
  222|  2.88k|    buffer->allocated = needed;
  223|       |
  224|  2.88k|    buffer_verify(buffer);
  225|  2.88k|    return 0;
  226|  2.90k|}

_ssh_remove_legacy_log_cb:
   49|    558|{
   50|    558|    if (ssh_get_log_callback() == ssh_legacy_log_callback) {
  ------------------
  |  Branch (50:9): [True: 0, False: 558]
  ------------------
   51|      0|        _ssh_reset_log_cb();
   52|       |        ssh_set_log_userdata(NULL);
   53|      0|    }
   54|    558|}

ssh_get_openssh_version:
  734|     42|{
  735|     42|    if (session == NULL) {
  ------------------
  |  Branch (735:9): [True: 0, False: 42]
  ------------------
  736|      0|        return 0;
  737|      0|    }
  738|       |
  739|     42|    return session->openssh;
  740|     42|}

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;
  ------------------
  |  |  316|      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;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  273|      2|}

ssh_dh_cleanup:
  449|    463|{
  450|    463|    if (crypto->dh_ctx != NULL) {
  ------------------
  |  Branch (450:9): [True: 0, False: 463]
  ------------------
  451|      0|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  452|      0|        DH_free(crypto->dh_ctx->keypair[0]);
  453|      0|        DH_free(crypto->dh_ctx->keypair[1]);
  454|       |#else
  455|       |        EVP_PKEY_free(crypto->dh_ctx->keypair[0]);
  456|       |        EVP_PKEY_free(crypto->dh_ctx->keypair[1]);
  457|       |#endif /* OPENSSL_VERSION_NUMBER */
  458|      0|        free(crypto->dh_ctx);
  459|       |        crypto->dh_ctx = NULL;
  460|      0|    }
  461|    463|}

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

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

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

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

ssh_list_new:
  865|  3.25k|{
  866|  3.25k|    struct ssh_list *ret = malloc(sizeof(struct ssh_list));
  867|  3.25k|    if (ret == NULL) {
  ------------------
  |  Branch (867:9): [True: 1, False: 3.25k]
  ------------------
  868|      1|        return NULL;
  869|      1|    }
  870|  3.25k|    ret->root = ret->end = NULL;
  871|  3.25k|    return ret;
  872|  3.25k|}
ssh_list_free:
  882|  4.01k|{
  883|  4.01k|    struct ssh_iterator *ptr = NULL, *next = NULL;
  884|  4.01k|    if (!list)
  ------------------
  |  Branch (884:9): [True: 754, False: 3.25k]
  ------------------
  885|    754|        return;
  886|  3.25k|    ptr = list->root;
  887|  3.25k|    while (ptr) {
  ------------------
  |  Branch (887:12): [True: 0, False: 3.25k]
  ------------------
  888|      0|        next = ptr->next;
  889|      0|        SAFE_FREE(ptr);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  890|      0|        ptr = next;
  891|      0|    }
  892|       |    SAFE_FREE(list);
  ------------------
  |  |  373|  3.25k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 3.25k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 3.25k]
  |  |  ------------------
  ------------------
  893|  3.25k|}
ssh_list_get_iterator:
  903|    558|{
  904|    558|    if (!list)
  ------------------
  |  Branch (904:9): [True: 558, False: 0]
  ------------------
  905|    558|        return NULL;
  906|      0|    return list->root;
  907|    558|}
ssh_list_append:
  969|  1.08k|{
  970|  1.08k|  struct ssh_iterator *iterator = NULL;
  971|       |
  972|  1.08k|  if (list == NULL) {
  ------------------
  |  Branch (972:7): [True: 0, False: 1.08k]
  ------------------
  973|      0|      return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  974|      0|  }
  975|       |
  976|  1.08k|  iterator = ssh_iterator_new(data);
  977|  1.08k|  if (iterator == NULL) {
  ------------------
  |  Branch (977:7): [True: 0, False: 1.08k]
  ------------------
  978|      0|      return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  979|      0|  }
  980|       |
  981|  1.08k|  if(!list->end){
  ------------------
  |  Branch (981:6): [True: 362, False: 724]
  ------------------
  982|       |    /* list is empty */
  983|    362|    list->root=list->end=iterator;
  984|    724|  } else {
  985|       |    /* put it on end of list */
  986|    724|    list->end->next=iterator;
  987|    724|    list->end=iterator;
  988|    724|  }
  989|  1.08k|  return SSH_OK;
  ------------------
  |  |  316|  1.08k|#define SSH_OK 0     /* No error */
  ------------------
  990|  1.08k|}
_ssh_list_pop_head:
 1073|  4.37k|{
 1074|  4.37k|  struct ssh_iterator *iterator = NULL;
 1075|  4.37k|  const void *data = NULL;
 1076|       |
 1077|  4.37k|  if (list == NULL) {
  ------------------
  |  Branch (1077:7): [True: 392, False: 3.98k]
  ------------------
 1078|    392|      return NULL;
 1079|    392|  }
 1080|       |
 1081|  3.98k|  iterator = list->root;
 1082|  3.98k|  if (iterator == NULL) {
  ------------------
  |  Branch (1082:7): [True: 2.89k, False: 1.08k]
  ------------------
 1083|  2.89k|      return NULL;
 1084|  2.89k|  }
 1085|  1.08k|  data=iterator->data;
 1086|  1.08k|  list->root=iterator->next;
 1087|  1.08k|  if(list->end==iterator)
  ------------------
  |  Branch (1087:6): [True: 362, False: 724]
  ------------------
 1088|    362|    list->end=NULL;
 1089|       |  SAFE_FREE(iterator);
  ------------------
  |  |  373|  1.08k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.08k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 1.08k]
  |  |  ------------------
  ------------------
 1090|  1.08k|  return data;
 1091|  3.98k|}
ssh_proxyjumps_free:
 2637|    558|{
 2638|    558|    struct ssh_jump_info_struct *jump = NULL;
 2639|       |
 2640|    558|    for (jump =
 2641|    558|             ssh_list_pop_head(struct ssh_jump_info_struct *, proxy_jump_list);
  ------------------
  |  |  122|    558|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2642|    558|         jump != NULL;
  ------------------
  |  Branch (2642:10): [True: 0, False: 558]
  ------------------
 2643|    558|         jump = ssh_list_pop_head(struct ssh_jump_info_struct *,
  ------------------
  |  |  122|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2644|    558|                                  proxy_jump_list)) {
 2645|      0|        SAFE_FREE(jump->hostname);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2646|      0|        SAFE_FREE(jump->username);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2647|       |        SAFE_FREE(jump);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2648|      0|    }
 2649|    558|}
misc.c:ssh_iterator_new:
  947|  1.08k|{
  948|  1.08k|    struct ssh_iterator *iterator = malloc(sizeof(struct ssh_iterator));
  949|       |
  950|  1.08k|    if (iterator == NULL) {
  ------------------
  |  Branch (950:9): [True: 0, False: 1.08k]
  ------------------
  951|      0|        return NULL;
  952|      0|    }
  953|  1.08k|    iterator->next = NULL;
  954|  1.08k|    iterator->data = data;
  955|  1.08k|    return iterator;
  956|  1.08k|}

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

ssh_pki_ctx_new:
   49|    362|{
   50|    362|    struct ssh_pki_ctx_struct *ctx = NULL;
   51|       |
   52|    362|    ctx = calloc(1, sizeof(struct ssh_pki_ctx_struct));
   53|    362|    if (ctx == NULL) {
  ------------------
  |  Branch (53:9): [True: 0, False: 362]
  ------------------
   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|    362|    return ctx;
   77|    362|}
ssh_pki_ctx_free:
   86|    362|{
   87|    362|    if (context == NULL) {
  ------------------
  |  Branch (87:9): [True: 0, False: 362]
  ------------------
   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|    362|    SAFE_FREE(context);
  ------------------
  |  |  373|    362|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 362, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 362]
  |  |  ------------------
  ------------------
   99|    362|}

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

ssh_new:
   66|    761|{
   67|    761|    ssh_session session = NULL;
   68|    761|    char *id = NULL;
   69|    761|    int rc;
   70|       |
   71|    761|    session = calloc(1, sizeof (struct ssh_session_struct));
   72|    761|    if (session == NULL) {
  ------------------
  |  Branch (72:9): [True: 203, False: 558]
  ------------------
   73|    203|        return NULL;
   74|    203|    }
   75|       |
   76|    558|    session->next_crypto = crypto_new();
   77|    558|    if (session->next_crypto == NULL) {
  ------------------
  |  Branch (77:9): [True: 95, False: 463]
  ------------------
   78|     95|        goto err;
   79|     95|    }
   80|       |
   81|    463|    session->socket = ssh_socket_new(session);
   82|    463|    if (session->socket == NULL) {
  ------------------
  |  Branch (82:9): [True: 98, False: 365]
  ------------------
   83|     98|        goto err;
   84|     98|    }
   85|       |
   86|    365|    session->out_buffer = ssh_buffer_new();
   87|    365|    if (session->out_buffer == NULL) {
  ------------------
  |  Branch (87:9): [True: 2, False: 363]
  ------------------
   88|      2|        goto err;
   89|      2|    }
   90|       |
   91|    363|    session->in_buffer = ssh_buffer_new();
   92|    363|    if (session->in_buffer == NULL) {
  ------------------
  |  Branch (92:9): [True: 0, False: 363]
  ------------------
   93|      0|        goto err;
   94|      0|    }
   95|       |
   96|    363|    session->out_queue = ssh_list_new();
   97|    363|    if (session->out_queue == NULL) {
  ------------------
  |  Branch (97:9): [True: 1, False: 362]
  ------------------
   98|      1|        goto err;
   99|      1|    }
  100|       |
  101|    362|    session->alive = 0;
  102|    362|    session->auth.supported_methods = 0;
  103|    362|    ssh_set_blocking(session, 1);
  104|    362|    session->maxchannel = FIRST_CHANNEL;
  ------------------
  |  |   49|    362|#define FIRST_CHANNEL 42 // why not ? it helps to find bugs.
  ------------------
  105|    362|    session->proxy_root = true;
  106|       |
  107|    362|    session->agent = ssh_agent_new(session);
  108|    362|    if (session->agent == NULL) {
  ------------------
  |  Branch (108:9): [True: 0, False: 362]
  ------------------
  109|      0|        goto err;
  110|      0|    }
  111|       |
  112|       |    /* Initialise a default PKI context */
  113|    362|    session->pki_context = ssh_pki_ctx_new();
  114|    362|    if (session->pki_context == NULL) {
  ------------------
  |  Branch (114:9): [True: 0, False: 362]
  ------------------
  115|      0|        goto err;
  116|      0|    }
  117|       |
  118|       |    /* OPTIONS */
  119|    362|    session->opts.StrictHostKeyChecking = SSH_STRICT_HOSTKEY_ASK;
  120|    362|    session->opts.port = 22;
  121|    362|    session->opts.fd = -1;
  122|    362|    session->opts.compressionlevel = 7;
  123|    362|    session->opts.nodelay = 0;
  124|    362|    session->opts.identities_only = false;
  125|    362|    session->opts.batch_mode = false;
  126|    362|    session->opts.control_master = SSH_CONTROL_MASTER_NO;
  127|       |
  128|    362|    session->opts.flags = SSH_OPT_FLAG_PASSWORD_AUTH |
  ------------------
  |  |  109|    362|#define SSH_OPT_FLAG_PASSWORD_AUTH 0x1
  ------------------
  129|    362|                          SSH_OPT_FLAG_PUBKEY_AUTH |
  ------------------
  |  |  110|    362|#define SSH_OPT_FLAG_PUBKEY_AUTH 0x2
  ------------------
  130|    362|                          SSH_OPT_FLAG_KBDINT_AUTH |
  ------------------
  |  |  111|    362|#define SSH_OPT_FLAG_KBDINT_AUTH 0x4
  ------------------
  131|    362|                          SSH_OPT_FLAG_GSSAPI_AUTH;
  ------------------
  |  |  112|    362|#define SSH_OPT_FLAG_GSSAPI_AUTH 0x8
  ------------------
  132|    362|    session->opts.pubkey_auth = SSH_PUBKEY_AUTH_ALL;
  133|       |
  134|    362|    session->opts.exp_flags = 0;
  135|       |
  136|    362|    session->opts.identity = ssh_list_new();
  137|    362|    if (session->opts.identity == NULL) {
  ------------------
  |  Branch (137:9): [True: 0, False: 362]
  ------------------
  138|      0|        goto err;
  139|      0|    }
  140|    362|    session->opts.identity_non_exp = ssh_list_new();
  141|    362|    if (session->opts.identity_non_exp == NULL) {
  ------------------
  |  Branch (141:9): [True: 0, False: 362]
  ------------------
  142|      0|        goto err;
  143|      0|    }
  144|       |
  145|    362|    session->opts.certificate = ssh_list_new();
  146|    362|    if (session->opts.certificate == NULL) {
  ------------------
  |  Branch (146:9): [True: 0, False: 362]
  ------------------
  147|      0|        goto err;
  148|      0|    }
  149|    362|    session->opts.certificate_non_exp = ssh_list_new();
  150|    362|    if (session->opts.certificate_non_exp == NULL) {
  ------------------
  |  Branch (150:9): [True: 0, False: 362]
  ------------------
  151|      0|        goto err;
  152|      0|    }
  153|       |    /* the default certificates are loaded automatically from the default
  154|       |     * identities later */
  155|       |
  156|    362|    session->opts.local_forward = ssh_list_new();
  157|    362|    if (session->opts.local_forward == NULL) {
  ------------------
  |  Branch (157:9): [True: 0, False: 362]
  ------------------
  158|      0|        goto err;
  159|      0|    }
  160|       |
  161|    362|    session->opts.proxy_jumps = ssh_list_new();
  162|    362|    if (session->opts.proxy_jumps == NULL) {
  ------------------
  |  Branch (162:9): [True: 0, False: 362]
  ------------------
  163|      0|        goto err;
  164|      0|    }
  165|       |
  166|    362|    session->opts.send_env = ssh_list_new();
  167|    362|    if (session->opts.send_env == NULL) {
  ------------------
  |  Branch (167:9): [True: 0, False: 362]
  ------------------
  168|      0|        goto err;
  169|      0|    }
  170|       |
  171|    362|    session->opts.proxy_jumps_user_cb = ssh_list_new();
  172|    362|    if (session->opts.proxy_jumps_user_cb == NULL) {
  ------------------
  |  Branch (172:9): [True: 0, False: 362]
  ------------------
  173|      0|        goto err;
  174|      0|    }
  175|       |
  176|       |#ifdef WITH_GSSAPI
  177|       |    session->opts.gssapi_key_exchange_algs =
  178|       |        strdup(GSSAPI_KEY_EXCHANGE_SUPPORTED);
  179|       |    if (session->opts.gssapi_key_exchange_algs == NULL) {
  180|       |        goto err;
  181|       |    }
  182|       |#endif /* WITH_GSSAPI */
  183|       |
  184|    362|    id = strdup("%d/.ssh/id_ed25519");
  185|    362|    if (id == NULL) {
  ------------------
  |  Branch (185:9): [True: 0, False: 362]
  ------------------
  186|      0|        goto err;
  187|      0|    }
  188|       |
  189|    362|    rc = ssh_list_append(session->opts.identity_non_exp, id);
  190|    362|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    362|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (190:9): [True: 0, False: 362]
  ------------------
  191|      0|        goto err;
  192|      0|    }
  193|       |
  194|    362|#ifdef HAVE_ECC
  195|    362|    id = strdup("%d/.ssh/id_ecdsa");
  196|    362|    if (id == NULL) {
  ------------------
  |  Branch (196:9): [True: 0, False: 362]
  ------------------
  197|      0|        goto err;
  198|      0|    }
  199|    362|    rc = ssh_list_append(session->opts.identity_non_exp, id);
  200|    362|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    362|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (200:9): [True: 0, False: 362]
  ------------------
  201|      0|        goto err;
  202|      0|    }
  203|    362|#endif
  204|       |
  205|    362|    id = strdup("%d/.ssh/id_rsa");
  206|    362|    if (id == NULL) {
  ------------------
  |  Branch (206:9): [True: 0, False: 362]
  ------------------
  207|      0|        goto err;
  208|      0|    }
  209|    362|    rc = ssh_list_append(session->opts.identity_non_exp, id);
  210|    362|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    362|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (210:9): [True: 0, False: 362]
  ------------------
  211|      0|        goto err;
  212|      0|    }
  213|       |
  214|       |#ifdef WITH_FIDO2
  215|       |    /* Add security key identities */
  216|       |    id = strdup("%d/.ssh/id_ed25519_sk");
  217|       |    if (id == NULL) {
  218|       |        goto err;
  219|       |    }
  220|       |    rc = ssh_list_append(session->opts.identity_non_exp, id);
  221|       |    if (rc == SSH_ERROR) {
  222|       |        goto err;
  223|       |    }
  224|       |
  225|       |#ifdef HAVE_ECC
  226|       |    id = strdup("%d/.ssh/id_ecdsa_sk");
  227|       |    if (id == NULL) {
  228|       |        goto err;
  229|       |    }
  230|       |    rc = ssh_list_append(session->opts.identity_non_exp, id);
  231|       |    if (rc == SSH_ERROR) {
  232|       |        goto err;
  233|       |    }
  234|       |#endif /* HAVE_ECC */
  235|       |#endif /* WITH_FIDO2 */
  236|       |
  237|       |    /* Explicitly initialize states */
  238|    362|    session->session_state = SSH_SESSION_STATE_NONE;
  239|    362|    session->pending_call_state = SSH_PENDING_CALL_NONE;
  240|    362|    session->packet_state = PACKET_STATE_INIT;
  241|    362|    session->dh_handshake_state = DH_STATE_INIT;
  242|    362|    session->global_req_state = SSH_CHANNEL_REQ_STATE_NONE;
  243|       |
  244|    362|    session->auth.state = SSH_AUTH_STATE_NONE;
  245|    362|    session->auth.service_state = SSH_AUTH_SERVICE_NONE;
  246|       |
  247|    362|    return session;
  248|       |
  249|    196|err:
  250|    196|    free(id);
  251|    196|    ssh_free(session);
  252|       |    return NULL;
  253|    362|}
ssh_free:
  264|    957|{
  265|    957|  int i;
  266|    957|  struct ssh_iterator *it = NULL;
  267|    957|  struct ssh_buffer_struct *b = NULL;
  268|       |
  269|    957|  if (session == NULL) {
  ------------------
  |  Branch (269:7): [True: 399, False: 558]
  ------------------
  270|    399|    return;
  271|    399|  }
  272|       |
  273|       |  /*
  274|       |   * Delete all channels
  275|       |   *
  276|       |   * This needs the first thing we clean up cause if there is still an open
  277|       |   * channel we call ssh_channel_close() first. So we need a working socket
  278|       |   * and poll context for it.
  279|       |   */
  280|    558|  for (it = ssh_list_get_iterator(session->channels);
  281|    558|       it != NULL;
  ------------------
  |  Branch (281:8): [True: 0, False: 558]
  ------------------
  282|    558|       it = ssh_list_get_iterator(session->channels)) {
  283|      0|      ssh_channel_do_free(ssh_iterator_value(ssh_channel,it));
  ------------------
  |  |  114|      0|  ((type)((iterator)->data))
  ------------------
  284|      0|      ssh_list_remove(session->channels, it);
  285|      0|  }
  286|    558|  ssh_list_free(session->channels);
  287|    558|  session->channels = NULL;
  288|       |
  289|    558|#ifdef WITH_PCAP
  290|    558|  if (session->pcap_ctx) {
  ------------------
  |  Branch (290:7): [True: 0, False: 558]
  ------------------
  291|      0|      ssh_pcap_context_free(session->pcap_ctx);
  292|      0|      session->pcap_ctx = NULL;
  293|      0|  }
  294|    558|#endif
  295|       |
  296|    558|  ssh_socket_free(session->socket);
  297|    558|  session->socket = NULL;
  298|       |
  299|    558|  if (session->default_poll_ctx) {
  ------------------
  |  Branch (299:7): [True: 0, False: 558]
  ------------------
  300|      0|      ssh_poll_ctx_free(session->default_poll_ctx);
  301|      0|  }
  302|       |
  303|    558|  SSH_BUFFER_FREE(session->in_buffer);
  ------------------
  |  |  957|    558|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 363, False: 195]
  |  |  |  Branch (957:69): [Folded, False: 558]
  |  |  ------------------
  ------------------
  304|    558|  SSH_BUFFER_FREE(session->out_buffer);
  ------------------
  |  |  957|    558|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 363, False: 195]
  |  |  |  Branch (957:69): [Folded, False: 558]
  |  |  ------------------
  ------------------
  305|    558|  session->in_buffer = session->out_buffer = NULL;
  306|       |
  307|    558|  if (session->in_hashbuf != NULL) {
  ------------------
  |  Branch (307:7): [True: 0, False: 558]
  ------------------
  308|      0|      SSH_BUFFER_FREE(session->in_hashbuf);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  309|      0|  }
  310|    558|  if (session->out_hashbuf != NULL) {
  ------------------
  |  Branch (310:7): [True: 0, False: 558]
  ------------------
  311|      0|      SSH_BUFFER_FREE(session->out_hashbuf);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  312|      0|  }
  313|       |
  314|    558|  crypto_free(session->current_crypto);
  315|    558|  crypto_free(session->next_crypto);
  316|       |
  317|    558|  ssh_agent_free(session->agent);
  318|       |
  319|    558|  SSH_PKI_CTX_FREE(session->pki_context);
  ------------------
  |  | 1050|    558|    do {                         \
  |  | 1051|    558|        if ((x) != NULL) {       \
  |  |  ------------------
  |  |  |  Branch (1051:13): [True: 362, False: 196]
  |  |  ------------------
  |  | 1052|    362|            ssh_pki_ctx_free(x); \
  |  | 1053|    362|            x = NULL;            \
  |  | 1054|    362|        }                        \
  |  | 1055|    558|    } while (0)
  |  |  ------------------
  |  |  |  Branch (1055:14): [Folded, False: 558]
  |  |  ------------------
  ------------------
  320|       |
  321|    558|  ssh_key_free(session->srv.rsa_key);
  322|    558|  session->srv.rsa_key = NULL;
  323|    558|  ssh_key_free(session->srv.ecdsa_key);
  324|    558|  session->srv.ecdsa_key = NULL;
  325|    558|  ssh_key_free(session->srv.ed25519_key);
  326|    558|  session->srv.ed25519_key = NULL;
  327|       |
  328|    558|  if (session->ssh_message_list) {
  ------------------
  |  Branch (328:7): [True: 0, False: 558]
  ------------------
  329|      0|      ssh_message msg;
  330|       |
  331|      0|      for (msg = ssh_list_pop_head(ssh_message, session->ssh_message_list);
  ------------------
  |  |  122|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  332|      0|           msg != NULL;
  ------------------
  |  Branch (332:12): [True: 0, False: 0]
  ------------------
  333|      0|           msg = ssh_list_pop_head(ssh_message, session->ssh_message_list)) {
  ------------------
  |  |  122|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  334|      0|          ssh_message_free(msg);
  335|      0|      }
  336|      0|      ssh_list_free(session->ssh_message_list);
  337|      0|  }
  338|       |
  339|    558|  if (session->kbdint != NULL) {
  ------------------
  |  Branch (339:7): [True: 0, False: 558]
  ------------------
  340|      0|    ssh_kbdint_free(session->kbdint);
  341|      0|  }
  342|       |
  343|    558|  if (session->packet_callbacks) {
  ------------------
  |  Branch (343:7): [True: 0, False: 558]
  ------------------
  344|      0|    ssh_list_free(session->packet_callbacks);
  345|      0|  }
  346|       |
  347|       |#ifdef WITH_GSSAPI
  348|       |    ssh_gssapi_free(session);
  349|       |    SAFE_FREE(session->opts.gssapi_key_exchange_algs);
  350|       |#endif
  351|       |
  352|       |  /* options */
  353|    558|  if (session->opts.identity) {
  ------------------
  |  Branch (353:7): [True: 362, False: 196]
  ------------------
  354|    362|      char *id = NULL;
  355|       |
  356|    362|      for (id = ssh_list_pop_head(char *, session->opts.identity);
  ------------------
  |  |  122|    362|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  357|    362|           id != NULL;
  ------------------
  |  Branch (357:12): [True: 0, False: 362]
  ------------------
  358|    362|           id = ssh_list_pop_head(char *, session->opts.identity)) {
  ------------------
  |  |  122|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  359|      0|          SAFE_FREE(id);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  360|      0|      }
  361|    362|      ssh_list_free(session->opts.identity);
  362|    362|  }
  363|       |
  364|    558|  if (session->opts.identity_non_exp) {
  ------------------
  |  Branch (364:7): [True: 362, False: 196]
  ------------------
  365|    362|      char *id = NULL;
  366|       |
  367|    362|      for (id = ssh_list_pop_head(char *, session->opts.identity_non_exp);
  ------------------
  |  |  122|    362|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  368|  1.44k|           id != NULL;
  ------------------
  |  Branch (368:12): [True: 1.08k, False: 362]
  ------------------
  369|  1.08k|           id = ssh_list_pop_head(char *, session->opts.identity_non_exp)) {
  ------------------
  |  |  122|  1.08k|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  370|  1.08k|          SAFE_FREE(id);
  ------------------
  |  |  373|  1.08k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.08k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 1.08k]
  |  |  ------------------
  ------------------
  371|  1.08k|      }
  372|    362|      ssh_list_free(session->opts.identity_non_exp);
  373|    362|  }
  374|       |
  375|    558|    if (session->opts.certificate) {
  ------------------
  |  Branch (375:9): [True: 362, False: 196]
  ------------------
  376|    362|        char *cert = NULL;
  377|       |
  378|    362|        for (cert = ssh_list_pop_head(char *, session->opts.certificate);
  ------------------
  |  |  122|    362|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  379|    362|             cert != NULL;
  ------------------
  |  Branch (379:14): [True: 0, False: 362]
  ------------------
  380|    362|             cert = ssh_list_pop_head(char *, session->opts.certificate)) {
  ------------------
  |  |  122|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  381|      0|            SAFE_FREE(cert);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  382|      0|        }
  383|    362|        ssh_list_free(session->opts.certificate);
  384|    362|    }
  385|       |
  386|    558|    if (session->opts.certificate_non_exp) {
  ------------------
  |  Branch (386:9): [True: 362, False: 196]
  ------------------
  387|    362|        char *cert = NULL;
  388|       |
  389|    362|        for (cert = ssh_list_pop_head(char *, session->opts.certificate_non_exp);
  ------------------
  |  |  122|    362|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  390|    362|             cert != NULL;
  ------------------
  |  Branch (390:14): [True: 0, False: 362]
  ------------------
  391|    362|             cert = ssh_list_pop_head(char *, session->opts.certificate_non_exp)) {
  ------------------
  |  |  122|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  392|      0|            SAFE_FREE(cert);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  393|      0|        }
  394|    362|        ssh_list_free(session->opts.certificate_non_exp);
  395|    362|    }
  396|       |
  397|    558|    ssh_proxyjumps_free(session->opts.proxy_jumps);
  398|    558|    SSH_LIST_FREE(session->opts.proxy_jumps);
  ------------------
  |  |  125|    558|    do { if ((x) != NULL) { ssh_list_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (125:14): [True: 362, False: 196]
  |  |  |  Branch (125:69): [Folded, False: 558]
  |  |  ------------------
  ------------------
  399|    558|    SSH_LIST_FREE(session->opts.proxy_jumps_user_cb);
  ------------------
  |  |  125|    558|    do { if ((x) != NULL) { ssh_list_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (125:14): [True: 362, False: 196]
  |  |  |  Branch (125:69): [Folded, False: 558]
  |  |  ------------------
  ------------------
  400|    558|    SAFE_FREE(session->opts.proxy_jumps_str);
  ------------------
  |  |  373|    558|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 558]
  |  |  |  Branch (373:71): [Folded, False: 558]
  |  |  ------------------
  ------------------
  401|       |
  402|    558|    if (session->opts.send_env) {
  ------------------
  |  Branch (402:9): [True: 362, False: 196]
  ------------------
  403|    362|        char *pattern = NULL;
  404|       |
  405|    362|        for (pattern = ssh_list_pop_head(char *, session->opts.send_env);
  ------------------
  |  |  122|    362|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  406|    362|             pattern != NULL;
  ------------------
  |  Branch (406:14): [True: 0, False: 362]
  ------------------
  407|    362|             pattern = ssh_list_pop_head(char *, session->opts.send_env)) {
  ------------------
  |  |  122|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  408|      0|            SAFE_FREE(pattern);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  409|      0|        }
  410|    362|        ssh_list_free(session->opts.send_env);
  411|    362|    }
  412|       |
  413|    558|    while ((b = ssh_list_pop_head(struct ssh_buffer_struct *,
  ------------------
  |  |  122|    558|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  |  Branch (413:12): [True: 0, False: 558]
  ------------------
  414|    558|                                  session->out_queue)) != NULL) {
  415|      0|        SSH_BUFFER_FREE(b);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  416|      0|    }
  417|    558|    ssh_list_free(session->out_queue);
  418|       |
  419|    558|  ssh_agent_state_free(session->agent_state);
  420|    558|  session->agent_state = NULL;
  421|       |
  422|    558|  SAFE_FREE(session->auth.auto_state);
  ------------------
  |  |  373|    558|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 558]
  |  |  |  Branch (373:71): [Folded, False: 558]
  |  |  ------------------
  ------------------
  423|    558|  SAFE_FREE(session->serverbanner);
  ------------------
  |  |  373|    558|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 558]
  |  |  |  Branch (373:71): [Folded, False: 558]
  |  |  ------------------
  ------------------
  424|    558|  SAFE_FREE(session->clientbanner);
  ------------------
  |  |  373|    558|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 558]
  |  |  |  Branch (373:71): [Folded, False: 558]
  |  |  ------------------
  ------------------
  425|    558|  SAFE_FREE(session->banner);
  ------------------
  |  |  373|    558|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 558]
  |  |  |  Branch (373:71): [Folded, False: 558]
  |  |  ------------------
  ------------------
  426|    558|  SAFE_FREE(session->disconnect_message);
  ------------------
  |  |  373|    558|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 558]
  |  |  |  Branch (373:71): [Folded, False: 558]
  |  |  ------------------
  ------------------
  427|    558|  SAFE_FREE(session->peer_discon_msg);
  ------------------
  |  |  373|    558|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 558]
  |  |  |  Branch (373:71): [Folded, False: 558]
  |  |  ------------------
  ------------------
  428|       |
  429|    558|  SAFE_FREE(session->opts.agent_socket);
  ------------------
  |  |  373|    558|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 558]
  |  |  |  Branch (373:71): [Folded, False: 558]
  |  |  ------------------
  ------------------
  430|    558|  SAFE_FREE(session->opts.bindaddr);
  ------------------
  |  |  373|    558|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 558]
  |  |  |  Branch (373:71): [Folded, False: 558]
  |  |  ------------------
  ------------------
  431|    558|  SAFE_FREE(session->opts.username);
  ------------------
  |  |  373|    558|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 558]
  |  |  |  Branch (373:71): [Folded, False: 558]
  |  |  ------------------
  ------------------
  432|    558|  SAFE_FREE(session->opts.host);
  ------------------
  |  |  373|    558|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 558]
  |  |  |  Branch (373:71): [Folded, False: 558]
  |  |  ------------------
  ------------------
  433|    558|  SAFE_FREE(session->opts.originalhost);
  ------------------
  |  |  373|    558|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 558]
  |  |  |  Branch (373:71): [Folded, False: 558]
  |  |  ------------------
  ------------------
  434|    558|  SAFE_FREE(session->opts.config_hostname);
  ------------------
  |  |  373|    558|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 558]
  |  |  |  Branch (373:71): [Folded, False: 558]
  |  |  ------------------
  ------------------
  435|    558|  SAFE_FREE(session->opts.tag);
  ------------------
  |  |  373|    558|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 558]
  |  |  |  Branch (373:71): [Folded, False: 558]
  |  |  ------------------
  ------------------
  436|    558|  SAFE_FREE(session->opts.homedir);
  ------------------
  |  |  373|    558|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 558]
  |  |  |  Branch (373:71): [Folded, False: 558]
  |  |  ------------------
  ------------------
  437|    558|  SAFE_FREE(session->opts.sshdir);
  ------------------
  |  |  373|    558|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 558]
  |  |  |  Branch (373:71): [Folded, False: 558]
  |  |  ------------------
  ------------------
  438|    558|  SAFE_FREE(session->opts.knownhosts);
  ------------------
  |  |  373|    558|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 558]
  |  |  |  Branch (373:71): [Folded, False: 558]
  |  |  ------------------
  ------------------
  439|    558|  SAFE_FREE(session->opts.global_knownhosts);
  ------------------
  |  |  373|    558|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 558]
  |  |  |  Branch (373:71): [Folded, False: 558]
  |  |  ------------------
  ------------------
  440|    558|  SAFE_FREE(session->opts.ProxyCommand);
  ------------------
  |  |  373|    558|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 558]
  |  |  |  Branch (373:71): [Folded, False: 558]
  |  |  ------------------
  ------------------
  441|    558|  SAFE_FREE(session->opts.gss_server_identity);
  ------------------
  |  |  373|    558|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 558]
  |  |  |  Branch (373:71): [Folded, False: 558]
  |  |  ------------------
  ------------------
  442|    558|  SAFE_FREE(session->opts.gss_client_identity);
  ------------------
  |  |  373|    558|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 558]
  |  |  |  Branch (373:71): [Folded, False: 558]
  |  |  ------------------
  ------------------
  443|    558|  SAFE_FREE(session->opts.pubkey_accepted_types);
  ------------------
  |  |  373|    558|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 558]
  |  |  |  Branch (373:71): [Folded, False: 558]
  |  |  ------------------
  ------------------
  444|    558|  SAFE_FREE(session->opts.control_path);
  ------------------
  |  |  373|    558|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 558]
  |  |  |  Branch (373:71): [Folded, False: 558]
  |  |  ------------------
  ------------------
  445|    558|  SAFE_FREE(session->opts.preferred_authentications);
  ------------------
  |  |  373|    558|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 558]
  |  |  |  Branch (373:71): [Folded, False: 558]
  |  |  ------------------
  ------------------
  446|       |
  447|    558|  if (session->opts.local_forward) {
  ------------------
  |  Branch (447:7): [True: 362, False: 196]
  ------------------
  448|    362|      char *entry = NULL;
  449|       |
  450|    362|      for (entry = ssh_list_pop_head(char *, session->opts.local_forward);
  ------------------
  |  |  122|    362|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  451|    362|           entry != NULL;
  ------------------
  |  Branch (451:12): [True: 0, False: 362]
  ------------------
  452|    362|           entry = ssh_list_pop_head(char *, session->opts.local_forward)) {
  ------------------
  |  |  122|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  453|      0|          SAFE_FREE(entry);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  454|      0|      }
  455|    362|      ssh_list_free(session->opts.local_forward);
  456|    362|  }
  457|       |
  458|  6.13k|  for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  6.13k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (458:15): [True: 5.58k, False: 558]
  ------------------
  459|  5.58k|      if (session->opts.wanted_methods[i]) {
  ------------------
  |  Branch (459:11): [True: 0, False: 5.58k]
  ------------------
  460|      0|          SAFE_FREE(session->opts.wanted_methods[i]);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  461|      0|      }
  462|  5.58k|  }
  463|       |
  464|    558|  SAFE_FREE(session->server_opts.custombanner);
  ------------------
  |  |  373|    558|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 558]
  |  |  |  Branch (373:71): [Folded, False: 558]
  |  |  ------------------
  ------------------
  465|    558|  SAFE_FREE(session->server_opts.moduli_file);
  ------------------
  |  |  373|    558|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 558]
  |  |  |  Branch (373:71): [Folded, False: 558]
  |  |  ------------------
  ------------------
  466|       |
  467|    558|  _ssh_remove_legacy_log_cb();
  468|       |
  469|       |  /* burn connection, it could contain sensitive data */
  470|    558|  ssh_burn(session, sizeof(struct ssh_session_struct));
  ------------------
  |  |  388|    558|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  471|       |  SAFE_FREE(session);
  ------------------
  |  |  373|    558|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 558, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 558]
  |  |  ------------------
  ------------------
  472|    558|}
ssh_set_blocking:
  686|    362|{
  687|    362|    if (session == NULL) {
  ------------------
  |  Branch (687:9): [True: 0, False: 362]
  ------------------
  688|      0|        return;
  689|      0|    }
  690|    362|    session->flags &= ~SSH_SESSION_FLAG_BLOCKING;
  ------------------
  |  |   75|    362|#define SSH_SESSION_FLAG_BLOCKING 0x0001
  ------------------
  691|    362|    session->flags |= blocking ? SSH_SESSION_FLAG_BLOCKING : 0;
  ------------------
  |  |   75|    362|#define SSH_SESSION_FLAG_BLOCKING 0x0001
  ------------------
  |  Branch (691:23): [True: 362, False: 0]
  ------------------
  692|    362|}

sftp_attributes_free:
  903|  1.44k|void sftp_attributes_free(sftp_attributes file){
  904|  1.44k|  if (file == NULL) {
  ------------------
  |  Branch (904:7): [True: 1.21k, False: 236]
  ------------------
  905|  1.21k|    return;
  906|  1.21k|  }
  907|       |
  908|    236|  SSH_STRING_FREE(file->acl);
  ------------------
  |  |  915|    236|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 32, False: 204]
  |  |  |  Branch (915:69): [Folded, False: 236]
  |  |  ------------------
  ------------------
  909|    236|  SSH_STRING_FREE(file->extended_data);
  ------------------
  |  |  915|    236|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 1, False: 235]
  |  |  |  Branch (915:69): [Folded, False: 236]
  |  |  ------------------
  ------------------
  910|    236|  SSH_STRING_FREE(file->extended_type);
  ------------------
  |  |  915|    236|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 1, False: 235]
  |  |  |  Branch (915:69): [Folded, False: 236]
  |  |  ------------------
  ------------------
  911|       |
  912|    236|  SAFE_FREE(file->name);
  ------------------
  |  |  373|    236|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 21, False: 215]
  |  |  |  Branch (373:71): [Folded, False: 236]
  |  |  ------------------
  ------------------
  913|    236|  SAFE_FREE(file->longname);
  ------------------
  |  |  373|    236|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 21, False: 215]
  |  |  |  Branch (373:71): [Folded, False: 236]
  |  |  ------------------
  ------------------
  914|    236|  SAFE_FREE(file->group);
  ------------------
  |  |  373|    236|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 30, False: 206]
  |  |  |  Branch (373:71): [Folded, False: 236]
  |  |  ------------------
  ------------------
  915|    236|  SAFE_FREE(file->owner);
  ------------------
  |  |  373|    236|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 30, False: 206]
  |  |  |  Branch (373:71): [Folded, False: 236]
  |  |  ------------------
  ------------------
  916|       |
  917|       |  SAFE_FREE(file);
  ------------------
  |  |  373|    236|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 236, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 236]
  |  |  ------------------
  ------------------
  918|    236|}

sftp_parse_attr:
  666|  1.44k|{
  667|  1.44k|    switch (session->version) {
  668|    724|    case 4:
  ------------------
  |  Branch (668:5): [True: 724, False: 724]
  ------------------
  669|    724|        return sftp_parse_attr_4(session, buf, expectname);
  670|    724|    case 3:
  ------------------
  |  Branch (670:5): [True: 724, False: 724]
  ------------------
  671|    724|    case 2:
  ------------------
  |  Branch (671:5): [True: 0, False: 1.44k]
  ------------------
  672|    724|    case 1:
  ------------------
  |  Branch (672:5): [True: 0, False: 1.44k]
  ------------------
  673|    724|    case 0:
  ------------------
  |  Branch (673:5): [True: 0, False: 1.44k]
  ------------------
  674|    724|        return sftp_parse_attr_3(session, buf, expectname);
  675|      0|    default:
  ------------------
  |  Branch (675:5): [True: 0, False: 1.44k]
  ------------------
  676|      0|        ssh_set_error(session->session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  677|      0|                      "Version %d unsupported by client",
  678|      0|                      session->server_version);
  679|      0|        return NULL;
  680|  1.44k|    }
  681|       |
  682|      0|    return NULL;
  683|  1.44k|}
sftp_set_error:
  686|    600|{
  687|    600|    if (sftp != NULL) {
  ------------------
  |  Branch (687:9): [True: 600, False: 0]
  ------------------
  688|    600|        sftp->errnum = errnum;
  689|    600|    }
  690|    600|}
sftp_common.c:sftp_parse_attr_4:
  279|    724|{
  280|    724|    sftp_attributes attr = NULL;
  281|    724|    ssh_string owner = NULL;
  282|    724|    ssh_string group = NULL;
  283|    724|    uint32_t flags = 0;
  284|    724|    int ok = 0;
  285|       |
  286|       |    /* unused member variable */
  287|    724|    (void) expectnames;
  288|       |
  289|    724|    attr = calloc(1, sizeof(struct sftp_attributes_struct));
  290|    724|    if (attr == NULL) {
  ------------------
  |  Branch (290:9): [True: 0, False: 724]
  ------------------
  291|      0|        ssh_set_error_oom(sftp->session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  292|      0|        sftp_set_error(sftp, SSH_FX_FAILURE);
  ------------------
  |  | 1584|      0|#define SSH_FX_FAILURE 4
  ------------------
  293|      0|        return NULL;
  294|      0|    }
  295|       |
  296|       |    /* This isn't really a loop, but it is like a try..catch.. */
  297|    724|    do {
  298|    724|        if (ssh_buffer_get_u32(buf, &flags) != 4) {
  ------------------
  |  Branch (298:13): [True: 38, False: 686]
  ------------------
  299|     38|            break;
  300|     38|        }
  301|       |
  302|    686|        flags = ntohl(flags);
  303|    686|        attr->flags = flags;
  304|       |
  305|    686|        if (flags & SSH_FILEXFER_ATTR_SIZE) {
  ------------------
  |  | 1549|    686|#define SSH_FILEXFER_ATTR_SIZE 0x00000001
  ------------------
  |  Branch (305:13): [True: 190, False: 496]
  ------------------
  306|    190|            if (ssh_buffer_get_u64(buf, &attr->size) != 8) {
  ------------------
  |  Branch (306:17): [True: 22, False: 168]
  ------------------
  307|     22|                break;
  308|     22|            }
  309|    168|            attr->size = ntohll(attr->size);
  ------------------
  |  |  488|    168|    (((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32))
  ------------------
  310|    168|        }
  311|       |
  312|    664|        if (flags & SSH_FILEXFER_ATTR_OWNERGROUP) {
  ------------------
  |  | 1556|    664|#define SSH_FILEXFER_ATTR_OWNERGROUP 0x00000080
  ------------------
  |  Branch (312:13): [True: 266, False: 398]
  ------------------
  313|    266|            owner = ssh_buffer_get_ssh_string(buf);
  314|    266|            if (owner == NULL) {
  ------------------
  |  Branch (314:17): [True: 126, False: 140]
  ------------------
  315|    126|                break;
  316|    126|            }
  317|    140|            attr->owner = ssh_string_to_char(owner);
  318|    140|            SSH_STRING_FREE(owner);
  ------------------
  |  |  915|    140|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 140, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 140]
  |  |  ------------------
  ------------------
  319|    140|            if (attr->owner == NULL) {
  ------------------
  |  Branch (319:17): [True: 0, False: 140]
  ------------------
  320|      0|                break;
  321|      0|            }
  322|       |
  323|    140|            group = ssh_buffer_get_ssh_string(buf);
  324|    140|            if (group == NULL) {
  ------------------
  |  Branch (324:17): [True: 64, False: 76]
  ------------------
  325|     64|                break;
  326|     64|            }
  327|     76|            attr->group = ssh_string_to_char(group);
  328|     76|            SSH_STRING_FREE(group);
  ------------------
  |  |  915|     76|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 76, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 76]
  |  |  ------------------
  ------------------
  329|     76|            if (attr->group == NULL) {
  ------------------
  |  Branch (329:17): [True: 0, False: 76]
  ------------------
  330|      0|                break;
  331|      0|            }
  332|     76|        }
  333|       |
  334|    474|        if (flags & SSH_FILEXFER_ATTR_PERMISSIONS) {
  ------------------
  |  | 1550|    474|#define SSH_FILEXFER_ATTR_PERMISSIONS 0x00000004
  ------------------
  |  Branch (334:13): [True: 116, False: 358]
  ------------------
  335|    116|            if (ssh_buffer_get_u32(buf, &attr->permissions) != 4) {
  ------------------
  |  Branch (335:17): [True: 20, False: 96]
  ------------------
  336|     20|                break;
  337|     20|            }
  338|     96|            attr->permissions = ntohl(attr->permissions);
  339|       |
  340|       |            /* FIXME on windows! */
  341|     96|            switch (attr->permissions & SSH_S_IFMT) {
  ------------------
  |  | 1616|     96|#define SSH_S_IFMT   00170000
  ------------------
  342|      4|            case SSH_S_IFSOCK:
  ------------------
  |  | 1617|      4|#define SSH_S_IFSOCK 0140000
  ------------------
  |  Branch (342:13): [True: 4, False: 92]
  ------------------
  343|      4|            case SSH_S_IFBLK:
  ------------------
  |  | 1620|      4|#define SSH_S_IFBLK  0060000
  ------------------
  |  Branch (343:13): [True: 0, False: 96]
  ------------------
  344|      6|            case SSH_S_IFCHR:
  ------------------
  |  | 1622|      6|#define SSH_S_IFCHR  0020000
  ------------------
  |  Branch (344:13): [True: 2, False: 94]
  ------------------
  345|     10|            case SSH_S_IFIFO:
  ------------------
  |  | 1623|     10|#define SSH_S_IFIFO  0010000
  ------------------
  |  Branch (345:13): [True: 4, False: 92]
  ------------------
  346|     10|                attr->type = SSH_FILEXFER_TYPE_SPECIAL;
  ------------------
  |  | 1565|     10|#define SSH_FILEXFER_TYPE_SPECIAL 4
  ------------------
  347|     10|                break;
  348|      4|            case SSH_S_IFLNK:
  ------------------
  |  | 1618|      4|#define SSH_S_IFLNK  0120000
  ------------------
  |  Branch (348:13): [True: 4, False: 92]
  ------------------
  349|      4|                attr->type = SSH_FILEXFER_TYPE_SYMLINK;
  ------------------
  |  | 1564|      4|#define SSH_FILEXFER_TYPE_SYMLINK 3
  ------------------
  350|      4|                break;
  351|      0|            case SSH_S_IFREG:
  ------------------
  |  | 1619|      0|#define SSH_S_IFREG  0100000
  ------------------
  |  Branch (351:13): [True: 0, False: 96]
  ------------------
  352|      0|                attr->type = SSH_FILEXFER_TYPE_REGULAR;
  ------------------
  |  | 1562|      0|#define SSH_FILEXFER_TYPE_REGULAR 1
  ------------------
  353|      0|                break;
  354|      2|            case SSH_S_IFDIR:
  ------------------
  |  | 1621|      2|#define SSH_S_IFDIR  0040000
  ------------------
  |  Branch (354:13): [True: 2, False: 94]
  ------------------
  355|      2|                attr->type = SSH_FILEXFER_TYPE_DIRECTORY;
  ------------------
  |  | 1563|      2|#define SSH_FILEXFER_TYPE_DIRECTORY 2
  ------------------
  356|      2|                break;
  357|     80|            default:
  ------------------
  |  Branch (357:13): [True: 80, False: 16]
  ------------------
  358|     80|                attr->type = SSH_FILEXFER_TYPE_UNKNOWN;
  ------------------
  |  | 1566|     80|#define SSH_FILEXFER_TYPE_UNKNOWN 5
  ------------------
  359|     80|                break;
  360|     96|            }
  361|     96|        }
  362|       |
  363|    454|        if (flags & SSH_FILEXFER_ATTR_ACCESSTIME) {
  ------------------
  |  | 1551|    454|#define SSH_FILEXFER_ATTR_ACCESSTIME 0x00000008
  ------------------
  |  Branch (363:13): [True: 94, False: 360]
  ------------------
  364|     94|            if (ssh_buffer_get_u64(buf, &attr->atime64) != 8) {
  ------------------
  |  Branch (364:17): [True: 16, False: 78]
  ------------------
  365|     16|                break;
  366|     16|            }
  367|     78|            attr->atime64 = ntohll(attr->atime64);
  ------------------
  |  |  488|     78|    (((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32))
  ------------------
  368|       |
  369|     78|            if (flags & SSH_FILEXFER_ATTR_SUBSECOND_TIMES) {
  ------------------
  |  | 1557|     78|#define SSH_FILEXFER_ATTR_SUBSECOND_TIMES 0x00000100
  ------------------
  |  Branch (369:17): [True: 50, False: 28]
  ------------------
  370|     50|                if (ssh_buffer_get_u32(buf, &attr->atime_nseconds) != 4) {
  ------------------
  |  Branch (370:21): [True: 6, False: 44]
  ------------------
  371|      6|                    break;
  372|      6|                }
  373|     44|                attr->atime_nseconds = ntohl(attr->atime_nseconds);
  374|     44|            }
  375|     78|        }
  376|       |
  377|    432|        if (flags & SSH_FILEXFER_ATTR_CREATETIME) {
  ------------------
  |  | 1553|    432|#define SSH_FILEXFER_ATTR_CREATETIME 0x00000010
  ------------------
  |  Branch (377:13): [True: 78, False: 354]
  ------------------
  378|     78|            if (ssh_buffer_get_u64(buf, &attr->createtime) != 8) {
  ------------------
  |  Branch (378:17): [True: 10, False: 68]
  ------------------
  379|     10|                break;
  380|     10|            }
  381|     68|            attr->createtime = ntohll(attr->createtime);
  ------------------
  |  |  488|     68|    (((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32))
  ------------------
  382|       |
  383|     68|            if (flags & SSH_FILEXFER_ATTR_SUBSECOND_TIMES) {
  ------------------
  |  | 1557|     68|#define SSH_FILEXFER_ATTR_SUBSECOND_TIMES 0x00000100
  ------------------
  |  Branch (383:17): [True: 42, False: 26]
  ------------------
  384|     42|                if (ssh_buffer_get_u32(buf, &attr->createtime_nseconds) != 4) {
  ------------------
  |  Branch (384:21): [True: 4, False: 38]
  ------------------
  385|      4|                    break;
  386|      4|                }
  387|     38|                attr->createtime_nseconds = ntohl(attr->createtime_nseconds);
  388|     38|            }
  389|     68|        }
  390|       |
  391|    418|        if (flags & SSH_FILEXFER_ATTR_MODIFYTIME) {
  ------------------
  |  | 1554|    418|#define SSH_FILEXFER_ATTR_MODIFYTIME 0x00000020
  ------------------
  |  Branch (391:13): [True: 102, False: 316]
  ------------------
  392|    102|            if (ssh_buffer_get_u64(buf, &attr->mtime64) != 8) {
  ------------------
  |  Branch (392:17): [True: 14, False: 88]
  ------------------
  393|     14|                break;
  394|     14|            }
  395|     88|            attr->mtime64 = ntohll(attr->mtime64);
  ------------------
  |  |  488|     88|    (((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32))
  ------------------
  396|       |
  397|     88|            if (flags & SSH_FILEXFER_ATTR_SUBSECOND_TIMES) {
  ------------------
  |  | 1557|     88|#define SSH_FILEXFER_ATTR_SUBSECOND_TIMES 0x00000100
  ------------------
  |  Branch (397:17): [True: 44, False: 44]
  ------------------
  398|     44|                if (ssh_buffer_get_u32(buf, &attr->mtime_nseconds) != 4) {
  ------------------
  |  Branch (398:21): [True: 2, False: 42]
  ------------------
  399|      2|                    break;
  400|      2|                }
  401|     42|                attr->mtime_nseconds = ntohl(attr->mtime_nseconds);
  402|     42|            }
  403|     88|        }
  404|       |
  405|    402|        if (flags & SSH_FILEXFER_ATTR_ACL) {
  ------------------
  |  | 1555|    402|#define SSH_FILEXFER_ATTR_ACL 0x00000040
  ------------------
  |  Branch (405:13): [True: 98, False: 304]
  ------------------
  406|     98|            if ((attr->acl = ssh_buffer_get_ssh_string(buf)) == NULL) {
  ------------------
  |  Branch (406:17): [True: 30, False: 68]
  ------------------
  407|     30|                break;
  408|     30|            }
  409|     98|        }
  410|       |
  411|    372|        if (flags & SSH_FILEXFER_ATTR_EXTENDED) {
  ------------------
  |  | 1558|    372|#define SSH_FILEXFER_ATTR_EXTENDED 0x80000000
  ------------------
  |  Branch (411:13): [True: 274, False: 98]
  ------------------
  412|    274|            if (ssh_buffer_get_u32(buf,&attr->extended_count) != 4) {
  ------------------
  |  Branch (412:17): [True: 60, False: 214]
  ------------------
  413|     60|                break;
  414|     60|            }
  415|    214|            attr->extended_count = ntohl(attr->extended_count);
  416|       |
  417|  46.5k|            while (attr->extended_count &&
  ------------------
  |  Branch (417:20): [True: 46.5k, False: 14]
  ------------------
  418|  46.5k|                   (attr->extended_type = ssh_buffer_get_ssh_string(buf)) &&
  ------------------
  |  Branch (418:20): [True: 46.4k, False: 146]
  ------------------
  419|  46.4k|                   (attr->extended_data = ssh_buffer_get_ssh_string(buf))) {
  ------------------
  |  Branch (419:20): [True: 46.3k, False: 54]
  ------------------
  420|  46.3k|                attr->extended_count--;
  421|       |                /* just ignore the extensions -- we can't interpret them */
  422|  46.3k|                SSH_STRING_FREE(attr->extended_type);
  ------------------
  |  |  915|  46.3k|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 46.3k, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 46.3k]
  |  |  ------------------
  ------------------
  423|  46.3k|                SSH_STRING_FREE(attr->extended_data);
  ------------------
  |  |  915|  46.3k|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 46.3k, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 46.3k]
  |  |  ------------------
  ------------------
  424|  46.3k|            }
  425|       |
  426|    214|            if (attr->extended_count) {
  ------------------
  |  Branch (426:17): [True: 200, False: 14]
  ------------------
  427|    200|                break;
  428|    200|            }
  429|    214|        }
  430|    112|        ok = 1;
  431|    112|    } while (0);
  ------------------
  |  Branch (431:14): [Folded, False: 112]
  ------------------
  432|       |
  433|    724|    if (ok == 0) {
  ------------------
  |  Branch (433:9): [True: 612, False: 112]
  ------------------
  434|       |        /* break issued somewhere */
  435|    612|        SSH_STRING_FREE(attr->acl);
  ------------------
  |  |  915|    612|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 36, False: 576]
  |  |  |  Branch (915:69): [Folded, False: 612]
  |  |  ------------------
  ------------------
  436|    612|        SSH_STRING_FREE(attr->extended_type);
  ------------------
  |  |  915|    612|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 54, False: 558]
  |  |  |  Branch (915:69): [Folded, False: 612]
  |  |  ------------------
  ------------------
  437|    612|        SSH_STRING_FREE(attr->extended_data);
  ------------------
  |  |  915|    612|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 612]
  |  |  |  Branch (915:69): [Folded, False: 612]
  |  |  ------------------
  ------------------
  438|    612|        SAFE_FREE(attr->owner);
  ------------------
  |  |  373|    612|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 110, False: 502]
  |  |  |  Branch (373:71): [Folded, False: 612]
  |  |  ------------------
  ------------------
  439|    612|        SAFE_FREE(attr->group);
  ------------------
  |  |  373|    612|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 46, False: 566]
  |  |  |  Branch (373:71): [Folded, False: 612]
  |  |  ------------------
  ------------------
  440|    612|        SAFE_FREE(attr);
  ------------------
  |  |  373|    612|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 612, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 612]
  |  |  ------------------
  ------------------
  441|       |
  442|    612|        ssh_set_error(sftp->session, SSH_FATAL, "Invalid ATTR structure");
  ------------------
  |  |  311|    612|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  443|       |
  444|    612|        return NULL;
  445|    612|    }
  446|       |
  447|    112|    return attr;
  448|    724|}
sftp_common.c:sftp_parse_attr_3:
  522|    724|{
  523|    724|    sftp_attributes attr;
  524|    724|    int rc;
  525|       |
  526|    724|    attr = calloc(1, sizeof(struct sftp_attributes_struct));
  527|    724|    if (attr == NULL) {
  ------------------
  |  Branch (527:9): [True: 0, False: 724]
  ------------------
  528|      0|        ssh_set_error_oom(sftp->session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  529|      0|        sftp_set_error(sftp, SSH_FX_FAILURE);
  ------------------
  |  | 1584|      0|#define SSH_FX_FAILURE 4
  ------------------
  530|      0|        return NULL;
  531|      0|    }
  532|       |
  533|    724|    if (expectname) {
  ------------------
  |  Branch (533:9): [True: 362, False: 362]
  ------------------
  534|    362|        rc = ssh_buffer_unpack(buf, "ss",
  ------------------
  |  |   60|    362|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    362|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    362|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    362|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    362|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    362|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    362|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  535|    362|                               &attr->name,
  536|    362|                               &attr->longname);
  537|    362|        if (rc != SSH_OK){
  ------------------
  |  |  316|    362|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (537:13): [True: 320, False: 42]
  ------------------
  538|    320|            goto error;
  539|    320|        }
  540|     42|        SSH_LOG(SSH_LOG_DEBUG, "Name: %s", attr->name);
  ------------------
  |  |  281|     42|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  541|       |
  542|       |        /* Set owner and group if we talk to openssh and have the longname */
  543|     42|        if (ssh_get_openssh_version(sftp->session)) {
  ------------------
  |  Branch (543:13): [True: 0, False: 42]
  ------------------
  544|      0|            attr->owner = sftp_parse_longname(attr->longname,
  545|      0|                                              SFTP_LONGNAME_OWNER);
  546|      0|            if (attr->owner == NULL) {
  ------------------
  |  Branch (546:17): [True: 0, False: 0]
  ------------------
  547|      0|                goto error;
  548|      0|            }
  549|       |
  550|      0|            attr->group = sftp_parse_longname(attr->longname,
  551|      0|                                              SFTP_LONGNAME_GROUP);
  552|      0|            if (attr->group == NULL) {
  ------------------
  |  Branch (552:17): [True: 0, False: 0]
  ------------------
  553|      0|                goto error;
  554|      0|            }
  555|      0|        }
  556|     42|    }
  557|       |
  558|    404|    rc = ssh_buffer_unpack(buf, "d", &attr->flags);
  ------------------
  |  |   60|    404|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    404|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    404|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    404|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    404|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    404|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    404|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  559|    404|    if (rc != SSH_OK){
  ------------------
  |  |  316|    404|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (559:9): [True: 22, False: 382]
  ------------------
  560|     22|        goto error;
  561|     22|    }
  562|    382|    SSH_LOG(SSH_LOG_DEBUG, "Flags: %.8" PRIx32, attr->flags);
  ------------------
  |  |  281|    382|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  563|       |
  564|    382|    if (attr->flags & SSH_FILEXFER_ATTR_SIZE) {
  ------------------
  |  | 1549|    382|#define SSH_FILEXFER_ATTR_SIZE 0x00000001
  ------------------
  |  Branch (564:9): [True: 106, False: 276]
  ------------------
  565|    106|        rc = ssh_buffer_unpack(buf, "q", &attr->size);
  ------------------
  |  |   60|    106|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    106|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    106|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    106|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    106|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    106|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    106|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  566|    106|        if(rc != SSH_OK) {
  ------------------
  |  |  316|    106|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (566:12): [True: 14, False: 92]
  ------------------
  567|     14|            goto error;
  568|     14|        }
  569|     92|        SSH_LOG(SSH_LOG_DEBUG, "Size: %" PRIu64, (uint64_t)attr->size);
  ------------------
  |  |  281|     92|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  570|     92|    }
  571|       |
  572|    368|    if (attr->flags & SSH_FILEXFER_ATTR_UIDGID) {
  ------------------
  |  | 1559|    368|#define SSH_FILEXFER_ATTR_UIDGID 0x00000002
  ------------------
  |  Branch (572:9): [True: 129, False: 239]
  ------------------
  573|    129|        rc = ssh_buffer_unpack(buf, "dd",
  ------------------
  |  |   60|    129|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    129|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    129|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    129|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    129|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    129|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    129|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  574|    129|                               &attr->uid,
  575|    129|                               &attr->gid);
  576|    129|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    129|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (576:13): [True: 20, False: 109]
  ------------------
  577|     20|            goto error;
  578|     20|        }
  579|    129|    }
  580|       |
  581|    348|    if (attr->flags & SSH_FILEXFER_ATTR_PERMISSIONS) {
  ------------------
  |  | 1550|    348|#define SSH_FILEXFER_ATTR_PERMISSIONS 0x00000004
  ------------------
  |  Branch (581:9): [True: 114, False: 234]
  ------------------
  582|    114|        rc = ssh_buffer_unpack(buf, "d", &attr->permissions);
  ------------------
  |  |   60|    114|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    114|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    114|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    114|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    114|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    114|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    114|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  583|    114|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    114|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (583:13): [True: 15, False: 99]
  ------------------
  584|     15|            goto error;
  585|     15|        }
  586|       |
  587|     99|        switch (attr->permissions & SSH_S_IFMT) {
  ------------------
  |  | 1616|     99|#define SSH_S_IFMT   00170000
  ------------------
  588|      5|        case SSH_S_IFSOCK:
  ------------------
  |  | 1617|      5|#define SSH_S_IFSOCK 0140000
  ------------------
  |  Branch (588:9): [True: 5, False: 94]
  ------------------
  589|      9|        case SSH_S_IFBLK:
  ------------------
  |  | 1620|      9|#define SSH_S_IFBLK  0060000
  ------------------
  |  Branch (589:9): [True: 4, False: 95]
  ------------------
  590|     11|        case SSH_S_IFCHR:
  ------------------
  |  | 1622|     11|#define SSH_S_IFCHR  0020000
  ------------------
  |  Branch (590:9): [True: 2, False: 97]
  ------------------
  591|     16|        case SSH_S_IFIFO:
  ------------------
  |  | 1623|     16|#define SSH_S_IFIFO  0010000
  ------------------
  |  Branch (591:9): [True: 5, False: 94]
  ------------------
  592|     16|            attr->type = SSH_FILEXFER_TYPE_SPECIAL;
  ------------------
  |  | 1565|     16|#define SSH_FILEXFER_TYPE_SPECIAL 4
  ------------------
  593|     16|            break;
  594|      2|        case SSH_S_IFLNK:
  ------------------
  |  | 1618|      2|#define SSH_S_IFLNK  0120000
  ------------------
  |  Branch (594:9): [True: 2, False: 97]
  ------------------
  595|      2|            attr->type = SSH_FILEXFER_TYPE_SYMLINK;
  ------------------
  |  | 1564|      2|#define SSH_FILEXFER_TYPE_SYMLINK 3
  ------------------
  596|      2|            break;
  597|      3|        case SSH_S_IFREG:
  ------------------
  |  | 1619|      3|#define SSH_S_IFREG  0100000
  ------------------
  |  Branch (597:9): [True: 3, False: 96]
  ------------------
  598|      3|            attr->type = SSH_FILEXFER_TYPE_REGULAR;
  ------------------
  |  | 1562|      3|#define SSH_FILEXFER_TYPE_REGULAR 1
  ------------------
  599|      3|            break;
  600|      0|        case SSH_S_IFDIR:
  ------------------
  |  | 1621|      0|#define SSH_S_IFDIR  0040000
  ------------------
  |  Branch (600:9): [True: 0, False: 99]
  ------------------
  601|      0|            attr->type = SSH_FILEXFER_TYPE_DIRECTORY;
  ------------------
  |  | 1563|      0|#define SSH_FILEXFER_TYPE_DIRECTORY 2
  ------------------
  602|      0|            break;
  603|     78|        default:
  ------------------
  |  Branch (603:9): [True: 78, False: 21]
  ------------------
  604|     78|            attr->type = SSH_FILEXFER_TYPE_UNKNOWN;
  ------------------
  |  | 1566|     78|#define SSH_FILEXFER_TYPE_UNKNOWN 5
  ------------------
  605|     78|            break;
  606|     99|        }
  607|     99|    }
  608|       |
  609|    333|    if (attr->flags & SSH_FILEXFER_ATTR_ACMODTIME) {
  ------------------
  |  | 1552|    333|#define SSH_FILEXFER_ATTR_ACMODTIME  0x00000008
  ------------------
  |  Branch (609:9): [True: 107, False: 226]
  ------------------
  610|    107|        rc = ssh_buffer_unpack(buf, "dd",
  ------------------
  |  |   60|    107|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    107|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    107|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    107|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    107|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    107|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    107|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  611|    107|                               &attr->atime,
  612|    107|                               &attr->mtime);
  613|    107|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    107|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (613:13): [True: 21, False: 86]
  ------------------
  614|     21|            goto error;
  615|     21|        }
  616|    107|    }
  617|       |
  618|    312|    if (attr->flags & SSH_FILEXFER_ATTR_EXTENDED) {
  ------------------
  |  | 1558|    312|#define SSH_FILEXFER_ATTR_EXTENDED 0x80000000
  ------------------
  |  Branch (618:9): [True: 203, False: 109]
  ------------------
  619|    203|        rc = ssh_buffer_unpack(buf, "d", &attr->extended_count);
  ------------------
  |  |   60|    203|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    203|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    203|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    203|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    203|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    203|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    203|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  620|    203|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    203|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (620:13): [True: 26, False: 177]
  ------------------
  621|     26|            goto error;
  622|     26|        }
  623|       |
  624|    177|        if (attr->extended_count > 0) {
  ------------------
  |  Branch (624:13): [True: 163, False: 14]
  ------------------
  625|    163|            rc = ssh_buffer_unpack(buf, "ss",
  ------------------
  |  |   60|    163|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    163|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    163|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    163|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    163|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    163|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    163|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  626|    163|                                   &attr->extended_type,
  627|    163|                                   &attr->extended_data);
  628|    163|            if (rc != SSH_OK) {
  ------------------
  |  |  316|    163|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (628:17): [True: 76, False: 87]
  ------------------
  629|     76|                goto error;
  630|     76|            }
  631|     87|            attr->extended_count--;
  632|     87|        }
  633|       |        /* just ignore the remaining extensions */
  634|       |
  635|  40.6k|        while (attr->extended_count > 0) {
  ------------------
  |  Branch (635:16): [True: 40.5k, False: 15]
  ------------------
  636|  40.5k|            ssh_string tmp1,tmp2;
  637|  40.5k|            rc = ssh_buffer_unpack(buf, "SS", &tmp1, &tmp2);
  ------------------
  |  |   60|  40.5k|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|  40.5k|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|  40.5k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|  40.5k|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|  40.5k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|  40.5k|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|  40.5k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  638|  40.5k|            if (rc != SSH_OK){
  ------------------
  |  |  316|  40.5k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (638:17): [True: 86, False: 40.5k]
  ------------------
  639|     86|                goto error;
  640|     86|            }
  641|  40.5k|            SAFE_FREE(tmp1);
  ------------------
  |  |  373|  40.5k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 40.5k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 40.5k]
  |  |  ------------------
  ------------------
  642|  40.5k|            SAFE_FREE(tmp2);
  ------------------
  |  |  373|  40.5k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 40.5k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 40.5k]
  |  |  ------------------
  ------------------
  643|  40.5k|            attr->extended_count--;
  644|  40.5k|        }
  645|    101|    }
  646|       |
  647|    124|    return attr;
  648|       |
  649|    600|error:
  650|    600|    SSH_STRING_FREE(attr->extended_type);
  ------------------
  |  |  915|    600|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 86, False: 514]
  |  |  |  Branch (915:69): [Folded, False: 600]
  |  |  ------------------
  ------------------
  651|    600|    SSH_STRING_FREE(attr->extended_data);
  ------------------
  |  |  915|    600|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 86, False: 514]
  |  |  |  Branch (915:69): [Folded, False: 600]
  |  |  ------------------
  ------------------
  652|    600|    SAFE_FREE(attr->name);
  ------------------
  |  |  373|    600|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 21, False: 579]
  |  |  |  Branch (373:71): [Folded, False: 600]
  |  |  ------------------
  ------------------
  653|    600|    SAFE_FREE(attr->longname);
  ------------------
  |  |  373|    600|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 21, False: 579]
  |  |  |  Branch (373:71): [Folded, False: 600]
  |  |  ------------------
  ------------------
  654|    600|    SAFE_FREE(attr->owner);
  ------------------
  |  |  373|    600|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 600]
  |  |  |  Branch (373:71): [Folded, False: 600]
  |  |  ------------------
  ------------------
  655|    600|    SAFE_FREE(attr->group);
  ------------------
  |  |  373|    600|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 600]
  |  |  |  Branch (373:71): [Folded, False: 600]
  |  |  ------------------
  ------------------
  656|    600|    SAFE_FREE(attr);
  ------------------
  |  |  373|    600|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 600, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 600]
  |  |  ------------------
  ------------------
  657|    600|    ssh_set_error(sftp->session, SSH_FATAL, "Invalid ATTR structure");
  ------------------
  |  |  311|    600|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  658|    600|    sftp_set_error(sftp, SSH_FX_FAILURE);
  ------------------
  |  | 1584|    600|#define SSH_FX_FAILURE 4
  ------------------
  659|       |
  660|       |    return NULL;
  661|    312|}

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|    825|{
  183|    825|    ssh_socket s;
  184|       |
  185|    825|    s = calloc(1, sizeof(struct ssh_socket_struct));
  186|    825|    if (s == NULL) {
  ------------------
  |  Branch (186:9): [True: 45, False: 780]
  ------------------
  187|     45|        ssh_set_error_oom(session);
  ------------------
  |  |  318|     45|    _ssh_set_error_oom(error, __func__)
  ------------------
  188|     45|        return NULL;
  189|     45|    }
  190|    780|    s->fd = SSH_INVALID_SOCKET;
  ------------------
  |  |  124|    780|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  191|    780|    s->last_errno = -1;
  192|    780|    s->fd_is_socket = 1;
  193|    780|    s->session = session;
  194|    780|    s->in_buffer = ssh_buffer_new();
  195|    780|    if (s->in_buffer == NULL) {
  ------------------
  |  Branch (195:9): [True: 37, False: 743]
  ------------------
  196|     37|        ssh_set_error_oom(session);
  ------------------
  |  |  318|     37|    _ssh_set_error_oom(error, __func__)
  ------------------
  197|     37|        SAFE_FREE(s);
  ------------------
  |  |  373|     37|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 37, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 37]
  |  |  ------------------
  ------------------
  198|     37|        return NULL;
  199|     37|    }
  200|    743|    s->out_buffer=ssh_buffer_new();
  201|    743|    if (s->out_buffer == NULL) {
  ------------------
  |  Branch (201:9): [True: 16, False: 727]
  ------------------
  202|     16|        ssh_set_error_oom(session);
  ------------------
  |  |  318|     16|    _ssh_set_error_oom(error, __func__)
  ------------------
  203|     16|        SSH_BUFFER_FREE(s->in_buffer);
  ------------------
  |  |  957|     16|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 16, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 16]
  |  |  ------------------
  ------------------
  204|     16|        SAFE_FREE(s);
  ------------------
  |  |  373|     16|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 16, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 16]
  |  |  ------------------
  ------------------
  205|     16|        return NULL;
  206|     16|    }
  207|    727|    s->read_wontblock = 0;
  208|    727|    s->write_wontblock = 0;
  209|    727|    s->data_except = 0;
  210|       |    s->poll_handle = NULL;
  211|    727|    s->state=SSH_SOCKET_NONE;
  212|    727|    return s;
  213|    743|}
ssh_socket_free:
  473|    920|{
  474|    920|    if (s == NULL) {
  ------------------
  |  Branch (474:9): [True: 193, False: 727]
  ------------------
  475|    193|        return;
  476|    193|    }
  477|    727|    ssh_socket_close(s);
  478|    727|    SSH_BUFFER_FREE(s->in_buffer);
  ------------------
  |  |  957|    727|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 727, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 727]
  |  |  ------------------
  ------------------
  479|    727|    SSH_BUFFER_FREE(s->out_buffer);
  ------------------
  |  |  957|    727|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 727, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 727]
  |  |  ------------------
  ------------------
  480|       |    SAFE_FREE(s);
  ------------------
  |  |  373|    727|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 727, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 727]
  |  |  ------------------
  ------------------
  481|    727|}
ssh_socket_close:
  546|  1.08k|{
  547|  1.08k|    if (ssh_socket_is_open(s)) {
  ------------------
  |  Branch (547:9): [True: 0, False: 1.08k]
  ------------------
  548|       |#ifdef _WIN32
  549|       |        CLOSE_SOCKET(s->fd);
  550|       |        s->last_errno = WSAGetLastError();
  551|       |#else
  552|      0|        CLOSE_SOCKET(s->fd);
  ------------------
  |  |  472|      0|#define CLOSE_SOCKET(s) do { if ((s) != SSH_INVALID_SOCKET) { _XCLOSESOCKET(s); (s) = SSH_INVALID_SOCKET;} } while(0)
  |  |  ------------------
  |  |  |  |  124|      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)
  |  |  ------------------
  |  |  |  |  124|      0|#define SSH_INVALID_SOCKET ((socket_t) -1)
  |  |  ------------------
  |  |  |  Branch (472:34): [True: 0, False: 0]
  |  |  |  Branch (472:116): [Folded, False: 0]
  |  |  ------------------
  ------------------
  553|      0|        s->last_errno = errno;
  554|      0|#endif
  555|      0|    }
  556|       |
  557|  1.08k|    if (s->poll_handle != NULL && !ssh_poll_is_locked(s->poll_handle)) {
  ------------------
  |  Branch (557:9): [True: 0, False: 1.08k]
  |  Branch (557:35): [True: 0, False: 0]
  ------------------
  558|      0|        ssh_poll_free(s->poll_handle);
  559|      0|        s->poll_handle = NULL;
  560|      0|    }
  561|       |
  562|  1.08k|    s->state = SSH_SOCKET_CLOSED;
  563|       |
  564|  1.08k|#ifndef _WIN32
  565|       |    /* If the proxy command still runs try to kill it */
  566|  1.08k|    if (s->proxy_pid != 0) {
  ------------------
  |  Branch (566:9): [True: 0, False: 1.08k]
  ------------------
  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");
  ------------------
  |  |  283|      0|    do {                                                            \
  |  |  284|      0|        char err_msg[SSH_ERRNO_MSG_MAX] = {0};                      \
  |  |  285|      0|        _ssh_log(priority,                                          \
  |  |  286|      0|                 __func__,                                          \
  |  |  287|      0|                 __VA_ARGS__,                                       \
  |  |  288|      0|                 ssh_strerror(errnum, err_msg, SSH_ERRNO_MSG_MAX)); \
  |  |  ------------------
  |  |  |  |  520|      0|#define SSH_ERRNO_MSG_MAX   1024
  |  |  ------------------
  |  |  289|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (289: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");
  ------------------
  |  |  281|      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));
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  583|      0|    }
  584|  1.08k|#endif
  585|  1.08k|}
ssh_socket_is_open:
  643|  1.08k|{
  644|  1.08k|    return s->fd != SSH_INVALID_SOCKET;
  ------------------
  |  |  124|  1.08k|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  645|  1.08k|}

ssh_string_new:
   57|   174k|{
   58|   174k|    struct ssh_string_struct *str = NULL;
   59|       |
   60|   174k|    if (size > STRING_SIZE_MAX) {
  ------------------
  |  |   38|   174k|#define STRING_SIZE_MAX 0x10000000
  ------------------
  |  Branch (60:9): [True: 0, False: 174k]
  ------------------
   61|      0|        errno = EINVAL;
   62|      0|        return NULL;
   63|      0|    }
   64|       |
   65|   174k|    str = calloc(1, sizeof(struct ssh_string_struct) + size);
   66|   174k|    if (str == NULL) {
  ------------------
  |  Branch (66:9): [True: 0, False: 174k]
  ------------------
   67|      0|        return NULL;
   68|      0|    }
   69|       |
   70|   174k|    str->size = htonl((uint32_t)size);
   71|       |
   72|   174k|    return str;
   73|   174k|}
ssh_string_len:
  177|    216|{
  178|    216|    size_t size;
  179|       |
  180|    216|    if (s == NULL) {
  ------------------
  |  Branch (180:9): [True: 0, False: 216]
  ------------------
  181|      0|        return 0;
  182|      0|    }
  183|       |
  184|    216|    size = ntohl(s->size);
  185|    216|    if (size > 0 && size <= STRING_SIZE_MAX) {
  ------------------
  |  |   38|    124|#define STRING_SIZE_MAX 0x10000000
  ------------------
  |  Branch (185:9): [True: 124, False: 92]
  |  Branch (185:21): [True: 124, False: 0]
  ------------------
  186|    124|        return size;
  187|    124|    }
  188|       |
  189|     92|    return 0;
  190|    216|}
ssh_string_to_char:
  223|    216|{
  224|    216|    size_t len;
  225|    216|    char *new = NULL;
  226|       |
  227|    216|    if (s == NULL) {
  ------------------
  |  Branch (227:9): [True: 0, False: 216]
  ------------------
  228|      0|        return NULL;
  229|      0|    }
  230|       |
  231|    216|    len = ssh_string_len(s);
  232|    216|    if (len + 1 < len) {
  ------------------
  |  Branch (232:9): [True: 0, False: 216]
  ------------------
  233|      0|        return NULL;
  234|      0|    }
  235|       |
  236|    216|    new = malloc(len + 1);
  237|    216|    if (new == NULL) {
  ------------------
  |  Branch (237:9): [True: 0, False: 216]
  ------------------
  238|      0|        return NULL;
  239|      0|    }
  240|    216|    memcpy(new, s->data, len);
  241|    216|    new[len] = '\0';
  242|       |
  243|    216|    return new;
  244|    216|}
ssh_string_burn:
  341|    463|{
  342|    463|    if (s == NULL || s->size == 0) {
  ------------------
  |  Branch (342:9): [True: 463, False: 0]
  |  Branch (342:22): [True: 0, False: 0]
  ------------------
  343|    463|        return;
  344|    463|    }
  345|       |
  346|      0|    ssh_burn(s->data, ssh_string_len(s));
  ------------------
  |  |  388|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  347|      0|}
ssh_string_data:
  357|   174k|{
  358|   174k|    if (s == NULL) {
  ------------------
  |  Branch (358:9): [True: 0, False: 174k]
  ------------------
  359|      0|        return NULL;
  360|      0|    }
  361|       |
  362|   174k|    return s->data;
  363|   174k|}
ssh_string_free:
  371|  95.5k|{
  372|       |    SAFE_FREE(s);
  ------------------
  |  |  373|  95.5k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 93.2k, False: 2.31k]
  |  |  |  Branch (373:71): [Folded, False: 95.5k]
  |  |  ------------------
  ------------------
  373|  95.5k|}

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;
  ------------------
  |  |  316|      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) {
  ------------------
  |  |  316|      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;
  ------------------
  |  |  316|      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_cipher_clear:
  124|    926|void ssh_cipher_clear(struct ssh_cipher_struct *cipher){
  125|       |#ifdef HAVE_LIBGCRYPT
  126|       |    unsigned int i;
  127|       |#endif
  128|       |
  129|    926|    if (cipher == NULL) {
  ------------------
  |  Branch (129:9): [True: 926, False: 0]
  ------------------
  130|    926|        return;
  131|    926|    }
  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|      0|    if (cipher->cleanup != NULL) {
  ------------------
  |  Branch (142:9): [True: 0, False: 0]
  ------------------
  143|      0|        cipher->cleanup(cipher);
  144|      0|    }
  145|      0|}
crypto_new:
  153|    558|{
  154|    558|    struct ssh_crypto_struct *crypto = NULL;
  155|       |
  156|    558|    crypto = calloc(1, sizeof(struct ssh_crypto_struct));
  157|    558|    if (crypto == NULL) {
  ------------------
  |  Branch (157:9): [True: 95, False: 463]
  ------------------
  158|     95|        return NULL;
  159|     95|    }
  160|    463|    return crypto;
  161|    558|}
crypto_free:
  164|  1.11k|{
  165|  1.11k|    size_t i;
  166|       |
  167|  1.11k|    if (crypto == NULL) {
  ------------------
  |  Branch (167:9): [True: 653, False: 463]
  ------------------
  168|    653|        return;
  169|    653|    }
  170|       |
  171|    463|    ssh_key_free(crypto->server_pubkey);
  172|       |
  173|    463|    ssh_dh_cleanup(crypto);
  174|    463|    bignum_safe_free(crypto->shared_secret);
  ------------------
  |  |   71|    463|#define bignum_safe_free(num) do { \
  |  |   72|    463|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 463]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|    463|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 463]
  |  |  ------------------
  ------------------
  175|    463|#ifdef HAVE_ECDH
  176|    463|    SAFE_FREE(crypto->ecdh_client_pubkey);
  ------------------
  |  |  373|    463|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 463]
  |  |  |  Branch (373:71): [Folded, False: 463]
  |  |  ------------------
  ------------------
  177|    463|    SAFE_FREE(crypto->ecdh_server_pubkey);
  ------------------
  |  |  373|    463|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 463]
  |  |  |  Branch (373:71): [Folded, False: 463]
  |  |  ------------------
  ------------------
  178|    463|    if (crypto->ecdh_privkey != NULL) {
  ------------------
  |  Branch (178:9): [True: 0, False: 463]
  ------------------
  179|      0|#ifdef HAVE_OPENSSL_ECC
  180|      0|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  181|      0|        EC_KEY_free(crypto->ecdh_privkey);
  182|       |#else
  183|       |        EVP_PKEY_free(crypto->ecdh_privkey);
  184|       |#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|    463|#endif
  194|    463|#ifdef HAVE_LIBCRYPTO
  195|    463|    EVP_PKEY_free(crypto->curve25519_privkey);
  196|       |#elif defined(HAVE_GCRYPT_CURVE25519)
  197|       |    gcry_sexp_release(crypto->curve25519_privkey);
  198|       |#endif
  199|    463|    SAFE_FREE(crypto->dh_server_signature);
  ------------------
  |  |  373|    463|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 463]
  |  |  |  Branch (373:71): [Folded, False: 463]
  |  |  ------------------
  ------------------
  200|    463|    if (crypto->session_id != NULL) {
  ------------------
  |  Branch (200:9): [True: 0, False: 463]
  ------------------
  201|      0|        ssh_burn(crypto->session_id, crypto->session_id_len);
  ------------------
  |  |  388|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  202|      0|        SAFE_FREE(crypto->session_id);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  203|      0|    }
  204|    463|    if (crypto->secret_hash != NULL) {
  ------------------
  |  Branch (204:9): [True: 0, False: 463]
  ------------------
  205|      0|        ssh_burn(crypto->secret_hash, crypto->digest_len);
  ------------------
  |  |  388|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  206|      0|        SAFE_FREE(crypto->secret_hash);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  207|      0|    }
  208|    463|    compress_cleanup(crypto);
  209|    463|    SAFE_FREE(crypto->encryptIV);
  ------------------
  |  |  373|    463|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 463]
  |  |  |  Branch (373:71): [Folded, False: 463]
  |  |  ------------------
  ------------------
  210|    463|    SAFE_FREE(crypto->decryptIV);
  ------------------
  |  |  373|    463|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 463]
  |  |  |  Branch (373:71): [Folded, False: 463]
  |  |  ------------------
  ------------------
  211|    463|    SAFE_FREE(crypto->encryptMAC);
  ------------------
  |  |  373|    463|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 463]
  |  |  |  Branch (373:71): [Folded, False: 463]
  |  |  ------------------
  ------------------
  212|    463|    SAFE_FREE(crypto->decryptMAC);
  ------------------
  |  |  373|    463|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 463]
  |  |  |  Branch (373:71): [Folded, False: 463]
  |  |  ------------------
  ------------------
  213|    463|    if (crypto->encryptkey != NULL) {
  ------------------
  |  Branch (213:9): [True: 0, False: 463]
  ------------------
  214|      0|        ssh_burn(crypto->encryptkey, crypto->out_cipher->keysize / 8);
  ------------------
  |  |  388|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  215|      0|        SAFE_FREE(crypto->encryptkey);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  216|      0|    }
  217|    463|    if (crypto->decryptkey != NULL) {
  ------------------
  |  Branch (217:9): [True: 0, False: 463]
  ------------------
  218|      0|        ssh_burn(crypto->decryptkey, crypto->in_cipher->keysize / 8);
  ------------------
  |  |  388|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  219|      0|        SAFE_FREE(crypto->decryptkey);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  220|      0|    }
  221|       |
  222|    463|    cipher_free(crypto->in_cipher);
  223|    463|    cipher_free(crypto->out_cipher);
  224|       |
  225|  5.09k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  5.09k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (225:17): [True: 4.63k, False: 463]
  ------------------
  226|  4.63k|        SAFE_FREE(crypto->client_kex.methods[i]);
  ------------------
  |  |  373|  4.63k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 4.63k]
  |  |  |  Branch (373:71): [Folded, False: 4.63k]
  |  |  ------------------
  ------------------
  227|  4.63k|        SAFE_FREE(crypto->server_kex.methods[i]);
  ------------------
  |  |  373|  4.63k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 4.63k]
  |  |  |  Branch (373:71): [Folded, False: 4.63k]
  |  |  ------------------
  ------------------
  228|  4.63k|        SAFE_FREE(crypto->kex_methods[i]);
  ------------------
  |  |  373|  4.63k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 4.63k]
  |  |  |  Branch (373:71): [Folded, False: 4.63k]
  |  |  ------------------
  ------------------
  229|  4.63k|    }
  230|       |
  231|       |#ifdef HAVE_OPENSSL_MLKEM
  232|       |    EVP_PKEY_free(crypto->mlkem_privkey);
  233|       |#else
  234|    463|    if (crypto->mlkem_privkey != NULL) {
  ------------------
  |  Branch (234:9): [True: 0, False: 463]
  ------------------
  235|      0|        ssh_burn(crypto->mlkem_privkey, crypto->mlkem_privkey_len);
  ------------------
  |  |  388|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  236|      0|        SAFE_FREE(crypto->mlkem_privkey);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  237|      0|        crypto->mlkem_privkey_len = 0;
  238|      0|    }
  239|    463|#endif
  240|    463|    ssh_string_burn(crypto->hybrid_shared_secret);
  241|    463|    ssh_string_free(crypto->mlkem_client_pubkey);
  242|    463|    ssh_string_free(crypto->mlkem_ciphertext);
  243|    463|    ssh_string_free(crypto->hybrid_client_init);
  244|    463|    ssh_string_free(crypto->hybrid_server_reply);
  245|    463|    ssh_string_free(crypto->hybrid_shared_secret);
  246|       |
  247|    463|    ssh_burn(crypto, sizeof(struct ssh_crypto_struct));
  ------------------
  |  |  388|    463|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  248|       |
  249|       |    SAFE_FREE(crypto);
  ------------------
  |  |  373|    463|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 463, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 463]
  |  |  ------------------
  ------------------
  250|    463|}
wrapper.c:cipher_free:
  147|    926|static void cipher_free(struct ssh_cipher_struct *cipher) {
  148|    926|  ssh_cipher_clear(cipher);
  149|       |  SAFE_FREE(cipher);
  ------------------
  |  |  373|    926|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 926]
  |  |  |  Branch (373:71): [Folded, False: 926]
  |  |  ------------------
  ------------------
  150|    926|}

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|}
calloc:
  307|   181k|{
  308|   181k|    if (nalloc_fail(size, "calloc")) {
  ------------------
  |  Branch (308:9): [True: 378, False: 181k]
  ------------------
  309|    378|        errno = ENOMEM;
  310|    378|        return NULL;
  311|    378|    }
  312|   181k|    return nalloc_calloc(nmemb, size);
  ------------------
  |  |  259|   181k|#define nalloc_calloc(s, n)          __libc_calloc(s, n)
  ------------------
  313|   181k|}
malloc:
  316|  16.7k|{
  317|  16.7k|    if (nalloc_fail(size, "malloc")) {
  ------------------
  |  Branch (317:9): [True: 1, False: 16.7k]
  ------------------
  318|      1|        errno = ENOMEM;
  319|      1|        return NULL;
  320|      1|    }
  321|  16.7k|    return nalloc_malloc(size);
  ------------------
  |  |  258|  16.7k|#define nalloc_malloc(s)             __libc_malloc(s)
  ------------------
  322|  16.7k|}
realloc:
  325|  2.90k|{
  326|  2.90k|    if (nalloc_fail(size, "realloc")) {
  ------------------
  |  Branch (326:9): [True: 20, False: 2.88k]
  ------------------
  327|     20|        errno = ENOMEM;
  328|     20|        return NULL;
  329|     20|    }
  330|  2.88k|    return nalloc_realloc(ptr, size);
  ------------------
  |  |  260|  2.88k|#define nalloc_realloc(p, s)         __libc_realloc(p, s)
  ------------------
  331|  2.90k|}
ssh_sftp_attr_fuzzer.c:nalloc_fail:
  194|   201k|{
  195|       |    // do not fail before thread init
  196|   201k|    if (nalloc_runs == 0) {
  ------------------
  |  Branch (196:9): [True: 7.03k, False: 194k]
  ------------------
  197|  7.03k|        return false;
  198|  7.03k|    }
  199|   194k|    if (__sync_fetch_and_add(&nalloc_running, 1) != 1) {
  ------------------
  |  Branch (199:9): [True: 3.80k, False: 190k]
  ------------------
  200|       |        // do not fail allocations outside of fuzzer input
  201|       |        // and do not fail inside of this function
  202|  3.80k|        __sync_fetch_and_sub(&nalloc_running, 1);
  203|  3.80k|        return false;
  204|  3.80k|    }
  205|   190k|    nalloc_random_update((uint8_t)size);
  206|   190k|    if (size >= 0x100) {
  ------------------
  |  Branch (206:9): [True: 2.11k, False: 188k]
  ------------------
  207|  2.11k|        nalloc_random_update((uint8_t)(size >> 8));
  208|  2.11k|        if (size >= 0x10000) {
  ------------------
  |  Branch (208:13): [True: 314, False: 1.79k]
  ------------------
  209|    314|            nalloc_random_update((uint8_t)(size >> 16));
  210|       |            // bigger may already fail or oom
  211|    314|        }
  212|  2.11k|    }
  213|   190k|    if (((nalloc_random_state ^ nalloc_magic) & nalloc_bitmask) == 0) {
  ------------------
  |  Branch (213:9): [True: 399, False: 189k]
  ------------------
  214|    399|        if (nalloc_backtrace_exclude(size, op)) {
  ------------------
  |  Branch (214:13): [True: 0, False: 399]
  ------------------
  215|      0|            __sync_fetch_and_sub(&nalloc_running, 1);
  216|      0|            return false;
  217|      0|        }
  218|    399|        __sync_fetch_and_sub(&nalloc_running, 1);
  219|    399|        return true;
  220|    399|    }
  221|   189k|    __sync_fetch_and_sub(&nalloc_running, 1);
  222|       |    return false;
  223|   190k|}
ssh_sftp_attr_fuzzer.c:nalloc_random_update:
  143|  35.3M|{
  144|  35.3M|    nalloc_random_state =
  145|  35.3M|        ((uint32_t)((uint32_t)nalloc_random_state << 8)) ^
  146|  35.3M|        nalloc_crc32_table[((nalloc_random_state >> 24) ^ b) & 0xFF];
  147|  35.3M|}
ssh_sftp_attr_fuzzer.c:nalloc_backtrace_exclude:
  181|    399|{
  182|    399|    if (nalloc_verbose) {
  ------------------
  |  Branch (182:9): [True: 0, False: 399]
  ------------------
  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|    399|}
ssh_sftp_attr_fuzzer.c:nalloc_start:
  151|    761|{
  152|    761|    if (nalloc_random_bitmask) {
  ------------------
  |  Branch (152:9): [True: 761, False: 0]
  ------------------
  153|    761|        if (nalloc_random_state & 0x10) {
  ------------------
  |  Branch (153:13): [True: 362, False: 399]
  ------------------
  154|    362|            nalloc_bitmask = 0xFFFFFFFF;
  155|    399|        } else {
  156|    399|            nalloc_bitmask = 1 << (5 + (nalloc_random_state & 0xF));
  157|    399|        }
  158|    761|    } else if (nalloc_bitmask == 0) {
  ------------------
  |  Branch (158:16): [True: 0, False: 0]
  ------------------
  159|       |        // nalloc disabled
  160|      0|        return 2;
  161|      0|    }
  162|    761|    nalloc_random_state = 0;
  163|  35.1M|    for (size_t i = 0; i < size; i++) {
  ------------------
  |  Branch (163:24): [True: 35.1M, False: 761]
  ------------------
  164|  35.1M|        nalloc_random_update(data[i]);
  165|  35.1M|    }
  166|    761|    if (__sync_fetch_and_add(&nalloc_running, 1)) {
  ------------------
  |  Branch (166:9): [True: 0, False: 761]
  ------------------
  167|      0|        __sync_fetch_and_sub(&nalloc_running, 1);
  168|      0|        return 0;
  169|      0|    }
  170|    761|    nalloc_runs++;
  171|    761|    return 1;
  172|    761|}
ssh_sftp_attr_fuzzer.c:nalloc_end:
  176|    761|{
  177|    761|    __sync_fetch_and_sub(&nalloc_running, 1);
  178|    761|}

LLVMFuzzerInitialize:
   63|      2|{
   64|      2|    (void)argc;
   65|       |
   66|      2|    nalloc_init(*argv[0]);
   67|       |
   68|      2|    ssh_init();
   69|       |
   70|      2|    atexit(_fuzz_finalize);
   71|       |
   72|      2|    return 0;
   73|      2|}
LLVMFuzzerTestOneInput:
   76|    761|{
   77|    761|    ssh_session session = NULL;
   78|    761|    sftp_session sftp = NULL;
   79|    761|    ssh_buffer buffer = NULL;
   80|    761|    sftp_attributes attr = NULL;
   81|    761|    int versions[] = {
   82|    761|        SFTP_PROTOCOL_VERSION_3, SFTP_PROTOCOL_VERSION_3,
  ------------------
  |  |   33|    761|#define SFTP_PROTOCOL_VERSION_3 3
  ------------------
                      SFTP_PROTOCOL_VERSION_3, SFTP_PROTOCOL_VERSION_3,
  ------------------
  |  |   33|    761|#define SFTP_PROTOCOL_VERSION_3 3
  ------------------
   83|    761|        SFTP_PROTOCOL_VERSION_4, SFTP_PROTOCOL_VERSION_4
  ------------------
  |  |   34|    761|#define SFTP_PROTOCOL_VERSION_4 4
  ------------------
                      SFTP_PROTOCOL_VERSION_4, SFTP_PROTOCOL_VERSION_4
  ------------------
  |  |   34|    761|#define SFTP_PROTOCOL_VERSION_4 4
  ------------------
   84|    761|    };
   85|    761|    int expectnames[] = {SFTP_NO_NAME, SFTP_EXPECT_NAME, SFTP_NO_NAME, SFTP_EXPECT_NAME};
  ------------------
  |  |   38|    761|#define SFTP_NO_NAME 0
  ------------------
                  int expectnames[] = {SFTP_NO_NAME, SFTP_EXPECT_NAME, SFTP_NO_NAME, SFTP_EXPECT_NAME};
  ------------------
  |  |   37|    761|#define SFTP_EXPECT_NAME 1
  ------------------
                  int expectnames[] = {SFTP_NO_NAME, SFTP_EXPECT_NAME, SFTP_NO_NAME, SFTP_EXPECT_NAME};
  ------------------
  |  |   38|    761|#define SFTP_NO_NAME 0
  ------------------
                  int expectnames[] = {SFTP_NO_NAME, SFTP_EXPECT_NAME, SFTP_NO_NAME, SFTP_EXPECT_NAME};
  ------------------
  |  |   37|    761|#define SFTP_EXPECT_NAME 1
  ------------------
   86|    761|    size_t i;
   87|       |
   88|       |    /* Minimum bytes for a valid SFTP message */
   89|    761|    if (size == 0) {
  ------------------
  |  Branch (89:9): [True: 0, False: 761]
  ------------------
   90|      0|        return 0;
   91|      0|    }
   92|       |
   93|    761|    assert(nalloc_start(data, size) > 0);
  ------------------
  |  Branch (93:5): [True: 0, False: 761]
  |  Branch (93:5): [True: 761, False: 0]
  ------------------
   94|       |
   95|       |    /* Allocate shared resources once for all test iterations */
   96|    761|    session = ssh_new();
   97|    761|    if (session == NULL) {
  ------------------
  |  Branch (97:9): [True: 399, False: 362]
  ------------------
   98|    399|        goto cleanup;
   99|    399|    }
  100|       |
  101|    362|    sftp = create_minimal_sftp_session(session);
  102|    362|    if (sftp == NULL) {
  ------------------
  |  Branch (102:9): [True: 0, False: 362]
  ------------------
  103|      0|        goto cleanup;
  104|      0|    }
  105|       |
  106|    362|    buffer = ssh_buffer_new();
  107|    362|    if (buffer == NULL) {
  ------------------
  |  Branch (107:9): [True: 0, False: 362]
  ------------------
  108|      0|        goto cleanup;
  109|      0|    }
  110|       |
  111|       |    /* Main fuzzing target: sftp_parse_attr */
  112|       |    /* Parses untrusted SFTP messages from client */
  113|       |    /* Test all combinations (v3/v4, with/without name) */
  114|  1.81k|    for (i = 0; i < ARRAY_SIZE(versions); i++) {
  ------------------
  |  |  382|  1.81k|#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
  ------------------
  |  Branch (114:17): [True: 1.44k, False: 362]
  ------------------
  115|  1.44k|        sftp->version = versions[i];
  116|       |
  117|       |        /* Reset and repopulate buffer for each iteration */
  118|  1.44k|        ssh_buffer_reinit(buffer);
  119|  1.44k|        if (ssh_buffer_add_data(buffer, data, size) == SSH_OK) {
  ------------------
  |  |  316|  1.44k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (119:13): [True: 1.44k, False: 0]
  ------------------
  120|  1.44k|            attr = sftp_parse_attr(sftp, buffer, expectnames[i]);
  121|  1.44k|            sftp_attributes_free(attr);
  122|  1.44k|            attr = NULL;
  123|  1.44k|        }
  124|  1.44k|    }
  125|       |
  126|    761|cleanup:
  127|    761|    ssh_buffer_free(buffer);
  128|    761|    free(sftp);
  129|    761|    ssh_free(session);
  130|    761|    nalloc_end();
  131|       |
  132|    761|    return 0;
  133|    362|}
ssh_sftp_attr_fuzzer.c:_fuzz_finalize:
   58|      2|{
   59|      2|    ssh_finalize();
   60|      2|}
ssh_sftp_attr_fuzzer.c:create_minimal_sftp_session:
   45|    362|{
   46|    362|    sftp_session sftp;
   47|       |
   48|    362|    sftp = calloc(1, sizeof(struct sftp_session_struct));
   49|    362|    if (sftp == NULL) {
  ------------------
  |  Branch (49:9): [True: 0, False: 362]
  ------------------
   50|      0|        return NULL;
   51|      0|    }
   52|    362|    sftp->session = session;
   53|       |
   54|    362|    return sftp;
   55|    362|}

