Blame SOURCES/httpd-2.4.6-CVE-2014-0231.patch

008793
--- a/modules/generators/mod_cgid.c	2014/07/14 20:16:45	1610511
008793
+++ b/modules/generators/mod_cgid.c	2014/07/14 20:18:26	1610512
008793
@@ -97,6 +97,10 @@
008793
 static pid_t parent_pid;
008793
 static ap_unix_identity_t empty_ugid = { (uid_t)-1, (gid_t)-1, -1 };
008793
 
008793
+typedef struct { 
008793
+    apr_interval_time_t timeout;
008793
+} cgid_dirconf;
008793
+
008793
 /* The APR other-child API doesn't tell us how the daemon exited
008793
  * (SIGSEGV vs. exit(1)).  The other-child maintenance function
008793
  * needs to decide whether to restart the daemon after a failure
008793
@@ -968,7 +972,14 @@
008793
     return overrides->logname ? overrides : base;
008793
 }
008793
 
008793
+static void *create_cgid_dirconf(apr_pool_t *p, char *dummy)
008793
+{
008793
+    cgid_dirconf *c = (cgid_dirconf *) apr_pcalloc(p, sizeof(cgid_dirconf));
008793
+    return c;
008793
+}
008793
+
008793
 static const char *set_scriptlog(cmd_parms *cmd, void *dummy, const char *arg)
008793
+
008793
 {
008793
     server_rec *s = cmd->server;
008793
     cgid_server_conf *conf = ap_get_module_config(s->module_config,
008793
@@ -1021,7 +1032,16 @@
008793
 
008793
     return NULL;
008793
 }
008793
+static const char *set_script_timeout(cmd_parms *cmd, void *dummy, const char *arg)
008793
+{
008793
+    cgid_dirconf *dc = dummy;
008793
 
008793
+    if (ap_timeout_parameter_parse(arg, &dc->timeout, "s") != APR_SUCCESS) { 
008793
+        return "CGIDScriptTimeout has wrong format";
008793
+    }
008793
+ 
008793
+    return NULL;
008793
+}
008793
 static const command_rec cgid_cmds[] =
008793
 {
008793
     AP_INIT_TAKE1("ScriptLog", set_scriptlog, NULL, RSRC_CONF,
008793
@@ -1033,6 +1053,10 @@
008793
     AP_INIT_TAKE1("ScriptSock", set_script_socket, NULL, RSRC_CONF,
008793
                   "the name of the socket to use for communication with "
008793
                   "the cgi daemon."),
008793
+    AP_INIT_TAKE1("CGIDScriptTimeout", set_script_timeout, NULL, RSRC_CONF | ACCESS_CONF,
008793
+                  "The amount of time to wait between successful reads from "
008793
+                  "the CGI script, in seconds."),
008793
+                  
008793
     {NULL}
008793
 };
008793
 
008793
@@ -1356,12 +1380,16 @@
008793
     apr_file_t *tempsock;
008793
     struct cleanup_script_info *info;
008793
     apr_status_t rv;
008793
+    cgid_dirconf *dc;
008793
 
008793
     if (strcmp(r->handler, CGI_MAGIC_TYPE) && strcmp(r->handler, "cgi-script")) {
008793
         return DECLINED;
008793
     }
008793
 
008793
     conf = ap_get_module_config(r->server->module_config, &cgid_module);
008793
+    dc = ap_get_module_config(r->per_dir_config, &cgid_module);
008793
+
008793
+    
008793
     is_included = !strcmp(r->protocol, "INCLUDED");
008793
 
008793
     if ((argv0 = strrchr(r->filename, '/')) != NULL) {
008793
@@ -1441,6 +1469,12 @@
008793
      */
008793
 
008793
     apr_os_pipe_put_ex(&tempsock, &sd, 1, r->pool);
008793
+    if (dc->timeout > 0) { 
008793
+        apr_file_pipe_timeout_set(tempsock, dc->timeout);
008793
+    }
008793
+    else { 
008793
+        apr_file_pipe_timeout_set(tempsock, r->server->timeout);
008793
+    }
008793
     apr_pool_cleanup_kill(r->pool, (void *)((long)sd), close_unix_socket);
008793
 
008793
     /* Transfer any put/post args, CERN style...
008793
@@ -1517,6 +1551,10 @@
008793
             if (rv != APR_SUCCESS) {
008793
                 /* silly script stopped reading, soak up remaining message */
008793
                 child_stopped_reading = 1;
008793
+                ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(02651)
008793
+                              "Error writing request body to script %s", 
008793
+                              r->filename);
008793
+
008793
             }
008793
         }
008793
         apr_brigade_cleanup(bb);
008793
@@ -1610,7 +1648,13 @@
008793
             return HTTP_MOVED_TEMPORARILY;
008793
         }
008793
 
008793
-        ap_pass_brigade(r->output_filters, bb);
008793
+        rv = ap_pass_brigade(r->output_filters, bb);
008793
+        if (rv != APR_SUCCESS) { 
008793
+            /* APLOG_ERR because the core output filter message is at error,
008793
+             * but doesn't know it's passing CGI output 
008793
+             */
008793
+            ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(02550) "Failed to flush CGI output to client");
008793
+        }
008793
     }
008793
 
008793
     if (nph) {
008793
@@ -1741,6 +1785,8 @@
008793
     request_rec *r = f->r;
008793
     cgid_server_conf *conf = ap_get_module_config(r->server->module_config,
008793
                                                   &cgid_module);
008793
+    cgid_dirconf *dc = ap_get_module_config(r->per_dir_config, &cgid_module);
008793
+
008793
     struct cleanup_script_info *info;
008793
 
008793
     add_ssi_vars(r);
008793
@@ -1770,6 +1816,13 @@
008793
      * get rid of the cleanup we registered when we created the socket.
008793
      */
008793
     apr_os_pipe_put_ex(&tempsock, &sd, 1, r->pool);
008793
+    if (dc->timeout > 0) {
008793
+        apr_file_pipe_timeout_set(tempsock, dc->timeout);
008793
+    }
008793
+    else {
008793
+        apr_file_pipe_timeout_set(tempsock, r->server->timeout);
008793
+    }
008793
+
008793
     apr_pool_cleanup_kill(r->pool, (void *)((long)sd), close_unix_socket);
008793
 
008793
     APR_BRIGADE_INSERT_TAIL(bb, apr_bucket_pipe_create(tempsock,
008793
@@ -1875,7 +1928,7 @@
008793
 
008793
 AP_DECLARE_MODULE(cgid) = {
008793
     STANDARD20_MODULE_STUFF,
008793
-    NULL, /* dir config creater */
008793
+    create_cgid_dirconf, /* dir config creater */
008793
     NULL, /* dir merger --- default is to override */
008793
     create_cgid_config, /* server config */
008793
     merge_cgid_config, /* merge server config */