]> granicus.if.org Git - apache/commitdiff
suexec: Allow to log an error if exec fails by setting FD_CLOEXEC
authorStefan Fritsch <sf@apache.org>
Sat, 3 Oct 2009 13:46:48 +0000 (13:46 +0000)
committerStefan Fritsch <sf@apache.org>
Sat, 3 Oct 2009 13:46:48 +0000 (13:46 +0000)
on the log file instead of closing it.

PR: 10744
Submitted by: Nicolas Rachinsky
Reviewed by: Stefan Fritsch

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

CHANGES
support/suexec.c

diff --git a/CHANGES b/CHANGES
index 39770e95b538ffebd5835f7df56141f95b5cf13f..653af892d7d78e05116987c8f7c5340516a15a92 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -10,6 +10,9 @@ Changes with Apache 2.3.3
      mod_proxy_ftp: NULL pointer dereference on error paths.
      [Stefan Fritsch <sf fritsch.de>, Joe Orton]
 
+  *) suxec: Allow to log an error if exec fails by setting FD_CLOEXEC
+     on the log file instead of closing it. PR 10744. [Nicolas Rachinsky]
+
   *) mod_mime: Make RemoveType override the info from TypesConfig.
      PR 38330. [Stefan Fritsch]
 
index a6a82b5ec2ea3ed99602ce051aead46be5d22dc2..1ef4e0928f5f00a00b454aee584c8de6fc9d4e0e 100644 (file)
@@ -46,6 +46,7 @@
 #include <stdio.h>
 #include <stdarg.h>
 #include <stdlib.h>
+#include <fcntl.h>
 
 #ifdef HAVE_PWD_H
 #include <pwd.h>
@@ -575,17 +576,16 @@ int main(int argc, char *argv[])
 #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.
+     * ask fcntl(2) to set the FD_CLOEXEC flag on the log file,
+     * so it'll be automagically closed if the exec() call succeeds.
      */
     if (log != NULL) {
-        fclose(log);
-        log = NULL;
+        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);
+        }
     }
 
     /*