Package: apache2 / 2.2.22-13+deb7u6

045_suexec_log_cloexec Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#! /bin/sh /usr/share/dpatch/dpatch-run
## suexec_log_cloexec.dpatch
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Patch to allow suexec to log after a cgi error (#312385)
## DP: http://issues.apache.org/bugzilla/show_bug.cgi?id=10744

@DPATCH@

--- a/support/suexec.c
+++ b/support/suexec.c
@@ -46,6 +46,7 @@
 #include <stdio.h>
 #include <stdarg.h>
 #include <stdlib.h>
+#include <fcntl.h>
 
 #ifdef HAVE_PWD_H
 #include <pwd.h>
@@ -598,17 +599,14 @@
 #endif /* AP_SUEXEC_UMASK */
 
     /*
-     * Be sure to close the log file so the CGI can't
-     * mess with it.  If the exec fails, it will be reopened
-     * automatically when log_err is called.  Note that the log
-     * might not actually be open if AP_LOG_EXEC isn't defined.
-     * However, the "log" cell isn't ifdef'd so let's be defensive
-     * and assume someone might have done something with it
-     * outside an ifdef'd AP_LOG_EXEC block.
-     */
-    if (log != NULL) {
-        fclose(log);
-        log = NULL;
+     * ask fcntl(2) to set the FD_CLOEXEC flag on the log file,
+     * so it'll be automagically closed if the exec() call succeeds.
+     */
+    fflush(log);
+    setbuf(log,NULL);
+    if(fcntl(fileno(log),F_SETFD,FD_CLOEXEC)==-1) {
+      log_err("error: can't set close-on-exec flag");
+      exit(122);
     }
 
     /*