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

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

ssh_buffer_new:
  126|  1.54k|{
  127|  1.54k|    struct ssh_buffer_struct *buf = NULL;
  128|  1.54k|    int rc;
  129|       |
  130|  1.54k|    buf = calloc(1, sizeof(struct ssh_buffer_struct));
  131|  1.54k|    if (buf == NULL) {
  ------------------
  |  Branch (131:9): [True: 14, False: 1.53k]
  ------------------
  132|     14|        return NULL;
  133|     14|    }
  134|       |
  135|       |    /*
  136|       |     * Always preallocate 64 bytes.
  137|       |     *
  138|       |     * -1 for realloc_buffer magic.
  139|       |     */
  140|  1.53k|    rc = ssh_buffer_allocate_size(buf, 64 - 1);
  141|  1.53k|    if (rc != 0) {
  ------------------
  |  Branch (141:9): [True: 7, False: 1.52k]
  ------------------
  142|      7|        SAFE_FREE(buf);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  143|      7|        return NULL;
  144|      7|    }
  145|  1.52k|    buffer_verify(buf);
  146|       |
  147|  1.52k|    return buf;
  148|  1.53k|}
ssh_buffer_free:
  156|  1.71k|{
  157|  1.71k|    if (buffer == NULL) {
  ------------------
  |  Branch (157:9): [True: 191, False: 1.52k]
  ------------------
  158|    191|        return;
  159|    191|    }
  160|  1.52k|    buffer_verify(buffer);
  161|       |
  162|  1.52k|    if (buffer->secure && buffer->allocated > 0) {
  ------------------
  |  Branch (162:9): [True: 0, False: 1.52k]
  |  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.52k|    } else {
  169|  1.52k|        SAFE_FREE(buffer->data);
  ------------------
  |  |  375|  1.52k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 1.52k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 1.52k]
  |  |  ------------------
  ------------------
  170|  1.52k|    }
  171|       |    SAFE_FREE(buffer);
  ------------------
  |  |  375|  1.52k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 1.52k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 1.52k]
  |  |  ------------------
  ------------------
  172|  1.52k|}
ssh_buffer_reinit:
  266|    868|{
  267|    868|    if (buffer == NULL) {
  ------------------
  |  Branch (267:9): [True: 0, False: 868]
  ------------------
  268|      0|        return -1;
  269|      0|    }
  270|       |
  271|    868|    buffer_verify(buffer);
  272|       |
  273|    868|    if (buffer->secure && buffer->allocated > 0) {
  ------------------
  |  Branch (273:9): [True: 0, False: 868]
  |  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|    868|    buffer->used = 0;
  277|    868|    buffer->pos = 0;
  278|       |
  279|       |    /* If the buffer is bigger then 64K, reset it to 64K */
  280|    868|    if (buffer->allocated > 65536) {
  ------------------
  |  Branch (280:9): [True: 75, False: 793]
  ------------------
  281|     75|        int rc;
  282|       |
  283|       |        /* -1 for realloc_buffer magic */
  284|     75|        rc = realloc_buffer(buffer, 65536 - 1);
  285|     75|        if (rc != 0) {
  ------------------
  |  Branch (285:13): [True: 0, False: 75]
  ------------------
  286|      0|            return -1;
  287|      0|        }
  288|     75|    }
  289|       |
  290|    868|    buffer_verify(buffer);
  291|       |
  292|    868|    return 0;
  293|    868|}
ssh_buffer_add_data:
  307|    868|{
  308|    868|    if (buffer == NULL) {
  ------------------
  |  Branch (308:9): [True: 0, False: 868]
  ------------------
  309|      0|        return -1;
  310|      0|    }
  311|       |
  312|    868|    buffer_verify(buffer);
  313|       |
  314|    868|    if (data == NULL) {
  ------------------
  |  Branch (314:9): [True: 0, False: 868]
  ------------------
  315|      0|        return -1;
  316|      0|    }
  317|       |
  318|    868|    if (buffer->used + len < len) {
  ------------------
  |  Branch (318:9): [True: 0, False: 868]
  ------------------
  319|      0|        return -1;
  320|      0|    }
  321|       |
  322|    868|    if (buffer->allocated < (buffer->used + len)) {
  ------------------
  |  Branch (322:9): [True: 174, False: 694]
  ------------------
  323|    174|        if (buffer->pos > 0) {
  ------------------
  |  Branch (323:13): [True: 0, False: 174]
  ------------------
  324|      0|            buffer_shift(buffer);
  325|      0|        }
  326|    174|        if (realloc_buffer(buffer, buffer->used + len) < 0) {
  ------------------
  |  Branch (326:13): [True: 0, False: 174]
  ------------------
  327|      0|            return -1;
  328|      0|        }
  329|    174|    }
  330|       |
  331|    868|    memcpy(buffer->data + buffer->used, data, len);
  332|    868|    buffer->used += len;
  333|    868|    buffer_verify(buffer);
  334|    868|    return 0;
  335|    868|}
ssh_buffer_allocate_size:
  348|  1.53k|{
  349|  1.53k|    buffer_verify(buffer);
  350|       |
  351|  1.53k|    if (buffer->allocated < len) {
  ------------------
  |  Branch (351:9): [True: 1.53k, False: 0]
  ------------------
  352|  1.53k|        if (buffer->pos > 0) {
  ------------------
  |  Branch (352:13): [True: 0, False: 1.53k]
  ------------------
  353|      0|            buffer_shift(buffer);
  354|      0|        }
  355|  1.53k|        if (realloc_buffer(buffer, len) < 0) {
  ------------------
  |  Branch (355:13): [True: 7, False: 1.52k]
  ------------------
  356|      7|            return -1;
  357|      7|        }
  358|  1.53k|    }
  359|       |
  360|  1.52k|    buffer_verify(buffer);
  361|       |
  362|  1.52k|    return 0;
  363|  1.53k|}
ssh_buffer_get_len:
  620|  44.0k|uint32_t ssh_buffer_get_len(struct ssh_buffer_struct *buffer){
  621|  44.0k|  buffer_verify(buffer);
  622|  44.0k|  return buffer->used - buffer->pos;
  623|  44.0k|}
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: 260, False: 523k]
  ------------------
  746|    260|        return 0;
  747|    260|    }
  748|   523k|    memcpy(data,buffer->data+buffer->pos,len);
  749|   523k|    buffer->pos+=len;
  750|   523k|    return len;   /* no yet support for partial reads (is it really needed ?? ) */
  751|   524k|}
