Skip to content

Commit 9a2b786

Browse files
committed
Address review comments
1 parent ae00d41 commit 9a2b786

File tree

9 files changed

+224
-98
lines changed

9 files changed

+224
-98
lines changed

ext/mbstring/mbstring.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3499,7 +3499,7 @@ PHP_FUNCTION(mb_send_mail)
34993499
str_headers = php_trim(str_headers, NULL, 0, 2);
35003500
} else if (headers_ht) {
35013501
str_headers = php_mail_build_headers(headers_ht);
3502-
if (!str_headers) {
3502+
if (EG(exception)) {
35033503
RETURN_THROWS();
35043504
}
35053505
}

ext/standard/file.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -942,20 +942,23 @@ PHP_FUNCTION(popen)
942942
mode_len--;
943943
}
944944
}
945+
#endif
945946

946947
/* Musl only partially validates the mode. Manually check it to ensure consistent behavior. */
947-
if (mode_len != 1 || (*posix_mode != 'r' && *posix_mode != 'w')) {
948-
zend_argument_value_error(2, "must be either \"r\" or \"w\"");
948+
if (mode_len > 2 ||
949+
(mode_len == 1 && (*posix_mode != 'r' && *posix_mode != 'w')) ||
950+
(mode_len == 2 && (memcmp(posix_mode, "rb", 2) || memcmp(posix_mode, "wb", 2)))
951+
) {
952+
zend_argument_value_error(2, "must be one of \"r\", \"rb\", \"w\", or \"wb\"");
949953
efree(posix_mode);
950954
RETURN_THROWS();
951955
}
952-
#endif
953956

954957
fp = VCWD_POPEN(command, posix_mode);
955958
if (!fp) {
956959
php_error_docref2(NULL, command, posix_mode, E_WARNING, "%s", strerror(errno));
957960
efree(posix_mode);
958-
RETURN_FALSE;
961+
RETURN_THROWS();
959962
}
960963

961964
stream = php_stream_fopen_from_pipe(fp, mode);

ext/standard/mail.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ static void php_mail_build_headers_elems(smart_str *s, zend_string *key, zval *v
134134
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(val), tmp_key, tmp_val) {
135135
if (tmp_key) {
136136
zend_type_error("Header \"%s\" must only contain numeric keys, \"%s\" found", ZSTR_VAL(key), ZSTR_VAL(tmp_key));
137-
continue;
137+
break;
138138
}
139139
if (Z_TYPE_P(tmp_val) != IS_STRING) {
140140
zend_type_error("Header \"%s\" must only contain values of type string, %s found", ZSTR_VAL(key), zend_zval_type_name(tmp_val));
141-
continue;
141+
break;
142142
}
143143
php_mail_build_headers_elem(s, key, tmp_val);
144144
} ZEND_HASH_FOREACH_END();
@@ -276,7 +276,7 @@ PHP_FUNCTION(mail)
276276
headers_str = php_trim(headers_str, NULL, 0, 2);
277277
} else if (headers_ht) {
278278
headers_str = php_mail_build_headers(headers_ht);
279-
if (!headers_str) {
279+
if (EG(exception)) {
280280
RETURN_THROWS();
281281
}
282282
}

ext/standard/password.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static zend_string* php_password_make_salt(size_t length) /* {{{ */
109109

110110
static zend_string* php_password_get_salt(zval *unused_, size_t required_salt_len, HashTable *options) {
111111
if (options && zend_hash_str_exists(options, "salt", sizeof("salt") - 1)) {
112-
php_error_docref(NULL, E_WARNING, "The \"salt\" option is ignored, since providing a custom salt is no longer supported");
112+
php_error_docref(NULL, E_WARNING, "The \"salt\" option has been ignored, since providing a custom salt is no longer supported");
113113
}
114114

115115
return php_password_make_salt(required_salt_len);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Test popen() and pclose function
3+
--SKIPIF--
4+
<?php
5+
if (strtoupper( substr(PHP_OS, 0, 3) ) == 'SUN')
6+
die("skip Not valid for Sun Solaris");
7+
8+
if (strtoupper( substr(PHP_OS, 0, 3) ) == 'WIN')
9+
die("skip Not valid for Windows");
10+
?>
11+
--FILE--
12+
<?php
13+
$file_path = __DIR__;
14+
15+
$file_handle = fopen($file_path."/popen.tmp", "w");
16+
fclose($file_handle);
17+
18+
$file_handle = fopen($file_path."/popen.tmp", "wb");
19+
fclose($file_handle);
20+
echo "--- Done ---";
21+
22+
?>
23+
--CLEAN--
24+
<?php
25+
$file_path = __DIR__;
26+
unlink($file_path."/popen.tmp");
27+
?>
28+
--EXPECT--
29+
--- Done ---
Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,28 @@
11
--TEST--
22
Test popen() and pclose function: error conditions
3-
--SKIPIF--
4-
<?php
5-
if (strtoupper( substr(PHP_OS, 0, 3) ) == 'SUN')
6-
die("skip Not valid for Sun Solaris");
7-
8-
if (strtoupper( substr(PHP_OS, 0, 3) ) == 'WIN')
9-
die("skip Not valid for Windows");
10-
?>
113
--FILE--
124
<?php
13-
$file_path = __DIR__;
14-
echo "*** Testing for error conditions ***\n";
155

166
try {
17-
popen("abc.txt", "rw"); // Invalid mode Argument
7+
popen("abc.txt", "x");
188
} catch (ValueError $exception) {
199
echo $exception->getMessage() . "\n";
2010
}
2111

22-
$file_handle = fopen($file_path."/popen.tmp", "w");
23-
fclose($file_handle);
24-
echo "\n--- Done ---";
12+
try {
13+
popen("abc.txt", "rw");
14+
} catch (ValueError $exception) {
15+
echo $exception->getMessage() . "\n";
16+
}
17+
18+
try {
19+
popen("abc.txt", "rwb");
20+
} catch (ValueError $exception) {
21+
echo $exception->getMessage() . "\n";
22+
}
2523

26-
?>
27-
--CLEAN--
28-
<?php
29-
$file_path = __DIR__;
30-
unlink($file_path."/popen.tmp");
3124
?>
3225
--EXPECT--
33-
*** Testing for error conditions ***
34-
popen(): Argument #2 ($mode) must be either "r" or "w"
35-
36-
--- Done ---
26+
popen(): Argument #2 ($mode) must be one of "r", "rb", "w", or "wb"
27+
popen(): Argument #2 ($mode) must be one of "r", "rb", "w", or "wb"
28+
popen(): Argument #2 ($mode) must be one of "r", "rb", "w", or "wb"

ext/standard/tests/general_functions/bug41037.phpt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Bug #41037 (unregister_tick_function() inside the tick function crash PHP)
44
<?php
55

66
function a() {
7-
echo "hello";
7+
echo "hello\n";
88
try {
99
unregister_tick_function('a');
1010
} catch (Error $exception) {
@@ -19,6 +19,8 @@ declare (ticks=1) {
1919
}
2020
?>
2121
--EXPECT--
22-
helloRegistered tick function cannot be unregistered while it is being executed
22+
hello
23+
Registered tick function cannot be unregistered while it is being executed
2324
Done
24-
helloRegistered tick function cannot be unregistered while it is being executed
25+
hello
26+
Registered tick function cannot be unregistered while it is being executed

0 commit comments

Comments
 (0)