From: Christopher Faulet Date: Thu, 3 Dec 2026 14:32:39 +0000 (+0100) Subject: BUG/MINOR: h1: reject a short status code without reason phrase X-Git-Url: https://git.kaiwu.me/web/http/static/%7Bsubstring-before(@doc,%20'.xml')%7D.html?a=commitdiff_plain;h=a1f0fae525d815a614d2fc07c4520e15dc47cab7;p=haproxy.git BUG/MINOR: h1: reject a short status code without reason phrase Since the commit 8a47f9028 ("MEDIUM: http: add the "short-status-code" violation exception"), status codes shorter than 3 digits are rejected by default. But the check was only performed when the status code was followed by a space. When it was directly followed by the end of line, without reason phrase, the status code was still accepted. For instance, "HTTP/1.1 20\r\n" was accepted while "HTTP/1.1 20 OK\r\n" was rejected. Now the status code length is checked in both cases. This patch must be backported to 3.5, and with the commit above if it is backported further. --- diff --git a/src/h1.c b/src/h1.c index 563a1b773..cce2c3580 100644 --- a/src/h1.c +++ b/src/h1.c @@ -778,23 +778,22 @@ int h1_headers_to_hdr_list(char *start, const char *stop, goto http_msg_invalid; } - if (likely(HTTP_IS_SPHT(*ptr))) { - sl.st.c.len = ptr - sl.st.c.ptr; - if (sl.st.c.len < 3) { - /* less than 3 digits */ - if (h1m->err_pos < -1 || !(global.acc_hres_vio & (1U << HTTP_VIO_STATUS_SHORT))) { - state = H1_MSG_RPCODE; - goto http_msg_invalid; - } else if (h1m->err_pos == -1) { - /* only capture the error pointer */ - h1m->err_pos = ptr - start + skip; - } + sl.st.c.len = ptr - sl.st.c.ptr; + if (sl.st.c.len < 3) { + /* less than 3 digits */ + if (h1m->err_pos < -1 || !(global.acc_hres_vio & (1U << HTTP_VIO_STATUS_SHORT))) { + state = H1_MSG_RPCODE; + goto http_msg_invalid; + } else if (h1m->err_pos == -1) { + /* only capture the error pointer */ + h1m->err_pos = ptr - start + skip; } - EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_rpcode_sp, http_msg_ood, state, H1_MSG_RPCODE_SP); } + if (likely(HTTP_IS_SPHT(*ptr))) + EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_rpcode_sp, http_msg_ood, state, H1_MSG_RPCODE_SP); + /* so it's a CR/LF, so there is no reason phrase */ - sl.st.c.len = ptr - sl.st.c.ptr; http_msg_rsp_reason: sl.st.r = ist2(ptr, 0);