ssh_buffer_get_u32:
  780|   262k|uint32_t ssh_buffer_get_u32(struct ssh_buffer_struct *buffer, uint32_t *data){
  781|   262k|    return ssh_buffer_get_data(buffer,data,sizeof(uint32_t));
  782|   262k|}
ssh_buffer_get_u64:
  795|    530|uint32_t ssh_buffer_get_u64(struct ssh_buffer_struct *buffer, uint64_t *data){
  796|    530|    return ssh_buffer_get_data(buffer,data,sizeof(uint64_t));
  797|    530|}
ssh_buffer_validate_length:
  809|   784k|{
  810|   784k|    if (buffer == NULL || buffer->pos + len < len ||
  ------------------
  |  Branch (810:9): [True: 0, False: 784k]
  |  Branch (810:27): [True: 0, False: 784k]
  ------------------
  811|   784k|        buffer->pos + len > buffer->used) {
  ------------------
  |  Branch (811:9): [True: 487, False: 784k]
  ------------------
  812|    487|        return SSH_ERROR;
  ------------------
  |  |  317|    487|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  813|    487|    }
  814|       |
  815|   784k|    return SSH_OK;
  ------------------
  |  |  316|   784k|#define SSH_OK 0     /* No error */
  ------------------
  816|   784k|}
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: 102, False: 260k]
  ------------------
  837|    102|        return NULL;
  838|    102|    }
  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: 220, False: 260k]
  ------------------
  843|    220|      return NULL; /* it is indeed */
  844|    220|    }
  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|  44.0k|{
 1174|  44.0k|    int rc = SSH_ERROR;
  ------------------
  |  |  317|  44.0k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1175|  44.0k|    const char *p = format, *last = NULL;
 1176|  44.0k|    union {
 1177|  44.0k|        uint8_t *byte;
 1178|  44.0k|        uint16_t *word;
 1179|  44.0k|        uint32_t *dword;
 1180|  44.0k|        uint64_t *qword;
 1181|  44.0k|        ssh_string *string;
 1182|  44.0k|        char **cstring;
 1183|  44.0k|        bignum *bignum;
 1184|  44.0k|        void **data;
 1185|  44.0k|    } o;
 1186|  44.0k|    size_t len;
 1187|  44.0k|    uint32_t rlen, max_len;
 1188|  44.0k|    ssh_string tmp_string = NULL;
 1189|  44.0k|    va_list ap_copy;
 1190|  44.0k|    size_t count;
 1191|       |
 1192|  44.0k|    max_len = ssh_buffer_get_len(buffer);
 1193|       |
 1194|       |    /* copy the argument list in case a rollback is needed */
 1195|  44.0k|    va_copy(ap_copy, ap);
 1196|       |
 1197|  44.0k|    if (argc > 256) {
  ------------------
  |  Branch (1197:9): [True: 0, False: 44.0k]
  ------------------
 1198|      0|        rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1199|      0|        goto cleanup;
 1200|      0|    }
 1201|       |
 1202|   130k|    for (count = 0; *p != '\0'; p++, count++) {
  ------------------
  |  Branch (1202:21): [True: 87.2k, False: 43.6k]
  ------------------
 1203|       |        /* Invalid number of arguments passed */
 1204|  87.2k|        if (count > argc) {
  ------------------
  |  Branch (1204:13): [True: 0, False: 87.2k]
  ------------------
 1205|      0|            rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1206|      0|            goto cleanup;
 1207|      0|        }
 1208|       |
 1209|  87.2k|        rc = SSH_ERROR;
  ------------------
  |  |  317|  87.2k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1210|  87.2k|        switch (*p) {
 1211|      0|        case 'b':
  ------------------
  |  Branch (1211:9): [True: 0, False: 87.2k]
  ------------------
 1212|      0|            o.byte = va_arg(ap, uint8_t *);
 1213|      0|            rlen = ssh_buffer_get_u8(buffer, o.byte);
 1214|      0|            rc = rlen==1 ? SSH_OK : SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
                          rc = rlen==1 ? SSH_OK : SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1214:18): [True: 0, False: 0]
  ------------------
 1215|      0|            break;
 1216|      0|        case 'w':
  ------------------
  |  Branch (1216:9): [True: 0, False: 87.2k]
  ------------------
 1217|      0|            o.word = va_arg(ap,  uint16_t *);
 1218|      0|            rlen = ssh_buffer_get_data(buffer, o.word, sizeof(uint16_t));
 1219|      0|            if (rlen == 2) {
  ------------------
  |  Branch (1219:17): [True: 0, False: 0]
  ------------------
 1220|      0|                *o.word = ntohs(*o.word);
 1221|      0|                rc = SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 1222|      0|            }
 1223|      0|            break;
 1224|    772|        case 'd':
  ------------------
  |  Branch (1224:9): [True: 772, False: 86.4k]
  ------------------
 1225|    772|            o.dword = va_arg(ap, uint32_t *);
 1226|    772|            rlen = ssh_buffer_get_u32(buffer, o.dword);
 1227|    772|            if (rlen == 4) {
  ------------------
  |  Branch (1227:17): [True: 728, False: 44]
  ------------------
 1228|    728|                *o.dword = ntohl(*o.dword);
 1229|    728|                rc = SSH_OK;
  ------------------
  |  |  316|    728|#define SSH_OK 0     /* No error */
  ------------------
 1230|    728|            }
 1231|    772|            break;
 1232|     90|        case 'q':
  ------------------
  |  Branch (1232:9): [True: 90, False: 87.1k]
  ------------------
 1233|     90|            o.qword = va_arg(ap, uint64_t*);
 1234|     90|            rlen = ssh_buffer_get_u64(buffer, o.qword);
 1235|     90|            if (rlen == 8) {
  ------------------
  |  Branch (1235:17): [True: 82, False: 8]
  ------------------
 1236|     82|                *o.qword = ntohll(*o.qword);
  ------------------
  |  |  490|     82|    (((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32))
  ------------------
 1237|     82|                rc = SSH_OK;
  ------------------
  |  |  316|     82|#define SSH_OK 0     /* No error */
  ------------------
 1238|     82|            }
 1239|     90|            break;
 1240|      0|        case 'B':
  ------------------
  |  Branch (1240:9): [True: 0, False: 87.2k]
  ------------------
 1241|      0|            o.bignum = va_arg(ap, bignum *);
 1242|      0|            *o.bignum = NULL;
 1243|      0|            tmp_string = ssh_buffer_get_ssh_string(buffer);
 1244|      0|            if (tmp_string == NULL) {
  ------------------
  |  Branch (1244:17): [True: 0, False: 0]
  ------------------
 1245|      0|                break;
 1246|      0|            }
 1247|      0|            *o.bignum = ssh_make_string_bn(tmp_string);
 1248|      0|            ssh_string_burn(tmp_string);
 1249|      0|            SSH_STRING_FREE(tmp_string);
  ------------------
  |  |  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|  85.9k|        case 'S':
  ------------------
  |  Branch (1252:9): [True: 85.9k, False: 1.29k]
  ------------------
 1253|  85.9k|            o.string = va_arg(ap, ssh_string *);
 1254|  85.9k|            *o.string = ssh_buffer_get_ssh_string(buffer);
 1255|  85.9k|            rc = *o.string != NULL ? SSH_OK : SSH_ERROR;
  ------------------
  |  |  316|  85.9k|#define SSH_OK 0     /* No error */
  ------------------
                          rc = *o.string != NULL ? SSH_OK : SSH_ERROR;
  ------------------
  |  |  317|  86.0k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1255:18): [True: 85.9k, False: 56]
  ------------------
 1256|  85.9k|            o.string = NULL;
 1257|  85.9k|            break;
 1258|    435|        case 's': {
  ------------------
  |  Branch (1258:9): [True: 435, False: 86.8k]
  ------------------
 1259|    435|            uint32_t u32len = 0;
 1260|       |
 1261|    435|            o.cstring = va_arg(ap, char **);
 1262|    435|            *o.cstring = NULL;
 1263|    435|            rlen = ssh_buffer_get_u32(buffer, &u32len);
 1264|    435|            if (rlen != 4){
  ------------------
  |  Branch (1264:17): [True: 24, False: 411]
  ------------------
 1265|     24|                break;
 1266|     24|            }
 1267|    411|            u32len = ntohl(u32len);
 1268|    411|            if (u32len > max_len - 1) {
  ------------------
  |  Branch (1268:17): [True: 246, False: 165]
  ------------------
 1269|    246|                break;
 1270|    246|            }
 1271|       |
 1272|    165|            rc = ssh_buffer_validate_length(buffer, u32len);
 1273|    165|            if (rc != SSH_OK) {
  ------------------
  |  |  316|    165|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1273:17): [True: 7, False: 158]
  ------------------
 1274|      7|                break;
 1275|      7|            }
 1276|       |
 1277|    158|            *o.cstring = malloc(u32len + 1);
 1278|    158|            if (*o.cstring == NULL){
  ------------------
  |  Branch (1278:17): [True: 0, False: 158]
  ------------------
 1279|      0|                rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1280|      0|                break;
 1281|      0|            }
 1282|    158|            rlen = ssh_buffer_get_data(buffer, *o.cstring, u32len);
 1283|    158|            if (rlen != u32len) {
  ------------------
  |  Branch (1283:17): [True: 0, False: 158]
  ------------------
 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|    158|            (*o.cstring)[u32len] = '\0';
 1289|    158|            o.cstring = NULL;
 1290|    158|            rc = SSH_OK;
  ------------------
  |  |  316|    158|#define SSH_OK 0     /* No error */
  ------------------
 1291|    158|            break;
 1292|    158|        }
 1293|      0|        case 'P':
  ------------------
  |  Branch (1293:9): [True: 0, False: 87.2k]
  ------------------
 1294|      0|            len = va_arg(ap, size_t);
 1295|      0|            if (len > max_len - 1) {
  ------------------
  |  Branch (1295:17): [True: 0, False: 0]
  ------------------
 1296|      0|                rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1297|      0|                break;
 1298|      0|            }
 1299|       |
 1300|      0|            rc = ssh_buffer_validate_length(buffer, len);
 1301|      0|            if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1301:17): [True: 0, False: 0]
  ------------------
 1302|      0|                break;
 1303|      0|            }
 1304|       |
 1305|      0|            o.data = va_arg(ap, void **);
 1306|      0|            count++;
 1307|       |
 1308|      0|            *o.data = malloc(len);
 1309|      0|            if(*o.data == NULL){
  ------------------
  |  Branch (1309:16): [True: 0, False: 0]
  ------------------
 1310|      0|                rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1311|      0|                break;
 1312|      0|            }
 1313|      0|            rlen = ssh_buffer_get_data(buffer, *o.data, (uint32_t)len);
 1314|      0|            if (rlen != len){
  ------------------
  |  Branch (1314:17): [True: 0, False: 0]
  ------------------
 1315|      0|                SAFE_FREE(*o.data);
  ------------------
  |  |  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: 87.2k]
  ------------------
 1323|      0|            SSH_LOG(SSH_LOG_TRACE, "Invalid buffer format %c", *p);
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1324|  87.2k|        }
 1325|  87.2k|        if (rc != SSH_OK) {
  ------------------
  |  |  316|  87.2k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1325:13): [True: 385, False: 86.8k]
  ------------------
 1326|    385|            break;
 1327|    385|        }
 1328|  87.2k|    }
 1329|       |
 1330|  44.0k|    if (argc != count) {
  ------------------
  |  Branch (1330:9): [True: 385, False: 43.6k]
  ------------------
 1331|    385|        rc = SSH_ERROR;
  ------------------
  |  |  317|    385|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1332|    385|    }
 1333|       |
 1334|  44.0k|cleanup:
 1335|  44.0k|    if (rc != SSH_ERROR){
  ------------------
  |  |  317|  44.0k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1335:9): [True: 43.6k, False: 385]
  ------------------
 1336|       |        /* Check if our canary is intact, if not something really bad happened */
 1337|  43.6k|        uint32_t canary = va_arg(ap, uint32_t);
 1338|  43.6k|        if (canary != SSH_BUFFER_PACK_END){
  ------------------
  |  |   28|  43.6k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  ------------------
  |  Branch (1338:13): [True: 0, False: 43.6k]
  ------------------
 1339|      0|            abort();
 1340|      0|        }
 1341|  43.6k|    }
 1342|       |
 1343|  44.0k|    if (rc != SSH_OK){
  ------------------
  |  |  316|  44.0k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1343:9): [True: 385, False: 43.6k]
  ------------------
 1344|       |        /* Reset the format string and erase everything that was allocated */
 1345|    385|        last = p;
 1346|    430|        for(p=format;p<last;++p){
  ------------------
  |  Branch (1346:22): [True: 45, False: 385]
  ------------------
 1347|     45|            switch(*p){
 1348|      0|            case 'b':
  ------------------
  |  Branch (1348:13): [True: 0, False: 45]
  ------------------
 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: 45]
  ------------------
 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|      6|            case 'd':
  ------------------
  |  Branch (1362:13): [True: 6, False: 39]
  ------------------
 1363|      6|                o.dword = va_arg(ap_copy, uint32_t *);
 1364|      6|                if (buffer->secure) {
  ------------------
  |  Branch (1364:21): [True: 0, False: 6]
  ------------------
 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|      6|                break;
 1369|      6|            case 'q':
  ------------------
  |  Branch (1369:13): [True: 0, False: 45]
  ------------------
 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: 45]
  ------------------
 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|     17|            case 'S':
  ------------------
  |  Branch (1380:13): [True: 17, False: 28]
  ------------------
 1381|     17|                o.string = va_arg(ap_copy, ssh_string *);
 1382|     17|                if (buffer->secure) {
  ------------------
  |  Branch (1382:21): [True: 0, False: 17]
  ------------------
 1383|      0|                    ssh_string_burn(*o.string);
 1384|      0|                }
 1385|     17|                SAFE_FREE(*o.string);
  ------------------
  |  |  375|     17|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 17, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 17]
  |  |  ------------------
  ------------------
 1386|     17|                break;
 1387|     22|            case 's':
  ------------------
  |  Branch (1387:13): [True: 22, False: 23]
  ------------------
 1388|     22|                o.cstring = va_arg(ap_copy, char **);
 1389|     22|                if (buffer->secure) {
  ------------------
  |  Branch (1389:21): [True: 0, False: 22]
  ------------------
 1390|      0|                    ssh_burn(*o.cstring, strlen(*o.cstring));
  ------------------
  |  |  390|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
 1391|      0|                }
 1392|     22|                SAFE_FREE(*o.cstring);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1393|     22|                break;
 1394|      0|            case 'P':
  ------------------
  |  Branch (1394:13): [True: 0, False: 45]
  ------------------
 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: 45]
  ------------------
 1403|      0|                (void)va_arg(ap_copy, void *);
 1404|      0|                break;
 1405|     45|            }
 1406|     45|        }
 1407|    385|    }
 1408|  44.0k|    va_end(ap_copy);
 1409|       |
 1410|  44.0k|    return rc;
 1411|  44.0k|}
