Skip to content

Commit 5f8c7dc

Browse files
committed
ext/standard/mail.c: refactor php_mail_build_headers_check_field_value()
Change paremeter type to be zend_string* rather than assuming the zval IS_STRING Use zend_string macros Add const qualifier
1 parent 402f084 commit 5f8c7dc

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

ext/standard/mail.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,20 @@ typedef enum {
6868
CONTAINS_NULL
6969
} php_mail_header_value_error_type;
7070

71-
static php_mail_header_value_error_type php_mail_build_headers_check_field_value(zval *val)
71+
static php_mail_header_value_error_type php_mail_build_headers_check_field_value(const zend_string *value)
7272
{
7373
size_t len = 0;
74-
zend_string *value = Z_STR_P(val);
7574

7675
/* https://tools.ietf.org/html/rfc2822#section-2.2.1 */
7776
/* https://tools.ietf.org/html/rfc2822#section-2.2.3 */
78-
while (len < value->len) {
79-
if (*(value->val+len) == '\r') {
80-
if (*(value->val+len+1) != '\n') {
77+
while (len < ZSTR_LEN(value)) {
78+
if (*(ZSTR_VAL(value)+len) == '\r') {
79+
if (*(ZSTR_VAL(value)+len+1) != '\n') {
8180
return CONTAINS_CR_ONLY;
8281
}
8382

84-
if (value->len - len >= 3
85-
&& (*(value->val+len+2) == ' ' || *(value->val+len+2) == '\t')) {
83+
if (ZSTR_LEN(value) - len >= 3
84+
&& (*(ZSTR_VAL(value)+len+2) == ' ' || *(ZSTR_VAL(value)+len+2) == '\t')) {
8685
len += 3;
8786
continue;
8887
}
@@ -96,15 +95,15 @@ static php_mail_header_value_error_type php_mail_build_headers_check_field_value
9695
* Therefore, considering such an environment, folding with LF alone
9796
* is allowed.
9897
*/
99-
if (*(value->val+len) == '\n') {
100-
if (value->len - len >= 2
101-
&& (*(value->val+len+1) == ' ' || *(value->val+len+1) == '\t')) {
98+
if (*(ZSTR_VAL(value)+len) == '\n') {
99+
if (ZSTR_LEN(value) - len >= 2
100+
&& (*(ZSTR_VAL(value)+len+1) == ' ' || *(ZSTR_VAL(value)+len+1) == '\t')) {
102101
len += 2;
103102
continue;
104103
}
105104
return CONTAINS_LF_ONLY;
106105
}
107-
if (*(value->val+len) == '\0') {
106+
if (*(ZSTR_VAL(value)+len) == '\0') {
108107
return CONTAINS_NULL;
109108
}
110109
len++;
@@ -138,7 +137,8 @@ static void php_mail_build_headers_elem(smart_str *s, const zend_string *key, zv
138137
return;
139138
}
140139

141-
php_mail_header_value_error_type error_type = php_mail_build_headers_check_field_value(val);
140+
zend_string *str_value = Z_STR_P(val);
141+
php_mail_header_value_error_type error_type = php_mail_build_headers_check_field_value(str_value);
142142
switch (error_type) {
143143
case NO_HEADER_ERROR:
144144
break;
@@ -161,7 +161,7 @@ static void php_mail_build_headers_elem(smart_str *s, const zend_string *key, zv
161161
}
162162
smart_str_append(s, key);
163163
smart_str_appendl(s, ": ", 2);
164-
smart_str_append(s, Z_STR_P(val));
164+
smart_str_append(s, str_value);
165165
smart_str_appendl(s, "\r\n", 2);
166166
break;
167167
case IS_ARRAY:

0 commit comments

Comments
 (0)