Branch Coverage

feersum_tls.c.inc
Criterion Covered Total %
branch 173 470 36.8


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 struct feer_listen *lsnr = c ? c->listener : NULL;
58 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 (int i = 0; i < lsnr->n_sni_entries; i++) {
143 3 154 if (ret != 0) {
152 2 152 if (!fp) {
160 0 152 if (!pkey) {
167 0 152 if (ptls_openssl_init_sign_certificate(sign_cert, pkey) != 0) {
177 0 152 if (h2)
196 0 156 if (!ctx) return;
197 156 0 if (ctx->certificates.list) {
199 153 156 for (i = 0; i < ctx->certificates.count; i++)
204 151 5 if (ctx->sign_certificate) {
232 151 64 if (--ref->refcount <= 0) {
244 85 147 if (lsnr->tls_ctx_ref) {
248 3 232 for (int i = 0; i < lsnr->n_sni_entries; i++) {
262 0 68 if (unlikely(!c->tls)) {
282 63 587 if (c->tls) {
286 63 587 if (c->tls_ctx_ref) {
291 0 650 if (c->tls_rbuf) {
296 9 641 if (c->tls_tunnel) {
300 9 0 if (c->tls_tunnel_sv0 >= 0) {
304 0 9 if (c->tls_tunnel_sv1 >= 0) {
308 0 9 if (c->tls_tunnel_wbuf) {
324 0 140 if (c->tls_wbuf.off == 0)
328 0 140 if (written < 0) {
329 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) {
336 0 140 if ((size_t)written < c->tls_wbuf.off) {
372 0 13 if (c->tls_tunnel_sv0 < 0) return -1;
375 13 0 if (nw == (ssize_t)len)
378 0 0 if (nw < 0) {
379 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)
385 0 0 if (!c->tls_tunnel_wbuf) {
390 0 0 if (c->tls_tunnel_wbuf_pos > 0) {
392 0 0 if (remain > 0)
400 0 0 if (SvCUR(c->tls_tunnel_wbuf) + remaining > FEER_TUNNEL_MAX_WBUF) {
406 0 0 if (!ev_is_active(&c->tls_tunnel_write_w))
416 13 0 while (c->tls_tunnel && c->tls_rbuf_len > 0) {
0 13 while (c->tls_tunnel && c->tls_rbuf_len > 0) {
417 0 0 if (ev_is_active(&c->tls_tunnel_write_w))
421 0 0 if (drain_rv < 0) break;
422 0 0 if (drain_rv == 1) continue; /* non-data (e.g. KeyUpdate) */
423 0 0 if (tls_tunnel_write_or_buffer(c, (const char *)db.base, db.off) < 0) {
446 2 21 if (nread == 0) {
451 0 21 if (nread < 0) {
452 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)
459 0 21 if (feer_tls_send(c, buf, nread) != 0) {
466 0 21 if (flush_ret == -2) {
470 21 0 if (c->tls_wbuf.off > 0)
488 0 0 if (!c->tls_tunnel_wbuf ||
489 0 0 SvCUR(c->tls_tunnel_wbuf) <= c->tls_tunnel_wbuf_pos) {
491 0 0 if (c->tls_tunnel_wbuf) {
502 0 0 if (nw < 0) {
503 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)
510 0 0 if (c->tls_tunnel_wbuf_pos >= SvCUR(c->tls_tunnel_wbuf)) {
516 0 0 if (c->tls_rbuf_len > 0)
530 0 9 if (c->tls_tunnel) return;
533 0 9 if (feer_socketpair_nb(sv) < 0) {
554 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) {
556 0 0 if (tls_tunnel_write_or_buffer(c, SvPVX(c->rbuf), SvCUR(c->rbuf)) < 0) {
591 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;
601 0 0 if (ret == 0 && consumed < saved_len)
0 0 if (ret == 0 && consumed < saved_len)
605 0 0 if (ret != 0) {
609 0 0 if (decbuf->off == 0) {
657 1 347 if (unlikely(c->pipelined)) goto tls_pipelined;
659 0 347 if (unlikely(!c->tls)) {
670 7 340 if (nread == 0) {
679 0 340 if (nread < 0) {
680 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)
693 152 188 if (unlikely(c->receiving == RECEIVE_PROXY_HEADER)) {
694 23 129 if (!c->rbuf) {
700 4 148 if (ret == -1) {
705 129 19 if (ret == -2) goto tls_read_cleanup; /* need more data */
711 0 19 feer_clear_remote_cache(c);
0 19 feer_clear_remote_cache(c);
715 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);
773 0 55 if (flush_ret == -2) {
776 0 0 if (merged) Safefree(merged);
781 55 0 if (flush_ret == -1 || c->tls_wbuf.off > 0) {
0 55 if (flush_ret == -1 || c->tls_wbuf.off > 0) {
788 51 13 if (ret == 0) {
795 0 51 if (proto && strcmp(proto, "h2") == 0) {
805 0 51 if (consumed < inlen) {
848 0 0 if (dec_ret != 0) {
850 0 0 if (merged) Safefree(merged);
855 0 0 if (dec_consumed < remaining)
857 0 0 if (decbuf.off > 0) {
859 0 0 if (!c->rbuf) {
867 0 0 if (parse_ret == -1) {
870 0 0 if (merged) Safefree(merged);
873 0 0 if (parse_ret > 0) {
874 0 0 if (!process_request_headers(c, parse_ret))
881 0 0 if (c->tls_rbuf_len > 0) {
883 0 0 while (c->tls_rbuf_len > 0) {
885 0 0 if (drain_rv < 0) break;
886 0 0 if (drain_rv == 1) continue;
890 0 0 if (parse_ret == -2) {
894 0 0 if (pr == -1) {
899 0 0 if (pr > 0) {
900 0 0 if (!process_request_headers(c, pr))
909 0 0 if (parse_ret > 0 && c->receiving == RECEIVE_BODY) {
0 0 if (parse_ret > 0 && c->receiving == RECEIVE_BODY) {
911 0 0 if (c->expected_cl > 0
912 0 0 && c->received_cl >= c->expected_cl) {
917 0 0 else if (parse_ret > 0 && c->receiving == RECEIVE_CHUNKED) {
0 0 else if (parse_ret > 0 && c->receiving == RECEIVE_CHUNKED) {
923 0 0 if (cret == -1) {
927 0 0 else if (cret == 0) {
938 9 4 } else if (ret == PTLS_ERROR_IN_PROGRESS) {
942 0 9 if (consumed < inlen)
950 0 64 if (merged) Safefree(merged);
962 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) {
976 51 73 if (decbuf.off == 0) {
998 13 60 if (c->tls_tunnel) {
999 0 13 if (tls_tunnel_write_or_buffer(c, (const char *)decbuf.base, decbuf.off) < 0) {
1017 51 9 if (!c->rbuf) {
1027 0 60 while ((drain_rv = feer_tls_drain_one_record(c, &db)) >= 0) {
1028 0 0 if (drain_rv == 1) continue; /* non-data TLS record */
1043 8 53 if (c->receiving == RECEIVE_WAIT)
1046 59 2 if (likely(c->receiving <= RECEIVE_HEADERS)) {
1048 0 59 if (parse_ret == -1) {
1053 0 59 if (parse_ret == -2) {
1058 57 2 if (!process_request_headers(c, parse_ret))
1061 2 0 else if (likely(c->receiving == RECEIVE_BODY)) {
1063 2 0 if (c->received_cl >= c->expected_cl) {
1068 0 0 else if (c->receiving == RECEIVE_CHUNKED) {
1070 0 0 if (ret == -1) {
1074 0 0 else if (ret == 0) {
1080 0 0 else if (c->receiving == RECEIVE_STREAMING) {
1082 0 0 if (c->poll_read_cb) {
1085 0 0 if (c->receiving >= RECEIVE_SHUTDOWN) {
1089 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)
1114 0 60 if (unlikely(!c->tls)) {
1121 0 60 if (c->tls_wbuf.off > 0) {
1123 0 0 if (flush_ret == -1) goto tls_write_cleanup; /* EAGAIN, keep write watcher active */
1124 0 0 if (flush_ret == -2) goto tls_write_error;
1126 0 0 if (c->tls_wbuf.off > 0) goto tls_write_cleanup;
1150 60 0 if (c->wbuf_rinq && c->cached_wbuf_low_water > 0
1 59 if (c->wbuf_rinq && c->cached_wbuf_low_water > 0
1151 1 0 && c->wbuf_len <= c->cached_wbuf_low_water
1152 1 0 && c->responding == RESPOND_STREAMING && c->poll_write_cb) {
1 0 && c->responding == RESPOND_STREAMING && c->poll_write_cb) {
1153 0 1 if (c->poll_write_cb_is_io_handle)
1160 60 0 if (c->wbuf_rinq) {
1162 63 60 while ((m = (struct iomatrix *)rinq_shift(&c->wbuf_rinq)) != NULL) {
1164 65 63 for (i = 0; i < m->count; i++) {
1165 0 65 if (m->iov[i].iov_len == 0) continue;
1173 0 65 if (ret != 0) {
1178 0 0 for (j = 0; j < m->count; j++) SvREFCNT_dec(m->sv[j]);
1179 0 0 IOMATRIX_FREE(m);
1182 65 0 if (encbuf.off > 0) {
1183 0 65 if (tls_wbuf_append(&c->tls_wbuf, encbuf.base, encbuf.off) != 0) {
1187 0 0 for (j = 0; j < m->count; j++) SvREFCNT_dec(m->sv[j]);
1188 0 0 IOMATRIX_FREE(m);
1196 65 63 for (i = 0; i < m->count; i++) SvREFCNT_dec(m->sv[i]);
1197 63 0 IOMATRIX_FREE(m);
1200 4 59 if (c->cached_wbuf_low_water > 0
1201 4 0 && c->wbuf_len <= c->cached_wbuf_low_water
1202 3 1 && c->responding == RESPOND_STREAMING && c->poll_write_cb) {
3 0 && c->responding == RESPOND_STREAMING && c->poll_write_cb) {
1203 0 3 if (c->poll_write_cb_is_io_handle)
1213 0 60 if (flush_ret == -1) goto tls_write_cleanup; /* EAGAIN */
1214 0 60 if (flush_ret == -2) goto tls_write_error;
1215 60 0 if (flush_ret > 0) restart_write_timer(c);
1219 2 58 if (c->sendfile_fd >= 0 && c->sendfile_remain > 0) {
0 2 if (c->sendfile_fd >= 0 && c->sendfile_remain > 0) {
1222 0 2 if (to_read > sizeof(filebuf)) to_read = sizeof(filebuf);
1225 0 2 if (file_nread < 0) {
1226 0 0 if (errno == EINTR)
1229 0 0 CLOSE_SENDFILE_FD(c);
0 0 CLOSE_SENDFILE_FD(c);
1236 0 2 if (file_nread == 0) {
1237 0 0 CLOSE_SENDFILE_FD(c);
0 0 CLOSE_SENDFILE_FD(c);
1246 0 2 if (ret != 0) {
1249 0 0 CLOSE_SENDFILE_FD(c);
0 0 CLOSE_SENDFILE_FD(c);
1254 2 0 if (encbuf.off > 0) {
1255 0 2 if (tls_wbuf_append(&c->tls_wbuf, encbuf.base, encbuf.off) != 0) {
1258 0 0 CLOSE_SENDFILE_FD(c);
0 0 CLOSE_SENDFILE_FD(c);
1267 2 0 if (c->sendfile_remain == 0) {
1268 2 0 CLOSE_SENDFILE_FD(c);
0 2 CLOSE_SENDFILE_FD(c);
1275 0 2 if (sf_flush_ret == -1) goto tls_write_cleanup; /* EAGAIN */
1276 0 2 if (sf_flush_ret == -2) goto tls_write_error;
1278 2 0 if (c->sendfile_remain > 0 || c->tls_wbuf.off > 0)
0 2 if (c->sendfile_remain > 0 || c->tls_wbuf.off > 0)
1284 0 60 if ((!c->wbuf_rinq || (c->cached_wbuf_low_water > 0
0 0 if ((!c->wbuf_rinq || (c->cached_wbuf_low_water > 0
1285 0 0 && c->wbuf_len <= c->cached_wbuf_low_water))
1286 60 0 && c->sendfile_fd < 0 && c->tls_wbuf.off == 0) {
60 0 && c->sendfile_fd < 0 && c->tls_wbuf.off == 0) {
1287 10 50 if (c->responding == RESPOND_SHUTDOWN || c->responding == RESPOND_NORMAL) {
0 10 if (c->responding == RESPOND_SHUTDOWN || c->responding == RESPOND_NORMAL) {
1289 10 0 } else if (c->responding == RESPOND_STREAMING && c->poll_write_cb) {
10 0 } else if (c->responding == RESPOND_STREAMING && c->poll_write_cb) {
1290 0 10 if (c->poll_write_cb_is_io_handle)
1294 0 0 } else if (c->responding == RESPOND_STREAMING) {
1297 0 0 } else if (c->responding == RESPOND_NOT_STARTED) {
1320 23 0 if (!c->tls || len == 0) return 0;
0 23 if (!c->tls || len == 0) return 0;
1325 0 23 if (ret != 0) {
1330 23 0 if (encbuf.off > 0) {
1331 0 23 if (tls_wbuf_append(&c->tls_wbuf, encbuf.base, encbuf.off) != 0) {