]> granicus.if.org Git - apache/commitdiff
mod_cgid: Catch configuration problem where two web server instances
authorJeff Trawick <trawick@apache.org>
Wed, 24 Nov 2004 11:24:32 +0000 (11:24 +0000)
committerJeff Trawick <trawick@apache.org>
Wed, 24 Nov 2004 11:24:32 +0000 (11:24 +0000)
share same ServerRoot but admin forgot to use ScriptSock.

reviewed by: nd, stoddard

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

CHANGES
modules/generators/mod_cgid.c

diff --git a/CHANGES b/CHANGES
index 12a50e2fd3fe1c72453878c50bc4e4bdcffda833..912b04a4627aef00c324919058d2d7d7ff022452 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,10 @@ Changes with Apache 2.1.2-dev
 
   [Remove entries to the current 2.0 section below, when backported]
 
+  *) mod_cgid: Catch configuration problem where two web server instances
+     share same ServerRoot but admin forgot to use ScriptSock.
+     [Jeff Trawick]
+
   *) mod_cgi: Ensure that all stderr is logged for a script which returns
      a Location header to generate a non-local redirect.  PR 20111.
      [Joe Orton]
index 43c0491e02007d81d2fb676977808006f0f3f006..eb91134acbbef4eab87dda7150a46dd530b3d696 100644 (file)
@@ -89,6 +89,7 @@ static int daemon_should_exit = 0;
 static server_rec *root_server = NULL;
 static apr_pool_t *root_pool = NULL;
 static const char *sockname;
+static pid_t parent_pid;
 
 /* Read and discard the data in the brigade produced by a CGI script */
 static void discard_script_output(apr_bucket_brigade *bb);
@@ -153,6 +154,9 @@ typedef struct {
                             * to find the script pid when it is time for that
                             * process to be cleaned up
                             */
+    pid_t ppid;            /* sanity check for config problems leading to
+                            * wrong cgid socket use
+                            */
     int core_module_index;
     int have_suexec;
     int suexec_module_index;
@@ -439,6 +443,7 @@ static apr_status_t send_req(int fd, request_rec *r, char *argv0, char **env,
     apr_status_t stat;
 
     req.req_type = req_type;
+    req.ppid = parent_pid;
     req.conn_id = r->connection->id;
     req.core_module_index = core_module.module_index;
     if (suexec_mod) {
@@ -667,6 +672,14 @@ static int cgid_server(void *data)
             continue;
         }
 
+        if (cgid_req.ppid != parent_pid) {
+            ap_log_error(APLOG_MARK, APLOG_CRIT, 0, main_server,
+                         "CGI request received from wrong server instance; "
+                         "see ScriptSock directive");
+            close(sd2);
+            continue;
+        }
+
         if (cgid_req.req_type == GETPID_REQ) {
             pid_t pid;
 
@@ -839,6 +852,7 @@ static int cgid_init(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp,
         for (m = ap_preloaded_modules; *m != NULL; m++)
             total_modules++;
 
+        parent_pid = getpid();
         sockname = ap_server_root_relative(p, sockname);
         ret = cgid_start(p, main_server, procnew);
         if (ret != OK ) {
@@ -1237,6 +1251,7 @@ static apr_status_t cleanup_script(void *vptr)
     /* we got a socket, and there is already a cleanup registered for it */
 
     req.req_type = GETPID_REQ;
+    req.ppid = parent_pid;
     req.conn_id = info->r->connection->id;
 
     stat = sock_write(sd, &req, sizeof(req));