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

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

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

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

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

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

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

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

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

ssh_list_new:
  865|    530|{
  866|    530|    struct ssh_list *ret = malloc(sizeof(struct ssh_list));
  867|    530|    if (ret == NULL) {
  ------------------
  |  Branch (867:9): [True: 0, False: 530]
  ------------------
  868|      0|        return NULL;
  869|      0|    }
  870|    530|    ret->root = ret->end = NULL;
  871|    530|    return ret;
  872|    530|}
ssh_list_free:
  882|  1.02k|{
  883|  1.02k|    struct ssh_iterator *ptr = NULL, *next = NULL;
  884|  1.02k|    if (!list)
  ------------------
  |  Branch (884:9): [True: 495, False: 530]
  ------------------
  885|    495|        return;
  886|    530|    ptr = list->root;
  887|    530|    while (ptr) {
  ------------------
  |  Branch (887:12): [True: 0, False: 530]
  ------------------
  888|      0|        next = ptr->next;
  889|      0|        SAFE_FREE(ptr);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  890|      0|        ptr = next;
  891|      0|    }
  892|       |    SAFE_FREE(list);
  ------------------
  |  |  375|    530|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 530, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 530]
  |  |  ------------------
  ------------------
  893|    530|}
ssh_list_get_iterator:
  903|    380|{
  904|    380|    if (!list)
  ------------------
  |  Branch (904:9): [True: 380, False: 0]
  ------------------
  905|    380|        return NULL;
  906|      0|    return list->root;
  907|    380|}
ssh_list_append:
  969|    795|{
  970|    795|  struct ssh_iterator *iterator = NULL;
  971|       |
  972|    795|  if (list == NULL) {
  ------------------
  |  Branch (972:7): [True: 0, False: 795]
  ------------------
  973|      0|      return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  974|      0|  }
  975|       |
  976|    795|  iterator = ssh_iterator_new(data);
  977|    795|  if (iterator == NULL) {
  ------------------
  |  Branch (977:7): [True: 0, False: 795]
  ------------------
  978|      0|      return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  979|      0|  }
  980|       |
  981|    795|  if(!list->end){
  ------------------
  |  Branch (981:6): [True: 265, False: 530]
  ------------------
  982|       |    /* list is empty */
  983|    265|    list->root=list->end=iterator;
  984|    530|  } else {
  985|       |    /* put it on end of list */
  986|    530|    list->end->next=iterator;
  987|    530|    list->end=iterator;
  988|    530|  }
  989|    795|  return SSH_OK;
  ------------------
  |  |  316|    795|#define SSH_OK 0     /* No error */
  ------------------
  990|    795|}
_ssh_list_pop_head:
 1073|  1.82k|{
 1074|  1.82k|  struct ssh_iterator *iterator = NULL;
 1075|  1.82k|  const void *data = NULL;
 1076|       |
 1077|  1.82k|  if (list == NULL) {
  ------------------
  |  Branch (1077:7): [True: 495, False: 1.32k]
  ------------------
 1078|    495|      return NULL;
 1079|    495|  }
 1080|       |
 1081|  1.32k|  iterator = list->root;
 1082|  1.32k|  if (iterator == NULL) {
  ------------------
  |  Branch (1082:7): [True: 530, False: 795]
  ------------------
 1083|    530|      return NULL;
 1084|    530|  }
 1085|    795|  data=iterator->data;
 1086|    795|  list->root=iterator->next;
 1087|    795|  if(list->end==iterator)
  ------------------
  |  Branch (1087:6): [True: 265, False: 530]
  ------------------
 1088|    265|    list->end=NULL;
 1089|       |  SAFE_FREE(iterator);
  ------------------
  |  |  375|    795|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 795, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 795]
  |  |  ------------------
  ------------------
 1090|    795|  return data;
 1091|  1.32k|}
ssh_proxyjumps_free:
 2659|    380|{
 2660|    380|    struct ssh_jump_info_struct *jump = NULL;
 2661|       |
 2662|    380|    for (jump =
 2663|    380|             ssh_list_pop_head(struct ssh_jump_info_struct *, proxy_jump_list);
  ------------------
  |  |  128|    380|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2664|    380|         jump != NULL;
  ------------------
  |  Branch (2664:10): [True: 0, False: 380]
  ------------------
 2665|    380|         jump = ssh_list_pop_head(struct ssh_jump_info_struct *,
  ------------------
  |  |  128|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2666|    380|                                  proxy_jump_list)) {
 2667|      0|        SAFE_FREE(jump->hostname);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2668|      0|        SAFE_FREE(jump->username);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2669|       |        SAFE_FREE(jump);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2670|      0|    }
 2671|    380|}
misc.c:ssh_iterator_new:
  947|    795|{
  948|    795|    struct ssh_iterator *iterator = malloc(sizeof(struct ssh_iterator));
  949|       |
  950|    795|    if (iterator == NULL) {
  ------------------
  |  Branch (950:9): [True: 0, False: 795]
  ------------------
  951|      0|        return NULL;
  952|      0|    }
  953|    795|    iterator->next = NULL;
  954|    795|    iterator->data = data;
  955|    795|    return iterator;
  956|    795|}

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

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

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

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

sftp_attributes_free:
  931|  1.06k|void sftp_attributes_free(sftp_attributes file){
  932|  1.06k|  if (file == NULL) {
  ------------------
  |  Branch (932:7): [True: 900, False: 160]
  ------------------
  933|    900|    return;
  934|    900|  }
  935|       |
  936|    160|  SSH_STRING_FREE(file->acl);
  ------------------
  |  |  924|    160|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 16, False: 144]
  |  |  |  Branch (924:69): [Folded, False: 160]
  |  |  ------------------
  ------------------
  937|    160|  SSH_STRING_FREE(file->extended_data);
  ------------------
  |  |  924|    160|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 3, False: 157]
  |  |  |  Branch (924:69): [Folded, False: 160]
  |  |  ------------------
  ------------------
  938|    160|  SSH_STRING_FREE(file->extended_type);
  ------------------
  |  |  924|    160|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 3, False: 157]
  |  |  |  Branch (924:69): [Folded, False: 160]
  |  |  ------------------
  ------------------
  939|       |
  940|    160|  SAFE_FREE(file->name);
  ------------------
  |  |  375|    160|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 4, False: 156]
  |  |  |  Branch (375:71): [Folded, False: 160]
  |  |  ------------------
  ------------------
  941|    160|  SAFE_FREE(file->longname);
  ------------------
  |  |  375|    160|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 4, False: 156]
  |  |  |  Branch (375:71): [Folded, False: 160]
  |  |  ------------------
  ------------------
  942|    160|  SAFE_FREE(file->group);
  ------------------
  |  |  375|    160|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 20, False: 140]
  |  |  |  Branch (375:71): [Folded, False: 160]
  |  |  ------------------
  ------------------
  943|    160|  SAFE_FREE(file->owner);
  ------------------
  |  |  375|    160|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 20, False: 140]
  |  |  |  Branch (375:71): [Folded, False: 160]
  |  |  ------------------
  ------------------
  944|       |
  945|       |  SAFE_FREE(file);
  ------------------
  |  |  375|    160|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 160, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 160]
  |  |  ------------------
  ------------------
  946|    160|}

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

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

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

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

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

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

