]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
mod_proxy_http: single point of failure in ap_proxy_http_process_response().
authorYann Ylavic <ylavic@apache.org>
Sun, 10 May 2020 20:52:30 +0000 (20:52 +0000)
committerYann Ylavic <ylavic@apache.org>
Sun, 10 May 2020 20:52:30 +0000 (20:52 +0000)
No functional change (intended).

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1877557 13f79535-47bb-0310-9956-ffa450edef68

modules/proxy/mod_proxy_http.c

index 71c05e89982bbc3eda661b141ee3dd5d630195a7..989c47d7c5391852850c1b9cc3c1e29b809f7038 100644 (file)
@@ -1264,8 +1264,9 @@ int ap_proxy_http_process_response(proxy_http_req_t *req)
                 apr_table_setn(r->notes, "proxy_timedout", "1");
                 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01103) "read timeout");
                 if (do_100_continue) {
-                    proxy_run_detach_backend(r, backend);
-                    return ap_proxyerror(r, HTTP_SERVICE_UNAVAILABLE, "Timeout on 100-Continue");
+                    proxy_status = ap_proxyerror(r, HTTP_SERVICE_UNAVAILABLE,
+                                                 "Timeout on 100-Continue");
+                    goto cleanup;
                 }
             }
             /*
@@ -1297,19 +1298,19 @@ int ap_proxy_http_process_response(proxy_http_req_t *req)
                 /* Mark the backend connection for closing */
                 backend->close = 1;
                 /* Need to return OK to avoid sending an error message */
-                proxy_run_detach_backend(r, backend);
-                return OK;
+                proxy_status = OK;
+                goto cleanup;
             }
-            else if (!c->keepalives) {
-                     ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01105)
-                                   "NOT Closing connection to client"
-                                   " although reading from backend server %s:%d"
-                                   " failed.",
-                                   backend->hostname, backend->port);
+            if (!c->keepalives) {
+                ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01105)
+                              "NOT Closing connection to client"
+                              " although reading from backend server %s:%d"
+                              " failed.",
+                              backend->hostname, backend->port);
             }
-            proxy_run_detach_backend(r, backend);
-            return ap_proxyerror(r, HTTP_GATEWAY_TIME_OUT,
-                                 "Error reading from remote server");
+            proxy_status = ap_proxyerror(r, HTTP_GATEWAY_TIME_OUT,
+                                         "Error reading from remote server");
+            goto cleanup;
         }
         /* XXX: Is this a real headers length send from remote? */
         backend->worker->s->read += len;
@@ -1325,10 +1326,11 @@ int ap_proxy_http_process_response(proxy_http_req_t *req)
              * if the status line was > 8192 bytes
              */
             if ((major != 1) || (len >= response_field_size - 1)) {
-                proxy_run_detach_backend(r, backend);
-                return ap_proxyerror(r, HTTP_BAD_GATEWAY,
-                apr_pstrcat(p, "Corrupt status line returned by remote "
-                            "server: ", buffer, NULL));
+                proxy_status = ap_proxyerror(r, HTTP_BAD_GATEWAY,
+                                   apr_pstrcat(p, "Corrupt status line "
+                                               "returned by remote server: ",
+                                               buffer, NULL));
+                goto cleanup;
             }
             backasswards = 0;
 
@@ -1384,8 +1386,8 @@ int ap_proxy_http_process_response(proxy_http_req_t *req)
                 r->headers_out = apr_table_make(r->pool,1);
                 r->status = HTTP_BAD_GATEWAY;
                 r->status_line = "bad gateway";
-                proxy_run_detach_backend(r, backend);
-                return r->status;
+                proxy_status = r->status;
+                goto cleanup;
             }
 
             /* Now, add in the just read cookies */
@@ -1431,9 +1433,9 @@ int ap_proxy_http_process_response(proxy_http_req_t *req)
             if (toclose) {
                 backend->close = 1;
                 if (toclose < 0) {
-                    proxy_run_detach_backend(r, backend);
-                    return ap_proxyerror(r, HTTP_BAD_GATEWAY,
-                                         "Malformed connection header");
+                    proxy_status = ap_proxyerror(r, HTTP_BAD_GATEWAY,
+                                                 "Malformed connection header");
+                    goto cleanup;
                 }
             }
 
@@ -1598,8 +1600,8 @@ int ap_proxy_http_process_response(proxy_http_req_t *req)
                             c->remote_host ? c->remote_host : "",
                             status);
                     backend->close = 1;
-                    proxy_run_detach_backend(r, backend);
-                    return status;
+                    proxy_status = status;
+                    goto cleanup;
                 }
             }
             else {
@@ -1664,13 +1666,12 @@ int ap_proxy_http_process_response(proxy_http_req_t *req)
                 }
                 ap_discard_request_body(backend->r);
             }
-            proxy_run_detach_backend(r, backend);
             /*
              * prevent proxy_handler() from treating this as an
              * internal error.
              */
             apr_table_setn(r->notes, "proxy-error-override", "1");
-            return proxy_status;
+            goto cleanup;
         }
 
         r->sent_bodyct = 1;
@@ -1929,6 +1930,10 @@ int ap_proxy_http_process_response(proxy_http_req_t *req)
     }
 
     return OK;
+
+cleanup:
+    proxy_run_detach_backend(r, backend);
+    return proxy_status;
 }
 
 static