_ssh_buffer_unpack:
 1439|  44.0k|{
 1440|  44.0k|    va_list ap;
 1441|  44.0k|    int rc;
 1442|       |
 1443|  44.0k|    va_start(ap, argc);
 1444|  44.0k|    rc = ssh_buffer_unpack_va(buffer, format, argc, ap);
 1445|       |    va_end(ap);
 1446|  44.0k|    return rc;
 1447|  44.0k|}
buffer.c:realloc_buffer:
  188|  1.78k|{
  189|  1.78k|    uint32_t smallest = 1;
  190|  1.78k|    uint8_t *new = NULL;
  191|       |
  192|  1.78k|    buffer_verify(buffer);
  193|       |
  194|       |    /* Find the smallest power of two which is greater or equal to needed */
  195|  14.8k|    while(smallest <= needed) {
  ------------------
  |  Branch (195:11): [True: 13.0k, False: 1.78k]
  ------------------
  196|  13.0k|        if (smallest == 0) {
  ------------------
  |  Branch (196:13): [True: 0, False: 13.0k]
  ------------------
  197|      0|            return -1;
  198|      0|        }
  199|  13.0k|        smallest <<= 1;
  200|  13.0k|    }
  201|  1.78k|    needed = smallest;
  202|       |
  203|  1.78k|    if (needed > BUFFER_SIZE_MAX) {
  ------------------
  |  |   57|  1.78k|#define BUFFER_SIZE_MAX 0x10000000
  ------------------
  |  Branch (203:9): [True: 0, False: 1.78k]
  ------------------
  204|      0|        return -1;
  205|      0|    }
  206|       |
  207|  1.78k|    if (buffer->secure) {
  ------------------
  |  Branch (207:9): [True: 0, False: 1.78k]
  ------------------
  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|  1.78k|    } else {
  216|  1.78k|        new = realloc(buffer->data, needed);
  217|  1.78k|        if (new == NULL) {
  ------------------
  |  Branch (217:13): [True: 7, False: 1.77k]
  ------------------
  218|      7|            return -1;
  219|      7|        }
  220|  1.78k|    }
  221|  1.77k|    buffer->data = new;
  222|  1.77k|    buffer->allocated = needed;
  223|       |
  224|  1.77k|    buffer_verify(buffer);
  225|  1.77k|    return 0;
  226|  1.78k|}

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

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

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

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

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

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

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

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

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

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

