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

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

ssh_buffer_new:
  126|  2.37k|{
  127|  2.37k|    struct ssh_buffer_struct *buf = NULL;
  128|  2.37k|    int rc;
  129|       |
  130|  2.37k|    buf = calloc(1, sizeof(struct ssh_buffer_struct));
  131|  2.37k|    if (buf == NULL) {
  ------------------
  |  Branch (131:9): [True: 37, False: 2.33k]
  ------------------
  132|     37|        return NULL;
  133|     37|    }
  134|       |
  135|       |    /*
  136|       |     * Always preallocate 64 bytes.
  137|       |     *
  138|       |     * -1 for realloc_buffer magic.
  139|       |     */
  140|  2.33k|    rc = ssh_buffer_allocate_size(buf, 64 - 1);
  141|  2.33k|    if (rc != 0) {
  ------------------
  |  Branch (141:9): [True: 16, False: 2.32k]
  ------------------
  142|     16|        SAFE_FREE(buf);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  143|     16|        return NULL;
  144|     16|    }
  145|  2.32k|    buffer_verify(buf);
  146|       |
  147|  2.32k|    return buf;
  148|  2.33k|}
ssh_buffer_free:
  156|  2.68k|{
  157|  2.68k|    if (buffer == NULL) {
  ------------------
  |  Branch (157:9): [True: 367, False: 2.32k]
  ------------------
  158|    367|        return;
  159|    367|    }
  160|  2.32k|    buffer_verify(buffer);
  161|       |
  162|  2.32k|    if (buffer->secure && buffer->allocated > 0) {
  ------------------
  |  Branch (162:9): [True: 0, False: 2.32k]
  |  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.32k|    } else {
  169|  2.32k|        SAFE_FREE(buffer->data);
  ------------------
  |  |  373|  2.32k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 2.32k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 2.32k]
  |  |  ------------------
  ------------------
  170|  2.32k|    }
  171|       |    SAFE_FREE(buffer);
  ------------------
  |  |  373|  2.32k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 2.32k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 2.32k]
  |  |  ------------------
  ------------------
  172|  2.32k|}
ssh_buffer_reinit:
  266|  1.31k|{
  267|  1.31k|    if (buffer == NULL) {
  ------------------
  |  Branch (267:9): [True: 0, False: 1.31k]
  ------------------
  268|      0|        return -1;
  269|      0|    }
  270|       |
  271|  1.31k|    buffer_verify(buffer);
  272|       |
  273|  1.31k|    if (buffer->secure && buffer->allocated > 0) {
  ------------------
  |  Branch (273:9): [True: 0, False: 1.31k]
  |  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.31k|    buffer->used = 0;
  277|  1.31k|    buffer->pos = 0;
  278|       |
  279|       |    /* If the buffer is bigger then 64K, reset it to 64K */
  280|  1.31k|    if (buffer->allocated > 65536) {
  ------------------
  |  Branch (280:9): [True: 71, False: 1.24k]
  ------------------
  281|     71|        int rc;
  282|       |
  283|       |        /* -1 for realloc_buffer magic */
  284|     71|        rc = realloc_buffer(buffer, 65536 - 1);
  285|     71|        if (rc != 0) {
  ------------------
  |  Branch (285:13): [True: 0, False: 71]
  ------------------
  286|      0|            return -1;
  287|      0|        }
  288|     71|    }
  289|       |
  290|  1.31k|    buffer_verify(buffer);
  291|       |
  292|  1.31k|    return 0;
  293|  1.31k|}
ssh_buffer_add_data:
  307|  1.31k|{
  308|  1.31k|    if (buffer == NULL) {
  ------------------
  |  Branch (308:9): [True: 0, False: 1.31k]
  ------------------
  309|      0|        return -1;
  310|      0|    }
  311|       |
  312|  1.31k|    buffer_verify(buffer);
  313|       |
  314|  1.31k|    if (data == NULL) {
  ------------------
  |  Branch (314:9): [True: 0, False: 1.31k]
  ------------------
  315|      0|        return -1;
  316|      0|    }
  317|       |
  318|  1.31k|    if (buffer->used + len < len) {
  ------------------
  |  Branch (318:9): [True: 0, False: 1.31k]
  ------------------
  319|      0|        return -1;
  320|      0|    }
  321|       |
  322|  1.31k|    if (buffer->allocated < (buffer->used + len)) {
  ------------------
  |  Branch (322:9): [True: 180, False: 1.13k]
  ------------------
  323|    180|        if (buffer->pos > 0) {
  ------------------
  |  Branch (323:13): [True: 0, False: 180]
  ------------------
  324|      0|            buffer_shift(buffer);
  325|      0|        }
  326|    180|        if (realloc_buffer(buffer, buffer->used + len) < 0) {
  ------------------
  |  Branch (326:13): [True: 0, False: 180]
  ------------------
  327|      0|            return -1;
  328|      0|        }
  329|    180|    }
  330|       |
  331|  1.31k|    memcpy(buffer->data + buffer->used, data, len);
  332|  1.31k|    buffer->used += len;
  333|  1.31k|    buffer_verify(buffer);
  334|  1.31k|    return 0;
  335|  1.31k|}
ssh_buffer_allocate_size:
  348|  2.33k|{
  349|  2.33k|    buffer_verify(buffer);
  350|       |
  351|  2.33k|    if (buffer->allocated < len) {
  ------------------
  |  Branch (351:9): [True: 2.33k, False: 0]
  ------------------
  352|  2.33k|        if (buffer->pos > 0) {
  ------------------
  |  Branch (352:13): [True: 0, False: 2.33k]
  ------------------
  353|      0|            buffer_shift(buffer);
  354|      0|        }
  355|  2.33k|        if (realloc_buffer(buffer, len) < 0) {
  ------------------
  |  Branch (355:13): [True: 16, False: 2.32k]
  ------------------
  356|     16|            return -1;
  357|     16|        }
  358|  2.33k|    }
  359|       |
  360|  2.32k|    buffer_verify(buffer);
  361|       |
  362|  2.32k|    return 0;
  363|  2.33k|}
ssh_buffer_get_len:
  620|  30.6k|uint32_t ssh_buffer_get_len(struct ssh_buffer_struct *buffer){
  621|  30.6k|  buffer_verify(buffer);
  622|  30.6k|  return buffer->used - buffer->pos;
  623|  30.6k|}
ssh_buffer_get_data:
  737|   433k|{
  738|   433k|    int rc;
  739|       |
  740|       |    /*
  741|       |     * Check for a integer overflow first, then check if not enough data is in
  742|       |     * the buffer.
  743|       |     */
  744|   433k|    rc = ssh_buffer_validate_length(buffer, len);
  745|   433k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|   433k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (745:9): [True: 546, False: 433k]
  ------------------
  746|    546|        return 0;
  747|    546|    }
  748|   433k|    memcpy(data,buffer->data+buffer->pos,len);
  749|   433k|    buffer->pos+=len;
  750|   433k|    return len;   /* no yet support for partial reads (is it really needed ?? ) */
  751|   433k|}
