summaryrefslogtreecommitdiff
path: root/ext/standard/mail.c
diff options
context:
space:
mode:
authorMikko Koppanen <mkoppanen@php.net>2008-10-03 13:32:41 +0000
committerMikko Koppanen <mkoppanen@php.net>2008-10-03 13:32:41 +0000
commite3c65a369f176a51bee3b41ee96170ea78c1fa62 (patch)
tree899fad1423c2e6c0062db9f4d083015a59faf388 /ext/standard/mail.c
parente72b3afeb53080a1376fb4950de2974721634807 (diff)
downloadphp-git-e3c65a369f176a51bee3b41ee96170ea78c1fa62.tar.gz
Adds signal handling around popen/pclose in mail.c.
Related information on bugs #8992 and #14032 Original patch by D. Parthey
Diffstat (limited to 'ext/standard/mail.c')
-rw-r--r--ext/standard/mail.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/ext/standard/mail.c b/ext/standard/mail.c
index 1f2d470d74..8fc778440a 100644
--- a/ext/standard/mail.c
+++ b/ext/standard/mail.c
@@ -31,6 +31,12 @@
#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"
@@ -193,6 +199,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)
@@ -217,6 +226,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
@@ -235,6 +254,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
@@ -246,6 +272,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
@@ -264,6 +296,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;
}