1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Use zend_string API for mail.cr_lf_mode validation (#19759)

This commit is contained in:
Alexandre Daubois
2025-09-09 10:18:42 +02:00
committed by GitHub
parent 5a177eedd5
commit 3f66cbeb4d
3 changed files with 13 additions and 14 deletions

View File

@@ -495,14 +495,14 @@ PHPAPI bool php_mail(const char *to, const char *subject, const char *message, c
}
char *line_sep;
const char *cr_lf_mode = PG(mail_cr_lf_mode);
zend_string *cr_lf_mode = PG(mail_cr_lf_mode);
if (cr_lf_mode && strcmp(cr_lf_mode, "crlf") != 0) {
if (strcmp(cr_lf_mode, "lf") == 0) {
if (cr_lf_mode && !zend_string_equals_literal(cr_lf_mode, "crlf")) {
if (zend_string_equals_literal(cr_lf_mode, "lf")) {
line_sep = "\n";
} else if (strcmp(cr_lf_mode, "mixed") == 0) {
} else if (zend_string_equals_literal(cr_lf_mode, "mixed")) {
line_sep = "\n";
} else if (strcmp(cr_lf_mode, "os") == 0) {
} else if (zend_string_equals_literal(cr_lf_mode, "os")) {
#ifdef PHP_WIN32
line_sep = "\r\n";
#else
@@ -609,7 +609,7 @@ PHPAPI bool php_mail(const char *to, const char *subject, const char *message, c
fprintf(sendmail, "%s", line_sep);
if (cr_lf_mode && strcmp(cr_lf_mode, "lf") == 0) {
if (cr_lf_mode && zend_string_equals_literal(cr_lf_mode, "lf")) {
char *converted_message = NULL;
size_t msg_len = strlen(message);
size_t new_len = 0;

View File

@@ -725,12 +725,11 @@ static PHP_INI_MH(OnUpdateMailLog)
static PHP_INI_MH(OnUpdateMailCrLfMode)
{
if (new_value) {
const char *val = ZSTR_VAL(new_value);
if (ZSTR_LEN(new_value) > 0 &&
strcmp(val, "crlf") != 0 &&
strcmp(val, "lf") != 0 &&
strcmp(val, "mixed") != 0 &&
strcmp(val, "os") != 0) {
!zend_string_equals_literal(new_value, "crlf") &&
!zend_string_equals_literal(new_value, "lf") &&
!zend_string_equals_literal(new_value, "mixed") &&
!zend_string_equals_literal(new_value, "os")) {
int err_type;
if (stage == ZEND_INI_STAGE_RUNTIME) {
@@ -740,13 +739,13 @@ static PHP_INI_MH(OnUpdateMailCrLfMode)
}
if (stage != ZEND_INI_STAGE_DEACTIVATE) {
php_error_docref(NULL, err_type, "Invalid value \"%s\" for mail.cr_lf_mode. Must be one of: \"crlf\", \"lf\", \"mixed\", \"os\"", val);
php_error_docref(NULL, err_type, "Invalid value \"%s\" for mail.cr_lf_mode. Must be one of: \"crlf\", \"lf\", \"mixed\", \"os\"", ZSTR_VAL(new_value));
}
return FAILURE;
}
}
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
OnUpdateStr(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
return SUCCESS;
}
/* }}} */

View File

@@ -152,9 +152,9 @@ struct _php_core_globals {
char *request_order;
char *mail_log;
zend_string *mail_cr_lf_mode;
bool mail_x_header;
bool mail_mixed_lf_and_crlf;
char *mail_cr_lf_mode;
bool in_error_log;