]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: ocsp: fix NULL dereference when the OCSP responder sends no header
authorRemi Tricot-Le Breton <rlebreton@haproxy.com>
Thu, 19 Nov 2026 15:44:03 +0000 (16:44 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 20 Nov 2026 11:36:57 +0000 (12:36 +0100)
Both OCSP response handlers look for a "Content-Type" header in the
response received from the responder by iterating over hc->res.hdrs
until they reach the end-of-array marker. But this array is only
allocated when the response contains at least one header so the array
may be NULL.

This is reachable in production as soon as the OCSP auto-update is
enabled. Any responder which answers with a header-less HTTP/1.0
response (a plain error page, a minimal embedded server, a proxy that
strips the headers) crashes the worker. The same issue applies to the
client-certificate OCSP check used by the "do-ocsp-request" action,
where the request is sent to the URI found in the client certificate.

This patch must be backported to 3.3.

src/ssl_ocsp.c

index e7355835aa06b980e69ea783f00f78573b550fc2..d16b37c34d2120818b3e96db4b14783361831eae 100644 (file)
@@ -1333,7 +1333,7 @@ static struct task *ssl_ocsp_update_responses(struct task *task, void *context,
                        int found = 0;
                        /* Look for "Content-Type" header which should have
                         * "application/ocsp-response" value. */
-                       for (hdr = hc->res.hdrs; isttest(hdr->v); hdr++) {
+                       for (hdr = hc->res.hdrs; hdr && isttest(hdr->n); hdr++) {
                                if (isteqi(hdr->n, ist("Content-Type")) &&
                                    isteqi(hdr->v, ist("application/ocsp-response"))) {
                                        found = 1;
@@ -1942,7 +1942,7 @@ int ssl_ocsp_check_ocsp_response(struct ocsp_clt_check_ctx *ctx)
 
        /* Look for "Content-Type" header which should have
         * "application/ocsp-response" value. */
-       for (hdr = hc->res.hdrs; isttest(hdr->v); hdr++) {
+       for (hdr = hc->res.hdrs; hdr && isttest(hdr->n); hdr++) {
                if (isteqi(hdr->n, ist("Content-Type")) &&
                    isteqi(hdr->v, ist("application/ocsp-response"))) {
                        found = 1;