ssh_new:
   66|    408|{
   67|    408|    ssh_session session = NULL;
   68|    408|    char *id = NULL;
   69|    408|    int rc;
   70|       |
   71|    408|    session = calloc(1, sizeof (struct ssh_session_struct));
   72|    408|    if (session == NULL) {
  ------------------
  |  Branch (72:9): [True: 102, False: 306]
  ------------------
   73|    102|        return NULL;
   74|    102|    }
   75|       |
   76|    306|    session->next_crypto = crypto_new();
   77|    306|    if (session->next_crypto == NULL) {
  ------------------
  |  Branch (77:9): [True: 40, False: 266]
  ------------------
   78|     40|        goto err;
   79|     40|    }
   80|       |
   81|    266|    session->socket = ssh_socket_new(session);
   82|    266|    if (session->socket == NULL) {
  ------------------
  |  Branch (82:9): [True: 48, False: 218]
  ------------------
   83|     48|        goto err;
   84|     48|    }
   85|       |
   86|    218|    session->out_buffer = ssh_buffer_new();
   87|    218|    if (session->out_buffer == NULL) {
  ------------------
  |  Branch (87:9): [True: 1, False: 217]
  ------------------
   88|      1|        goto err;
   89|      1|    }
   90|       |
   91|    217|    session->in_buffer = ssh_buffer_new();
   92|    217|    if (session->in_buffer == NULL) {
  ------------------
  |  Branch (92:9): [True: 0, False: 217]
  ------------------
   93|      0|        goto err;
   94|      0|    }
   95|       |
   96|    217|    session->out_queue = ssh_list_new();
   97|    217|    if (session->out_queue == NULL) {
  ------------------
  |  Branch (97:9): [True: 0, False: 217]
  ------------------
   98|      0|        goto err;
   99|      0|    }
  100|       |
  101|    217|    session->alive = 0;
  102|    217|    session->auth.supported_methods = 0;
  103|    217|    ssh_set_blocking(session, 1);
  104|    217|    session->maxchannel = FIRST_CHANNEL;
  ------------------
  |  |   49|    217|#define FIRST_CHANNEL 42 // why not ? it helps to find bugs.
  ------------------
  105|    217|    session->proxy_root = true;
  106|       |
  107|    217|    session->agent = ssh_agent_new(session);
  108|    217|    if (session->agent == NULL) {
  ------------------
  |  Branch (108:9): [True: 0, False: 217]
  ------------------
  109|      0|        goto err;
  110|      0|    }
  111|       |
  112|       |    /* Initialise a default PKI context */
  113|    217|    session->pki_context = ssh_pki_ctx_new();
  114|    217|    if (session->pki_context == NULL) {
  ------------------
  |  Branch (114:9): [True: 0, False: 217]
  ------------------
  115|      0|        goto err;
  116|      0|    }
  117|       |
  118|       |    /* OPTIONS */
  119|    217|    session->opts.StrictHostKeyChecking = SSH_STRICT_HOSTKEY_ASK;
  120|    217|    session->opts.port = 22;
  121|    217|    session->opts.fd = -1;
  122|    217|    session->opts.compressionlevel = 7;
  123|    217|    session->opts.nodelay = 0;
  124|    217|    session->opts.identities_only = false;
  125|    217|    session->opts.server_alive_interval = 0;
  126|    217|    session->opts.server_alive_count_max = 3;
  127|    217|    session->opts.batch_mode = false;
  128|    217|    session->opts.gateway_ports = false;
  129|    217|    session->opts.control_master = SSH_CONTROL_MASTER_NO;
  130|       |
  131|    217|    session->opts.flags = SSH_OPT_FLAG_PASSWORD_AUTH |
  ------------------
  |  |  109|    217|#define SSH_OPT_FLAG_PASSWORD_AUTH 0x1
  ------------------
  132|    217|                          SSH_OPT_FLAG_PUBKEY_AUTH |
  ------------------
  |  |  110|    217|#define SSH_OPT_FLAG_PUBKEY_AUTH 0x2
  ------------------
  133|    217|                          SSH_OPT_FLAG_KBDINT_AUTH |
  ------------------
  |  |  111|    217|#define SSH_OPT_FLAG_KBDINT_AUTH 0x4
  ------------------
  134|    217|                          SSH_OPT_FLAG_GSSAPI_AUTH;
  ------------------
  |  |  112|    217|#define SSH_OPT_FLAG_GSSAPI_AUTH 0x8
  ------------------
  135|    217|    session->opts.pubkey_auth = SSH_PUBKEY_AUTH_ALL;
  136|       |
  137|    217|    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|    217|    if (session->opts.identity_non_exp == NULL) {
  ------------------
  |  Branch (148:9): [True: 217, False: 0]
  ------------------
  149|    217|        session->opts.identity_non_exp = ssh_list_new();
  150|    217|        if (session->opts.identity_non_exp == NULL) {
  ------------------
  |  Branch (150:13): [True: 0, False: 217]
  ------------------
  151|      0|            goto err;
  152|      0|        }
  153|    217|    }
  154|       |
  155|    217|    id = strdup("%d/.ssh/id_ed25519");
  156|    217|    if (id == NULL) {
  ------------------
  |  Branch (156:9): [True: 0, False: 217]
  ------------------
  157|      0|        goto err;
  158|      0|    }
  159|       |
  160|    217|    rc = ssh_list_append(session->opts.identity_non_exp, id);
  161|    217|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    217|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (161:9): [True: 0, False: 217]
  ------------------
  162|      0|        goto err;
  163|      0|    }
  164|       |
  165|    217|#ifdef HAVE_ECC
  166|    217|    id = strdup("%d/.ssh/id_ecdsa");
  167|    217|    if (id == NULL) {
  ------------------
  |  Branch (167:9): [True: 0, False: 217]
  ------------------
  168|      0|        goto err;
  169|      0|    }
  170|    217|    rc = ssh_list_append(session->opts.identity_non_exp, id);
  171|    217|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    217|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (171:9): [True: 0, False: 217]
  ------------------
  172|      0|        goto err;
  173|      0|    }
  174|    217|#endif
  175|       |
  176|    217|    id = strdup("%d/.ssh/id_rsa");
  177|    217|    if (id == NULL) {
  ------------------
  |  Branch (177:9): [True: 0, False: 217]
  ------------------
  178|      0|        goto err;
  179|      0|    }
  180|    217|    rc = ssh_list_append(session->opts.identity_non_exp, id);
  181|    217|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    217|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (181:9): [True: 0, False: 217]
  ------------------
  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|    217|    session->session_state = SSH_SESSION_STATE_NONE;
  210|    217|    session->pending_call_state = SSH_PENDING_CALL_NONE;
  211|    217|    session->packet_state = PACKET_STATE_INIT;
  212|    217|    session->dh_handshake_state = DH_STATE_INIT;
  213|    217|    session->global_req_state = SSH_CHANNEL_REQ_STATE_NONE;
  214|       |
  215|    217|    session->auth.state = SSH_AUTH_STATE_NONE;
  216|    217|    session->auth.service_state = SSH_AUTH_SERVICE_NONE;
  217|       |
  218|    217|    return session;
  219|       |
  220|     89|err:
  221|     89|    free(id);
  222|     89|    ssh_free(session);
  223|       |    return NULL;
  224|    217|}
