]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
OSSL_HTTP_REQ_CTX_nbio(): Fix parsing of responses with status code != 200
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>
Tue, 30 Nov 2021 15:44:59 +0000 (16:44 +0100)
committerDr. David von Oheimb <dev@ddvo.net>
Fri, 3 Dec 2021 11:21:12 +0000 (12:21 +0100)
This way keep-alive is not (needlessly) cancelled on error.

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

crypto/http/http_client.c

index 0e47dbbd926f0e4ae78f44e308e1c03f274f458c..45e92cd7fd3bfe4e875bd8268440e2af53558feb 100644 (file)
@@ -624,7 +624,7 @@ int OSSL_HTTP_REQ_CTX_nbio(OSSL_HTTP_REQ_CTX *rctx)
                 /* fall through */
             default:
                 rctx->state = OHS_ERROR;
-                return 0;
+                goto next_line;
             }
         }
         key = (char *)rctx->buf;
@@ -683,11 +683,6 @@ int OSSL_HTTP_REQ_CTX_nbio(OSSL_HTTP_REQ_CTX *rctx)
         if (*p != '\0') /* not end of headers */
             goto next_line;
 
-        if (rctx->expected_ct != NULL && !found_expected_ct) {
-            ERR_raise_data(ERR_LIB_HTTP, HTTP_R_MISSING_CONTENT_TYPE,
-                           "expected=%s", rctx->expected_ct);
-            return 0;
-        }
         if (rctx->keep_alive != 0 /* do not let server initiate keep_alive */
                 && !found_keep_alive /* otherwise there is no change */) {
             if (rctx->keep_alive == 2) {
@@ -698,6 +693,14 @@ int OSSL_HTTP_REQ_CTX_nbio(OSSL_HTTP_REQ_CTX *rctx)
             rctx->keep_alive = 0;
         }
 
+        if (rctx->state == OHS_ERROR)
+            return 0;
+
+        if (rctx->expected_ct != NULL && !found_expected_ct) {
+            ERR_raise_data(ERR_LIB_HTTP, HTTP_R_MISSING_CONTENT_TYPE,
+                           "expected=%s", rctx->expected_ct);
+            return 0;
+        }
         if (rctx->state == OHS_REDIRECT) {
             /* http status code indicated redirect but there was no Location */
             ERR_raise(ERR_LIB_HTTP, HTTP_R_MISSING_REDIRECT_LOCATION);