mod_cgid: fix doubled script timeout (#1977234)

Resolves: rhbz#1977234
This commit is contained in:
Joe Orton 2021-07-12 15:47:59 +01:00
parent 694f7e90dc
commit daf3bf9ef7
2 changed files with 57 additions and 56 deletions

View File

@ -1,9 +1,6 @@
diff --git a/modules/generators/cgi_common.h b/modules/generators/cgi_common.h --- httpd-2.4.48/modules/generators/cgi_common.h.r1828172+
new file mode 100644 +++ httpd-2.4.48/modules/generators/cgi_common.h
index 0000000..85c9685 @@ -0,0 +1,366 @@
--- /dev/null
+++ b/modules/generators/cgi_common.h
@@ -0,0 +1,359 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more +/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with + * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. + * this work for additional information regarding copyright ownership.
@ -261,6 +258,13 @@ index 0000000..85c9685
+ if ((ret = ap_scan_script_header_err_brigade_ex(r, bb, sbuf, + if ((ret = ap_scan_script_header_err_brigade_ex(r, bb, sbuf,
+ APLOG_MODULE_INDEX))) + APLOG_MODULE_INDEX)))
+ { + {
+ /* In the case of a timeout reading script output, clear
+ * the brigade to avoid a second attempt to read the
+ * output. */
+ if (ret == HTTP_GATEWAY_TIME_OUT) {
+ apr_brigade_cleanup(bb);
+ }
+
+ ret = log_script(r, conf, ret, logdata, sbuf, bb, script_err); + ret = log_script(r, conf, ret, logdata, sbuf, bb, script_err);
+ +
+ /* + /*
@ -363,11 +367,9 @@ index 0000000..85c9685
+ +
+ return OK; /* NOT r->status, even if it has changed. */ + return OK; /* NOT r->status, even if it has changed. */
+} +}
diff --git a/modules/generators/config5.m4 b/modules/generators/config5.m4 --- httpd-2.4.48/modules/generators/config5.m4.r1828172+
index bf29521..0863553 100644 +++ httpd-2.4.48/modules/generators/config5.m4
--- a/modules/generators/config5.m4 @@ -78,4 +78,15 @@
+++ b/modules/generators/config5.m4
@@ -78,4 +78,15 @@ fi
APR_ADDTO(INCLUDES, [-I\$(top_srcdir)/$modpath_current]) APR_ADDTO(INCLUDES, [-I\$(top_srcdir)/$modpath_current])
@ -383,11 +385,9 @@ index bf29521..0863553 100644
+]) +])
+ +
APACHE_MODPATH_FINISH APACHE_MODPATH_FINISH
diff --git a/modules/generators/mod_cgi.c b/modules/generators/mod_cgi.c --- httpd-2.4.48/modules/generators/mod_cgi.c.r1828172+
index 7e4b126..f438b35 100644 +++ httpd-2.4.48/modules/generators/mod_cgi.c
--- a/modules/generators/mod_cgi.c @@ -92,6 +92,10 @@
+++ b/modules/generators/mod_cgi.c
@@ -92,6 +92,10 @@ typedef struct {
apr_size_t bufbytes; apr_size_t bufbytes;
} cgi_server_conf; } cgi_server_conf;
@ -398,7 +398,7 @@ index 7e4b126..f438b35 100644
static void *create_cgi_config(apr_pool_t *p, server_rec *s) static void *create_cgi_config(apr_pool_t *p, server_rec *s)
{ {
cgi_server_conf *c = cgi_server_conf *c =
@@ -112,6 +116,12 @@ static void *merge_cgi_config(apr_pool_t *p, void *basev, void *overridesv) @@ -112,6 +116,12 @@
return overrides->logname ? overrides : base; return overrides->logname ? overrides : base;
} }
@ -411,7 +411,7 @@ index 7e4b126..f438b35 100644
static const char *set_scriptlog(cmd_parms *cmd, void *dummy, const char *arg) static const char *set_scriptlog(cmd_parms *cmd, void *dummy, const char *arg)
{ {
server_rec *s = cmd->server; server_rec *s = cmd->server;
@@ -150,6 +160,17 @@ static const char *set_scriptlog_buffer(cmd_parms *cmd, void *dummy, @@ -150,6 +160,17 @@
return NULL; return NULL;
} }
@ -429,7 +429,7 @@ index 7e4b126..f438b35 100644
static const command_rec cgi_cmds[] = static const command_rec cgi_cmds[] =
{ {
AP_INIT_TAKE1("ScriptLog", set_scriptlog, NULL, RSRC_CONF, AP_INIT_TAKE1("ScriptLog", set_scriptlog, NULL, RSRC_CONF,
@@ -158,6 +179,9 @@ AP_INIT_TAKE1("ScriptLogLength", set_scriptlog_length, NULL, RSRC_CONF, @@ -158,6 +179,9 @@
"the maximum length (in bytes) of the script debug log"), "the maximum length (in bytes) of the script debug log"),
AP_INIT_TAKE1("ScriptLogBuffer", set_scriptlog_buffer, NULL, RSRC_CONF, AP_INIT_TAKE1("ScriptLogBuffer", set_scriptlog_buffer, NULL, RSRC_CONF,
"the maximum size (in bytes) to record of a POST request"), "the maximum size (in bytes) to record of a POST request"),
@ -439,7 +439,7 @@ index 7e4b126..f438b35 100644
{NULL} {NULL}
}; };
@@ -466,23 +490,26 @@ static apr_status_t run_cgi_child(apr_file_t **script_out, @@ -466,23 +490,26 @@
apr_filepath_name_get(r->filename)); apr_filepath_name_get(r->filename));
} }
else { else {
@ -469,7 +469,7 @@ index 7e4b126..f438b35 100644
} }
} }
} }
@@ -536,209 +563,12 @@ static apr_status_t default_build_command(const char **cmd, const char ***argv, @@ -536,209 +563,12 @@
return APR_SUCCESS; return APR_SUCCESS;
} }
@ -682,7 +682,7 @@ index 7e4b126..f438b35 100644
static int cgi_handler(request_rec *r) static int cgi_handler(request_rec *r)
{ {
int nph; int nph;
@@ -757,6 +587,8 @@ static int cgi_handler(request_rec *r) @@ -757,6 +587,8 @@
apr_status_t rv; apr_status_t rv;
cgi_exec_info_t e_info; cgi_exec_info_t e_info;
conn_rec *c; conn_rec *c;
@ -691,7 +691,7 @@ index 7e4b126..f438b35 100644
if (strcmp(r->handler, CGI_MAGIC_TYPE) && strcmp(r->handler, "cgi-script")) { if (strcmp(r->handler, CGI_MAGIC_TYPE) && strcmp(r->handler, "cgi-script")) {
return DECLINED; return DECLINED;
@@ -916,10 +748,7 @@ static int cgi_handler(request_rec *r) @@ -916,10 +748,7 @@
AP_DEBUG_ASSERT(script_in != NULL); AP_DEBUG_ASSERT(script_in != NULL);
#if APR_FILES_AS_SOCKETS #if APR_FILES_AS_SOCKETS
@ -703,7 +703,7 @@ index 7e4b126..f438b35 100644
if (b == NULL) if (b == NULL)
return HTTP_INTERNAL_SERVER_ERROR; return HTTP_INTERNAL_SERVER_ERROR;
#else #else
@@ -929,111 +758,7 @@ static int cgi_handler(request_rec *r) @@ -929,111 +758,7 @@
b = apr_bucket_eos_create(c->bucket_alloc); b = apr_bucket_eos_create(c->bucket_alloc);
APR_BRIGADE_INSERT_TAIL(bb, b); APR_BRIGADE_INSERT_TAIL(bb, b);
@ -816,7 +816,7 @@ index 7e4b126..f438b35 100644
} }
/*============================================================================ /*============================================================================
@@ -1268,7 +993,7 @@ static void register_hooks(apr_pool_t *p) @@ -1268,7 +993,7 @@
AP_DECLARE_MODULE(cgi) = AP_DECLARE_MODULE(cgi) =
{ {
STANDARD20_MODULE_STUFF, STANDARD20_MODULE_STUFF,
@ -825,11 +825,9 @@ index 7e4b126..f438b35 100644
NULL, /* dir merger --- default is to override */ NULL, /* dir merger --- default is to override */
create_cgi_config, /* server config */ create_cgi_config, /* server config */
merge_cgi_config, /* merge server config */ merge_cgi_config, /* merge server config */
diff --git a/modules/generators/mod_cgid.c b/modules/generators/mod_cgid.c --- httpd-2.4.48/modules/generators/mod_cgid.c.r1828172+
index 9f4282c..102d2b3 100644 +++ httpd-2.4.48/modules/generators/mod_cgid.c
--- a/modules/generators/mod_cgid.c @@ -342,15 +342,19 @@
+++ b/modules/generators/mod_cgid.c
@@ -342,15 +342,19 @@ static apr_status_t close_unix_socket(void *thefd)
return close(fd); return close(fd);
} }
@ -854,7 +852,7 @@ index 9f4282c..102d2b3 100644
do { do {
do { do {
rc = read(fd, buf + bytes_read, buf_size - bytes_read); rc = read(fd, buf + bytes_read, buf_size - bytes_read);
@@ -365,9 +369,60 @@ static apr_status_t sock_read(int fd, void *vbuf, size_t buf_size) @@ -365,9 +369,60 @@
} }
} while (bytes_read < buf_size); } while (bytes_read < buf_size);
@ -915,7 +913,7 @@ index 9f4282c..102d2b3 100644
/* deal with signals /* deal with signals
*/ */
static apr_status_t sock_write(int fd, const void *buf, size_t buf_size) static apr_status_t sock_write(int fd, const void *buf, size_t buf_size)
@@ -384,7 +439,7 @@ static apr_status_t sock_write(int fd, const void *buf, size_t buf_size) @@ -384,7 +439,7 @@
return APR_SUCCESS; return APR_SUCCESS;
} }
@ -924,7 +922,7 @@ index 9f4282c..102d2b3 100644
{ {
va_list ap; va_list ap;
int rc; int rc;
@@ -399,9 +454,39 @@ static apr_status_t sock_writev(int fd, request_rec *r, int count, ...) @@ -399,9 +454,39 @@
} }
va_end(ap); va_end(ap);
@ -964,7 +962,7 @@ index 9f4282c..102d2b3 100644
if (rc < 0) { if (rc < 0) {
return errno; return errno;
} }
@@ -410,7 +495,7 @@ static apr_status_t sock_writev(int fd, request_rec *r, int count, ...) @@ -410,7 +495,7 @@
} }
static apr_status_t get_req(int fd, request_rec *r, char **argv0, char ***env, static apr_status_t get_req(int fd, request_rec *r, char **argv0, char ***env,
@ -973,7 +971,7 @@ index 9f4282c..102d2b3 100644
{ {
int i; int i;
char **environ; char **environ;
@@ -421,7 +506,7 @@ static apr_status_t get_req(int fd, request_rec *r, char **argv0, char ***env, @@ -421,7 +506,7 @@
r->server = apr_pcalloc(r->pool, sizeof(server_rec)); r->server = apr_pcalloc(r->pool, sizeof(server_rec));
/* read the request header */ /* read the request header */
@ -982,7 +980,7 @@ index 9f4282c..102d2b3 100644
if (stat != APR_SUCCESS) { if (stat != APR_SUCCESS) {
return stat; return stat;
} }
@@ -479,14 +564,15 @@ static apr_status_t get_req(int fd, request_rec *r, char **argv0, char ***env, @@ -479,14 +564,15 @@
return APR_SUCCESS; return APR_SUCCESS;
} }
@ -1000,7 +998,7 @@ index 9f4282c..102d2b3 100644
if (ugid == NULL) { if (ugid == NULL) {
@@ -507,16 +593,21 @@ static apr_status_t send_req(int fd, request_rec *r, char *argv0, char **env, @@ -507,16 +593,21 @@
req.args_len = r->args ? strlen(r->args) : 0; req.args_len = r->args ? strlen(r->args) : 0;
req.loglevel = r->server->log.level; req.loglevel = r->server->log.level;
@ -1024,7 +1022,7 @@ index 9f4282c..102d2b3 100644
&req, sizeof(req), &req, sizeof(req),
r->filename, req.filename_len, r->filename, req.filename_len,
argv0, req.argv0_len, argv0, req.argv0_len,
@@ -531,7 +622,7 @@ static apr_status_t send_req(int fd, request_rec *r, char *argv0, char **env, @@ -531,7 +622,7 @@
for (i = 0; i < req.env_count; i++) { for (i = 0; i < req.env_count; i++) {
apr_size_t curlen = strlen(env[i]); apr_size_t curlen = strlen(env[i]);
@ -1033,7 +1031,7 @@ index 9f4282c..102d2b3 100644
env[i], curlen)) != APR_SUCCESS) { env[i], curlen)) != APR_SUCCESS) {
return stat; return stat;
} }
@@ -582,20 +673,34 @@ static void daemon_signal_handler(int sig) @@ -582,20 +673,34 @@
} }
} }
@ -1076,7 +1074,7 @@ index 9f4282c..102d2b3 100644
} }
static int cgid_server(void *data) static int cgid_server(void *data)
@@ -669,7 +774,7 @@ static int cgid_server(void *data) @@ -670,7 +775,7 @@
} }
while (!daemon_should_exit) { while (!daemon_should_exit) {
@ -1085,7 +1083,7 @@ index 9f4282c..102d2b3 100644
char *argv0 = NULL; char *argv0 = NULL;
char **env = NULL; char **env = NULL;
const char * const *argv; const char * const *argv;
@@ -709,7 +814,7 @@ static int cgid_server(void *data) @@ -710,7 +815,7 @@
r = apr_pcalloc(ptrans, sizeof(request_rec)); r = apr_pcalloc(ptrans, sizeof(request_rec));
procnew = apr_pcalloc(ptrans, sizeof(*procnew)); procnew = apr_pcalloc(ptrans, sizeof(*procnew));
r->pool = ptrans; r->pool = ptrans;
@ -1094,7 +1092,7 @@ index 9f4282c..102d2b3 100644
if (stat != APR_SUCCESS) { if (stat != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR, stat, ap_log_error(APLOG_MARK, APLOG_ERR, stat,
main_server, APLOGNO(01248) main_server, APLOGNO(01248)
@@ -741,6 +846,16 @@ static int cgid_server(void *data) @@ -742,6 +847,16 @@
continue; continue;
} }
@ -1111,7 +1109,7 @@ index 9f4282c..102d2b3 100644
apr_os_file_put(&r->server->error_log, &errfileno, 0, r->pool); apr_os_file_put(&r->server->error_log, &errfileno, 0, r->pool);
apr_os_file_put(&inout, &sd2, 0, r->pool); apr_os_file_put(&inout, &sd2, 0, r->pool);
@@ -800,7 +915,10 @@ static int cgid_server(void *data) @@ -801,7 +916,10 @@
close(sd2); close(sd2);
} }
else { else {
@ -1123,7 +1121,7 @@ index 9f4282c..102d2b3 100644
argv = (const char * const *)create_argv(r->pool, NULL, NULL, NULL, argv0, r->args); argv = (const char * const *)create_argv(r->pool, NULL, NULL, NULL, argv0, r->args);
@@ -1099,6 +1217,33 @@ static int log_scripterror(request_rec *r, cgid_server_conf * conf, int ret, @@ -1101,6 +1219,33 @@
return ret; return ret;
} }
@ -1157,7 +1155,7 @@ index 9f4282c..102d2b3 100644
static int log_script(request_rec *r, cgid_server_conf * conf, int ret, static int log_script(request_rec *r, cgid_server_conf * conf, int ret,
char *dbuf, const char *sbuf, apr_bucket_brigade *bb, char *dbuf, const char *sbuf, apr_bucket_brigade *bb,
apr_file_t *script_err) apr_file_t *script_err)
@@ -1204,6 +1349,13 @@ static int log_script(request_rec *r, cgid_server_conf * conf, int ret, @@ -1206,6 +1351,13 @@
return ret; return ret;
} }
@ -1171,7 +1169,7 @@ index 9f4282c..102d2b3 100644
static int connect_to_daemon(int *sdptr, request_rec *r, static int connect_to_daemon(int *sdptr, request_rec *r,
cgid_server_conf *conf) cgid_server_conf *conf)
{ {
@@ -1270,23 +1422,6 @@ static int connect_to_daemon(int *sdptr, request_rec *r, @@ -1272,23 +1424,6 @@
return OK; return OK;
} }
@ -1195,7 +1193,7 @@ index 9f4282c..102d2b3 100644
/**************************************************************** /****************************************************************
* *
* Actual cgid handling... * Actual cgid handling...
@@ -1391,6 +1526,7 @@ static apr_status_t cleanup_script(void *vptr) @@ -1393,6 +1528,7 @@
static int cgid_handler(request_rec *r) static int cgid_handler(request_rec *r)
{ {
@ -1203,7 +1201,7 @@ index 9f4282c..102d2b3 100644
int retval, nph, dbpos; int retval, nph, dbpos;
char *argv0, *dbuf; char *argv0, *dbuf;
apr_bucket_brigade *bb; apr_bucket_brigade *bb;
@@ -1400,10 +1536,11 @@ static int cgid_handler(request_rec *r) @@ -1402,10 +1538,11 @@
int seen_eos, child_stopped_reading; int seen_eos, child_stopped_reading;
int sd; int sd;
char **env; char **env;
@ -1216,7 +1214,7 @@ index 9f4282c..102d2b3 100644
if (strcmp(r->handler, CGI_MAGIC_TYPE) && strcmp(r->handler, "cgi-script")) { if (strcmp(r->handler, CGI_MAGIC_TYPE) && strcmp(r->handler, "cgi-script")) {
return DECLINED; return DECLINED;
@@ -1412,7 +1549,7 @@ static int cgid_handler(request_rec *r) @@ -1414,7 +1551,7 @@
conf = ap_get_module_config(r->server->module_config, &cgid_module); conf = ap_get_module_config(r->server->module_config, &cgid_module);
dc = ap_get_module_config(r->per_dir_config, &cgid_module); dc = ap_get_module_config(r->per_dir_config, &cgid_module);
@ -1225,7 +1223,7 @@ index 9f4282c..102d2b3 100644
is_included = !strcmp(r->protocol, "INCLUDED"); is_included = !strcmp(r->protocol, "INCLUDED");
if ((argv0 = strrchr(r->filename, '/')) != NULL) { if ((argv0 = strrchr(r->filename, '/')) != NULL) {
@@ -1465,6 +1602,17 @@ static int cgid_handler(request_rec *r) @@ -1467,6 +1604,17 @@
} }
*/ */
@ -1243,7 +1241,7 @@ index 9f4282c..102d2b3 100644
/* /*
* httpd core function used to add common environment variables like * httpd core function used to add common environment variables like
* DOCUMENT_ROOT. * DOCUMENT_ROOT.
@@ -1477,12 +1625,16 @@ static int cgid_handler(request_rec *r) @@ -1479,12 +1627,16 @@
return retval; return retval;
} }
@ -1261,7 +1259,7 @@ index 9f4282c..102d2b3 100644
info = apr_palloc(r->pool, sizeof(struct cleanup_script_info)); info = apr_palloc(r->pool, sizeof(struct cleanup_script_info));
info->conf = conf; info->conf = conf;
info->r = r; info->r = r;
@@ -1504,12 +1656,7 @@ static int cgid_handler(request_rec *r) @@ -1506,12 +1658,7 @@
*/ */
apr_os_pipe_put_ex(&tempsock, &sd, 1, r->pool); apr_os_pipe_put_ex(&tempsock, &sd, 1, r->pool);
@ -1275,7 +1273,7 @@ index 9f4282c..102d2b3 100644
apr_pool_cleanup_kill(r->pool, (void *)((long)sd), close_unix_socket); apr_pool_cleanup_kill(r->pool, (void *)((long)sd), close_unix_socket);
/* Transfer any put/post args, CERN style... /* Transfer any put/post args, CERN style...
@@ -1601,114 +1748,19 @@ static int cgid_handler(request_rec *r) @@ -1603,114 +1750,19 @@
*/ */
shutdown(sd, 1); shutdown(sd, 1);
@ -1402,7 +1400,7 @@ index 9f4282c..102d2b3 100644
} }
@@ -1825,7 +1877,7 @@ static int include_cmd(include_ctx_t *ctx, ap_filter_t *f, @@ -1827,7 +1879,7 @@
return retval; return retval;
} }