ssh_free:
  235|    497|{
  236|    497|  int i;
  237|    497|  struct ssh_iterator *it = NULL;
  238|    497|  struct ssh_buffer_struct *b = NULL;
  239|       |
  240|    497|  if (session == NULL) {
  ------------------
  |  Branch (240:7): [True: 191, False: 306]
  ------------------
  241|    191|    return;
  242|    191|  }
  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|    306|  for (it = ssh_list_get_iterator(session->channels);
  252|    306|       it != NULL;
  ------------------
  |  Branch (252:8): [True: 0, False: 306]
  ------------------
  253|    306|       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|    306|  ssh_list_free(session->channels);
  258|    306|  session->channels = NULL;
  259|       |
  260|    306|#ifdef WITH_PCAP
  261|    306|  if (session->pcap_ctx) {
  ------------------
  |  Branch (261:7): [True: 0, False: 306]
  ------------------
  262|      0|      ssh_pcap_context_free(session->pcap_ctx);
  263|      0|      session->pcap_ctx = NULL;
  264|      0|  }
  265|    306|#endif
  266|       |
  267|    306|  ssh_socket_free(session->socket);
  268|    306|  session->socket = NULL;
  269|       |
  270|    306|  if (session->default_poll_ctx) {
  ------------------
  |  Branch (270:7): [True: 0, False: 306]
  ------------------
  271|      0|      ssh_poll_ctx_free(session->default_poll_ctx);
  272|      0|  }
  273|       |
  274|    306|  SSH_BUFFER_FREE(session->in_buffer);
  ------------------
  |  |  966|    306|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 217, False: 89]
  |  |  |  Branch (966:69): [Folded, False: 306]
  |  |  ------------------
  ------------------
  275|    306|  SSH_BUFFER_FREE(session->out_buffer);
  ------------------
  |  |  966|    306|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 217, False: 89]
  |  |  |  Branch (966:69): [Folded, False: 306]
  |  |  ------------------
  ------------------
  276|    306|  session->in_buffer = session->out_buffer = NULL;
  277|       |
  278|    306|  if (session->in_hashbuf != NULL) {
  ------------------
  |  Branch (278:7): [True: 0, False: 306]
  ------------------
  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|    306|  if (session->out_hashbuf != NULL) {
  ------------------
  |  Branch (281:7): [True: 0, False: 306]
  ------------------
  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|    306|  crypto_free(session->current_crypto);
  286|    306|  crypto_free(session->next_crypto);
  287|       |
  288|    306|  ssh_agent_free(session->agent);
  289|       |
  290|    306|  SSH_PKI_CTX_FREE(session->pki_context);
  ------------------
  |  | 1059|    306|    do {                         \
  |  | 1060|    306|        if ((x) != NULL) {       \
  |  |  ------------------
  |  |  |  Branch (1060:13): [True: 217, False: 89]
  |  |  ------------------
  |  | 1061|    217|            ssh_pki_ctx_free(x); \
  |  | 1062|    217|            x = NULL;            \
  |  | 1063|    217|        }                        \
  |  | 1064|    306|    } while (0)
  |  |  ------------------
  |  |  |  Branch (1064:14): [Folded, False: 306]
  |  |  ------------------
  ------------------
  291|       |
  292|    306|  ssh_key_free(session->srv.rsa_key);
  293|    306|  session->srv.rsa_key = NULL;
  294|    306|  ssh_key_free(session->srv.ecdsa_key);
  295|    306|  session->srv.ecdsa_key = NULL;
  296|    306|  ssh_key_free(session->srv.ed25519_key);
  297|    306|  session->srv.ed25519_key = NULL;
  298|       |
  299|    306|  if (session->ssh_message_list) {
  ------------------
  |  Branch (299:7): [True: 0, False: 306]
  ------------------
  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|    306|  if (session->kbdint != NULL) {
  ------------------
  |  Branch (310:7): [True: 0, False: 306]
  ------------------
  311|      0|    ssh_kbdint_free(session->kbdint);
  312|      0|  }
  313|       |
  314|    306|  if (session->packet_callbacks) {
  ------------------
  |  Branch (314:7): [True: 0, False: 306]
  ------------------
  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|    306|  if (session->opts.identity) {
  ------------------
  |  Branch (324:7): [True: 0, False: 306]
  ------------------
  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|    306|  if (session->opts.identity_non_exp) {
  ------------------
  |  Branch (335:7): [True: 217, False: 89]
  ------------------
  336|    217|      char *id = NULL;
  337|       |
  338|    217|      for (id = ssh_list_pop_head(char *, session->opts.identity_non_exp);
  ------------------
  |  |  128|    217|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  339|    868|           id != NULL;
  ------------------
  |  Branch (339:12): [True: 651, False: 217]
  ------------------
  340|    651|           id = ssh_list_pop_head(char *, session->opts.identity_non_exp)) {
  ------------------
  |  |  128|    651|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  341|    651|          SAFE_FREE(id);
  ------------------
  |  |  375|    651|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 651, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 651]
  |  |  ------------------
  ------------------
  342|    651|      }
  343|    217|      ssh_list_free(session->opts.identity_non_exp);
  344|    217|  }
  345|       |
  346|    306|    if (session->opts.certificate) {
  ------------------
  |  Branch (346:9): [True: 0, False: 306]
  ------------------
  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|    306|    if (session->opts.certificate_non_exp) {
  ------------------
  |  Branch (357:9): [True: 0, False: 306]
  ------------------
  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|    306|    ssh_proxyjumps_free(session->opts.proxy_jumps);
  369|    306|    SSH_LIST_FREE(session->opts.proxy_jumps);
  ------------------
  |  |  131|    306|    do { if ((x) != NULL) { ssh_list_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (131:14): [True: 0, False: 306]
  |  |  |  Branch (131:69): [Folded, False: 306]
  |  |  ------------------
  ------------------
  370|    306|    SSH_LIST_FREE(session->opts.proxy_jumps_user_cb);
  ------------------
  |  |  131|    306|    do { if ((x) != NULL) { ssh_list_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (131:14): [True: 0, False: 306]
  |  |  |  Branch (131:69): [Folded, False: 306]
  |  |  ------------------
  ------------------
  371|    306|    SAFE_FREE(session->opts.proxy_jumps_str);
  ------------------
  |  |  375|    306|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 306]
  |  |  |  Branch (375:71): [Folded, False: 306]
  |  |  ------------------
  ------------------
  372|       |
  373|    306|    if (session->opts.send_env) {
  ------------------
  |  Branch (373:9): [True: 0, False: 306]
  ------------------
  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|    306|    while ((b = ssh_list_pop_head(struct ssh_buffer_struct *,
  ------------------
  |  |  128|    306|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  |  Branch (384:12): [True: 0, False: 306]
  ------------------
  385|    306|                                  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|    306|    ssh_list_free(session->out_queue);
  389|       |
  390|    306|  ssh_agent_state_free(session->agent_state);
  391|    306|  session->agent_state = NULL;
  392|       |
  393|    306|  SAFE_FREE(session->auth.auto_state);
  ------------------
  |  |  375|    306|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 306]
  |  |  |  Branch (375:71): [Folded, False: 306]
  |  |  ------------------
  ------------------
  394|    306|  SAFE_FREE(session->serverbanner);
  ------------------
  |  |  375|    306|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 306]
  |  |  |  Branch (375:71): [Folded, False: 306]
  |  |  ------------------
  ------------------
  395|    306|  SAFE_FREE(session->clientbanner);
  ------------------
  |  |  375|    306|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 306]
  |  |  |  Branch (375:71): [Folded, False: 306]
  |  |  ------------------
  ------------------
  396|    306|  SAFE_FREE(session->banner);
  ------------------
  |  |  375|    306|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 306]
  |  |  |  Branch (375:71): [Folded, False: 306]
  |  |  ------------------
  ------------------
  397|    306|  SAFE_FREE(session->disconnect_message);
  ------------------
  |  |  375|    306|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 306]
  |  |  |  Branch (375:71): [Folded, False: 306]
  |  |  ------------------
  ------------------
  398|    306|  SAFE_FREE(session->peer_discon_msg);
  ------------------
  |  |  375|    306|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 306]
  |  |  |  Branch (375:71): [Folded, False: 306]
  |  |  ------------------
  ------------------
  399|       |
  400|    306|  SAFE_FREE(session->opts.agent_socket);
  ------------------
  |  |  375|    306|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 306]
  |  |  |  Branch (375:71): [Folded, False: 306]
  |  |  ------------------
  ------------------
  401|    306|  SAFE_FREE(session->opts.bindaddr);
  ------------------
  |  |  375|    306|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 306]
  |  |  |  Branch (375:71): [Folded, False: 306]
  |  |  ------------------
  ------------------
  402|    306|  SAFE_FREE(session->opts.username);
  ------------------
  |  |  375|    306|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 306]
  |  |  |  Branch (375:71): [Folded, False: 306]
  |  |  ------------------
  ------------------
  403|    306|  SAFE_FREE(session->opts.host);
  ------------------
  |  |  375|    306|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 306]
  |  |  |  Branch (375:71): [Folded, False: 306]
  |  |  ------------------
  ------------------
  404|    306|  SAFE_FREE(session->opts.originalhost);
  ------------------
  |  |  375|    306|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 306]
  |  |  |  Branch (375:71): [Folded, False: 306]
  |  |  ------------------
  ------------------
  405|    306|  SAFE_FREE(session->opts.config_hostname);
  ------------------
  |  |  375|    306|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 306]
  |  |  |  Branch (375:71): [Folded, False: 306]
  |  |  ------------------
  ------------------
  406|    306|  SAFE_FREE(session->opts.tag);
  ------------------
  |  |  375|    306|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 306]
  |  |  |  Branch (375:71): [Folded, False: 306]
  |  |  ------------------
  ------------------
  407|    306|  SAFE_FREE(session->opts.homedir);
  ------------------
  |  |  375|    306|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 306]
  |  |  |  Branch (375:71): [Folded, False: 306]
  |  |  ------------------
  ------------------
  408|    306|  SAFE_FREE(session->opts.sshdir);
  ------------------
  |  |  375|    306|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 306]
  |  |  |  Branch (375:71): [Folded, False: 306]
  |  |  ------------------
  ------------------
  409|    306|  SAFE_FREE(session->opts.knownhosts);
  ------------------
  |  |  375|    306|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 306]
  |  |  |  Branch (375:71): [Folded, False: 306]
  |  |  ------------------
  ------------------
  410|    306|  SAFE_FREE(session->opts.global_knownhosts);
  ------------------
  |  |  375|    306|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 306]
  |  |  |  Branch (375:71): [Folded, False: 306]
  |  |  ------------------
  ------------------
  411|    306|  SAFE_FREE(session->opts.ProxyCommand);
  ------------------
  |  |  375|    306|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 306]
  |  |  |  Branch (375:71): [Folded, False: 306]
  |  |  ------------------
  ------------------
  412|    306|  SAFE_FREE(session->opts.gss_server_identity);
  ------------------
  |  |  375|    306|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 306]
  |  |  |  Branch (375:71): [Folded, False: 306]
  |  |  ------------------
  ------------------
  413|    306|  SAFE_FREE(session->opts.gss_client_identity);
  ------------------
  |  |  375|    306|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 306]
  |  |  |  Branch (375:71): [Folded, False: 306]
  |  |  ------------------
  ------------------
  414|    306|  SAFE_FREE(session->opts.pubkey_accepted_types);
  ------------------
  |  |  375|    306|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 306]
  |  |  |  Branch (375:71): [Folded, False: 306]
  |  |  ------------------
  ------------------
  415|    306|  SAFE_FREE(session->opts.control_path);
  ------------------
  |  |  375|    306|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 306]
  |  |  |  Branch (375:71): [Folded, False: 306]
  |  |  ------------------
  ------------------
  416|    306|  SAFE_FREE(session->opts.preferred_authentications);
  ------------------
  |  |  375|    306|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 306]
  |  |  |  Branch (375:71): [Folded, False: 306]
  |  |  ------------------
  ------------------
  417|    306|  SAFE_FREE(session->opts.forward_agent_sock_path);
  ------------------
  |  |  375|    306|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 306]
  |  |  |  Branch (375:71): [Folded, False: 306]
  |  |  ------------------
  ------------------
  418|       |
  419|    306|  if (session->opts.local_forward) {
  ------------------
  |  Branch (419:7): [True: 0, False: 306]
  ------------------
  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|    306|  if (session->opts.remote_forward) {
  ------------------
  |  Branch (430:7): [True: 0, False: 306]
  ------------------
  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|  3.36k|  for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  3.36k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (441:15): [True: 3.06k, False: 306]
  ------------------
  442|  3.06k|      if (session->opts.wanted_methods[i]) {
  ------------------
  |  Branch (442:11): [True: 0, False: 3.06k]
  ------------------
  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.06k|  }
  446|       |
  447|    306|  SAFE_FREE(session->server_opts.custombanner);
  ------------------
  |  |  375|    306|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 306]
  |  |  |  Branch (375:71): [Folded, False: 306]
  |  |  ------------------
  ------------------
  448|    306|  SAFE_FREE(session->server_opts.moduli_file);
  ------------------
  |  |  375|    306|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 306]
  |  |  |  Branch (375:71): [Folded, False: 306]
  |  |  ------------------
  ------------------
  449|       |
  450|    306|  _ssh_remove_legacy_log_cb();
  451|       |
  452|       |  /* burn connection, it could contain sensitive data */
  453|    306|  ssh_burn(session, sizeof(struct ssh_session_struct));
  ------------------
  |  |  390|    306|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  454|       |  SAFE_FREE(session);
  ------------------
  |  |  375|    306|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 306, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 306]
  |  |  ------------------
  ------------------
  455|    306|}