ssh_buffer_get_u32:
  780|   218k|uint32_t ssh_buffer_get_u32(struct ssh_buffer_struct *buffer, uint32_t *data){
  781|   218k|    return ssh_buffer_get_data(buffer,data,sizeof(uint32_t));
  782|   218k|}
ssh_buffer_get_u64:
  795|    502|uint32_t ssh_buffer_get_u64(struct ssh_buffer_struct *buffer, uint64_t *data){
  796|    502|    return ssh_buffer_get_data(buffer,data,sizeof(uint64_t));
  797|    502|}
ssh_buffer_validate_length:
  809|   649k|{
  810|   649k|    if (buffer == NULL || buffer->pos + len < len ||
  ------------------
  |  Branch (810:9): [True: 0, False: 649k]
  |  Branch (810:27): [True: 0, False: 649k]
  ------------------
  811|   649k|        buffer->pos + len > buffer->used) {
  ------------------
  |  Branch (811:9): [True: 803, False: 648k]
  ------------------
  812|    803|        return SSH_ERROR;
  ------------------
  |  |  317|    803|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  813|    803|    }
  814|       |
  815|   648k|    return SSH_OK;
  ------------------
  |  |  316|   648k|#define SSH_OK 0     /* No error */
  ------------------
  816|   649k|}
ssh_buffer_get_ssh_string:
  829|   215k|{
  830|   215k|    uint32_t stringlen;
  831|   215k|    uint32_t hostlen;
  832|   215k|    struct ssh_string_struct *str = NULL;
  833|   215k|    int rc;
  834|       |
  835|   215k|    rc = ssh_buffer_get_u32(buffer, &stringlen);
  836|   215k|    if (rc == 0) {
  ------------------
  |  Branch (836:9): [True: 225, False: 215k]
  ------------------
  837|    225|        return NULL;
  838|    225|    }
  839|   215k|    hostlen = ntohl(stringlen);
  840|       |    /* verify if there is enough space in buffer to get it */
  841|   215k|    rc = ssh_buffer_validate_length(buffer, hostlen);
  842|   215k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|   215k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (842:9): [True: 245, False: 214k]
  ------------------
  843|    245|      return NULL; /* it is indeed */
  844|    245|    }
  845|   214k|    str = ssh_string_new(hostlen);
  846|   214k|    if (str == NULL) {
  ------------------
  |  Branch (846:9): [True: 0, False: 214k]
  ------------------
  847|      0|        return NULL;
  848|      0|    }
  849|       |
  850|   214k|    stringlen = ssh_buffer_get_data(buffer, ssh_string_data(str), hostlen);
  851|   214k|    if (stringlen != hostlen) {
  ------------------
  |  Branch (851:9): [True: 0, False: 214k]
  ------------------
  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|   214k|    return str;
  858|   214k|}
