Download | Plain Text | No Line Numbers


  1. diff -Naur php-5.4.6.orig/ext/standard/mail.c php-5.4.6/ext/standard/mail.c
  2. --- php-5.4.6.orig/ext/standard/mail.c 2012-08-15 06:26:05.000000000 +0200
  3. +++ php-5.4.6/ext/standard/mail.c 2012-09-05 17:31:01.000000000 +0200
  4. @@ -62,6 +62,13 @@
  5. } \
  6. continue; \
  7. } \
  8. + else if (str[pos] == '\n' && (str[pos + 1] == ' ' || str[pos + 1] == '\t')) { \
  9. + pos += 1; \
  10. + while (str[pos + 1] == ' ' || str[pos + 1] == '\t') { \
  11. + pos++; \
  12. + } \
  13. + continue; \
  14. + } \
  15.  
  16. #define MAIL_ASCIIZ_CHECK(str, len) \
  17. p = str; \
  18. @@ -94,6 +101,46 @@
  19. }
  20. /* }}} */
  21.  
  22. +static long
  23. +count_recipients(const char *str, int len, int skip_field)
  24. +{
  25. + long recipients = 0;
  26. + int got_field, i;
  27. +
  28. + if (str == NULL || len <= 0)
  29. + return 0;
  30. +
  31. + got_field = skip_field;
  32. + for (i = 0; str[i]; i++) {
  33. + /* search for mime-fields
  34. + * either at beginning or after '\n' of the string
  35. + */
  36. + if (!got_field &&
  37. + (!strncasecmp(&str[i], "To: ", strlen("To: ")) ||
  38. + !strncasecmp(&str[i], "Cc: ", strlen("Cc: ")) ||
  39. + !strncasecmp(&str[i], "Bcc: ", strlen("Bcc: "))
  40. + )) {
  41. + if (i == 0 || (i > 0 && str[i - 1] == '\n'))
  42. + got_field = 1;
  43. + }
  44. +
  45. + /* search for every '@', don't stop at long headers */
  46. + if (got_field) {
  47. + if (str[i] == '@')
  48. + recipients++;
  49. + else if (str[i] == '\n')
  50. + if (i == len - 1 || (str[i + 1] != ' ' && str[i + 1] != '\t'))
  51. + got_field = 0;
  52. + }
  53. +
  54. + /* message body starts here */
  55. + if (i > 0 && str[i - 1] == '\n' && str[i] == '\n')
  56. + break;
  57. + }
  58. +
  59. + return recipients;
  60. +}
  61. +
  62. /* {{{ proto int mail(string to, string subject, string message [, string additional_headers [, string additional_parameters]])
  63. Send an email message */
  64. PHP_FUNCTION(mail)
  65. @@ -105,6 +152,8 @@
  66. char *force_extra_parameters = INI_STR("mail.force_extra_parameters");
  67. char *to_r, *subject_r;
  68. char *p, *e;
  69. + long recipients = 0;
  70. + long max_recipients = INI_INT("sendmail_max_recipients");
  71.  
  72. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss|ss", &to, &to_len, &subject, &subject_len, &message, &message_len, &headers, &headers_len, &extra_cmd, &extra_cmd_len) == FAILURE) {
  73. return;
  74. @@ -122,6 +171,16 @@
  75. MAIL_ASCIIZ_CHECK(extra_cmd, extra_cmd_len);
  76. }
  77.  
  78. + /* count recipients */
  79. + if (max_recipients > 0) {
  80. + recipients += count_recipients(to, to_len, 1);
  81. + recipients += count_recipients(headers, headers_len, 0);
  82. + if (recipients > max_recipients) {
  83. + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Max recipients reached, mail not sent.");
  84. + RETURN_FALSE;
  85. + }
  86. + }
  87. +
  88. if (to_len > 0) {
  89. to_r = estrndup(to, to_len);
  90. for (; to_len; to_len--) {
  91. @@ -137,7 +196,10 @@
  92. * To prevent these separators from being replaced with a space, we use the
  93. * SKIP_LONG_HEADER_SEP to skip over them. */
  94. SKIP_LONG_HEADER_SEP(to_r, i);
  95. - to_r[i] = ' ';
  96. + //to_r[i] = ' ';
  97. + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Disallowed characters in mail parameters, mail not sent.");
  98. + efree(to_r);
  99. + RETURN_FALSE;
  100. }
  101. }
  102. } else {
  103. @@ -155,7 +217,10 @@
  104. for (i = 0; subject_r[i]; i++) {
  105. if (iscntrl((unsigned char) subject_r[i])) {
  106. SKIP_LONG_HEADER_SEP(subject_r, i);
  107. - subject_r[i] = ' ';
  108. + //subject_r[i] = ' ';
  109. + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Disallowed characters in mail parameters, mail not sent.");
  110. + efree(subject_r);
  111. + RETURN_FALSE;
  112. }
  113. }
  114. } else {
  115. @@ -245,9 +310,22 @@
  116. } \
  117. return val; \
  118.  
  119. + zval **hgdata;
  120. + char *httphost = NULL;
  121. + if (mail_log || PG(mail_x_header)) {
  122. + zend_is_auto_global("_SERVER", sizeof("_SERVER") - 1 TSRMLS_CC);
  123. + if (PG(http_globals)[TRACK_VARS_SERVER] &&
  124. + zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_HOST",
  125. + sizeof("HTTP_HOST"), (void **) &hgdata) == SUCCESS &&
  126. + Z_TYPE_PP(hgdata) == IS_STRING &&
  127. + Z_STRLEN_PP(hgdata) != 0) {
  128. + httphost = Z_STRVAL_PP(hgdata);
  129. + }
  130. + }
  131. +
  132. if (mail_log && *mail_log) {
  133. char *tmp;
  134. - int l = spprintf(&tmp, 0, "mail() on [%s:%d]: To: %s -- Headers: %s\n", zend_get_executed_filename(TSRMLS_C), zend_get_executed_lineno(TSRMLS_C), to, hdr ? hdr : "");
  135. + int l = spprintf(&tmp, 0, "mail() on [%s:%d]: To: %s -- HTTP-Host: %s -- Headers: %s\n", zend_get_executed_filename(TSRMLS_C), zend_get_executed_lineno(TSRMLS_C), to, httphost ? httphost : "", hdr ? hdr : "");
  136.  
  137. if (hdr) {
  138. php_mail_log_crlf_to_spaces(tmp);
  139. @@ -268,17 +346,12 @@
  140. }
  141. if (PG(mail_x_header)) {
  142. const char *tmp = zend_get_executed_filename(TSRMLS_C);
  143. - char *f;
  144. - size_t f_len;
  145. -
  146. - php_basename(tmp, strlen(tmp), NULL, 0,&f, &f_len TSRMLS_CC);
  147.  
  148. if (headers != NULL) {
  149. - spprintf(&hdr, 0, "X-PHP-Originating-Script: %ld:%s\n%s", php_getuid(TSRMLS_C), f, headers);
  150. + spprintf(&hdr, 0, "X-PHP-Originating-Script: %ld:%s\nX-PHP-HTTP-Host: %s\n%s", php_getuid(), tmp, httphost ? httphost : "", headers);
  151. } else {
  152. - spprintf(&hdr, 0, "X-PHP-Originating-Script: %ld:%s", php_getuid(TSRMLS_C), f);
  153. + spprintf(&hdr, 0, "X-PHP-Originating-Script: %ld:%s\nX-PHP-HTTP-Host: %s", php_getuid(), tmp, httphost ? httphost : "");
  154. }
  155. - efree(f);
  156. }
  157.  
  158. if (!sendmail_path) {
  159. diff -Naur php-5.4.6.orig/main/main.c php-5.4.6/main/main.c
  160. --- php-5.4.6.orig/main/main.c 2012-08-15 06:26:05.000000000 +0200
  161. +++ php-5.4.6/main/main.c 2012-09-05 17:31:01.000000000 +0200
  162. @@ -549,6 +549,7 @@
  163. PHP_INI_ENTRY("precision", "14", PHP_INI_ALL, OnSetPrecision)
  164. PHP_INI_ENTRY("sendmail_from", NULL, PHP_INI_ALL, NULL)
  165. PHP_INI_ENTRY("sendmail_path", DEFAULT_SENDMAIL_PATH, PHP_INI_SYSTEM, NULL)
  166. + PHP_INI_ENTRY("sendmail_max_recipients", "5", PHP_INI_ALL, NULL)
  167. PHP_INI_ENTRY("mail.force_extra_parameters",NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnChangeMailForceExtra)
  168. PHP_INI_ENTRY("disable_functions", "", PHP_INI_SYSTEM, NULL)
  169. PHP_INI_ENTRY("disable_classes", "", PHP_INI_SYSTEM, NULL)
  170.