Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions ext/standard/basic_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,12 @@ PHP_FUNCTION(ip2long)
Z_PARAM_PATH(addr, addr_len)
ZEND_PARSE_PARAMETERS_END();

if (addr_len == 0 || inet_pton(AF_INET, addr, &ip) != 1) {
if (addr_len == 0) {
zend_argument_must_not_be_empty_error(1);
RETURN_THROWS();
}

if (inet_pton(AF_INET, addr, &ip) != 1) {
RETURN_FALSE;
}
#ifdef _AIX
Expand Down Expand Up @@ -1177,8 +1182,8 @@ PHP_FUNCTION(time_nanosleep)
zend_argument_value_error(1, "must be greater than or equal to 0");
RETURN_THROWS();
}
if (tv_nsec < 0) {
zend_argument_value_error(2, "must be greater than or equal to 0");
if (tv_nsec < 0 || tv_nsec > 999999999) {
zend_argument_value_error(2, "must be between 0 and 999999999");
RETURN_THROWS();
}

Expand All @@ -1192,10 +1197,8 @@ PHP_FUNCTION(time_nanosleep)
add_assoc_long_ex(return_value, "seconds", sizeof("seconds")-1, php_rem.tv_sec);
add_assoc_long_ex(return_value, "nanoseconds", sizeof("nanoseconds")-1, php_rem.tv_nsec);
return;
} else if (errno == EINVAL) {
zend_value_error("Nanoseconds was not in the range 0 to 999 999 999 or seconds was negative");
RETURN_THROWS();
}
ZEND_ASSERT(errno != EINVAL);

RETURN_FALSE;
}
Expand Down Expand Up @@ -2119,7 +2122,7 @@ PHP_FUNCTION(connection_aborted)
{
ZEND_PARSE_PARAMETERS_NONE();

RETURN_LONG(PG(connection_status) & PHP_CONNECTION_ABORTED);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, this change can break user code that checks the return value against PHP_CONNECTION_ABORTED

RETURN_BOOL(PG(connection_status) & PHP_CONNECTION_ABORTED);
}
/* }}} */