ssh_buffer_unpack_va:
 1173|  30.6k|{
 1174|  30.6k|    int rc = SSH_ERROR;
  ------------------
  |  |  317|  30.6k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1175|  30.6k|    const char *p = format, *last = NULL;
 1176|  30.6k|    union {
 1177|  30.6k|        uint8_t *byte;
 1178|  30.6k|        uint16_t *word;
 1179|  30.6k|        uint32_t *dword;
 1180|  30.6k|        uint64_t *qword;
 1181|  30.6k|        ssh_string *string;
 1182|  30.6k|        char **cstring;
 1183|  30.6k|        bignum *bignum;
 1184|  30.6k|        void **data;
 1185|  30.6k|    } o;
 1186|  30.6k|    size_t len;
 1187|  30.6k|    uint32_t rlen, max_len;
 1188|  30.6k|    ssh_string tmp_string = NULL;
 1189|  30.6k|    va_list ap_copy;
 1190|  30.6k|    size_t count;
 1191|       |
 1192|  30.6k|    max_len = ssh_buffer_get_len(buffer);
 1193|       |
 1194|       |    /* copy the argument list in case a rollback is needed */
 1195|  30.6k|    va_copy(ap_copy, ap);
 1196|       |
 1197|  30.6k|    if (argc > 256) {
  ------------------
  |  Branch (1197:9): [True: 0, False: 30.6k]
  ------------------
 1198|      0|        rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1199|      0|        goto cleanup;
 1200|      0|    }
 1201|       |
 1202|  90.3k|    for (count = 0; *p != '\0'; p++, count++) {
  ------------------
  |  Branch (1202:21): [True: 60.2k, False: 30.1k]
  ------------------
 1203|       |        /* Invalid number of arguments passed */
 1204|  60.2k|        if (count > argc) {
  ------------------
  |  Branch (1204:13): [True: 0, False: 60.2k]
  ------------------
 1205|      0|            rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1206|      0|            goto cleanup;
 1207|      0|        }
 1208|       |
 1209|  60.2k|        rc = SSH_ERROR;
  ------------------
  |  |  317|  60.2k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1210|  60.2k|        switch (*p) {
 1211|      0|        case 'b':
  ------------------
  |  Branch (1211:9): [True: 0, False: 60.2k]
  ------------------
 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: 60.2k]
  ------------------
 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|    989|        case 'd':
  ------------------
  |  Branch (1224:9): [True: 989, False: 59.2k]
  ------------------
 1225|    989|            o.dword = va_arg(ap, uint32_t *);
 1226|    989|            rlen = ssh_buffer_get_u32(buffer, o.dword);
 1227|    989|            if (rlen == 4) {
  ------------------
  |  Branch (1227:17): [True: 897, False: 92]
  ------------------
 1228|    897|                *o.dword = ntohl(*o.dword);
 1229|    897|                rc = SSH_OK;
  ------------------
  |  |  316|    897|#define SSH_OK 0     /* No error */
  ------------------
 1230|    897|            }
 1231|    989|            break;
 1232|     92|        case 'q':
  ------------------
  |  Branch (1232:9): [True: 92, False: 60.1k]
  ------------------
 1233|     92|            o.qword = va_arg(ap, uint64_t*);
 1234|     92|            rlen = ssh_buffer_get_u64(buffer, o.qword);
 1235|     92|            if (rlen == 8) {
  ------------------
  |  Branch (1235:17): [True: 77, False: 15]
  ------------------
 1236|     77|                *o.qword = ntohll(*o.qword);
  ------------------
  |  |  488|     77|    (((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32))
  ------------------
 1237|     77|                rc = SSH_OK;
  ------------------
  |  |  316|     77|#define SSH_OK 0     /* No error */
  ------------------
 1238|     77|            }
 1239|     92|            break;
 1240|      0|        case 'B':
  ------------------
  |  Branch (1240:9): [True: 0, False: 60.2k]
  ------------------
 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);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910: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|  58.5k|        case 'S':
  ------------------
  |  Branch (1252:9): [True: 58.5k, False: 1.71k]
  ------------------
 1253|  58.5k|            o.string = va_arg(ap, ssh_string *);
 1254|  58.5k|            *o.string = ssh_buffer_get_ssh_string(buffer);
 1255|  58.5k|            rc = *o.string != NULL ? SSH_OK : SSH_ERROR;
  ------------------
  |  |  316|  58.4k|#define SSH_OK 0     /* No error */
  ------------------
                          rc = *o.string != NULL ? SSH_OK : SSH_ERROR;
  ------------------
  |  |  317|  58.6k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1255:18): [True: 58.4k, False: 80]
  ------------------
 1256|  58.5k|            o.string = NULL;
 1257|  58.5k|            break;
 1258|    629|        case 's': {
  ------------------
  |  Branch (1258:9): [True: 629, False: 59.6k]
  ------------------
 1259|    629|            uint32_t u32len = 0;
 1260|       |
 1261|    629|            o.cstring = va_arg(ap, char **);
 1262|    629|            *o.cstring = NULL;
 1263|    629|            rlen = ssh_buffer_get_u32(buffer, &u32len);
 1264|    629|            if (rlen != 4){
  ------------------
  |  Branch (1264:17): [True: 56, False: 573]
  ------------------
 1265|     56|                break;
 1266|     56|            }
 1267|    573|            u32len = ntohl(u32len);
 1268|    573|            if (u32len > max_len - 1) {
  ------------------
  |  Branch (1268:17): [True: 308, False: 265]
  ------------------
 1269|    308|                break;
 1270|    308|            }
 1271|       |
 1272|    265|            rc = ssh_buffer_validate_length(buffer, u32len);
 1273|    265|            if (rc != SSH_OK) {
  ------------------
  |  |  316|    265|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1273:17): [True: 12, False: 253]
  ------------------
 1274|     12|                break;
 1275|     12|            }
 1276|       |
 1277|    253|            *o.cstring = malloc(u32len + 1);
 1278|    253|            if (*o.cstring == NULL){
  ------------------
  |  Branch (1278:17): [True: 0, False: 253]
  ------------------
 1279|      0|                rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1280|      0|                break;
 1281|      0|            }
 1282|    253|            rlen = ssh_buffer_get_data(buffer, *o.cstring, u32len);
 1283|    253|            if (rlen != u32len) {
  ------------------
  |  Branch (1283:17): [True: 0, False: 253]
  ------------------
 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|    253|            (*o.cstring)[u32len] = '\0';
 1289|    253|            o.cstring = NULL;
 1290|    253|            rc = SSH_OK;
  ------------------
  |  |  316|    253|#define SSH_OK 0     /* No error */
  ------------------
 1291|    253|            break;
 1292|    253|        }
 1293|      0|        case 'P':
  ------------------
  |  Branch (1293:9): [True: 0, False: 60.2k]
  ------------------
 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: 60.2k]
  ------------------
 1323|      0|            SSH_LOG(SSH_LOG_TRACE, "Invalid buffer format %c", *p);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1324|  60.2k|        }
 1325|  60.2k|        if (rc != SSH_OK) {
  ------------------
  |  |  316|  60.2k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1325:13): [True: 563, False: 59.6k]
  ------------------
 1326|    563|            break;
 1327|    563|        }
 1328|  60.2k|    }
 1329|       |
 1330|  30.6k|    if (argc != count) {
  ------------------
  |  Branch (1330:9): [True: 563, False: 30.1k]
  ------------------
 1331|    563|        rc = SSH_ERROR;
  ------------------
  |  |  317|    563|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1332|    563|    }
 1333|       |
 1334|  30.6k|cleanup:
 1335|  30.6k|    if (rc != SSH_ERROR){
  ------------------
  |  |  317|  30.6k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1335:9): [True: 30.1k, False: 563]
  ------------------
 1336|       |        /* Check if our canary is intact, if not something really bad happened */
 1337|  30.1k|        uint32_t canary = va_arg(ap, uint32_t);
 1338|  30.1k|        if (canary != SSH_BUFFER_PACK_END){
  ------------------
  |  |   28|  30.1k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  ------------------
  |  Branch (1338:13): [True: 0, False: 30.1k]
  ------------------
 1339|      0|            abort();
 1340|      0|        }
 1341|  30.1k|    }
 1342|       |
 1343|  30.6k|    if (rc != SSH_OK){
  ------------------
  |  |  316|  30.6k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1343:9): [True: 563, False: 30.1k]
  ------------------
 1344|       |        /* Reset the format string and erase everything that was allocated */
 1345|    563|        last = p;
 1346|    647|        for(p=format;p<last;++p){
  ------------------
  |  Branch (1346:22): [True: 84, False: 563]
  ------------------
 1347|     84|            switch(*p){
 1348|      0|            case 'b':
  ------------------
  |  Branch (1348:13): [True: 0, False: 84]
  ------------------
 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: 84]
  ------------------
 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|     27|            case 'd':
  ------------------
  |  Branch (1362:13): [True: 27, False: 57]
  ------------------
 1363|     27|                o.dword = va_arg(ap_copy, uint32_t *);
 1364|     27|                if (buffer->secure) {
  ------------------
  |  Branch (1364:21): [True: 0, False: 27]
  ------------------
 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|     27|                break;
 1369|     27|            case 'q':
  ------------------
  |  Branch (1369:13): [True: 0, False: 84]
  ------------------
 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: 84]
  ------------------
 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|     28|            case 'S':
  ------------------
  |  Branch (1380:13): [True: 28, False: 56]
  ------------------
 1381|     28|                o.string = va_arg(ap_copy, ssh_string *);
 1382|     28|                if (buffer->secure) {
  ------------------
  |  Branch (1382:21): [True: 0, False: 28]
  ------------------
 1383|      0|                    ssh_string_burn(*o.string);
 1384|      0|                }
 1385|     28|                SAFE_FREE(*o.string);
  ------------------
  |  |  373|     28|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 28, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 28]
  |  |  ------------------
  ------------------
 1386|     28|                break;
 1387|     29|            case 's':
  ------------------
  |  Branch (1387:13): [True: 29, False: 55]
  ------------------
 1388|     29|                o.cstring = va_arg(ap_copy, char **);
 1389|     29|                if (buffer->secure) {
  ------------------
  |  Branch (1389:21): [True: 0, False: 29]
  ------------------
 1390|      0|                    ssh_burn(*o.cstring, strlen(*o.cstring));
  ------------------
  |  |  388|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
 1391|      0|                }
 1392|     29|                SAFE_FREE(*o.cstring);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1393|     29|                break;
 1394|      0|            case 'P':
  ------------------
  |  Branch (1394:13): [True: 0, False: 84]
  ------------------
 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: 84]
  ------------------
 1403|      0|                (void)va_arg(ap_copy, void *);
 1404|      0|                break;
 1405|     84|            }
 1406|     84|        }
 1407|    563|    }
 1408|  30.6k|    va_end(ap_copy);
 1409|       |
 1410|  30.6k|    return rc;
 1411|  30.6k|}
