Branch Coverage

feersum_tls.c.inc
Criterion Covered Total %
branch 173 474 36.5


line true false branch
34 51 51 for (i = 0; i < num_protos; i++) {
35 0 51 for (j = 0; j < params->negotiated_protocols.count; j++) {
36 0 0 if (params->negotiated_protocols.list[j].len == protos[i].len &&
38 0 0 protos[i].len) == 0) {
57 51 0 if (!lsnr || lsnr->n_sni_entries == 0 || !params->server_name.base)
0 51 if (!lsnr || lsnr->n_sni_entries == 0 || !params->server_name.base)
0 0 if (!lsnr || lsnr->n_sni_entries == 0 || !params->server_name.base)
63 0 0 for (i = 0; i < lsnr->n_sni_entries; i++) {
65 0 0 if (strlen(e->hostname) == name_len &&
66 0 0 strncasecmp(e->hostname, (const char *)params->server_name.base, name_len) == 0) {
135 3 88 if (ret != 0) {
144 2 86 if (!fp) {
152 0 86 if (!pkey) {
159 0 86 if (ptls_openssl_init_sign_certificate(sign_cert, pkey) != 0) {
169 0 86 if (h2)
188 0 90 if (!ctx) return;
189 90 0 if (ctx->certificates.list) {
191 87 90 for (i = 0; i < ctx->certificates.count; i++)
196 85 5 if (ctx->sign_certificate) {
230 85 64 if (--ref->refcount <= 0) {
243 83 142 if (lsnr->tls_ctx_ref) {
247 2 225 for (i = 0; i < lsnr->n_sni_entries; i++) {
261 0 68 if (unlikely(!c->tls)) {
280 63 562 if (c->tls) {
284 63 562 if (c->tls_ctx_ref) {
289 0 625 if (c->tls_rbuf) {
294 9 616 if (c->tls_tunnel) {
298 9 0 if (c->tls_tunnel_sv0 >= 0) {
302 0 9 if (c->tls_tunnel_sv1 >= 0) {
306 0 9 if (c->tls_tunnel_wbuf) {
322 0 140 if (c->tls_wbuf.off == 0)
326 0 140 if (written < 0) {
327 0 0 if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
0 0 if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
0 0 if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
334 0 140 if ((size_t)written < c->tls_wbuf.off) {
370 0 13 if (c->tls_tunnel_sv0 < 0) return -1;
373 13 0 if (nw == (ssize_t)len)
376 0 0 if (nw < 0) {
377 0 0 if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR)
0 0 if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR)
0 0 if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR)
383 0 0 if (!c->tls_tunnel_wbuf) {
388 0 0 if (c->tls_tunnel_wbuf_pos > 0) {
390 0 0 if (remain > 0)
398 0 0 if (SvCUR(c->tls_tunnel_wbuf) + remaining > FEER_TUNNEL_MAX_WBUF) {
404 0 0 if (!ev_is_active(&c->tls_tunnel_write_w))
418 13 0 while (c->tls_tunnel && c->tls_rbuf_len > 0) {
0 13 while (c->tls_tunnel && c->tls_rbuf_len > 0) {
419 0 0 if (ev_is_active(&c->tls_tunnel_write_w))
423 0 0 if (drain_rv < 0) break;
424 0 0 if (drain_rv == 1) continue; /* non-data (e.g. KeyUpdate) */
425 0 0 if (tls_tunnel_write_or_buffer(c, (const char *)db.base, db.off) < 0) {
446 2 21 if (nread == 0) {
452 0 21 if (nread < 0) {
453 0 0 if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
0 0 if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
0 0 if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
461 0 21 if (feer_tls_send(c, buf, nread) != 0) {
469 0 21 if (flush_ret == -2) {
474 21 0 if (c->tls_wbuf.off > 0)
492 0 0 if (!c->tls_tunnel_wbuf ||
493 0 0 SvCUR(c->tls_tunnel_wbuf) <= c->tls_tunnel_wbuf_pos) {
495 0 0 if (c->tls_tunnel_wbuf) {
506 0 0 if (nw < 0) {
507 0 0 if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
0 0 if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
0 0 if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
515 0 0 if (c->tls_tunnel_wbuf_pos >= SvCUR(c->tls_tunnel_wbuf)) {
521 0 0 if (c->tls_rbuf_len > 0)
535 0 9 if (c->tls_tunnel) return;
538 0 9 if (feer_socketpair_nb(sv) < 0) {
559 9 0 if (c->rbuf && SvOK(c->rbuf) && SvCUR(c->rbuf) > 0) {
9 0 if (c->rbuf && SvOK(c->rbuf) && SvCUR(c->rbuf) > 0) {
0 9 if (c->rbuf && SvOK(c->rbuf) && SvCUR(c->rbuf) > 0) {
561 0 0 if (tls_tunnel_write_or_buffer(c, SvPVX(c->rbuf), SvCUR(c->rbuf)) < 0) {
584 0 60 if (!c->tls_rbuf || c->tls_rbuf_len == 0) return -1;
0 0 if (!c->tls_rbuf || c->tls_rbuf_len == 0) return -1;
594 0 0 if (ret == 0 && consumed < saved_len) {
0 0 if (ret == 0 && consumed < saved_len) {
602 0 0 if (ret != 0) {
606 0 0 if (decbuf->off == 0) {
655 1 347 if (unlikely(c->pipelined)) goto tls_pipelined;
657 0 347 if (unlikely(!c->tls)) {
668 7 340 if (nread == 0) {
677 0 340 if (nread < 0) {
678 0 0 if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
0 0 if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
0 0 if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
691 152 188 if (unlikely(c->receiving == RECEIVE_PROXY_HEADER)) {
692 23 129 if (!c->rbuf) {
698 4 148 if (ret == -1) {
703 129 19 if (ret == -2) goto tls_read_cleanup; /* need more data */
709 0 19 feer_clear_remote_cache(c);
0 19 feer_clear_remote_cache(c);
713 0 19 if (remaining > 0) {
724 19 0 if (remaining == 0)
737 0 188 if (c->tls_rbuf_len > 0) {
738 0 0 if (nread > 0) {
755 64 124 if (!c->tls_handshake_done) {
763 55 9 if (hsbuf.off > 0) {
764 0 55 if (tls_wbuf_append(&c->tls_wbuf, hsbuf.base, hsbuf.off) != 0) {
767 0 0 if (merged) Safefree(merged);
772 0 55 if (flush_ret == -2) {
775 0 0 if (merged) Safefree(merged);
779 55 0 if (flush_ret == -1 || c->tls_wbuf.off > 0) {
0 55 if (flush_ret == -1 || c->tls_wbuf.off > 0) {
786 51 13 if (ret == 0) {
793 0 51 if (proto && strlen(proto) == 2 && memcmp(proto, "h2", 2) == 0) {
0 0 if (proto && strlen(proto) == 2 && memcmp(proto, "h2", 2) == 0) {
0 0 if (proto && strlen(proto) == 2 && memcmp(proto, "h2", 2) == 0) {
804 0 51 if (consumed < inlen) {
852 0 0 if (dec_ret != 0) {
854 0 0 if (merged) Safefree(merged);
859 0 0 if (dec_consumed < remaining) {
865 0 0 if (decbuf.off > 0) {
867 0 0 if (!c->rbuf) {
875 0 0 if (parse_ret == -1) {
878 0 0 if (merged) Safefree(merged);
881 0 0 if (parse_ret > 0) {
882 0 0 if (!process_request_headers(c, parse_ret))
889 0 0 if (c->tls_rbuf_len > 0) {
891 0 0 while (c->tls_rbuf_len > 0) {
893 0 0 if (drain_rv < 0) break;
894 0 0 if (drain_rv == 1) continue;
898 0 0 if (parse_ret == -2) {
902 0 0 if (pr == -1) {
907 0 0 if (pr > 0) {
908 0 0 if (!process_request_headers(c, pr))
917 0 0 if (parse_ret > 0 && c->receiving == RECEIVE_BODY) {
0 0 if (parse_ret > 0 && c->receiving == RECEIVE_BODY) {
919 0 0 if (c->expected_cl > 0
920 0 0 && c->received_cl >= c->expected_cl) {
930 9 4 } else if (ret == PTLS_ERROR_IN_PROGRESS) {
934 0 9 if (consumed < inlen) {
946 0 64 if (merged) Safefree(merged);
958 124 0 if (ret == 0 && consumed < inlen) {
0 124 if (ret == 0 && consumed < inlen) {
965 0 124 if (merged) Safefree(merged);
967 0 124 if (ret != 0) {
979 51 73 if (decbuf.off == 0) {
1002 13 60 if (c->tls_tunnel) {
1003 0 13 if (tls_tunnel_write_or_buffer(c, (const char *)decbuf.base, decbuf.off) < 0) {
1023 51 9 if (!c->rbuf) {
1033 0 60 while ((drain_rv = feer_tls_drain_one_record(c, &db)) >= 0) {
1034 0 0 if (drain_rv == 1) continue; /* non-data TLS record */
1049 8 53 if (c->receiving == RECEIVE_WAIT)
1052 59 2 if (likely(c->receiving <= RECEIVE_HEADERS)) {
1054 0 59 if (parse_ret == -1) {
1059 0 59 if (parse_ret == -2) {
1064 57 2 if (!process_request_headers(c, parse_ret))
1067 2 0 else if (likely(c->receiving == RECEIVE_BODY)) {
1069 2 0 if (c->received_cl >= c->expected_cl) {
1074 0 0 else if (c->receiving == RECEIVE_CHUNKED) {
1076 0 0 if (ret == -1) {
1080 0 0 else if (ret == 0) {
1086 0 0 else if (c->receiving == RECEIVE_STREAMING) {
1088 0 0 if (c->poll_read_cb) {
1091 0 0 if (c->receiving >= RECEIVE_SHUTDOWN) {
1095 0 0 if (c->expected_cl > 0 && c->received_cl >= c->expected_cl)
0 0 if (c->expected_cl > 0 && c->received_cl >= c->expected_cl)
1120 0 60 if (unlikely(!c->tls)) {
1127 0 60 if (c->tls_wbuf.off > 0) {
1129 0 0 if (flush_ret == -1) goto tls_write_cleanup; /* EAGAIN, keep write watcher active */
1130 0 0 if (flush_ret == -2) goto tls_write_error;
1132 0 0 if (c->tls_wbuf.off > 0) goto tls_write_cleanup;
1157 60 0 if (c->wbuf_rinq && c->cached_wbuf_low_water > 0
1 59 if (c->wbuf_rinq && c->cached_wbuf_low_water > 0
1158 1 0 && c->wbuf_len <= c->cached_wbuf_low_water
1159 1 0 && c->responding == RESPOND_STREAMING && c->poll_write_cb) {
1 0 && c->responding == RESPOND_STREAMING && c->poll_write_cb) {
1160 0 1 if (c->poll_write_cb_is_io_handle)
1167 60 0 if (c->wbuf_rinq) {
1169 63 60 while ((m = (struct iomatrix *)rinq_shift(&c->wbuf_rinq)) != NULL) {
1171 65 63 for (i = 0; i < m->count; i++) {
1172 0 65 if (m->iov[i].iov_len == 0) continue;
1180 0 65 if (ret != 0) {
1184 0 0 for (j = 0; j < m->count; j++) {
1185 0 0 if (m->sv[j]) SvREFCNT_dec(m->sv[j]);
1187 0 0 IOMATRIX_FREE(m);
1190 65 0 if (encbuf.off > 0) {
1191 0 65 if (tls_wbuf_append(&c->tls_wbuf, encbuf.base, encbuf.off) != 0) {
1195 0 0 for (j = 0; j < m->count; j++) {
1196 0 0 if (m->sv[j]) SvREFCNT_dec(m->sv[j]);
1198 0 0 IOMATRIX_FREE(m);
1206 65 63 for (i = 0; i < m->count; i++) {
1207 65 0 if (m->sv[i]) SvREFCNT_dec(m->sv[i]);
1209 63 0 IOMATRIX_FREE(m);
1212 4 59 if (c->cached_wbuf_low_water > 0
1213 4 0 && c->wbuf_len <= c->cached_wbuf_low_water
1214 3 1 && c->responding == RESPOND_STREAMING && c->poll_write_cb) {
3 0 && c->responding == RESPOND_STREAMING && c->poll_write_cb) {
1215 0 3 if (c->poll_write_cb_is_io_handle)
1225 0 60 if (flush_ret == -1) goto tls_write_cleanup; /* EAGAIN */
1226 0 60 if (flush_ret == -2) goto tls_write_error;
1227 60 0 if (flush_ret > 0) restart_write_timer(c);
1231 2 58 if (c->sendfile_fd >= 0 && c->sendfile_remain > 0) {
0 2 if (c->sendfile_fd >= 0 && c->sendfile_remain > 0) {
1234 0 2 if (to_read > sizeof(filebuf)) to_read = sizeof(filebuf);
1237 0 2 if (file_nread < 0) {
1238 0 0 if (errno == EINTR)
1241 0 0 CLOSE_SENDFILE_FD(c);
0 0 CLOSE_SENDFILE_FD(c);
1245 0 2 if (file_nread == 0) {
1246 0 0 CLOSE_SENDFILE_FD(c);
0 0 CLOSE_SENDFILE_FD(c);
1255 0 2 if (ret != 0) {
1258 0 0 CLOSE_SENDFILE_FD(c);
0 0 CLOSE_SENDFILE_FD(c);
1263 2 0 if (encbuf.off > 0) {
1264 0 2 if (tls_wbuf_append(&c->tls_wbuf, encbuf.base, encbuf.off) != 0) {
1267 0 0 CLOSE_SENDFILE_FD(c);
0 0 CLOSE_SENDFILE_FD(c);
1276 2 0 if (c->sendfile_remain == 0) {
1277 2 0 CLOSE_SENDFILE_FD(c);
0 2 CLOSE_SENDFILE_FD(c);
1284 0 2 if (sf_flush_ret == -1) goto tls_write_cleanup; /* EAGAIN */
1285 0 2 if (sf_flush_ret == -2) goto tls_write_error;
1287 2 0 if (c->sendfile_remain > 0 || c->tls_wbuf.off > 0)
0 2 if (c->sendfile_remain > 0 || c->tls_wbuf.off > 0)
1293 0 60 if ((!c->wbuf_rinq || (c->cached_wbuf_low_water > 0
0 0 if ((!c->wbuf_rinq || (c->cached_wbuf_low_water > 0
1294 0 0 && c->wbuf_len <= c->cached_wbuf_low_water))
1295 60 0 && c->sendfile_fd < 0 && c->tls_wbuf.off == 0) {
60 0 && c->sendfile_fd < 0 && c->tls_wbuf.off == 0) {
1296 10 50 if (c->responding == RESPOND_SHUTDOWN || c->responding == RESPOND_NORMAL) {
0 10 if (c->responding == RESPOND_SHUTDOWN || c->responding == RESPOND_NORMAL) {
1298 10 0 } else if (c->responding == RESPOND_STREAMING && c->poll_write_cb) {
10 0 } else if (c->responding == RESPOND_STREAMING && c->poll_write_cb) {
1299 0 10 if (c->poll_write_cb_is_io_handle)
1303 0 0 } else if (c->responding == RESPOND_STREAMING) {
1306 0 0 } else if (c->responding == RESPOND_NOT_STARTED) {
1331 23 0 if (!c->tls || len == 0) return 0;
0 23 if (!c->tls || len == 0) return 0;
1336 0 23 if (ret != 0) {
1341 23 0 if (encbuf.off > 0) {
1342 0 23 if (tls_wbuf_append(&c->tls_wbuf, encbuf.base, encbuf.off) != 0) {