ssh_agent_new:
  170|    166|{
  171|    166|    ssh_agent agent = NULL;
  172|       |
  173|    166|    agent = calloc(1, sizeof(struct ssh_agent_struct));
  174|    166|    if (agent == NULL) {
  ------------------
  |  Branch (174:9): [True: 0, False: 166]
  ------------------
  175|      0|        return NULL;
  176|      0|    }
  177|       |
  178|    166|    agent->count = 0;
  179|    166|    agent->sock = ssh_socket_new(session);
  180|    166|    if (agent->sock == NULL) {
  ------------------
  |  Branch (180:9): [True: 0, False: 166]
  ------------------
  181|      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]
  |  |  ------------------
  ------------------
  182|      0|        return NULL;
  183|      0|    }
  184|    166|    agent->channel = NULL;
  185|       |#ifdef _WIN32
  186|       |    agent->pipe_handle = NULL;
  187|       |#endif
  188|    166|    return agent;
  189|    166|}
ssh_agent_close:
  258|    166|{
  259|    166|    if (agent == NULL) {
  ------------------
  |  Branch (259:9): [True: 0, False: 166]
  ------------------
  260|      0|        return;
  261|      0|    }
  262|       |
  263|       |#ifdef _WIN32
  264|       |    if (agent_pipe_is_open(agent)) {
  265|       |        CloseHandle((HANDLE)agent->pipe_handle);
  266|       |        agent->pipe_handle = NULL;
  267|       |    }
  268|       |#endif
  269|       |
  270|    166|    ssh_socket_close(agent->sock);
  271|    166|}
ssh_agent_free:
  274|    270|{
  275|    270|    if (agent) {
  ------------------
  |  Branch (275:9): [True: 166, False: 104]
  ------------------
  276|    166|        if (agent->ident) {
  ------------------
  |  Branch (276:13): [True: 0, False: 166]
  ------------------
  277|      0|            SSH_BUFFER_FREE(agent->ident);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  278|      0|        }
  279|    166|        if (agent->sock) {
  ------------------
  |  Branch (279:13): [True: 166, False: 0]
  ------------------
  280|    166|            ssh_agent_close(agent);
  281|    166|            ssh_socket_free(agent->sock);
  282|    166|        }
  283|       |        SAFE_FREE(agent);
  ------------------
  |  |  375|    166|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 166, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 166]
  |  |  ------------------
  ------------------
  284|    166|    }
  285|    270|}

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

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

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

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;
  ------------------
  |  |  315|      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;
  ------------------
  |  |  316|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  273|      2|}

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

_ssh_set_error:
   55|    551|{
   56|    551|    struct ssh_common_struct *err = error;
   57|    551|    va_list va;
   58|       |
   59|    551|    va_start(va, descr);
   60|    551|    vsnprintf(err->error.error_buffer, ERROR_BUFFERLEN, descr, va);
  ------------------
  |  |  219|    551|#define ERROR_BUFFERLEN 1024
  ------------------
   61|    551|    va_end(va);
   62|       |
   63|    551|    err->error.error_code = code;
   64|    551|    if (ssh_get_log_level() == SSH_LOG_TRACE) {
  ------------------
  |  |  362|    551|#define SSH_LOG_TRACE 4
  ------------------
  |  Branch (64:9): [True: 0, False: 551]
  ------------------
   65|      0|        ssh_log_function(SSH_LOG_TRACE,
  ------------------
  |  |  362|      0|#define SSH_LOG_TRACE 4
  ------------------
   66|      0|                         function,
   67|      0|                         err->error.error_buffer);
   68|      0|    }
   69|    551|}
_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|    215|{
  269|    215|    if (crypto->compress_out_ctx) {
  ------------------
  |  Branch (269:9): [True: 0, False: 215]
  ------------------
  270|      0|        deflateEnd(crypto->compress_out_ctx);
  271|      0|    }
  272|    215|    SAFE_FREE(crypto->compress_out_ctx);
  ------------------
  |  |  375|    215|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 215]
  |  |  |  Branch (375:71): [Folded, False: 215]
  |  |  ------------------
  ------------------
  273|       |
  274|    215|    if (crypto->compress_in_ctx) {
  ------------------
  |  Branch (274:9): [True: 0, False: 215]
  ------------------
  275|      0|        inflateEnd(crypto->compress_in_ctx);
  276|      0|    }
  277|       |    SAFE_FREE(crypto->compress_in_ctx);
  ------------------
  |  |  375|    215|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 215]
  |  |  |  Branch (375:71): [Folded, False: 215]
  |  |  ------------------
  ------------------
  278|    215|}

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;
  ------------------
  |  |  315|      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;
  ------------------
  |  |  315|      2|#define SSH_OK 0     /* No error */
  ------------------
 1435|      2|}

_ssh_log:
  168|    241|{
  169|    241|    va_list va;
  170|       |
  171|    241|    if (verbosity <= ssh_get_log_level()) {
  ------------------
  |  Branch (171:9): [True: 0, False: 241]
  ------------------
  172|      0|        va_start(va, format);
  173|      0|        ssh_vlog(verbosity, function, format, &va);
  174|       |        va_end(va);
  175|      0|    }
  176|    241|}
ssh_get_log_level:
  252|    792|int ssh_get_log_level(void) {
  253|    792|  return ssh_log_level;
  254|    792|}
ssh_get_log_callback:
  275|    270|ssh_logging_callback ssh_get_log_callback(void) {
  276|    270|  return ssh_log_cb;
  277|    270|}

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

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

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

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

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

sftp_attributes_free:
  931|    664|void sftp_attributes_free(sftp_attributes file){
  932|    664|  if (file == NULL) {
  ------------------
  |  Branch (932:7): [True: 551, False: 113]
  ------------------
  933|    551|    return;
  934|    551|  }
  935|       |
  936|    113|  SSH_STRING_FREE(file->acl);
  ------------------
  |  |  882|    113|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 2, False: 111]
  |  |  |  Branch (882:69): [Folded, False: 113]
  |  |  ------------------
  ------------------
  937|    113|  SSH_STRING_FREE(file->extended_data);
  ------------------
  |  |  882|    113|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 3, False: 110]
  |  |  |  Branch (882:69): [Folded, False: 113]
  |  |  ------------------
  ------------------
  938|    113|  SSH_STRING_FREE(file->extended_type);
  ------------------
  |  |  882|    113|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (882:14): [True: 3, False: 110]
  |  |  |  Branch (882:69): [Folded, False: 113]
  |  |  ------------------
  ------------------
  939|       |
  940|    113|  SAFE_FREE(file->name);
  ------------------
  |  |  375|    113|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 4, False: 109]
  |  |  |  Branch (375:71): [Folded, False: 113]
  |  |  ------------------
  ------------------
  941|    113|  SAFE_FREE(file->longname);
  ------------------
  |  |  375|    113|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 4, False: 109]
  |  |  |  Branch (375:71): [Folded, False: 113]
  |  |  ------------------
  ------------------
  942|    113|  SAFE_FREE(file->group);
  ------------------
  |  |  375|    113|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 10, False: 103]
  |  |  |  Branch (375:71): [Folded, False: 113]
  |  |  ------------------
  ------------------
  943|    113|  SAFE_FREE(file->owner);
  ------------------
  |  |  375|    113|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 10, False: 103]
  |  |  |  Branch (375:71): [Folded, False: 113]
  |  |  ------------------
  ------------------
  944|       |
  945|       |  SAFE_FREE(file);
  ------------------
  |  |  375|    113|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 113, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 113]
  |  |  ------------------
  ------------------
  946|    113|}

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

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

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

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

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

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