ssh_set_blocking:
  669|    217|{
  670|    217|    if (session == NULL) {
  ------------------
  |  Branch (670:9): [True: 0, False: 217]
  ------------------
  671|      0|        return;
  672|      0|    }
  673|    217|    session->flags &= ~SSH_SESSION_FLAG_BLOCKING;
  ------------------
  |  |   75|    217|#define SSH_SESSION_FLAG_BLOCKING 0x0001
  ------------------
  674|    217|    session->flags |= blocking ? SSH_SESSION_FLAG_BLOCKING : 0;
  ------------------
  |  |   75|    217|#define SSH_SESSION_FLAG_BLOCKING 0x0001
  ------------------
  |  Branch (674:23): [True: 217, False: 0]
  ------------------
  675|    217|}

sftp_attributes_free:
  931|    868|void sftp_attributes_free(sftp_attributes file){
  932|    868|  if (file == NULL) {
  ------------------
  |  Branch (932:7): [True: 733, False: 135]
  ------------------
  933|    733|    return;
  934|    733|  }
  935|       |
  936|    135|  SSH_STRING_FREE(file->acl);
  ------------------
  |  |  924|    135|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 30, False: 105]
  |  |  |  Branch (924:69): [Folded, False: 135]
  |  |  ------------------
  ------------------
  937|    135|  SSH_STRING_FREE(file->extended_data);
  ------------------
  |  |  924|    135|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 135]
  |  |  |  Branch (924:69): [Folded, False: 135]
  |  |  ------------------
  ------------------
  938|    135|  SSH_STRING_FREE(file->extended_type);
  ------------------
  |  |  924|    135|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 135]
  |  |  |  Branch (924:69): [Folded, False: 135]
  |  |  ------------------
  ------------------
  939|       |
  940|    135|  SAFE_FREE(file->name);
  ------------------
  |  |  375|    135|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 4, False: 131]
  |  |  |  Branch (375:71): [Folded, False: 135]
  |  |  ------------------
  ------------------
  941|    135|  SAFE_FREE(file->longname);
  ------------------
  |  |  375|    135|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 4, False: 131]
  |  |  |  Branch (375:71): [Folded, False: 135]
  |  |  ------------------
  ------------------
  942|    135|  SAFE_FREE(file->group);
  ------------------
  |  |  375|    135|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 28, False: 107]
  |  |  |  Branch (375:71): [Folded, False: 135]
  |  |  ------------------
  ------------------
  943|    135|  SAFE_FREE(file->owner);
  ------------------
  |  |  375|    135|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 28, False: 107]
  |  |  |  Branch (375:71): [Folded, False: 135]
  |  |  ------------------
  ------------------
  944|       |
  945|       |  SAFE_FREE(file);
  ------------------
  |  |  375|    135|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 135, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 135]
  |  |  ------------------
  ------------------
  946|    135|}

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

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

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|    130|{
  178|    130|    size_t size;
  179|       |
  180|    130|    if (s == NULL) {
  ------------------
  |  Branch (180:9): [True: 0, False: 130]
  ------------------
  181|      0|        return 0;
  182|      0|    }
  183|       |
  184|    130|    size = ntohl(s->size);
  185|    130|    if (size > 0 && size <= STRING_SIZE_MAX) {
  ------------------
  |  |   38|     50|#define STRING_SIZE_MAX 0x10000000
  ------------------
  |  Branch (185:9): [True: 50, False: 80]
  |  Branch (185:21): [True: 50, False: 0]
  ------------------
  186|     50|        return size;
  187|     50|    }
  188|       |
  189|     80|    return 0;
  190|    130|}
