Branch Coverage

feersum_tls.c.inc
Criterion Covered Total %
branch 172 462 37.2


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)
62 0 0 for (int i = 0; i < lsnr->n_sni_entries; i++) {
135 3 153 if (ret != 0) {
144 2 151 if (!fp) {
152 0 151 if (!pkey) {
159 0 151 if (ptls_openssl_init_sign_certificate(sign_cert, pkey) != 0) {
169 0 151 if (h2)
188 0 155 if (!ctx) return;
189 155 0 if (ctx->certificates.list) {
191 152 155 for (i = 0; i < ctx->certificates.count; i++)
196 150 5 if (ctx->sign_certificate) {
224 150 64 if (--ref->refcount <= 0) {
236 84 144 if (lsnr->tls_ctx_ref) {
240 3 228 for (int i = 0; i < lsnr->n_sni_entries; i++) {
254 0 68 if (unlikely(!c->tls)) {
273 63 581 if (c->tls) {
277 63 581 if (c->tls_ctx_ref) {
282 0 644 if (c->tls_rbuf) {
287 9 635 if (c->tls_tunnel) {
291 9 0 if (c->tls_tunnel_sv0 >= 0) {
295 0 9 if (c->tls_tunnel_sv1 >= 0) {
299 0 9 if (c->tls_tunnel_wbuf) {
315 0 140 if (c->tls_wbuf.off == 0)
319 0 140 if (written < 0) {
320 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) {
327 0 140 if ((size_t)written < c->tls_wbuf.off) {
363 0 13 if (c->tls_tunnel_sv0 < 0) return -1;
366 13 0 if (nw == (ssize_t)len)
369 0 0 if (nw < 0) {
370 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)
376 0 0 if (!c->tls_tunnel_wbuf) {
381 0 0 if (c->tls_tunnel_wbuf_pos > 0) {
383 0 0 if (remain > 0)
391 0 0 if (SvCUR(c->tls_tunnel_wbuf) + remaining > FEER_TUNNEL_MAX_WBUF) {
397 0 0 if (!ev_is_active(&c->tls_tunnel_write_w))
411 13 0 while (c->tls_tunnel && c->tls_rbuf_len > 0) {
0 13 while (c->tls_tunnel && c->tls_rbuf_len > 0) {
412 0 0 if (ev_is_active(&c->tls_tunnel_write_w))
416 0 0 if (drain_rv < 0) break;
417 0 0 if (drain_rv == 1) continue; /* non-data (e.g. KeyUpdate) */
418 0 0 if (tls_tunnel_write_or_buffer(c, (const char *)db.base, db.off) < 0) {
437 2 21 if (nread == 0) {
442 0 21 if (nread < 0) {
443 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)
450 0 21 if (feer_tls_send(c, buf, nread) != 0) {
457 0 21 if (flush_ret == -2) {
461 21 0 if (c->tls_wbuf.off > 0)
479 0 0 if (!c->tls_tunnel_wbuf ||
480 0 0 SvCUR(c->tls_tunnel_wbuf) <= c->tls_tunnel_wbuf_pos) {
482 0 0 if (c->tls_tunnel_wbuf) {
493 0 0 if (nw < 0) {
494 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)
501 0 0 if (c->tls_tunnel_wbuf_pos >= SvCUR(c->tls_tunnel_wbuf)) {
507 0 0 if (c->tls_rbuf_len > 0)
521 0 9 if (c->tls_tunnel) return;
524 0 9 if (feer_socketpair_nb(sv) < 0) {
545 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) {
547 0 0 if (tls_tunnel_write_or_buffer(c, SvPVX(c->rbuf), SvCUR(c->rbuf)) < 0) {
582 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;
592 0 0 if (ret == 0 && consumed < saved_len)
0 0 if (ret == 0 && consumed < saved_len)
596 0 0 if (ret != 0) {
600 0 0 if (decbuf->off == 0) {
648 1 347 if (unlikely(c->pipelined)) goto tls_pipelined;
650 0 347 if (unlikely(!c->tls)) {
661 7 340 if (nread == 0) {
670 0 340 if (nread < 0) {
671 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)
684 152 188 if (unlikely(c->receiving == RECEIVE_PROXY_HEADER)) {
685 23 129 if (!c->rbuf) {
691 4 148 if (ret == -1) {
696 129 19 if (ret == -2) goto tls_read_cleanup; /* need more data */
702 0 19 feer_clear_remote_cache(c);
0 19 feer_clear_remote_cache(c);
706 0 19 if (remaining > 0) {
715 19 0 if (remaining == 0)
728 0 188 if (c->tls_rbuf_len > 0) {
729 0 0 if (nread > 0) {
746 64 124 if (!c->tls_handshake_done) {
754 55 9 if (hsbuf.off > 0) {
755 0 55 if (tls_wbuf_append(&c->tls_wbuf, hsbuf.base, hsbuf.off) != 0) {
758 0 0 if (merged) Safefree(merged);
764 0 55 if (flush_ret == -2) {
767 0 0 if (merged) Safefree(merged);
772 55 0 if (flush_ret == -1 || c->tls_wbuf.off > 0) {
0 55 if (flush_ret == -1 || c->tls_wbuf.off > 0) {
779 51 13 if (ret == 0) {
786 0 51 if (proto && strcmp(proto, "h2") == 0) {
0 0 if (proto && strcmp(proto, "h2") == 0) {
797 0 51 if (consumed < inlen) {
840 0 0 if (dec_ret != 0) {
842 0 0 if (merged) Safefree(merged);
847 0 0 if (dec_consumed < remaining)
849 0 0 if (decbuf.off > 0) {
851 0 0 if (!c->rbuf) {
859 0 0 if (parse_ret == -1) {
862 0 0 if (merged) Safefree(merged);
865 0 0 if (parse_ret > 0) {
866 0 0 if (!process_request_headers(c, parse_ret))
873 0 0 if (c->tls_rbuf_len > 0) {
875 0 0 while (c->tls_rbuf_len > 0) {
877 0 0 if (drain_rv < 0) break;
878 0 0 if (drain_rv == 1) continue;
882 0 0 if (parse_ret == -2) {
886 0 0 if (pr == -1) {
891 0 0 if (pr > 0) {
892 0 0 if (!process_request_headers(c, pr))
901 0 0 if (parse_ret > 0 && c->receiving == RECEIVE_BODY) {
0 0 if (parse_ret > 0 && c->receiving == RECEIVE_BODY) {
903 0 0 if (c->expected_cl > 0
904 0 0 && c->received_cl >= c->expected_cl) {
914 9 4 } else if (ret == PTLS_ERROR_IN_PROGRESS) {
918 0 9 if (consumed < inlen)
926 0 64 if (merged) Safefree(merged);
938 124 0 if (ret == 0 && consumed < inlen)
0 124 if (ret == 0 && consumed < inlen)
941 0 124 if (merged) Safefree(merged);
943 0 124 if (ret != 0) {
955 51 73 if (decbuf.off == 0) {
977 13 60 if (c->tls_tunnel) {
978 0 13 if (tls_tunnel_write_or_buffer(c, (const char *)decbuf.base, decbuf.off) < 0) {
996 51 9 if (!c->rbuf) {
1006 0 60 while ((drain_rv = feer_tls_drain_one_record(c, &db)) >= 0) {
1007 0 0 if (drain_rv == 1) continue; /* non-data TLS record */
1022 8 53 if (c->receiving == RECEIVE_WAIT)
1025 59 2 if (likely(c->receiving <= RECEIVE_HEADERS)) {
1027 0 59 if (parse_ret == -1) {
1032 0 59 if (parse_ret == -2) {
1037 57 2 if (!process_request_headers(c, parse_ret))
1040 2 0 else if (likely(c->receiving == RECEIVE_BODY)) {
1042 2 0 if (c->received_cl >= c->expected_cl) {
1047 0 0 else if (c->receiving == RECEIVE_CHUNKED) {
1049 0 0 if (ret == -1) {
1053 0 0 else if (ret == 0) {
1059 0 0 else if (c->receiving == RECEIVE_STREAMING) {
1061 0 0 if (c->poll_read_cb) {
1064 0 0 if (c->receiving >= RECEIVE_SHUTDOWN) {
1068 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)
1093 0 60 if (unlikely(!c->tls)) {
1100 0 60 if (c->tls_wbuf.off > 0) {
1102 0 0 if (flush_ret == -1) goto tls_write_cleanup; /* EAGAIN, keep write watcher active */
1103 0 0 if (flush_ret == -2) goto tls_write_error;
1105 0 0 if (c->tls_wbuf.off > 0) goto tls_write_cleanup;
1129 60 0 if (c->wbuf_rinq && c->cached_wbuf_low_water > 0
1 59 if (c->wbuf_rinq && c->cached_wbuf_low_water > 0
1130 1 0 && c->wbuf_len <= c->cached_wbuf_low_water
1131 1 0 && c->responding == RESPOND_STREAMING && c->poll_write_cb) {
1 0 && c->responding == RESPOND_STREAMING && c->poll_write_cb) {
1132 0 1 if (c->poll_write_cb_is_io_handle)
1139 60 0 if (c->wbuf_rinq) {
1141 63 60 while ((m = (struct iomatrix *)rinq_shift(&c->wbuf_rinq)) != NULL) {
1143 65 63 for (i = 0; i < m->count; i++) {
1144 0 65 if (m->iov[i].iov_len == 0) continue;
1152 0 65 if (ret != 0) {
1157 0 0 for (j = 0; j < m->count; j++) SvREFCNT_dec(m->sv[j]);
1158 0 0 IOMATRIX_FREE(m);
1161 65 0 if (encbuf.off > 0) {
1162 0 65 if (tls_wbuf_append(&c->tls_wbuf, encbuf.base, encbuf.off) != 0) {
1166 0 0 for (j = 0; j < m->count; j++) SvREFCNT_dec(m->sv[j]);
1167 0 0 IOMATRIX_FREE(m);
1175 65 63 for (i = 0; i < m->count; i++) SvREFCNT_dec(m->sv[i]);
1176 63 0 IOMATRIX_FREE(m);
1179 4 59 if (c->cached_wbuf_low_water > 0
1180 4 0 && c->wbuf_len <= c->cached_wbuf_low_water
1181 3 1 && c->responding == RESPOND_STREAMING && c->poll_write_cb) {
3 0 && c->responding == RESPOND_STREAMING && c->poll_write_cb) {
1182 0 3 if (c->poll_write_cb_is_io_handle)
1192 0 60 if (flush_ret == -1) goto tls_write_cleanup; /* EAGAIN */
1193 0 60 if (flush_ret == -2) goto tls_write_error;
1194 60 0 if (flush_ret > 0) restart_write_timer(c);
1198 2 58 if (c->sendfile_fd >= 0 && c->sendfile_remain > 0) {
0 2 if (c->sendfile_fd >= 0 && c->sendfile_remain > 0) {
1201 0 2 if (to_read > sizeof(filebuf)) to_read = sizeof(filebuf);
1204 0 2 if (file_nread < 0) {
1205 0 0 if (errno == EINTR)
1208 0 0 CLOSE_SENDFILE_FD(c);
0 0 CLOSE_SENDFILE_FD(c);
1215 0 2 if (file_nread == 0) {
1216 0 0 CLOSE_SENDFILE_FD(c);
0 0 CLOSE_SENDFILE_FD(c);
1225 0 2 if (ret != 0) {
1228 0 0 CLOSE_SENDFILE_FD(c);
0 0 CLOSE_SENDFILE_FD(c);
1233 2 0 if (encbuf.off > 0) {
1234 0 2 if (tls_wbuf_append(&c->tls_wbuf, encbuf.base, encbuf.off) != 0) {
1237 0 0 CLOSE_SENDFILE_FD(c);
0 0 CLOSE_SENDFILE_FD(c);
1246 2 0 if (c->sendfile_remain == 0) {
1247 2 0 CLOSE_SENDFILE_FD(c);
0 2 CLOSE_SENDFILE_FD(c);
1254 0 2 if (sf_flush_ret == -1) goto tls_write_cleanup; /* EAGAIN */
1255 0 2 if (sf_flush_ret == -2) goto tls_write_error;
1257 2 0 if (c->sendfile_remain > 0 || c->tls_wbuf.off > 0)
0 2 if (c->sendfile_remain > 0 || c->tls_wbuf.off > 0)
1263 0 60 if ((!c->wbuf_rinq || (c->cached_wbuf_low_water > 0
0 0 if ((!c->wbuf_rinq || (c->cached_wbuf_low_water > 0
1264 0 0 && c->wbuf_len <= c->cached_wbuf_low_water))
1265 60 0 && c->sendfile_fd < 0 && c->tls_wbuf.off == 0) {
60 0 && c->sendfile_fd < 0 && c->tls_wbuf.off == 0) {
1266 10 50 if (c->responding == RESPOND_SHUTDOWN || c->responding == RESPOND_NORMAL) {
0 10 if (c->responding == RESPOND_SHUTDOWN || c->responding == RESPOND_NORMAL) {
1268 10 0 } else if (c->responding == RESPOND_STREAMING && c->poll_write_cb) {
10 0 } else if (c->responding == RESPOND_STREAMING && c->poll_write_cb) {
1269 0 10 if (c->poll_write_cb_is_io_handle)
1273 0 0 } else if (c->responding == RESPOND_STREAMING) {
1276 0 0 } else if (c->responding == RESPOND_NOT_STARTED) {
1299 23 0 if (!c->tls || len == 0) return 0;
0 23 if (!c->tls || len == 0) return 0;
1304 0 23 if (ret != 0) {
1309 23 0 if (encbuf.off > 0) {
1310 0 23 if (tls_wbuf_append(&c->tls_wbuf, encbuf.base, encbuf.off) != 0) {