Expand All @@ -2137,22 +2140,22 @@ PHP_FUNCTION(ignore_user_abort)
{
bool arg = 0;
bool arg_is_null = 1;
int old_setting;
bool old_setting;

ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
Z_PARAM_BOOL_OR_NULL(arg, arg_is_null)
ZEND_PARSE_PARAMETERS_END();

old_setting = (unsigned short)PG(ignore_user_abort);
old_setting = PG(ignore_user_abort);

if (!arg_is_null) {
zend_string *key = ZSTR_INIT_LITERAL("ignore_user_abort", 0);
zend_alter_ini_entry_chars(key, arg ? "1" : "0", 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
zend_string_release_ex(key, 0);
}

RETURN_LONG(old_setting);
RETURN_BOOL(old_setting);
}
/* }}} */

Expand Down
4 changes: 2 additions & 2 deletions ext/standard/basic_functions.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2039,11 +2039,11 @@ function get_include_path(): string|false {}
/** @refcount 1 */
function print_r(mixed $value, bool $return = false): string|true {}

function connection_aborted(): int {}
function connection_aborted(): bool {}

function connection_status(): int {}

function ignore_user_abort(?bool $enable = null): int {}
function ignore_user_abort(?bool $enable = null): bool {}

#ifdef HAVE_GETSERVBYNAME
function getservbyname(string $service, string $protocol): int|false {}
Expand Down
6 changes: 3 additions & 3 deletions ext/standard/basic_functions_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions ext/standard/basic_functions_decl.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions ext/standard/tests/general_functions/bug72300.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ var_dump(ini_get("ignore_user_abort"));

?>
--EXPECT--
int(0)
int(1)
bool(false)
bool(true)
string(1) "1"
int(1)
int(0)
bool(true)
bool(false)
string(1) "0"
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
--TEST--
int connection_aborted ( void );
Basic test for connection_aborted()
--CREDITS--
marcosptf - <marcosptf@yahoo.com.br> - #phparty7 - @phpsp - novatec/2015 - sao paulo - br
--FILE--
<?php
var_dump(connection_aborted());
?>
--EXPECT--
int(0)
bool(false)
14 changes: 7 additions & 7 deletions ext/standard/tests/misc/time_nanosleep_error4.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ if (!function_exists('time_nanosleep')) die("skip");
--FILE--
<?php

time_nanosleep(0, -10);
try {
time_nanosleep(0, -10);
} catch (ValueError $exception) {
echo $exception->getMessage(), "\n";
}

?>
--EXPECTF--
Fatal error: Uncaught ValueError: time_nanosleep(): Argument #2 ($nanoseconds) must be greater than or equal to 0 in %s:%d
Stack trace:
#0 %s(%d): time_nanosleep(0, -10)
#1 {main}
thrown in %s on line %d
--EXPECT--
time_nanosleep(): Argument #2 ($nanoseconds) must be between 0 and 999999999
14 changes: 7 additions & 7 deletions ext/standard/tests/misc/time_nanosleep_error5.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ time_nanosleep — Delay for a number of seconds and nanoseconds
--FILE--
<?php

time_nanosleep(0, 1000000000);
try {
time_nanosleep(0, 1000000000);
} catch (ValueError $exception) {
echo $exception->getMessage(), "\n";
}

?>
--EXPECTF--
Fatal error: Uncaught ValueError: Nanoseconds was not in the range 0 to 999 999 999 or seconds was negative in %s:%d
Stack trace:
#0 %s(%d): time_nanosleep(0, 1000000000)
#1 {main}
thrown in %s on line %d
--EXPECT--
time_nanosleep(): Argument #2 ($nanoseconds) must be between 0 and 999999999
6 changes: 2 additions & 4 deletions ext/standard/tests/network/ip.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@ if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
--FILE--
<?php

$array = array(
$array = [
"127.0.0.1",
"10.0.0.1",
"255.255.255.255",
"255.255.255.0",
"0.0.0.0",
"66.163.161.116",
);
];

foreach ($array as $ip) {
var_dump($long = ip2long($ip));
var_dump(long2ip($long));
}

var_dump(ip2long(""));
var_dump(ip2long("777.777.777.777"));
var_dump(ip2long("111.111.111.111"));

Expand All @@ -43,7 +42,6 @@ string(7) "0.0.0.0"
int(1118019956)
string(14) "66.163.161.116"
bool(false)
bool(false)
int(1869573999)
string(13) "255.254.82.80"
Done
20 changes: 20 additions & 0 deletions ext/standard/tests/network/ip2long_errors.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
ip2long() error conditions
--FILE--
<?php

try {
var_dump(ip2long(""));
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
try {
var_dump(ip2long("127\00.0.1"));
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
?>
--EXPECT--
ValueError: ip2long(): Argument #1 ($ip) must not be empty
ValueError: ip2long(): Argument #1 ($ip) must not contain any null bytes

7 changes: 2 additions & 5 deletions ext/standard/tests/network/ip_x86_64.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,19 @@ if (PHP_INT_SIZE == 4) die("skip this test is for >32bit platform only");
--FILE--
<?php

$array = array(
$array = [
"127.0.0.1",
"10.0.0.1",
"255.255.255.255",
"255.255.255.0",
"0.0.0.0",
"66.163.161.116",
);
];

foreach ($array as $ip) {
var_dump($long = ip2long($ip));
var_dump(long2ip($long));
}

var_dump(ip2long(""));
var_dump(ip2long("777.777.777.777"));
var_dump(ip2long("111.111.111.111"));

Expand All @@ -45,7 +43,6 @@ string(7) "0.0.0.0"
int(1118019956)
string(14) "66.163.161.116"
bool(false)
bool(false)
int(1869573999)
string(13) "255.254.82.80"
string(15) "255.255.255.255"
Expand Down
22 changes: 11 additions & 11 deletions ext/standard/tests/time/bug60222.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
Bug #60222 (time_nanosleep() does validate input params)
--FILE--
<?php
try {
time_nanosleep(-1, 0);
} catch (Throwable $exception) {
echo $exception::class, ': ', $exception->getMessage(), "\n";
}
try {
time_nanosleep(-1, 0);
} catch (Throwable $exception) {
echo $exception::class, ': ', $exception->getMessage(), "\n";
}

try {
time_nanosleep(0, -1);
} catch (Throwable $exception) {
echo $exception::class, ': ', $exception->getMessage(), "\n";
}
try {
time_nanosleep(0, -1);
} catch (Throwable $exception) {
echo $exception::class, ': ', $exception->getMessage(), "\n";
}
?>
--EXPECT--
ValueError: time_nanosleep(): Argument #1 ($seconds) must be greater than or equal to 0
ValueError: time_nanosleep(): Argument #2 ($nanoseconds) must be greater than or equal to 0
ValueError: time_nanosleep(): Argument #2 ($nanoseconds) must be between 0 and 999999999
Loading