View File

@ -13,7 +13,7 @@
Summary: Apache HTTP Server Summary: Apache HTTP Server
Name: httpd Name: httpd
Version: 2.4.48 Version: 2.4.48
Release: 10%{?dist} Release: 11%{?dist}
URL: https://httpd.apache.org/ URL: https://httpd.apache.org/
Source0: https://www.apache.org/dist/httpd/httpd-%{version}.tar.bz2 Source0: https://www.apache.org/dist/httpd/httpd-%{version}.tar.bz2
Source1: https://www.apache.org/dist/httpd/httpd-%{version}.tar.bz2.asc Source1: https://www.apache.org/dist/httpd/httpd-%{version}.tar.bz2.asc
@ -82,7 +82,7 @@ Patch38: httpd-2.4.43-sslciphdefault.patch
Patch39: httpd-2.4.43-sslprotdefault.patch Patch39: httpd-2.4.43-sslprotdefault.patch
Patch40: httpd-2.4.43-r1861269.patch Patch40: httpd-2.4.43-r1861269.patch
Patch41: httpd-2.4.43-r1861793+.patch Patch41: httpd-2.4.43-r1861793+.patch
Patch42: httpd-2.4.43-r1828172+.patch Patch42: httpd-2.4.48-r1828172+.patch
Patch45: httpd-2.4.43-logjournal.patch Patch45: httpd-2.4.43-logjournal.patch
Patch46: httpd-2.4.48-proxy-ws-idle-timeout.patch Patch46: httpd-2.4.48-proxy-ws-idle-timeout.patch
# https://bugzilla.redhat.com/show_bug.cgi?id=1949969 # https://bugzilla.redhat.com/show_bug.cgi?id=1949969
@ -802,6 +802,9 @@ exit $rv
%{_rpmconfigdir}/macros.d/macros.httpd %{_rpmconfigdir}/macros.d/macros.httpd
%changelog %changelog
* Mon Jul 12 2021 Joe Orton <jorton@redhat.com> - 2.4.48-11
- mod_cgid: fix doubled script timeout (#1977234)
* Fri Jul 9 2021 Joe Orton <jorton@redhat.com> - 2.4.48-10 * Fri Jul 9 2021 Joe Orton <jorton@redhat.com> - 2.4.48-10
- fix release in ServerTokens Full-Release (#1932442) - fix release in ServerTokens Full-Release (#1932442)