]> granicus.if.org Git - php/commitdiff
Adds signal handling around popen/pclose in mail.c.
authorMikko Koppanen <mkoppanen@php.net>
Fri, 3 Oct 2008 13:59:33 +0000 (13:59 +0000)
committerMikko Koppanen <mkoppanen@php.net>
Fri, 3 Oct 2008 13:59:33 +0000 (13:59 +0000)
Related information on bugs #8992 and #14032
Original patch by D. Parthey

NEWS
ext/standard/mail.c

diff --git a/NEWS b/NEWS
index 33c1832554173afdf268ef36bed03078f3d9c800..e9b06b3974565d48b9c58baf8bbc63f60c225f20 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,8 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2008, PHP 5.2.7
+- Fixed bug #14032 (Mail() always returns false but mail is sent). (Mikko)
+
 - Reverted fix for bug #44197 due to behaviour change in minor version.
   (Felipe)
 
index 6ad3bbeb2d2919acaf3b018fe88aa63c9b0bfe92..5acf1f0c80bee977a94c44bc5a408d762b044df0 100644 (file)
 #include <sys/sysexits.h>
 #endif
 
+#if PHP_SIGCHILD
+#if HAVE_SIGNAL_H
+#include <signal.h>
+#endif
+#endif
+
 #include "php_mail.h"
 #include "php_ini.h"
 #include "safe_mode.h"
@@ -200,6 +206,9 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char
        int ret;
        char *sendmail_path = INI_STR("sendmail_path");
        char *sendmail_cmd = NULL;
+#if PHP_SIGCHILD
+       void (*sig_handler)() = NULL;
+#endif
 
        if (!sendmail_path) {
 #if (defined PHP_WIN32 || defined NETWARE)
@@ -224,6 +233,16 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char
                sendmail_cmd = sendmail_path;
        }
 
+#if PHP_SIGCHILD
+       /* Set signal handler of SIGCHLD to default to prevent other signal handlers
+        * from being called and reaping the return code when our child exits.
+        * The original handler needs to be restored after pclose() */
+       sig_handler = (void *)signal(SIGCHLD, SIG_DFL);
+       if (sig_handler == SIG_ERR) {
+               sig_handler = NULL;
+       }
+#endif
+
 #ifdef PHP_WIN32
        sendmail = popen(sendmail_cmd, "wb");
 #else
@@ -241,6 +260,13 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char
                if (EACCES == errno) {
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Permission denied: unable to execute shell to run mail delivery binary '%s'", sendmail_path);
                        pclose(sendmail);
+#if PHP_SIGCHILD
+                       /* Restore handler in case of error on Windows
+                          Not sure if this applicable on Win but just in case. */
+                       if (sig_handler) {
+                               signal(SIGCHLD, sig_handler);
+                       }
+#endif 
                        return 0;
                }
 #endif
@@ -251,6 +277,12 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char
                }
                fprintf(sendmail, "\n%s\n", message);
                ret = pclose(sendmail);
+#if PHP_SIGCHILD
+               if (sig_handler) {
+                       signal(SIGCHLD, sig_handler);
+               }
+#endif
+
 #ifdef PHP_WIN32
                if (ret == -1)
 #else
@@ -269,6 +301,11 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char
                }
        } else {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not execute mail delivery program '%s'", sendmail_path);
+#if PHP_SIGCHILD
+               if (sig_handler) {
+                       signal(SIGCHLD, sig_handler);                                           
+               }
+#endif
                return 0;
        }