]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: http: don't call ist_find_http_ctl() before up http_header_has_forbidden_char()
authorWilly Tarreau <w@1wt.eu>
Wed, 4 Nov 2026 10:59:00 +0000 (11:59 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 4 Nov 2026 21:45:33 +0000 (22:45 +0100)
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.

src/h2.c
src/h3.c
src/http_htx.c

index cf911302f59ce706e2be20c4ca1a3a234bb0993d..926cb53a1dd228438a54532e80857640628049c9 100644 (file)
--- 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) {
index 226d1a8b416c73d4939b9eb3170694cca7ca5d00..e4ba9eb0b99f82612682772e5eab3e19fe977761 100644 (file)
--- 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;
        }
index 99f21157818702951516d69be1ddbe137491a4f1..163508340bc3bd5024ff3544565c4c6787b7a8cc 100644 (file)
@@ -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;
                }