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

ssh_agent_state_free:
 1148|    569|{
 1149|    569|    struct ssh_agent_state_struct *state = data;
 1150|       |
 1151|    569|    if (state) {
  ------------------
  |  Branch (1151:9): [True: 0, False: 569]
  ------------------
 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|    569|}

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

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

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

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

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

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

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

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

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

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

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

ssh_new:
   65|    732|{
   66|    732|    ssh_session session = NULL;
   67|    732|    char *id = NULL;
   68|    732|    int rc;
   69|       |
   70|    732|    session = calloc(1, sizeof (struct ssh_session_struct));
   71|    732|    if (session == NULL) {
  ------------------
  |  Branch (71:9): [True: 163, False: 569]
  ------------------
   72|    163|        return NULL;
   73|    163|    }
   74|       |
   75|    569|    session->next_crypto = crypto_new();
   76|    569|    if (session->next_crypto == NULL) {
  ------------------
  |  Branch (76:9): [True: 78, False: 491]
  ------------------
   77|     78|        goto err;
   78|     78|    }
   79|       |
   80|    491|    session->socket = ssh_socket_new(session);
   81|    491|    if (session->socket == NULL) {
  ------------------
  |  Branch (81:9): [True: 79, False: 412]
  ------------------
   82|     79|        goto err;
   83|     79|    }
   84|       |
   85|    412|    session->out_buffer = ssh_buffer_new();
   86|    412|    if (session->out_buffer == NULL) {
  ------------------
  |  Branch (86:9): [True: 1, False: 411]
  ------------------
   87|      1|        goto err;
   88|      1|    }
   89|       |
   90|    411|    session->in_buffer = ssh_buffer_new();
   91|    411|    if (session->in_buffer == NULL) {
  ------------------
  |  Branch (91:9): [True: 2, False: 409]
  ------------------
   92|      2|        goto err;
   93|      2|    }
   94|       |
   95|    409|    session->out_queue = ssh_list_new();
   96|    409|    if (session->out_queue == NULL) {
  ------------------
  |  Branch (96:9): [True: 0, False: 409]
  ------------------
   97|      0|        goto err;
   98|      0|    }
   99|       |
  100|    409|    session->alive = 0;
  101|    409|    session->auth.supported_methods = 0;
  102|    409|    ssh_set_blocking(session, 1);
  103|    409|    session->maxchannel = FIRST_CHANNEL;
  ------------------
  |  |   48|    409|#define FIRST_CHANNEL 42 // why not ? it helps to find bugs.
  ------------------
  104|    409|    session->proxy_root = true;
  105|       |
  106|    409|    session->agent = ssh_agent_new(session);
  107|    409|    if (session->agent == NULL) {
  ------------------
  |  Branch (107:9): [True: 0, False: 409]
  ------------------
  108|      0|        goto err;
  109|      0|    }
  110|       |
  111|       |    /* Initialise a default PKI context */
  112|    409|    session->pki_context = ssh_pki_ctx_new();
  113|    409|    if (session->pki_context == NULL) {
  ------------------
  |  Branch (113:9): [True: 1, False: 408]
  ------------------
  114|      1|        goto err;
  115|      1|    }
  116|       |
  117|       |    /* OPTIONS */
  118|    408|    session->opts.StrictHostKeyChecking = SSH_STRICT_HOSTKEY_ASK;
  119|    408|    session->opts.port = 22;
  120|    408|    session->opts.fd = -1;
  121|    408|    session->opts.compressionlevel = 7;
  122|    408|    session->opts.nodelay = 0;
  123|    408|    session->opts.identities_only = false;
  124|    408|    session->opts.batch_mode = false;
  125|    408|    session->opts.control_master = SSH_CONTROL_MASTER_NO;
  126|       |
  127|    408|    session->opts.flags = SSH_OPT_FLAG_PASSWORD_AUTH |
  ------------------
  |  |  109|    408|#define SSH_OPT_FLAG_PASSWORD_AUTH 0x1
  ------------------
  128|    408|                          SSH_OPT_FLAG_PUBKEY_AUTH |
  ------------------
  |  |  110|    408|#define SSH_OPT_FLAG_PUBKEY_AUTH 0x2
  ------------------
  129|    408|                          SSH_OPT_FLAG_KBDINT_AUTH |
  ------------------
  |  |  111|    408|#define SSH_OPT_FLAG_KBDINT_AUTH 0x4
  ------------------
  130|    408|                          SSH_OPT_FLAG_GSSAPI_AUTH;
  ------------------
  |  |  112|    408|#define SSH_OPT_FLAG_GSSAPI_AUTH 0x8
  ------------------
  131|    408|    session->opts.pubkey_auth = SSH_PUBKEY_AUTH_ALL;
  132|       |
  133|    408|    session->opts.exp_flags = 0;
  134|       |
  135|    408|    session->opts.identity = ssh_list_new();
  136|    408|    if (session->opts.identity == NULL) {
  ------------------
  |  Branch (136:9): [True: 0, False: 408]
  ------------------
  137|      0|        goto err;
  138|      0|    }
  139|    408|    session->opts.identity_non_exp = ssh_list_new();
  140|    408|    if (session->opts.identity_non_exp == NULL) {
  ------------------
  |  Branch (140:9): [True: 0, False: 408]
  ------------------
  141|      0|        goto err;
  142|      0|    }
  143|       |
  144|    408|    session->opts.certificate = ssh_list_new();
  145|    408|    if (session->opts.certificate == NULL) {
  ------------------
  |  Branch (145:9): [True: 0, False: 408]
  ------------------
  146|      0|        goto err;
  147|      0|    }
  148|    408|    session->opts.certificate_non_exp = ssh_list_new();
  149|    408|    if (session->opts.certificate_non_exp == NULL) {
  ------------------
  |  Branch (149:9): [True: 0, False: 408]
  ------------------
  150|      0|        goto err;
  151|      0|    }
  152|       |    /* the default certificates are loaded automatically from the default
  153|       |     * identities later */
  154|       |
  155|    408|    session->opts.proxy_jumps = ssh_list_new();
  156|    408|    if (session->opts.proxy_jumps == NULL) {
  ------------------
  |  Branch (156:9): [True: 0, False: 408]
  ------------------
  157|      0|        goto err;
  158|      0|    }
  159|       |
  160|    408|    session->opts.proxy_jumps_user_cb = ssh_list_new();
  161|    408|    if (session->opts.proxy_jumps_user_cb == NULL) {
  ------------------
  |  Branch (161:9): [True: 0, False: 408]
  ------------------
  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|    408|    id = strdup("%d/.ssh/id_ed25519");
  174|    408|    if (id == NULL) {
  ------------------
  |  Branch (174:9): [True: 0, False: 408]
  ------------------
  175|      0|        goto err;
  176|      0|    }
  177|       |
  178|    408|    rc = ssh_list_append(session->opts.identity_non_exp, id);
  179|    408|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    408|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (179:9): [True: 0, False: 408]
  ------------------
  180|      0|        goto err;
  181|      0|    }
  182|       |
  183|    408|#ifdef HAVE_ECC
  184|    408|    id = strdup("%d/.ssh/id_ecdsa");
  185|    408|    if (id == NULL) {
  ------------------
  |  Branch (185:9): [True: 0, False: 408]
  ------------------
  186|      0|        goto err;
  187|      0|    }
  188|    408|    rc = ssh_list_append(session->opts.identity_non_exp, id);
  189|    408|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    408|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (189:9): [True: 0, False: 408]
  ------------------
  190|      0|        goto err;
  191|      0|    }
  192|    408|#endif
  193|       |
  194|    408|    id = strdup("%d/.ssh/id_rsa");
  195|    408|    if (id == NULL) {
  ------------------
  |  Branch (195:9): [True: 0, False: 408]
  ------------------
  196|      0|        goto err;
  197|      0|    }
  198|    408|    rc = ssh_list_append(session->opts.identity_non_exp, id);
  199|    408|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    408|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (199:9): [True: 0, False: 408]
  ------------------
  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|    408|    session->session_state = SSH_SESSION_STATE_NONE;
  228|    408|    session->pending_call_state = SSH_PENDING_CALL_NONE;
  229|    408|    session->packet_state = PACKET_STATE_INIT;
  230|    408|    session->dh_handshake_state = DH_STATE_INIT;
  231|    408|    session->global_req_state = SSH_CHANNEL_REQ_STATE_NONE;
  232|       |
  233|    408|    session->auth.state = SSH_AUTH_STATE_NONE;
  234|    408|    session->auth.service_state = SSH_AUTH_SERVICE_NONE;
  235|       |
  236|    408|    return session;
  237|       |
  238|    161|err:
  239|    161|    free(id);
  240|    161|    ssh_free(session);
  241|       |    return NULL;
  242|    408|}
