]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Backport:
authorGraham Leggett <minfrin@apache.org>
Sun, 26 Sep 2021 14:11:22 +0000 (14:11 +0000)
committerGraham Leggett <minfrin@apache.org>
Sun, 26 Sep 2021 14:11:22 +0000 (14:11 +0000)
*) core: Add ap_pre_connection() as a wrapper to ap_run_pre_connection()
   and use it to prevent that failures in running the pre_connection
   hook cause crashes afterwards.
   Trunk version of patch:
      https://svn.apache.org/r1893497
      https://svn.apache.org/r1893507
   Backport version for 2.4.x of patch:
     https://patch-diff.githubusercontent.com/raw/apache/httpd/pull/269.diff
   Can be applied via apply_backport_pr.sh 269.
   +1: rpluem, icing, ylavic

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1893654 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
STATUS
include/ap_mmn.h
include/http_connection.h
server/connection.c
server/core.c
server/mpm/event/event.c

diff --git a/CHANGES b/CHANGES
index 33fab408c4779610a5532981d600123b5c1463df..90b82c23599dd7243b5e6658fe250cc28945432d 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,10 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache 2.4.50
 
+  *) core: Add ap_pre_connection() as a wrapper to ap_run_pre_connection()
+     and use it to prevent that failures in running the pre_connection
+     hook cause crashes afterwards. [Ruediger Pluem]
+
   *) mod_speling: Add CheckBasenameMatch PR 44221.  [Christophe Jaillet]
 
 Changes with Apache 2.4.49
diff --git a/STATUS b/STATUS
index a7d184de6f5c08490f46e0cfbc5bc1bc758d7ea5..1d1e2830ebbd6ab2862f3fb32e0794526165634c 100644 (file)
--- a/STATUS
+++ b/STATUS
@@ -142,17 +142,6 @@ RELEASE SHOWSTOPPERS:
 PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
   [ start all new proposals below, under PATCHES PROPOSED. ]
 
-  *) core: Add ap_pre_connection() as a wrapper to ap_run_pre_connection()
-     and use it to prevent that failures in running the pre_connection
-     hook cause crashes afterwards.
-     Trunk version of patch:
-        https://svn.apache.org/r1893497
-        https://svn.apache.org/r1893507
-     Backport version for 2.4.x of patch:
-       https://patch-diff.githubusercontent.com/raw/apache/httpd/pull/269.diff
-     Can be applied via apply_backport_pr.sh 269.
-     +1: rpluem, icing, ylavic
-
   *) core: do not install core input/output filters on secondary
      connections.
      Trunk version of patch:
index f874f96f2dfad0b52d6d0089c0caa1175b60d366..52876f843f27e43ff9cdfff250e6ab44ad476ce5 100644 (file)
  * 20120211.115 (2.4.49-dev) Add ap_proxy_get_worker_ex() and
  *                           ap_proxy_define_worker_ex() to mod_proxy.h
  * 20120211.116 (2.4.49-dev) add conn_rec->outgoing and ap_ssl_bind_outgoing()
+ * 20120211.117 (2.4.50-dev) Add ap_pre_connection
  */
 
 #define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */
 #ifndef MODULE_MAGIC_NUMBER_MAJOR
 #define MODULE_MAGIC_NUMBER_MAJOR 20120211
 #endif
-#define MODULE_MAGIC_NUMBER_MINOR 116                 /* 0...n */
+#define MODULE_MAGIC_NUMBER_MINOR 117                 /* 0...n */
 
 /**
  * Determine if the server's current MODULE_MAGIC_NUMBER is at least a
index 8bc009da3b7fb9f22854d141d9ad5ce24ce19a89..71f02bdd14b71d88f31324a420afcb963ccd769f 100644 (file)
@@ -135,6 +135,21 @@ AP_DECLARE_HOOK(int,process_connection,(conn_rec *c))
  */
 AP_DECLARE_HOOK(int,pre_close_connection,(conn_rec *c))
 
+/**
+ * This is a wrapper around ap_run_pre_connection. In case that
+ * ap_run_pre_connection returns an error it marks the connection as
+ * aborted and ensures that the basic connection setup normally done
+ * by the core module is done in case it was not done so far.
+ * @param c The connection on which the request has been received.
+ *          Same as for the pre_connection hook.
+ * @param csd The mechanism on which this connection is to be read.
+ *            Most times this will be a socket, but it is up to the module
+ *            that accepts the request to determine the exact type.
+ *            Same as for the pre_connection hook.
+ * @return The result of ap_run_pre_connection
+ */
+AP_DECLARE(int) ap_pre_connection(conn_rec *c, void *csd);
+
 /** End Of Connection (EOC) bucket */
 AP_DECLARE_DATA extern const apr_bucket_type_t ap_bucket_type_eoc;
 
index b0093e16c9d053b570f33e4eccc1206f83674fd3..03ecd90107c73dca49265819e03d9024ef57af02 100644 (file)
@@ -202,13 +202,9 @@ AP_DECLARE(void) ap_lingering_close(conn_rec *c)
 
 AP_CORE_DECLARE(void) ap_process_connection(conn_rec *c, void *csd)
 {
-    int rc;
     ap_update_vhost_given_ip(c);
 
-    rc = ap_run_pre_connection(c, csd);
-    if (rc != OK && rc != DONE) {
-        c->aborted = 1;
-    }
+    ap_pre_connection(c, csd);
 
     if (!c->aborted) {
         ap_run_process_connection(c);
index 15645210762485cdd43ff57874973b7a897cf4db..f30e23715cb40abb6674dc4f10173294be37f2f4 100644 (file)
@@ -5300,6 +5300,31 @@ static int core_pre_connection(conn_rec *c, void *csd)
     return DONE;
 }
 
+AP_DECLARE(int) ap_pre_connection(conn_rec *c, void *csd)
+{
+    int rc = OK;
+
+    rc = ap_run_pre_connection(c, csd);
+    if (rc != OK && rc != DONE) {
+        c->aborted = 1;
+        /*
+         * In case we errored, the pre_connection hook of the core
+         * module maybe did not run (it is APR_HOOK_REALLY_LAST) and
+         * hence we missed to
+         *
+         * - Put the socket in c->conn_config
+         * - Setup core output and input filters
+         * - Set socket options and timeouts
+         *
+         * Hence call it in this case.
+         */
+        if (!ap_get_conn_socket(c)) {
+            core_pre_connection(c, csd);
+        }
+    }
+    return rc;
+}
+
 AP_DECLARE(int) ap_state_query(int query)
 {
     switch (query) {
index 8302091cd5c4cd2d03e6c4c67109b4d481248e03..5458aa85e977240452e740b63bde879a04f8084d 100644 (file)
@@ -995,11 +995,10 @@ static void process_socket(apr_thread_t *thd, apr_pool_t * p, apr_socket_t * soc
 
         ap_update_vhost_given_ip(c);
 
-        rc = ap_run_pre_connection(c, sock);
+        rc = ap_pre_connection(c, sock);
         if (rc != OK && rc != DONE) {
             ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, c, APLOGNO(00469)
                           "process_socket: connection aborted");
-            c->aborted = 1;
         }
 
         /**