_ssh_buffer_unpack:
 1439|  30.6k|{
 1440|  30.6k|    va_list ap;
 1441|  30.6k|    int rc;
 1442|       |
 1443|  30.6k|    va_start(ap, argc);
 1444|  30.6k|    rc = ssh_buffer_unpack_va(buffer, format, argc, ap);
 1445|       |    va_end(ap);
 1446|  30.6k|    return rc;
 1447|  30.6k|}
buffer.c:realloc_buffer:
  188|  2.58k|{
  189|  2.58k|    uint32_t smallest = 1;
  190|  2.58k|    uint8_t *new = NULL;
  191|       |
  192|  2.58k|    buffer_verify(buffer);
  193|       |
  194|       |    /* Find the smallest power of two which is greater or equal to needed */
  195|  20.4k|    while(smallest <= needed) {
  ------------------
  |  Branch (195:11): [True: 17.9k, False: 2.58k]
  ------------------
  196|  17.9k|        if (smallest == 0) {
  ------------------
  |  Branch (196:13): [True: 0, False: 17.9k]
  ------------------
  197|      0|            return -1;
  198|      0|        }
  199|  17.9k|        smallest <<= 1;
  200|  17.9k|    }
  201|  2.58k|    needed = smallest;
  202|       |
  203|  2.58k|    if (needed > BUFFER_SIZE_MAX) {
  ------------------
  |  |   57|  2.58k|#define BUFFER_SIZE_MAX 0x10000000
  ------------------
  |  Branch (203:9): [True: 0, False: 2.58k]
  ------------------
  204|      0|        return -1;
  205|      0|    }
  206|       |
  207|  2.58k|    if (buffer->secure) {
  ------------------
  |  Branch (207:9): [True: 0, False: 2.58k]
  ------------------
  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.58k|    } else {
  216|  2.58k|        new = realloc(buffer->data, needed);
  217|  2.58k|        if (new == NULL) {
  ------------------
  |  Branch (217:13): [True: 16, False: 2.57k]
  ------------------
  218|     16|            return -1;
  219|     16|        }
  220|  2.58k|    }
  221|  2.57k|    buffer->data = new;
  222|  2.57k|    buffer->allocated = needed;
  223|       |
  224|  2.57k|    buffer_verify(buffer);
  225|  2.57k|    return 0;
  226|  2.58k|}

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

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

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|    429|{
  450|    429|    if (crypto->dh_ctx != NULL) {
  ------------------
  |  Branch (450:9): [True: 0, False: 429]
  ------------------
  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|    429|}

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

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

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|    451|{
  169|    451|    va_list va;
  170|       |
  171|    451|    if (verbosity <= ssh_get_log_level()) {
  ------------------
  |  Branch (171:9): [True: 0, False: 451]
  ------------------
  172|      0|        va_start(va, format);
  173|      0|        ssh_vlog(verbosity, function, format, &va);
  174|       |        va_end(va);
  175|      0|    }
  176|    451|}
ssh_get_log_level:
  252|  1.56k|int ssh_get_log_level(void) {
  253|  1.56k|  return ssh_log_level;
  254|  1.56k|}
ssh_get_log_callback:
  275|    514|ssh_logging_callback ssh_get_log_callback(void) {
  276|    514|  return ssh_log_cb;
  277|    514|}

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

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

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

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

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

sftp_attributes_free:
  903|  1.31k|void sftp_attributes_free(sftp_attributes file){
  904|  1.31k|  if (file == NULL) {
  ------------------
  |  Branch (904:7): [True: 1.11k, False: 201]
  ------------------
  905|  1.11k|    return;
  906|  1.11k|  }
  907|       |
  908|    201|  SSH_STRING_FREE(file->acl);
  ------------------
  |  |  910|    201|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 32, False: 169]
  |  |  |  Branch (910:69): [Folded, False: 201]
  |  |  ------------------
  ------------------
  909|    201|  SSH_STRING_FREE(file->extended_data);
  ------------------
  |  |  910|    201|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 2, False: 199]
  |  |  |  Branch (910:69): [Folded, False: 201]
  |  |  ------------------
  ------------------
  910|    201|  SSH_STRING_FREE(file->extended_type);
  ------------------
  |  |  910|    201|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 2, False: 199]
  |  |  |  Branch (910:69): [Folded, False: 201]
  |  |  ------------------
  ------------------
  911|       |
  912|    201|  SAFE_FREE(file->name);
  ------------------
  |  |  373|    201|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 17, False: 184]
  |  |  |  Branch (373:71): [Folded, False: 201]
  |  |  ------------------
  ------------------
  913|    201|  SAFE_FREE(file->longname);
  ------------------
  |  |  373|    201|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 17, False: 184]
  |  |  |  Branch (373:71): [Folded, False: 201]
  |  |  ------------------
  ------------------
  914|    201|  SAFE_FREE(file->group);
  ------------------
  |  |  373|    201|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 24, False: 177]
  |  |  |  Branch (373:71): [Folded, False: 201]
  |  |  ------------------
  ------------------
  915|    201|  SAFE_FREE(file->owner);
  ------------------
  |  |  373|    201|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 24, False: 177]
  |  |  |  Branch (373:71): [Folded, False: 201]
  |  |  ------------------
  ------------------
  916|       |
  917|       |  SAFE_FREE(file);
  ------------------
  |  |  373|    201|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 201, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 201]
  |  |  ------------------
  ------------------
  918|    201|}

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

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|    757|{
  183|    757|    ssh_socket s;
  184|       |
  185|    757|    s = calloc(1, sizeof(struct ssh_socket_struct));
  186|    757|    if (s == NULL) {
  ------------------
  |  Branch (186:9): [True: 47, False: 710]
  ------------------
  187|     47|        ssh_set_error_oom(session);
  ------------------
  |  |  318|     47|    _ssh_set_error_oom(error, __func__)
  ------------------
  188|     47|        return NULL;
  189|     47|    }
  190|    710|    s->fd = SSH_INVALID_SOCKET;
  ------------------
  |  |  124|    710|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  191|    710|    s->last_errno = -1;
  192|    710|    s->fd_is_socket = 1;
  193|    710|    s->session = session;
  194|    710|    s->in_buffer = ssh_buffer_new();
  195|    710|    if (s->in_buffer == NULL) {
  ------------------
  |  Branch (195:9): [True: 39, False: 671]
  ------------------
  196|     39|        ssh_set_error_oom(session);
  ------------------
  |  |  318|     39|    _ssh_set_error_oom(error, __func__)
  ------------------
  197|     39|        SAFE_FREE(s);
  ------------------
  |  |  373|     39|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 39, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 39]
  |  |  ------------------
  ------------------
  198|     39|        return NULL;
  199|     39|    }
  200|    671|    s->out_buffer=ssh_buffer_new();
  201|    671|    if (s->out_buffer == NULL) {
  ------------------
  |  Branch (201:9): [True: 8, False: 663]
  ------------------
  202|      8|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      8|    _ssh_set_error_oom(error, __func__)
  ------------------
  203|      8|        SSH_BUFFER_FREE(s->in_buffer);
  ------------------
  |  |  951|      8|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 8, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 8]
  |  |  ------------------
  ------------------
  204|      8|        SAFE_FREE(s);
  ------------------
  |  |  373|      8|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 8, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 8]
  |  |  ------------------
  ------------------
  205|      8|        return NULL;
  206|      8|    }
  207|    663|    s->read_wontblock = 0;
  208|    663|    s->write_wontblock = 0;
  209|    663|    s->data_except = 0;
  210|       |    s->poll_handle = NULL;
  211|    663|    s->state=SSH_SOCKET_NONE;
  212|    663|    return s;
  213|    671|}
