From: Willy Tarreau Date: Wed, 4 Nov 2026 10:59:00 +0000 (+0100) Subject: MINOR: http: don't call ist_find_http_ctl() before up http_header_has_forbidden_char() X-Git-Tag: v3.5-dev11~10 X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=1665f7f9cefbf5efdef74808073abd8c618f6b54;p=haproxy.git MINOR: http: don't call ist_find_http_ctl() before up http_header_has_forbidden_char() Now that the function was sped up to skip non-offending bytes, we don't need ist_find_ctl() anymore. And since it would block us from finding certain chars, let's now get rid of it. --- diff --git a/src/h2.c b/src/h2.c index cf911302f..926cb53a1 100644 --- a/src/h2.c +++ b/src/h2.c @@ -367,8 +367,7 @@ int h2_make_htx_request(struct http_hdr *list, struct htx *htx, unsigned int *ms if (unlikely(ctl) && http_path_has_forbidden_char(list[idx].v, ctl)) goto fail; } else { - ctl = ist_find_http_ctl(list[idx].v); - if (unlikely(ctl) && http_header_has_forbidden_char(list[idx].v, ctl)) + if (http_header_has_forbidden_char(list[idx].v, istptr(list[idx].v))) goto fail; } @@ -682,7 +681,6 @@ int h2_make_htx_response(struct http_hdr *list, struct htx *htx, unsigned int *m int i; struct htx_sl *sl = NULL; unsigned int sl_flags = 0; - const char *ctl; struct ist v; fields = 0; @@ -712,8 +710,7 @@ int h2_make_htx_response(struct http_hdr *list, struct htx *htx, unsigned int *m /* RFC7540#10.3: intermediaries forwarding to HTTP/1 must take care of * rejecting NUL, CR and LF characters. */ - ctl = ist_find_http_ctl(list[idx].v); - if (unlikely(ctl) && http_header_has_forbidden_char(list[idx].v, ctl)) + if (unlikely(http_header_has_forbidden_char(list[idx].v, istptr(list[idx].v)))) goto fail; if (phdr > 0 && phdr < H2_PHDR_NUM_ENTRIES) { diff --git a/src/h3.c b/src/h3.c index 226d1a8b4..e4ba9eb0b 100644 --- a/src/h3.c +++ b/src/h3.c @@ -566,8 +566,7 @@ static int h3_set_authority(struct qcs *qcs, struct ist *auth, const struct ist static int _h3_handle_phdr(struct qcs *qcs, const struct http_hdr *h) { /* look for forbidden control characters in the pseudo-header value */ - const char *ctl = ist_find_http_ctl(h->v); - if (unlikely(ctl) && http_header_has_forbidden_char(h->v, ctl)) { + if (unlikely(http_header_has_forbidden_char(h->v, istptr(h->v)))) { TRACE_ERROR("control character present in pseudo-header value", H3_EV_RX_FRAME|H3_EV_RX_HDR, qcs->qcc->conn, qcs); goto err; } @@ -583,7 +582,6 @@ static int _h3_handle_hdr(struct qcs *qcs, const struct http_hdr *hdr) { const struct ist name = hdr->n; const struct ist value = hdr->v; - const char *ctl; int i; if (isteq(name, ist(""))) @@ -617,8 +615,7 @@ static int _h3_handle_hdr(struct qcs *qcs, const struct http_hdr *hdr) */ /* look for forbidden control characters in the header value */ - ctl = ist_find_http_ctl(value); - if (unlikely(ctl) && http_header_has_forbidden_char(value, ctl)) { + if (unlikely(http_header_has_forbidden_char(value, istptr(value)))) { TRACE_ERROR("control character present in header value", H3_EV_RX_FRAME|H3_EV_RX_HDR, qcs->qcc->conn, qcs); goto err; } diff --git a/src/http_htx.c b/src/http_htx.c index 99f211578..163508340 100644 --- a/src/http_htx.c +++ b/src/http_htx.c @@ -1993,7 +1993,6 @@ enum http_parser_status http_trailers_to_htx(struct http_hdr *list, struct htx * { uint32_t data_ofs = htx->data; /* used to rollback on error */ enum http_parser_status ret = HTTP_PRS_SUCCESS; - const char *ctl; struct ist v; uint32_t idx; int i; @@ -2068,8 +2067,7 @@ enum http_parser_status http_trailers_to_htx(struct http_hdr *list, struct htx * * response that contains a character not permitted in a field * value MUST be treated as malformed */ - ctl = ist_find_http_ctl(list[idx].v); - if (unlikely(ctl) && http_header_has_forbidden_char(list[idx].v, ctl)) { + if (unlikely(http_header_has_forbidden_char(list[idx].v, istptr(list[idx].v)))) { ret = HTTP_PRS_INV_HVAL; goto fail; }