OSSL_HTTP_proxy_connect(): Fix glitch in response HTTP header parsing
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>
Sun, 21 Nov 2021 10:51:09 +0000 (11:51 +0100)
committerDr. David von Oheimb <dev@ddvo.net>
Mon, 13 Dec 2021 11:13:30 +0000 (12:13 +0100)
Fixes #17247

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17250)

crypto/http/http_client.c

index a85bfcec42dc8f35f7d16d66b56bbf8ad6fcc666..b4d42f2eb0b9e4e7d5869dca3112ba1fb95040f6 100644 (file)
@@ -1317,7 +1317,7 @@ int OSSL_HTTP_proxy_connect(BIO *bio, const char *server, const char *port,
 
         /* Check for HTTP/1.x */
         mbufp = mbuf;
-        if (!HAS_PREFIX(mbufp, HTTP_PREFIX)) {
+        if (!CHECK_AND_SKIP_PREFIX(mbufp, HTTP_PREFIX)) {
             ERR_raise(ERR_LIB_HTTP, HTTP_R_HEADER_PARSE_ERROR);
             BIO_printf(bio_err, "%s: HTTP CONNECT failed, non-HTTP response\n",
                        prog);
@@ -1335,6 +1335,8 @@ int OSSL_HTTP_proxy_connect(BIO *bio, const char *server, const char *port,
 
         /* RFC 7231 4.3.6: any 2xx status code is valid */
         if (!HAS_PREFIX(mbufp, " 2")) {
+            if (ossl_isspace(*mbufp))
+                mbufp++;
             /* chop any trailing whitespace */
             while (read_len > 0 && ossl_isspace(mbuf[read_len - 1]))
                 read_len--;