ssh_string_to_char:
  223|    130|{
  224|    130|    size_t len;
  225|    130|    char *new = NULL;
  226|       |
  227|    130|    if (s == NULL) {
  ------------------
  |  Branch (227:9): [True: 0, False: 130]
  ------------------
  228|      0|        return NULL;
  229|      0|    }
  230|       |
  231|    130|    len = ssh_string_len(s);
  232|    130|    if (len + 1 < len) {
  ------------------
  |  Branch (232:9): [True: 0, False: 130]
  ------------------
  233|      0|        return NULL;
  234|      0|    }
  235|       |
  236|    130|    new = malloc(len + 1);
  237|    130|    if (new == NULL) {
  ------------------
  |  Branch (237:9): [True: 0, False: 130]
  ------------------
  238|      0|        return NULL;
  239|      0|    }
  240|    130|    memcpy(new, s->data, len);
  241|    130|    new[len] = '\0';
  242|       |
  243|    130|    return new;
  244|    130|}
ssh_string_burn:
  341|    266|{
  342|    266|    if (s == NULL || s->size == 0) {
  ------------------
  |  Branch (342:9): [True: 266, False: 0]
  |  Branch (342:22): [True: 0, False: 0]
  ------------------
  343|    266|        return;
  344|    266|    }
  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|   175k|{
  372|       |    SAFE_FREE(s);
  ------------------
  |  |  375|   175k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 174k, False: 1.33k]
  |  |  |  Branch (375:71): [Folded, False: 175k]
  |  |  ------------------
  ------------------
  373|   175k|}

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

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

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