ssh_free:
  253|    893|{
  254|    893|  int i;
  255|    893|  struct ssh_iterator *it = NULL;
  256|    893|  struct ssh_buffer_struct *b = NULL;
  257|       |
  258|    893|  if (session == NULL) {
  ------------------
  |  Branch (258:7): [True: 324, False: 569]
  ------------------
  259|    324|    return;
  260|    324|  }
  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|    569|  for (it = ssh_list_get_iterator(session->channels);
  270|    569|       it != NULL;
  ------------------
  |  Branch (270:8): [True: 0, False: 569]
  ------------------
  271|    569|       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|    569|  ssh_list_free(session->channels);
  276|    569|  session->channels = NULL;
  277|       |
  278|    569|#ifdef WITH_PCAP
  279|    569|  if (session->pcap_ctx) {
  ------------------
  |  Branch (279:7): [True: 0, False: 569]
  ------------------
  280|      0|      ssh_pcap_context_free(session->pcap_ctx);
  281|      0|      session->pcap_ctx = NULL;
  282|      0|  }
  283|    569|#endif
  284|       |
  285|    569|  ssh_socket_free(session->socket);
  286|    569|  session->socket = NULL;
  287|       |
  288|    569|  if (session->default_poll_ctx) {
  ------------------
  |  Branch (288:7): [True: 0, False: 569]
  ------------------
  289|      0|      ssh_poll_ctx_free(session->default_poll_ctx);
  290|      0|  }
  291|       |
  292|    569|  SSH_BUFFER_FREE(session->in_buffer);
  ------------------
  |  |  951|    569|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 409, False: 160]
  |  |  |  Branch (951:69): [Folded, False: 569]
  |  |  ------------------
  ------------------
  293|    569|  SSH_BUFFER_FREE(session->out_buffer);
  ------------------
  |  |  951|    569|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 411, False: 158]
  |  |  |  Branch (951:69): [Folded, False: 569]
  |  |  ------------------
  ------------------
  294|    569|  session->in_buffer = session->out_buffer = NULL;
  295|       |
  296|    569|  if (session->in_hashbuf != NULL) {
  ------------------
  |  Branch (296:7): [True: 0, False: 569]
  ------------------
  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|    569|  if (session->out_hashbuf != NULL) {
  ------------------
  |  Branch (299:7): [True: 0, False: 569]
  ------------------
  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|    569|  crypto_free(session->current_crypto);
  304|    569|  crypto_free(session->next_crypto);
  305|       |
  306|    569|  ssh_agent_free(session->agent);
  307|       |
  308|    569|  SSH_PKI_CTX_FREE(session->pki_context);
  ------------------
  |  | 1044|    569|    do {                         \
  |  | 1045|    569|        if ((x) != NULL) {       \
  |  |  ------------------
  |  |  |  Branch (1045:13): [True: 408, False: 161]
  |  |  ------------------
  |  | 1046|    408|            ssh_pki_ctx_free(x); \
  |  | 1047|    408|            x = NULL;            \
  |  | 1048|    408|        }                        \
  |  | 1049|    569|    } while (0)
  |  |  ------------------
  |  |  |  Branch (1049:14): [Folded, False: 569]
  |  |  ------------------
  ------------------
  309|       |
  310|    569|  ssh_key_free(session->srv.rsa_key);
  311|    569|  session->srv.rsa_key = NULL;
  312|    569|  ssh_key_free(session->srv.ecdsa_key);
  313|    569|  session->srv.ecdsa_key = NULL;
  314|    569|  ssh_key_free(session->srv.ed25519_key);
  315|    569|  session->srv.ed25519_key = NULL;
  316|       |
  317|    569|  if (session->ssh_message_list) {
  ------------------
  |  Branch (317:7): [True: 0, False: 569]
  ------------------
  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|    569|  if (session->kbdint != NULL) {
  ------------------
  |  Branch (328:7): [True: 0, False: 569]
  ------------------
  329|      0|    ssh_kbdint_free(session->kbdint);
  330|      0|  }
  331|       |
  332|    569|  if (session->packet_callbacks) {
  ------------------
  |  Branch (332:7): [True: 0, False: 569]
  ------------------
  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|    569|  if (session->opts.identity) {
  ------------------
  |  Branch (342:7): [True: 408, False: 161]
  ------------------
  343|    408|      char *id = NULL;
  344|       |
  345|    408|      for (id = ssh_list_pop_head(char *, session->opts.identity);
  ------------------
  |  |  122|    408|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  346|    408|           id != NULL;
  ------------------
  |  Branch (346:12): [True: 0, False: 408]
  ------------------
  347|    408|           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|    408|      ssh_list_free(session->opts.identity);
  351|    408|  }
  352|       |
  353|    569|  if (session->opts.identity_non_exp) {
  ------------------
  |  Branch (353:7): [True: 408, False: 161]
  ------------------
  354|    408|      char *id = NULL;
  355|       |
  356|    408|      for (id = ssh_list_pop_head(char *, session->opts.identity_non_exp);
  ------------------
  |  |  122|    408|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  357|  1.63k|           id != NULL;
  ------------------
  |  Branch (357:12): [True: 1.22k, False: 408]
  ------------------
  358|  1.22k|           id = ssh_list_pop_head(char *, session->opts.identity_non_exp)) {
  ------------------
  |  |  122|  1.22k|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  359|  1.22k|          SAFE_FREE(id);
  ------------------
  |  |  373|  1.22k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.22k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 1.22k]
  |  |  ------------------
  ------------------
  360|  1.22k|      }
  361|    408|      ssh_list_free(session->opts.identity_non_exp);
  362|    408|  }
  363|       |
  364|    569|    if (session->opts.certificate) {
  ------------------
  |  Branch (364:9): [True: 408, False: 161]
  ------------------
  365|    408|        char *cert = NULL;
  366|       |
  367|    408|        for (cert = ssh_list_pop_head(char *, session->opts.certificate);
  ------------------
  |  |  122|    408|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  368|    408|             cert != NULL;
  ------------------
  |  Branch (368:14): [True: 0, False: 408]
  ------------------
  369|    408|             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|    408|        ssh_list_free(session->opts.certificate);
  373|    408|    }
  374|       |
  375|    569|    if (session->opts.certificate_non_exp) {
  ------------------
  |  Branch (375:9): [True: 408, False: 161]
  ------------------
  376|    408|        char *cert = NULL;
  377|       |
  378|    408|        for (cert = ssh_list_pop_head(char *, session->opts.certificate_non_exp);
  ------------------
  |  |  122|    408|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  379|    408|             cert != NULL;
  ------------------
  |  Branch (379:14): [True: 0, False: 408]
  ------------------
  380|    408|             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|    408|        ssh_list_free(session->opts.certificate_non_exp);
  384|    408|    }
  385|       |
  386|    569|    ssh_proxyjumps_free(session->opts.proxy_jumps);
  387|    569|    SSH_LIST_FREE(session->opts.proxy_jumps);
  ------------------
  |  |  125|    569|    do { if ((x) != NULL) { ssh_list_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (125:14): [True: 408, False: 161]
  |  |  |  Branch (125:69): [Folded, False: 569]
  |  |  ------------------
  ------------------
  388|    569|    SSH_LIST_FREE(session->opts.proxy_jumps_user_cb);
  ------------------
  |  |  125|    569|    do { if ((x) != NULL) { ssh_list_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (125:14): [True: 408, False: 161]
  |  |  |  Branch (125:69): [Folded, False: 569]
  |  |  ------------------
  ------------------
  389|    569|    SAFE_FREE(session->opts.proxy_jumps_str);
  ------------------
  |  |  373|    569|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 569]
  |  |  |  Branch (373:71): [Folded, False: 569]
  |  |  ------------------
  ------------------
  390|       |
  391|    569|    while ((b = ssh_list_pop_head(struct ssh_buffer_struct *,
  ------------------
  |  |  122|    569|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  |  Branch (391:12): [True: 0, False: 569]
  ------------------
  392|    569|                                  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|    569|    ssh_list_free(session->out_queue);
  396|       |
  397|    569|  ssh_agent_state_free(session->agent_state);
  398|    569|  session->agent_state = NULL;
  399|       |
  400|    569|  SAFE_FREE(session->auth.auto_state);
  ------------------
  |  |  373|    569|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 569]
  |  |  |  Branch (373:71): [Folded, False: 569]
  |  |  ------------------
  ------------------
  401|    569|  SAFE_FREE(session->serverbanner);
  ------------------
  |  |  373|    569|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 569]
  |  |  |  Branch (373:71): [Folded, False: 569]
  |  |  ------------------
  ------------------
  402|    569|  SAFE_FREE(session->clientbanner);
  ------------------
  |  |  373|    569|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 569]
  |  |  |  Branch (373:71): [Folded, False: 569]
  |  |  ------------------
  ------------------
  403|    569|  SAFE_FREE(session->banner);
  ------------------
  |  |  373|    569|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 569]
  |  |  |  Branch (373:71): [Folded, False: 569]
  |  |  ------------------
  ------------------
  404|    569|  SAFE_FREE(session->disconnect_message);
  ------------------
  |  |  373|    569|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 569]
  |  |  |  Branch (373:71): [Folded, False: 569]
  |  |  ------------------
  ------------------
  405|    569|  SAFE_FREE(session->peer_discon_msg);
  ------------------
  |  |  373|    569|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 569]
  |  |  |  Branch (373:71): [Folded, False: 569]
  |  |  ------------------
  ------------------
  406|       |
  407|    569|  SAFE_FREE(session->opts.agent_socket);
  ------------------
  |  |  373|    569|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 569]
  |  |  |  Branch (373:71): [Folded, False: 569]
  |  |  ------------------
  ------------------
  408|    569|  SAFE_FREE(session->opts.bindaddr);
  ------------------
  |  |  373|    569|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 569]
  |  |  |  Branch (373:71): [Folded, False: 569]
  |  |  ------------------
  ------------------
  409|    569|  SAFE_FREE(session->opts.username);
  ------------------
  |  |  373|    569|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 569]
  |  |  |  Branch (373:71): [Folded, False: 569]
  |  |  ------------------
  ------------------
  410|    569|  SAFE_FREE(session->opts.host);
  ------------------
  |  |  373|    569|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 569]
  |  |  |  Branch (373:71): [Folded, False: 569]
  |  |  ------------------
  ------------------
  411|    569|  SAFE_FREE(session->opts.originalhost);
  ------------------
  |  |  373|    569|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 569]
  |  |  |  Branch (373:71): [Folded, False: 569]
  |  |  ------------------
  ------------------
  412|    569|  SAFE_FREE(session->opts.config_hostname);
  ------------------
  |  |  373|    569|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 569]
  |  |  |  Branch (373:71): [Folded, False: 569]
  |  |  ------------------
  ------------------
  413|    569|  SAFE_FREE(session->opts.tag);
  ------------------
  |  |  373|    569|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 569]
  |  |  |  Branch (373:71): [Folded, False: 569]
  |  |  ------------------
  ------------------
  414|    569|  SAFE_FREE(session->opts.homedir);
  ------------------
  |  |  373|    569|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 569]
  |  |  |  Branch (373:71): [Folded, False: 569]
  |  |  ------------------
  ------------------
  415|    569|  SAFE_FREE(session->opts.sshdir);
  ------------------
  |  |  373|    569|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 569]
  |  |  |  Branch (373:71): [Folded, False: 569]
  |  |  ------------------
  ------------------
  416|    569|  SAFE_FREE(session->opts.knownhosts);
  ------------------
  |  |  373|    569|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 569]
  |  |  |  Branch (373:71): [Folded, False: 569]
  |  |  ------------------
  ------------------
  417|    569|  SAFE_FREE(session->opts.global_knownhosts);
  ------------------
  |  |  373|    569|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 569]
  |  |  |  Branch (373:71): [Folded, False: 569]
  |  |  ------------------
  ------------------
  418|    569|  SAFE_FREE(session->opts.ProxyCommand);
  ------------------
  |  |  373|    569|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 569]
  |  |  |  Branch (373:71): [Folded, False: 569]
  |  |  ------------------
  ------------------
  419|    569|  SAFE_FREE(session->opts.gss_server_identity);
  ------------------
  |  |  373|    569|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 569]
  |  |  |  Branch (373:71): [Folded, False: 569]
  |  |  ------------------
  ------------------
  420|    569|  SAFE_FREE(session->opts.gss_client_identity);
  ------------------
  |  |  373|    569|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 569]
  |  |  |  Branch (373:71): [Folded, False: 569]
  |  |  ------------------
  ------------------
  421|    569|  SAFE_FREE(session->opts.pubkey_accepted_types);
  ------------------
  |  |  373|    569|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 569]
  |  |  |  Branch (373:71): [Folded, False: 569]
  |  |  ------------------
  ------------------
  422|    569|  SAFE_FREE(session->opts.control_path);
  ------------------
  |  |  373|    569|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 569]
  |  |  |  Branch (373:71): [Folded, False: 569]
  |  |  ------------------
  ------------------
  423|    569|  SAFE_FREE(session->opts.preferred_authentications);
  ------------------
  |  |  373|    569|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 569]
  |  |  |  Branch (373:71): [Folded, False: 569]
  |  |  ------------------
  ------------------
  424|       |
  425|  6.25k|  for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  6.25k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (425:15): [True: 5.69k, False: 569]
  ------------------
  426|  5.69k|      if (session->opts.wanted_methods[i]) {
  ------------------
  |  Branch (426:11): [True: 0, False: 5.69k]
  ------------------
  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.69k|  }
  430|       |
  431|    569|  SAFE_FREE(session->server_opts.custombanner);
  ------------------
  |  |  373|    569|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 569]
  |  |  |  Branch (373:71): [Folded, False: 569]
  |  |  ------------------
  ------------------
  432|    569|  SAFE_FREE(session->server_opts.moduli_file);
  ------------------
  |  |  373|    569|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 569]
  |  |  |  Branch (373:71): [Folded, False: 569]
  |  |  ------------------
  ------------------
  433|       |
  434|    569|  _ssh_remove_legacy_log_cb();
  435|       |
  436|       |  /* burn connection, it could contain sensitive data */
  437|    569|  ssh_burn(session, sizeof(struct ssh_session_struct));
  ------------------
  |  |  388|    569|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  438|       |  SAFE_FREE(session);
  ------------------
  |  |  373|    569|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 569, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 569]
  |  |  ------------------
  ------------------
  439|    569|}
