From e77a1dbe409aa9f2a2910f1337c8b90786597f69 Mon Sep 17 00:00:00 2001 From: Tom Sommer Date: Sat, 14 Jan 2017 13:51:12 +0100 Subject: [PATCH] Fix bug #69061 Make mail.log append correct PHP_EOL and remove timestamp when sending to syslog. --- NEWS | 2 ++ ext/standard/mail.c | 41 +++++++++++++++++++++-------------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/NEWS b/NEWS index f1b065d020..a9d0bdb716 100644 --- a/NEWS +++ b/NEWS @@ -45,6 +45,8 @@ PHP NEWS . Fixed bug #72974 (imap is undefined service on AIX). (matthieu.sarter) . Fixed bug #72979 (money_format stores wrong length AIX). (matthieu.sarter) . Fixed bug #73374 (intval() with base 0 should detect binary). (Leigh) + . Fixed bug #69061 (mail.log = syslog contains double information). + (Tom Sommer) - ZIP: . Fixed bug #70103 (ZipArchive::addGlob ignores remove_all_path option). (cmb, diff --git a/ext/standard/mail.c b/ext/standard/mail.c index cce3c7d4ca..26272cd76d 100644 --- a/ext/standard/mail.c +++ b/ext/standard/mail.c @@ -286,34 +286,35 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char return val; \ if (mail_log && *mail_log) { - char *tmp; - time_t curtime; - size_t l; - zend_string *date_str; + char *logline; - time(&curtime); - date_str = php_format_date("d-M-Y H:i:s e", 13, curtime, 1); - - l = spprintf(&tmp, 0, "[%s] mail() on [%s:%d]: To: %s -- Headers: %s -- Subject: %s\n", ZSTR_VAL(date_str), zend_get_executed_filename(), zend_get_executed_lineno(), to, hdr ? hdr : "", subject); - - zend_string_free(date_str); + spprintf(&logline, 0, "mail() on [%s:%d]: To: %s -- Headers: %s -- Subject: %s", zend_get_executed_filename(), zend_get_executed_lineno(), to, hdr ? hdr : "", subject); if (hdr) { - php_mail_log_crlf_to_spaces(tmp); + php_mail_log_crlf_to_spaces(logline); } if (!strcmp(mail_log, "syslog")) { - /* Drop the final space when logging to syslog. */ - tmp[l - 1] = 0; - php_mail_log_to_syslog(tmp); - } - else { - /* Convert the final space to a newline when logging to file. */ - tmp[l - 1] = '\n'; - php_mail_log_to_file(mail_log, tmp, l); + php_mail_log_to_syslog(logline); + } else { + /* Add date when logging to file */ + char *tmp; + time_t curtime; + zend_string *date_str; + size_t len; + + + time(&curtime); + date_str = php_format_date("d-M-Y H:i:s e", 13, curtime, 1); + len = spprintf(&tmp, 0, "[%s] %s%s", date_str->val, logline, PHP_EOL); + + php_mail_log_to_file(mail_log, tmp, len); + + zend_string_free(date_str); + efree(tmp); } - efree(tmp); + efree(logline); } if (PG(mail_x_header)) { -- 2.40.0