ssh_socket_free:
  473|    842|{
  474|    842|    if (s == NULL) {
  ------------------
  |  Branch (474:9): [True: 179, False: 663]
  ------------------
  475|    179|        return;
  476|    179|    }
  477|    663|    ssh_socket_close(s);
  478|    663|    SSH_BUFFER_FREE(s->in_buffer);
  ------------------
  |  |  951|    663|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 663, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 663]
  |  |  ------------------
  ------------------
  479|    663|    SSH_BUFFER_FREE(s->out_buffer);
  ------------------
  |  |  951|    663|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 663, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 663]
  |  |  ------------------
  ------------------
  480|       |    SAFE_FREE(s);
  ------------------
  |  |  373|    663|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 663, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 663]
  |  |  ------------------
  ------------------
  481|    663|}
ssh_socket_close:
  546|    991|{
  547|    991|    if (ssh_socket_is_open(s)) {
  ------------------
  |  Branch (547:9): [True: 0, False: 991]
  ------------------
  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|    991|    if (s->poll_handle != NULL && !ssh_poll_is_locked(s->poll_handle)) {
  ------------------
  |  Branch (557:9): [True: 0, False: 991]
  |  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|    991|    s->state = SSH_SOCKET_CLOSED;
  563|       |
  564|    991|#ifndef _WIN32
  565|       |    /* If the proxy command still runs try to kill it */
  566|    991|    if (s->proxy_pid != 0) {
  ------------------
  |  Branch (566:9): [True: 0, False: 991]
  ------------------
  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|    991|#endif
  585|    991|}
ssh_socket_is_open:
  643|    991|{
  644|    991|    return s->fd != SSH_INVALID_SOCKET;
  ------------------
  |  |  124|    991|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  645|    991|}

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

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|    858|void ssh_cipher_clear(struct ssh_cipher_struct *cipher){
  125|       |#ifdef HAVE_LIBGCRYPT
  126|       |    unsigned int i;
  127|       |#endif
  128|       |
  129|    858|    if (cipher == NULL) {
  ------------------
  |  Branch (129:9): [True: 858, False: 0]
  ------------------
  130|    858|        return;
  131|    858|    }
  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|    514|{
  154|    514|    struct ssh_crypto_struct *crypto = NULL;
  155|       |
  156|    514|    crypto = calloc(1, sizeof(struct ssh_crypto_struct));
  157|    514|    if (crypto == NULL) {
  ------------------
  |  Branch (157:9): [True: 85, False: 429]
  ------------------
  158|     85|        return NULL;
  159|     85|    }
  160|    429|    return crypto;
  161|    514|}
crypto_free:
  164|  1.02k|{
  165|  1.02k|    size_t i;
  166|       |
  167|  1.02k|    if (crypto == NULL) {
  ------------------
  |  Branch (167:9): [True: 599, False: 429]
  ------------------
  168|    599|        return;
  169|    599|    }
  170|       |
  171|    429|    ssh_key_free(crypto->server_pubkey);
  172|       |
  173|    429|    ssh_dh_cleanup(crypto);
  174|    429|    bignum_safe_free(crypto->shared_secret);
  ------------------
  |  |   71|    429|#define bignum_safe_free(num) do { \
  |  |   72|    429|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 429]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|    429|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 429]
  |  |  ------------------
  ------------------
  175|    429|#ifdef HAVE_ECDH
  176|    429|    SAFE_FREE(crypto->ecdh_client_pubkey);
  ------------------
  |  |  373|    429|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 429]
  |  |  |  Branch (373:71): [Folded, False: 429]
  |  |  ------------------
  ------------------
  177|    429|    SAFE_FREE(crypto->ecdh_server_pubkey);
  ------------------
  |  |  373|    429|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 429]
  |  |  |  Branch (373:71): [Folded, False: 429]
  |  |  ------------------
  ------------------
  178|    429|    if (crypto->ecdh_privkey != NULL) {
  ------------------
  |  Branch (178:9): [True: 0, False: 429]
  ------------------
  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|    429|#endif
  194|    429|#ifdef HAVE_LIBCRYPTO
  195|    429|    EVP_PKEY_free(crypto->curve25519_privkey);
  196|       |#elif defined(HAVE_GCRYPT_CURVE25519)
  197|       |    gcry_sexp_release(crypto->curve25519_privkey);
  198|       |#endif
  199|    429|    SAFE_FREE(crypto->dh_server_signature);
  ------------------
  |  |  373|    429|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 429]
  |  |  |  Branch (373:71): [Folded, False: 429]
  |  |  ------------------
  ------------------
  200|    429|    if (crypto->session_id != NULL) {
  ------------------
  |  Branch (200:9): [True: 0, False: 429]
  ------------------
  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|    429|    if (crypto->secret_hash != NULL) {
  ------------------
  |  Branch (204:9): [True: 0, False: 429]
  ------------------
  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|    429|    compress_cleanup(crypto);
  209|    429|    SAFE_FREE(crypto->encryptIV);
  ------------------
  |  |  373|    429|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 429]
  |  |  |  Branch (373:71): [Folded, False: 429]
  |  |  ------------------
  ------------------
  210|    429|    SAFE_FREE(crypto->decryptIV);
  ------------------
  |  |  373|    429|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 429]
  |  |  |  Branch (373:71): [Folded, False: 429]
  |  |  ------------------
  ------------------
  211|    429|    SAFE_FREE(crypto->encryptMAC);
  ------------------
  |  |  373|    429|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 429]
  |  |  |  Branch (373:71): [Folded, False: 429]
  |  |  ------------------
  ------------------
  212|    429|    SAFE_FREE(crypto->decryptMAC);
  ------------------
  |  |  373|    429|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 429]
  |  |  |  Branch (373:71): [Folded, False: 429]
  |  |  ------------------
  ------------------
  213|    429|    if (crypto->encryptkey != NULL) {
  ------------------
  |  Branch (213:9): [True: 0, False: 429]
  ------------------
  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|    429|    if (crypto->decryptkey != NULL) {
  ------------------
  |  Branch (217:9): [True: 0, False: 429]
  ------------------
  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|    429|    cipher_free(crypto->in_cipher);
  223|    429|    cipher_free(crypto->out_cipher);
  224|       |
  225|  4.71k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  4.71k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (225:17): [True: 4.29k, False: 429]
  ------------------
  226|  4.29k|        SAFE_FREE(crypto->client_kex.methods[i]);
  ------------------
  |  |  373|  4.29k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 4.29k]
  |  |  |  Branch (373:71): [Folded, False: 4.29k]
  |  |  ------------------
  ------------------
  227|  4.29k|        SAFE_FREE(crypto->server_kex.methods[i]);
  ------------------
  |  |  373|  4.29k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 4.29k]
  |  |  |  Branch (373:71): [Folded, False: 4.29k]
  |  |  ------------------
  ------------------
  228|  4.29k|        SAFE_FREE(crypto->kex_methods[i]);
  ------------------
  |  |  373|  4.29k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 4.29k]
  |  |  |  Branch (373:71): [Folded, False: 4.29k]
  |  |  ------------------
  ------------------
  229|  4.29k|    }
  230|       |
  231|       |#ifdef HAVE_OPENSSL_MLKEM
  232|       |    EVP_PKEY_free(crypto->mlkem_privkey);
  233|       |#else
  234|    429|    if (crypto->mlkem_privkey != NULL) {
  ------------------
  |  Branch (234:9): [True: 0, False: 429]
  ------------------
  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|    429|#endif
  240|    429|    ssh_string_burn(crypto->hybrid_shared_secret);
  241|    429|    ssh_string_free(crypto->mlkem_client_pubkey);
  242|    429|    ssh_string_free(crypto->mlkem_ciphertext);
  243|    429|    ssh_string_free(crypto->hybrid_client_init);
  244|    429|    ssh_string_free(crypto->hybrid_server_reply);
  245|    429|    ssh_string_free(crypto->hybrid_shared_secret);
  246|       |
  247|    429|    ssh_burn(crypto, sizeof(struct ssh_crypto_struct));
  ------------------
  |  |  388|    429|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  248|       |
  249|       |    SAFE_FREE(crypto);
  ------------------
  |  |  373|    429|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 429, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 429]
  |  |  ------------------
  ------------------
  250|    429|}
