Skip to content

ext/standard warning to error promotions #5814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 15 commits into from
4 changes: 2 additions & 2 deletions ext/standard/basic_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -2647,8 +2647,8 @@ PHP_FUNCTION(parse_ini_file)
ZEND_PARSE_PARAMETERS_END();

if (filename_len == 0) {
php_error_docref(NULL, E_WARNING, "Filename cannot be empty!");
RETURN_FALSE;
zend_argument_value_error(1, "cannot be empty");
RETURN_THROWS();
}

/* Set callback function */
Expand Down
21 changes: 10 additions & 11 deletions ext/standard/dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ PHP_FUNCTION(gethostbyname)
Z_PARAM_STRING(hostname, hostname_len)
ZEND_PARSE_PARAMETERS_END();

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

Expand All @@ -233,9 +233,9 @@ PHP_FUNCTION(gethostbynamel)
Z_PARAM_STRING(hostname, hostname_len)
ZEND_PARSE_PARAMETERS_END();

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

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

Expand Down Expand Up @@ -837,14 +837,13 @@ PHP_FUNCTION(dns_get_record)

if (!raw) {
if ((type_param & ~PHP_DNS_ALL) && (type_param != PHP_DNS_ANY)) {
php_error_docref(NULL, E_WARNING, "Type '" ZEND_LONG_FMT "' not supported", type_param);
RETURN_FALSE;
zend_argument_value_error(2, "must be a DNS_* constant");
RETURN_THROWS();
}
} else {
if ((type_param < 1) || (type_param > 0xFFFF)) {
php_error_docref(NULL, E_WARNING,
"Numeric DNS record type must be between 1 and 65535, '" ZEND_LONG_FMT "' given", type_param);
RETURN_FALSE;
zend_argument_value_error(2, "must be between 1 and 65535 when argument #5 ($raw) is true");
RETURN_THROWS();
}
}

Expand Down
16 changes: 8 additions & 8 deletions ext/standard/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,12 @@ static void php_exec_ex(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ */
ZEND_PARSE_PARAMETERS_END();

if (!cmd_len) {
php_error_docref(NULL, E_WARNING, "Cannot execute a blank command");
RETURN_FALSE;
zend_argument_value_error(1, "cannot be empty");
RETURN_THROWS();
}
if (strlen(cmd) != cmd_len) {
php_error_docref(NULL, E_WARNING, "NULL byte detected. Possible attack");
RETURN_FALSE;
zend_argument_type_error(1, "must not contain any null bytes");
RETURN_THROWS();
}

if (!ret_array) {
Expand Down Expand Up @@ -523,12 +523,12 @@ PHP_FUNCTION(shell_exec)
ZEND_PARSE_PARAMETERS_END();

if (!command_len) {
php_error_docref(NULL, E_WARNING, "Cannot execute a blank command");
RETURN_FALSE;
zend_argument_value_error(1, "cannot be empty");
RETURN_THROWS();
}
if (strlen(command) != command_len) {
php_error_docref(NULL, E_WARNING, "NULL byte detected. Possible attack");
RETURN_FALSE;
zend_argument_type_error(1, "must not contain any null bytes");
RETURN_THROWS();
}

#ifdef PHP_WIN32
Expand Down
4 changes: 2 additions & 2 deletions ext/standard/ftok.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ PHP_FUNCTION(ftok)
ZEND_PARSE_PARAMETERS_END();

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

if (proj_len != 1){
Expand Down
4 changes: 2 additions & 2 deletions ext/standard/iptc.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ PHP_FUNCTION(iptcembed)
}

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

if ((fp = VCWD_FOPEN(jpeg_file, "rb")) == 0) {
Expand Down
4 changes: 2 additions & 2 deletions ext/standard/streamsfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1698,8 +1698,8 @@ PHP_FUNCTION(stream_socket_shutdown)
if (how != STREAM_SHUT_RD &&
how != STREAM_SHUT_WR &&
how != STREAM_SHUT_RDWR) {
php_error_docref(NULL, E_WARNING, "Second parameter $how needs to be one of STREAM_SHUT_RD, STREAM_SHUT_WR or STREAM_SHUT_RDWR");
RETURN_FALSE;
zend_argument_value_error(2, "must be one of STREAM_SHUT_RD, STREAM_SHUT_WR, or STREAM_SHUT_RDWR");
RETURN_THROWS();
}

php_stream_from_zval(stream, zstream);
Expand Down
33 changes: 19 additions & 14 deletions ext/standard/tests/misc/exec_basic1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,23 @@ exec, system, passthru — Basic command execution functions
--FILE--
<?php
$cmd = "echo abc\n\0command";
var_dump(exec($cmd, $output));
var_dump($output);
var_dump(system($cmd));
var_dump(passthru($cmd));
try {
var_dump(exec($cmd, $output));
} catch (\TypeError $e) {
echo $e->getMessage() . \PHP_EOL;
}
try {
var_dump(system($cmd, $output));
} catch (\TypeError $e) {
echo $e->getMessage() . \PHP_EOL;
}
try {
var_dump(passthru($cmd, $output));
} catch (\TypeError $e) {
echo $e->getMessage() . \PHP_EOL;
}
?>
--EXPECTF--
Warning: exec(): NULL byte detected. Possible attack in %s on line %d
bool(false)
NULL

Warning: system(): NULL byte detected. Possible attack in %s on line %d
bool(false)

Warning: passthru(): NULL byte detected. Possible attack in %s on line %d
bool(false)
--EXPECT--
exec(): Argument #1 ($command) must not contain any null bytes
system(): Argument #1 ($command) must not contain any null bytes
passthru(): Argument #1 ($command) must not contain any null bytes
4 changes: 2 additions & 2 deletions ext/standard/tests/network/bug68925.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ var_dump(gethostbyname(str_repeat("0", 2501)));
var_dump(gethostbynamel(str_repeat("0", 2501)));
?>
--EXPECTF--
Warning: gethostbyname(): Host name is too long, the limit is %d characters in %s%ebug68925.php on line %d
Warning: gethostbyname(): Host name cannot be longer than %d characters in %s%ebug68925.php on line %d
string(2501) "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"

Warning: gethostbynamel(): Host name is too long, the limit is %d characters in %s%ebug68925.php on line %d
Warning: gethostbynamel(): Host name cannot be longer than %d characters in %s%ebug68925.php on line %d
bool(false)
6 changes: 1 addition & 5 deletions ext/standard/user_filters.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,7 @@ static php_stream_filter *user_filter_factory_create(const char *filtername,
}
efree(wildcard);
}
if (fdat == NULL) {
php_error_docref(NULL, E_WARNING,
"Err, filter \"%s\" is not in the user-filter map, but somehow the user-filter-factory was invoked for it!?", filtername);
return NULL;
}
ZEND_ASSERT(fdat);
}

/* bind the classname to the actual class */
Expand Down
10 changes: 6 additions & 4 deletions ext/sysvshm/tests/001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ if (!function_exists('ftok')){ print 'skip'; }
?>
--FILE--
<?php

var_dump(ftok("",""));
try {
var_dump(ftok("",""));
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
var_dump(ftok(-1, -1));
var_dump(ftok("qwertyu","qwertyu"));

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

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