ssh_set_blocking:
  638|    409|{
  639|    409|    if (session == NULL) {
  ------------------
  |  Branch (639:9): [True: 0, False: 409]
  ------------------
  640|      0|        return;
  641|      0|    }
  642|    409|    session->flags &= ~SSH_SESSION_FLAG_BLOCKING;
  ------------------
  |  |   75|    409|#define SSH_SESSION_FLAG_BLOCKING 0x0001
  ------------------
  643|    409|    session->flags |= blocking ? SSH_SESSION_FLAG_BLOCKING : 0;
  ------------------
  |  |   75|    409|#define SSH_SESSION_FLAG_BLOCKING 0x0001
  ------------------
  |  Branch (643:23): [True: 409, False: 0]
  ------------------
  644|    409|}

sftp_attributes_free:
  903|  1.63k|void sftp_attributes_free(sftp_attributes file){
  904|  1.63k|  if (file == NULL) {
  ------------------
  |  Branch (904:7): [True: 1.39k, False: 238]
  ------------------
  905|  1.39k|    return;
  906|  1.39k|  }
  907|       |
  908|    238|  SSH_STRING_FREE(file->acl);
  ------------------
  |  |  910|    238|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 24, False: 214]
  |  |  |  Branch (910:69): [Folded, False: 238]
  |  |  ------------------
  ------------------
  909|    238|  SSH_STRING_FREE(file->extended_data);
  ------------------
  |  |  910|    238|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 1, False: 237]
  |  |  |  Branch (910:69): [Folded, False: 238]
  |  |  ------------------
  ------------------
  910|    238|  SSH_STRING_FREE(file->extended_type);
  ------------------
  |  |  910|    238|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 1, False: 237]
  |  |  |  Branch (910:69): [Folded, False: 238]
  |  |  ------------------
  ------------------
  911|       |
  912|    238|  SAFE_FREE(file->name);
  ------------------
  |  |  373|    238|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 11, False: 227]
  |  |  |  Branch (373:71): [Folded, False: 238]
  |  |  ------------------
  ------------------
  913|    238|  SAFE_FREE(file->longname);
  ------------------
  |  |  373|    238|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 11, False: 227]
  |  |  |  Branch (373:71): [Folded, False: 238]
  |  |  ------------------
  ------------------
  914|    238|  SAFE_FREE(file->group);
  ------------------
  |  |  373|    238|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 22, False: 216]
  |  |  |  Branch (373:71): [Folded, False: 238]
  |  |  ------------------
  ------------------
  915|    238|  SAFE_FREE(file->owner);
  ------------------
  |  |  373|    238|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 22, False: 216]
  |  |  |  Branch (373:71): [Folded, False: 238]
  |  |  ------------------
  ------------------
  916|       |
  917|       |  SAFE_FREE(file);
  ------------------
  |  |  373|    238|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 238, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 238]
  |  |  ------------------
  ------------------
  918|    238|}

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

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|    900|{
  183|    900|    ssh_socket s;
  184|       |
  185|    900|    s = calloc(1, sizeof(struct ssh_socket_struct));
  186|    900|    if (s == NULL) {
  ------------------
  |  Branch (186:9): [True: 39, False: 861]
  ------------------
  187|     39|        ssh_set_error_oom(session);
  ------------------
  |  |  318|     39|    _ssh_set_error_oom(error, __func__)
  ------------------
  188|     39|        return NULL;
  189|     39|    }
  190|    861|    s->fd = SSH_INVALID_SOCKET;
  ------------------
  |  |  124|    861|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  191|    861|    s->last_errno = -1;
  192|    861|    s->fd_is_socket = 1;
  193|    861|    s->session = session;
  194|    861|    s->in_buffer = ssh_buffer_new();
  195|    861|    if (s->in_buffer == NULL) {
  ------------------
  |  Branch (195:9): [True: 33, False: 828]
  ------------------
  196|     33|        ssh_set_error_oom(session);
  ------------------
  |  |  318|     33|    _ssh_set_error_oom(error, __func__)
  ------------------
  197|     33|        SAFE_FREE(s);
  ------------------
  |  |  373|     33|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 33, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 33]
  |  |  ------------------
  ------------------
  198|     33|        return NULL;
  199|     33|    }
  200|    828|    s->out_buffer=ssh_buffer_new();
  201|    828|    if (s->out_buffer == NULL) {
  ------------------
  |  Branch (201:9): [True: 7, False: 821]
  ------------------
  202|      7|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      7|    _ssh_set_error_oom(error, __func__)
  ------------------
  203|      7|        SSH_BUFFER_FREE(s->in_buffer);
  ------------------
  |  |  951|      7|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 7, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 7]
  |  |  ------------------
  ------------------
  204|      7|        SAFE_FREE(s);
  ------------------
  |  |  373|      7|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 7, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 7]
  |  |  ------------------
  ------------------
  205|      7|        return NULL;
  206|      7|    }
  207|    821|    s->read_wontblock = 0;
  208|    821|    s->write_wontblock = 0;
  209|    821|    s->data_except = 0;
  210|       |    s->poll_handle = NULL;
  211|    821|    s->state=SSH_SOCKET_NONE;
  212|    821|    return s;
  213|    828|}