wrapper.c:cipher_free:
  147|    858|static void cipher_free(struct ssh_cipher_struct *cipher) {
  148|    858|  ssh_cipher_clear(cipher);
  149|       |  SAFE_FREE(cipher);
  ------------------
  |  |  373|    858|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 858]
  |  |  |  Branch (373:71): [Folded, False: 858]
  |  |  ------------------
  ------------------
  150|    858|}

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

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|    695|{
   77|    695|    ssh_session session = NULL;
   78|    695|    sftp_session sftp = NULL;
   79|    695|    ssh_buffer buffer = NULL;
   80|    695|    sftp_attributes attr = NULL;
   81|    695|    int versions[] = {
   82|    695|        SFTP_PROTOCOL_VERSION_3, SFTP_PROTOCOL_VERSION_3,
  ------------------
  |  |   33|    695|#define SFTP_PROTOCOL_VERSION_3 3
  ------------------
                      SFTP_PROTOCOL_VERSION_3, SFTP_PROTOCOL_VERSION_3,
  ------------------
  |  |   33|    695|#define SFTP_PROTOCOL_VERSION_3 3
  ------------------
   83|    695|        SFTP_PROTOCOL_VERSION_4, SFTP_PROTOCOL_VERSION_4
  ------------------
  |  |   34|    695|#define SFTP_PROTOCOL_VERSION_4 4
  ------------------
                      SFTP_PROTOCOL_VERSION_4, SFTP_PROTOCOL_VERSION_4
  ------------------
  |  |   34|    695|#define SFTP_PROTOCOL_VERSION_4 4
  ------------------
   84|    695|    };
   85|    695|    int expectnames[] = {SFTP_NO_NAME, SFTP_EXPECT_NAME, SFTP_NO_NAME, SFTP_EXPECT_NAME};
  ------------------
  |  |   38|    695|#define SFTP_NO_NAME 0
  ------------------
                  int expectnames[] = {SFTP_NO_NAME, SFTP_EXPECT_NAME, SFTP_NO_NAME, SFTP_EXPECT_NAME};
  ------------------
  |  |   37|    695|#define SFTP_EXPECT_NAME 1
  ------------------
                  int expectnames[] = {SFTP_NO_NAME, SFTP_EXPECT_NAME, SFTP_NO_NAME, SFTP_EXPECT_NAME};
  ------------------
  |  |   38|    695|#define SFTP_NO_NAME 0
  ------------------
                  int expectnames[] = {SFTP_NO_NAME, SFTP_EXPECT_NAME, SFTP_NO_NAME, SFTP_EXPECT_NAME};
  ------------------
  |  |   37|    695|#define SFTP_EXPECT_NAME 1
  ------------------
   86|    695|    size_t i;
   87|       |
   88|       |    /* Minimum bytes for a valid SFTP message */
   89|    695|    if (size == 0) {
  ------------------
  |  Branch (89:9): [True: 0, False: 695]
  ------------------
   90|      0|        return 0;
   91|      0|    }
   92|       |
   93|    695|    assert(nalloc_start(data, size) > 0);
  ------------------
  |  Branch (93:5): [True: 0, False: 695]
  |  Branch (93:5): [True: 695, False: 0]
  ------------------
   94|       |
   95|       |    /* Allocate shared resources once for all test iterations */
   96|    695|    session = ssh_new();
   97|    695|    if (session == NULL) {
  ------------------
  |  Branch (97:9): [True: 367, False: 328]
  ------------------
   98|    367|        goto cleanup;
   99|    367|    }
  100|       |
  101|    328|    sftp = create_minimal_sftp_session(session);
  102|    328|    if (sftp == NULL) {
  ------------------
  |  Branch (102:9): [True: 0, False: 328]
  ------------------
  103|      0|        goto cleanup;
  104|      0|    }
  105|       |
  106|    328|    buffer = ssh_buffer_new();
  107|    328|    if (buffer == NULL) {
  ------------------
  |  Branch (107:9): [True: 0, False: 328]
  ------------------
  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.64k|    for (i = 0; i < ARRAY_SIZE(versions); i++) {
  ------------------
  |  |  382|  1.64k|#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
  ------------------
  |  Branch (114:17): [True: 1.31k, False: 328]
  ------------------
  115|  1.31k|        sftp->version = versions[i];
  116|       |
  117|       |        /* Reset and repopulate buffer for each iteration */
  118|  1.31k|        ssh_buffer_reinit(buffer);
  119|  1.31k|        if (ssh_buffer_add_data(buffer, data, size) == SSH_OK) {
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (119:13): [True: 1.31k, False: 0]
  ------------------
  120|  1.31k|            attr = sftp_parse_attr(sftp, buffer, expectnames[i]);
  121|  1.31k|            sftp_attributes_free(attr);
  122|  1.31k|            attr = NULL;
  123|  1.31k|        }
  124|  1.31k|    }
  125|       |
  126|    695|cleanup:
  127|    695|    ssh_buffer_free(buffer);
  128|    695|    free(sftp);
  129|    695|    ssh_free(session);
  130|    695|    nalloc_end();
  131|       |
  132|    695|    return 0;
  133|    328|}
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|    328|{
   46|    328|    sftp_session sftp;
   47|       |
   48|    328|    sftp = calloc(1, sizeof(struct sftp_session_struct));
   49|    328|    if (sftp == NULL) {
  ------------------
  |  Branch (49:9): [True: 0, False: 328]
  ------------------
   50|      0|        return NULL;
   51|      0|    }
   52|    328|    sftp->session = session;
   53|       |
   54|    328|    return sftp;
   55|    328|}

