Skip to content

Commit 4a438b4

Browse files
committed
Warning to Error promotion in ext/standard
Those should be the last ones other than set(raw)cookie() Closes GH-5814
1 parent cd1c36f commit 4a438b4

File tree

10 files changed

+54
-52
lines changed

10 files changed

+54
-52
lines changed

ext/standard/basic_functions.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,8 +2647,8 @@ PHP_FUNCTION(parse_ini_file)
26472647
ZEND_PARSE_PARAMETERS_END();
26482648

26492649
if (filename_len == 0) {
2650-
php_error_docref(NULL, E_WARNING, "Filename cannot be empty!");
2651-
RETURN_FALSE;
2650+
zend_argument_value_error(1, "cannot be empty");
2651+
RETURN_THROWS();
26522652
}
26532653

26542654
/* Set callback function */

ext/standard/dns.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ PHP_FUNCTION(gethostbyname)
210210
Z_PARAM_STRING(hostname, hostname_len)
211211
ZEND_PARSE_PARAMETERS_END();
212212

213-
if(hostname_len > MAXFQDNLEN) {
213+
if (hostname_len > MAXFQDNLEN) {
214214
/* name too long, protect from CVE-2015-0235 */
215-
php_error_docref(NULL, E_WARNING, "Host name is too long, the limit is %d characters", MAXFQDNLEN);
215+
php_error_docref(NULL, E_WARNING, "Host name cannot be longer than %d characters", MAXFQDNLEN);
216216
RETURN_STRINGL(hostname, hostname_len);
217217
}
218218

@@ -233,9 +233,9 @@ PHP_FUNCTION(gethostbynamel)
233233
Z_PARAM_STRING(hostname, hostname_len)
234234
ZEND_PARSE_PARAMETERS_END();
235235

236-
if(hostname_len > MAXFQDNLEN) {
236+
if (hostname_len > MAXFQDNLEN) {
237237
/* name too long, protect from CVE-2015-0235 */
238-
php_error_docref(NULL, E_WARNING, "Host name is too long, the limit is %d characters", MAXFQDNLEN);
238+
php_error_docref(NULL, E_WARNING, "Host name cannot be longer than %d characters", MAXFQDNLEN);
239239
RETURN_FALSE;
240240
}
241241

@@ -393,8 +393,8 @@ PHP_FUNCTION(dns_check_record)
393393
else if (!strcasecmp("NAPTR", rectype)) type = DNS_T_NAPTR;
394394
else if (!strcasecmp("A6", rectype)) type = DNS_T_A6;
395395
else {
396-
php_error_docref(NULL, E_WARNING, "Type '%s' not supported", rectype);
397-
RETURN_FALSE;
396+
zend_argument_value_error(2, "must be a valid DNS record type");
397+
RETURN_THROWS();
398398
}
399399
}
400400

@@ -837,14 +837,13 @@ PHP_FUNCTION(dns_get_record)
837837

838838
if (!raw) {
839839
if ((type_param & ~PHP_DNS_ALL) && (type_param != PHP_DNS_ANY)) {
840-
php_error_docref(NULL, E_WARNING, "Type '" ZEND_LONG_FMT "' not supported", type_param);
841-
RETURN_FALSE;
840+
zend_argument_value_error(2, "must be a DNS_* constant");
841+
RETURN_THROWS();
842842
}
843843
} else {
844844
if ((type_param < 1) || (type_param > 0xFFFF)) {
845-
php_error_docref(NULL, E_WARNING,
846-
"Numeric DNS record type must be between 1 and 65535, '" ZEND_LONG_FMT "' given", type_param);
847-
RETURN_FALSE;
845+
zend_argument_value_error(2, "must be between 1 and 65535 when argument #5 ($raw) is true");
846+
RETURN_THROWS();
848847
}
849848
}
850849

ext/standard/exec.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,12 @@ static void php_exec_ex(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ */
220220
ZEND_PARSE_PARAMETERS_END();
221221

222222
if (!cmd_len) {
223-
php_error_docref(NULL, E_WARNING, "Cannot execute a blank command");
224-
RETURN_FALSE;
223+
zend_argument_value_error(1, "cannot be empty");
224+
RETURN_THROWS();
225225
}
226226
if (strlen(cmd) != cmd_len) {
227-
php_error_docref(NULL, E_WARNING, "NULL byte detected. Possible attack");
228-
RETURN_FALSE;
227+
zend_argument_type_error(1, "must not contain any null bytes");
228+
RETURN_THROWS();
229229
}
230230

231231
if (!ret_array) {
@@ -523,12 +523,12 @@ PHP_FUNCTION(shell_exec)
523523
ZEND_PARSE_PARAMETERS_END();
524524

525525
if (!command_len) {
526-
php_error_docref(NULL, E_WARNING, "Cannot execute a blank command");
527-
RETURN_FALSE;
526+
zend_argument_value_error(1, "cannot be empty");
527+
RETURN_THROWS();
528528
}
529529
if (strlen(command) != command_len) {
530-
php_error_docref(NULL, E_WARNING, "NULL byte detected. Possible attack");
531-
RETURN_FALSE;
530+
zend_argument_type_error(1, "must not contain any null bytes");
531+
RETURN_THROWS();
532532
}
533533

534534
#ifdef PHP_WIN32

ext/standard/ftok.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ PHP_FUNCTION(ftok)
4040
ZEND_PARSE_PARAMETERS_END();
4141

4242
if (pathname_len == 0){
43-
php_error_docref(NULL, E_WARNING, "Pathname is invalid");
44-
RETURN_LONG(-1);
43+
zend_argument_value_error(1, "cannot be empty");
44+
RETURN_THROWS();
4545
}
4646

4747
if (proj_len != 1){

ext/standard/iptc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ PHP_FUNCTION(iptcembed)
193193
}
194194

195195
if (iptcdata_len >= SIZE_MAX - sizeof(psheader) - 1025) {
196-
php_error_docref(NULL, E_WARNING, "IPTC data too large");
197-
RETURN_FALSE;
196+
zend_argument_value_error(1, "is too large");
197+
RETURN_THROWS();
198198
}
199199

200200
if ((fp = VCWD_FOPEN(jpeg_file, "rb")) == 0) {

ext/standard/streamsfuncs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,8 +1698,8 @@ PHP_FUNCTION(stream_socket_shutdown)
16981698
if (how != STREAM_SHUT_RD &&
16991699
how != STREAM_SHUT_WR &&
17001700
how != STREAM_SHUT_RDWR) {
1701-
php_error_docref(NULL, E_WARNING, "Second parameter $how needs to be one of STREAM_SHUT_RD, STREAM_SHUT_WR or STREAM_SHUT_RDWR");
1702-
RETURN_FALSE;
1701+
zend_argument_value_error(2, "must be one of STREAM_SHUT_RD, STREAM_SHUT_WR, or STREAM_SHUT_RDWR");
1702+
RETURN_THROWS();
17031703
}
17041704

17051705
php_stream_from_zval(stream, zstream);

ext/standard/tests/misc/exec_basic1.phpt

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,23 @@ exec, system, passthru — Basic command execution functions
88
--FILE--
99
<?php
1010
$cmd = "echo abc\n\0command";
11-
var_dump(exec($cmd, $output));
12-
var_dump($output);
13-
var_dump(system($cmd));
14-
var_dump(passthru($cmd));
11+
try {
12+
var_dump(exec($cmd, $output));
13+
} catch (\TypeError $e) {
14+
echo $e->getMessage() . \PHP_EOL;
15+
}
16+
try {
17+
var_dump(system($cmd, $output));
18+
} catch (\TypeError $e) {
19+
echo $e->getMessage() . \PHP_EOL;
20+
}
21+
try {
22+
var_dump(passthru($cmd, $output));
23+
} catch (\TypeError $e) {
24+
echo $e->getMessage() . \PHP_EOL;
25+
}
1526
?>
16-
--EXPECTF--
17-
Warning: exec(): NULL byte detected. Possible attack in %s on line %d
18-
bool(false)
19-
NULL
20-
21-
Warning: system(): NULL byte detected. Possible attack in %s on line %d
22-
bool(false)
23-
24-
Warning: passthru(): NULL byte detected. Possible attack in %s on line %d
25-
bool(false)
27+
--EXPECT--
28+
exec(): Argument #1 ($command) must not contain any null bytes
29+
system(): Argument #1 ($command) must not contain any null bytes
30+
passthru(): Argument #1 ($command) must not contain any null bytes

ext/standard/tests/network/bug68925.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ var_dump(gethostbyname(str_repeat("0", 2501)));
66
var_dump(gethostbynamel(str_repeat("0", 2501)));
77
?>
88
--EXPECTF--
9-
Warning: gethostbyname(): Host name is too long, the limit is %d characters in %s%ebug68925.php on line %d
9+
Warning: gethostbyname(): Host name cannot be longer than %d characters in %s%ebug68925.php on line %d
1010
string(2501) "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
1111

12-
Warning: gethostbynamel(): Host name is too long, the limit is %d characters in %s%ebug68925.php on line %d
12+
Warning: gethostbynamel(): Host name cannot be longer than %d characters in %s%ebug68925.php on line %d
1313
bool(false)

ext/standard/user_filters.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,7 @@ static php_stream_filter *user_filter_factory_create(const char *filtername,
299299
}
300300
efree(wildcard);
301301
}
302-
if (fdat == NULL) {
303-
php_error_docref(NULL, E_WARNING,
304-
"Err, filter \"%s\" is not in the user-filter map, but somehow the user-filter-factory was invoked for it!?", filtername);
305-
return NULL;
306-
}
302+
ZEND_ASSERT(fdat);
307303
}
308304

309305
/* bind the classname to the actual class */

ext/sysvshm/tests/001.phpt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ if (!function_exists('ftok')){ print 'skip'; }
77
?>
88
--FILE--
99
<?php
10-
11-
var_dump(ftok("",""));
10+
try {
11+
var_dump(ftok("",""));
12+
} catch (\ValueError $e) {
13+
echo $e->getMessage() . \PHP_EOL;
14+
}
1215
var_dump(ftok(-1, -1));
1316
var_dump(ftok("qwertyu","qwertyu"));
1417

@@ -19,8 +22,7 @@ var_dump(ftok(__FILE__,"q"));
1922
echo "Done\n";
2023
?>
2124
--EXPECTF--
22-
Warning: ftok(): Pathname is invalid in %s on line %d
23-
int(-1)
25+
ftok(): Argument #1 ($pathname) cannot be empty
2426

2527
Warning: ftok(): Project identifier is invalid in %s on line %d
2628
int(-1)

0 commit comments

Comments
 (0)