com php-src: Remove confusing null checks in mb_send_mail : ext/mbstring/mbstring.c
| From: | Nikita Popov | Date: | Sun, 23 Jul 2017 09:55:43 +0000 |
| Subject: | com php-src: Remove confusing null checks in mb_send_mail : ext/mbstring/mbstring.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-98744@lists.php.net to get a copy of this message | ||
Commit: 80463579ce307dd9b748c8c0dc503a52b91657ad
Author: Nikita Popov <nikita.ppv@gmail.com> Sun, 23 Jul 2017 11:01:00 +0200
Parents: 216d711224194ab2d50e473d039eb1762c3fb5f7
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=80463579ce307dd9b748c8c0dc503a52b91657ad
Log:
Remove confusing null checks in mb_send_mail
These are required parameters, they cannot be missing.
Changed paths:
M ext/mbstring/mbstring.c
Diff:
diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c
index ba1ea78..f7a9bac 100644
--- a/ext/mbstring/mbstring.c
+++ b/ext/mbstring/mbstring.c
@@ -4316,15 +4316,15 @@ out:
PHP_FUNCTION(mb_send_mail)
{
size_t n;
- char *to = NULL;
+ char *to;
size_t to_len;
- char *message = NULL;
+ char *message;
size_t message_len;
- char *subject = NULL;
+ char *subject;
size_t subject_len;
zval *headers = NULL;
zend_string *extra_cmd = NULL;
- zend_string *str_headers=NULL, *tmp_headers;
+ zend_string *str_headers = NULL, *tmp_headers;
int i;
char *to_r = NULL;
char *force_extra_parameters = INI_STR("mail.force_extra_parameters");
@@ -4455,82 +4455,66 @@ PHP_FUNCTION(mb_send_mail)
}
/* To: */
- if (to != NULL) {
- if (to_len > 0) {
- to_r = estrndup(to, to_len);
- for (; to_len; to_len--) {
- if (!isspace((unsigned char) to_r[to_len - 1])) {
- break;
- }
- to_r[to_len - 1] = '\0';
- }
- for (i = 0; to_r[i]; i++) {
- if (iscntrl((unsigned char) to_r[i])) {
- /* According to RFC 822, section 3.1.1 long headers may be separated into
- * parts using CRLF followed at least one linear-white-space character ('\t' or
' ').
- * To prevent these separators from being replaced with a space, we use the
- * SKIP_LONG_HEADER_SEP_MBSTRING to skip over them.
- */
- SKIP_LONG_HEADER_SEP_MBSTRING(to_r, i);
- to_r[i] = ' ';
- }
+ if (to_len > 0) {
+ to_r = estrndup(to, to_len);
+ for (; to_len; to_len--) {
+ if (!isspace((unsigned char) to_r[to_len - 1])) {
+ break;
}
- } else {
- to_r = to;
+ to_r[to_len - 1] = '\0';
+ }
+ for (i = 0; to_r[i]; i++) {
+ if (iscntrl((unsigned char) to_r[i])) {
+ /* According to RFC 822, section 3.1.1 long headers may be separated into
+ * parts using CRLF followed at least one linear-white-space character ('\t' or '
')..
+ * To prevent these separators from being replaced with a space, we use the
+ * SKIP_LONG_HEADER_SEP_MBSTRING to skip over them.
+ */
+ SKIP_LONG_HEADER_SEP_MBSTRING(to_r, i);
+ to_r[i] = ' ';
+ }
}
} else {
- php_error_docref(NULL, E_WARNING, "Missing To: field");
- err = 1;
+ to_r = to;
}
/* Subject: */
- if (subject != NULL) {
- orig_str.no_language = MBSTRG(language);
- orig_str.val = (unsigned char *)subject;
- orig_str.len = subject_len;
- orig_str.encoding = MBSTRG(current_internal_encoding);
- if (orig_str.encoding->no_encoding == mbfl_no_encoding_invalid
- || orig_str.encoding->no_encoding == mbfl_no_encoding_pass) {
- orig_str.encoding = mbfl_identify_encoding(&orig_str, MBSTRG(current_detect_order_list),
MBSTRG(current_detect_order_list_size), MBSTRG(strict_detection));
- }
- pstr = mbfl_mime_header_encode(&orig_str, &conv_str, tran_cs, head_enc, "\n",
sizeof("Subject: [PHP-jp nnnnnnnn]"));
- if (pstr != NULL) {
- subject_buf = subject = (char *)pstr->val;
- }
- } else {
- php_error_docref(NULL, E_WARNING, "Missing Subject: field");
- err = 1;
+ orig_str.no_language = MBSTRG(language);
+ orig_str.val = (unsigned char *)subject;
+ orig_str.len = subject_len;
+ orig_str.encoding = MBSTRG(current_internal_encoding);
+ if (orig_str.encoding->no_encoding == mbfl_no_encoding_invalid
+ || orig_str.encoding->no_encoding == mbfl_no_encoding_pass) {
+ orig_str.encoding = mbfl_identify_encoding(&orig_str, MBSTRG(current_detect_order_list),
MBSTRG(current_detect_order_list_size), MBSTRG(strict_detection));
+ }
+ pstr = mbfl_mime_header_encode(&orig_str, &conv_str, tran_cs, head_enc, "\n",
sizeof("Subject: [PHP-jp nnnnnnnn]"));
+ if (pstr != NULL) {
+ subject_buf = subject = (char *)pstr->val;
}
/* message body */
- if (message != NULL) {
- orig_str.no_language = MBSTRG(language);
- orig_str.val = (unsigned char *)message;
- orig_str.len = (unsigned int)message_len;
- orig_str.encoding = MBSTRG(current_internal_encoding);
+ orig_str.no_language = MBSTRG(language);
+ orig_str.val = (unsigned char *)message;
+ orig_str.len = (unsigned int)message_len;
+ orig_str.encoding = MBSTRG(current_internal_encoding);
- if (orig_str.encoding->no_encoding == mbfl_no_encoding_invalid
- || orig_str.encoding->no_encoding == mbfl_no_encoding_pass) {
- orig_str.encoding = mbfl_identify_encoding(&orig_str, MBSTRG(current_detect_order_list),
MBSTRG(current_detect_order_list_size), MBSTRG(strict_detection));
- }
+ if (orig_str.encoding->no_encoding == mbfl_no_encoding_invalid
+ || orig_str.encoding->no_encoding == mbfl_no_encoding_pass) {
+ orig_str.encoding = mbfl_identify_encoding(&orig_str, MBSTRG(current_detect_order_list),
MBSTRG(current_detect_order_list_size), MBSTRG(strict_detection));
+ }
- pstr = NULL;
- {
- mbfl_string tmpstr;
+ pstr = NULL;
+ {
+ mbfl_string tmpstr;
- if (mbfl_convert_encoding(&orig_str, &tmpstr, tran_cs) != NULL) {
- tmpstr.encoding = &mbfl_encoding_8bit;
- pstr = mbfl_convert_encoding(&tmpstr, &conv_str, body_enc);
- efree(tmpstr.val);
- }
- }
- if (pstr != NULL) {
- message_buf = message = (char *)pstr->val;
+ if (mbfl_convert_encoding(&orig_str, &tmpstr, tran_cs) != NULL) {
+ tmpstr.encoding = &mbfl_encoding_8bit;
+ pstr = mbfl_convert_encoding(&tmpstr, &conv_str, body_enc);
+ efree(tmpstr.val);
}
- } else {
- /* this is not really an error, so it is allowed. */
- php_error_docref(NULL, E_WARNING, "Empty message body");
- message = NULL;
+ }
+ if (pstr != NULL) {
+ message_buf = message = (char *)pstr->val;
}
/* other headers */