ssh_socket_free:
  473|    978|{
  474|    978|    if (s == NULL) {
  ------------------
  |  Branch (474:9): [True: 157, False: 821]
  ------------------
  475|    157|        return;
  476|    157|    }
  477|    821|    ssh_socket_close(s);
  478|    821|    SSH_BUFFER_FREE(s->in_buffer);
  ------------------
  |  |  951|    821|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 821, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 821]
  |  |  ------------------
  ------------------
  479|    821|    SSH_BUFFER_FREE(s->out_buffer);
  ------------------
  |  |  951|    821|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 821, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 821]
  |  |  ------------------
  ------------------
  480|       |    SAFE_FREE(s);
  ------------------
  |  |  373|    821|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 821, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 821]
  |  |  ------------------
  ------------------
  481|    821|}
ssh_socket_close:
  546|  1.23k|{
  547|  1.23k|    if (ssh_socket_is_open(s)) {
  ------------------
  |  Branch (547:9): [True: 0, False: 1.23k]
  ------------------
  548|       |#ifdef _WIN32
  549|       |        CLOSE_SOCKET(s->fd);
  550|       |        s->last_errno = WSAGetLastError();
  551|       |#else
  552|      0|        CLOSE_SOCKET(s->fd);
  ------------------
  |  |  472|      0|#define CLOSE_SOCKET(s) do { if ((s) != SSH_INVALID_SOCKET) { _XCLOSESOCKET(s); (s) = SSH_INVALID_SOCKET;} } while(0)
  |  |  ------------------
  |  |  |  |  124|      0|#define SSH_INVALID_SOCKET ((socket_t) -1)
  |  |  ------------------
  |  |               #define CLOSE_SOCKET(s) do { if ((s) != SSH_INVALID_SOCKET) { _XCLOSESOCKET(s); (s) = SSH_INVALID_SOCKET;} } while(0)
  |  |  ------------------
  |  |  |  |  199|      0|#define _XCLOSESOCKET close
  |  |  ------------------
  |  |               #define CLOSE_SOCKET(s) do { if ((s) != SSH_INVALID_SOCKET) { _XCLOSESOCKET(s); (s) = SSH_INVALID_SOCKET;} } while(0)
  |  |  ------------------
  |  |  |  |  124|      0|#define SSH_INVALID_SOCKET ((socket_t) -1)
  |  |  ------------------
  |  |  |  Branch (472:34): [True: 0, False: 0]
  |  |  |  Branch (472:116): [Folded, False: 0]
  |  |  ------------------
  ------------------
  553|      0|        s->last_errno = errno;
  554|      0|#endif
  555|      0|    }
  556|       |
  557|  1.23k|    if (s->poll_handle != NULL && !ssh_poll_is_locked(s->poll_handle)) {
  ------------------
  |  Branch (557:9): [True: 0, False: 1.23k]
  |  Branch (557:35): [True: 0, False: 0]
  ------------------
  558|      0|        ssh_poll_free(s->poll_handle);
  559|      0|        s->poll_handle = NULL;
  560|      0|    }
  561|       |
  562|  1.23k|    s->state = SSH_SOCKET_CLOSED;
  563|       |
  564|  1.23k|#ifndef _WIN32
  565|       |    /* If the proxy command still runs try to kill it */
  566|  1.23k|    if (s->proxy_pid != 0) {
  ------------------
  |  Branch (566:9): [True: 0, False: 1.23k]
  ------------------
  567|      0|        int status;
  568|      0|        pid_t pid = s->proxy_pid;
  569|       |
  570|      0|        s->proxy_pid = 0;
  571|      0|        kill(pid, SIGTERM);
  572|      0|        while (waitpid(pid, &status, 0) == -1) {
  ------------------
  |  Branch (572:16): [True: 0, False: 0]
  ------------------
  573|      0|            if (errno != EINTR) {
  ------------------
  |  Branch (573:17): [True: 0, False: 0]
  ------------------
  574|      0|                SSH_LOG_STRERROR(SSH_LOG_TRACE, errno, "waitpid failed: %s");
  ------------------
  |  |  283|      0|    do {                                                            \
  |  |  284|      0|        char err_msg[SSH_ERRNO_MSG_MAX] = {0};                      \
  |  |  285|      0|        _ssh_log(priority,                                          \
  |  |  286|      0|                 __func__,                                          \
  |  |  287|      0|                 __VA_ARGS__,                                       \
  |  |  288|      0|                 ssh_strerror(errnum, err_msg, SSH_ERRNO_MSG_MAX)); \
  |  |  ------------------
  |  |  |  |  520|      0|#define SSH_ERRNO_MSG_MAX   1024
  |  |  ------------------
  |  |  289|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (289:14): [Folded, False: 0]
  |  |  ------------------
  ------------------
  575|      0|                return;
  576|      0|            }
  577|      0|        }
  578|      0|        if (!WIFEXITED(status)) {
  ------------------
  |  Branch (578:13): [True: 0, False: 0]
  ------------------
  579|      0|            SSH_LOG(SSH_LOG_TRACE, "Proxy command exited abnormally");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  580|      0|            return;
  581|      0|        }
  582|      0|        SSH_LOG(SSH_LOG_TRACE, "Proxy command returned %d", WEXITSTATUS(status));
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  583|      0|    }
  584|  1.23k|#endif
  585|  1.23k|}
ssh_socket_is_open:
  643|  1.23k|{
  644|  1.23k|    return s->fd != SSH_INVALID_SOCKET;
  ------------------
  |  |  124|  1.23k|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  645|  1.23k|}

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

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

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

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

