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

ssh_agent_state_free:
 1056|    429|{
 1057|    429|    struct ssh_agent_state_struct *state = data;
 1058|       |
 1059|    429|    if (state) {
  ------------------
  |  Branch (1059:9): [True: 0, False: 429]
  ------------------
 1060|       |        SSH_STRING_FREE_CHAR(state->comment);
  ------------------
  |  |  902|      0|    do { if ((x) != NULL) { ssh_string_free_char(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (902:14): [True: 0, False: 0]
  |  |  |  Branch (902:74): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1061|      0|        ssh_key_free(state->pubkey);
 1062|      0|        free(state);
 1063|      0|    }
 1064|    429|}

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

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

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

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

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

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

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

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

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

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

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

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

sftp_attributes_free:
  903|  1.14k|void sftp_attributes_free(sftp_attributes file){
  904|  1.14k|  if (file == NULL) {
  ------------------
  |  Branch (904:7): [True: 994, False: 154]
  ------------------
  905|    994|    return;
  906|    994|  }
  907|       |
  908|    154|  SSH_STRING_FREE(file->acl);
  ------------------
  |  |  893|    154|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (893:14): [True: 14, False: 140]
  |  |  |  Branch (893:69): [Folded, False: 154]
  |  |  ------------------
  ------------------
  909|    154|  SSH_STRING_FREE(file->extended_data);
  ------------------
  |  |  893|    154|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (893:14): [True: 2, False: 152]
  |  |  |  Branch (893:69): [Folded, False: 154]
  |  |  ------------------
  ------------------
  910|    154|  SSH_STRING_FREE(file->extended_type);
  ------------------
  |  |  893|    154|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (893:14): [True: 2, False: 152]
  |  |  |  Branch (893:69): [Folded, False: 154]
  |  |  ------------------
  ------------------
  911|       |
  912|    154|  SAFE_FREE(file->name);
  ------------------
  |  |  373|    154|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 11, False: 143]
  |  |  |  Branch (373:71): [Folded, False: 154]
  |  |  ------------------
  ------------------
  913|    154|  SAFE_FREE(file->longname);
  ------------------
  |  |  373|    154|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 11, False: 143]
  |  |  |  Branch (373:71): [Folded, False: 154]
  |  |  ------------------
  ------------------
  914|    154|  SAFE_FREE(file->group);
  ------------------
  |  |  373|    154|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 18, False: 136]
  |  |  |  Branch (373:71): [Folded, False: 154]
  |  |  ------------------
  ------------------
  915|    154|  SAFE_FREE(file->owner);
  ------------------
  |  |  373|    154|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 18, False: 136]
  |  |  |  Branch (373:71): [Folded, False: 154]
  |  |  ------------------
  ------------------
  916|       |
  917|       |  SAFE_FREE(file);
  ------------------
  |  |  373|    154|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 154, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 154]
  |  |  ------------------
  ------------------
  918|    154|}

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

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

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

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

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

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

