Skip to content
Open
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
37 changes: 16 additions & 21 deletions ext/standard/basic_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,10 +593,15 @@ PHP_FUNCTION(ip2long)
struct in_addr ip;

ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STRING(addr, addr_len)
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;
}
RETURN_LONG(ntohl(ip.s_addr));
Expand Down Expand Up @@ -1158,8 +1163,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 @@ -1173,10 +1178,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 @@ -1342,11 +1345,7 @@ PHP_FUNCTION(error_log)
Z_PARAM_STRING_OR_NULL(headers, headers_len)
ZEND_PARSE_PARAMETERS_END();

if (_php_error_log_ex((int) erropt, message, message_len, opt, headers) == FAILURE) {
RETURN_FALSE;
}

RETURN_TRUE;
RETURN_BOOL(_php_error_log_ex((int) erropt, message, message_len, opt, headers) == SUCCESS);
}
/* }}} */

Expand Down Expand Up @@ -2092,7 +2091,7 @@ PHP_FUNCTION(connection_aborted)
{
ZEND_PARSE_PARAMETERS_NONE();

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

Expand All @@ -2110,22 +2109,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 Expand Up @@ -2322,11 +2321,7 @@ PHP_FUNCTION(is_uploaded_file)
RETURN_FALSE;
}

if (zend_hash_exists(SG(rfc1867_uploaded_files), path)) {
RETURN_TRUE;
} else {
RETURN_FALSE;
}
RETURN_BOOL(zend_hash_exists(SG(rfc1867_uploaded_files), path));
}
/* }}} */

Expand Down
8 changes: 4 additions & 4 deletions ext/standard/basic_functions.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -1491,7 +1491,7 @@ function set_time_limit(int $seconds): bool {}

/* main/SAPI.c */

function header_register_callback(callable $callback): bool {}
function header_register_callback(callable $callback): true {}

/* main/output.c */

Expand Down Expand Up @@ -2016,11 +2016,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 All @@ -2040,7 +2040,7 @@ function getprotobyname(string $protocol): int|false {}
function getprotobynumber(int $protocol): string|false {}
#endif

function register_tick_function(callable $callback, mixed ...$args): bool {}
function register_tick_function(callable $callback, mixed ...$args): true {}

function unregister_tick_function(callable $callback): void {}

Expand Down
10 changes: 5 additions & 5 deletions ext/standard/basic_functions_arginfo.h

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

12 changes: 2 additions & 10 deletions ext/standard/head.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,7 @@ static void php_setcookie_common(INTERNAL_FUNCTION_PARAMETERS, bool is_raw)
}
}

if (php_setcookie(name, value, expires, path, domain, secure, httponly, samesite, partitioned, !is_raw) == SUCCESS) {
RETVAL_TRUE;
} else {
RETVAL_FALSE;
}
RETVAL_BOOL(php_setcookie(name, value, expires, path, domain, secure, httponly, samesite, partitioned, !is_raw) == SUCCESS);

if (options) {
cleanup:
Expand Down Expand Up @@ -328,11 +324,7 @@ PHP_FUNCTION(headers_sent)
break;
}

if (SG(headers_sent)) {
RETURN_TRUE;
} else {
RETURN_FALSE;
}
RETURN_BOOL(SG(headers_sent));
}
/* }}} */

Expand Down
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 (ValueError $exception) {
echo $exception->getMessage() . "\n";
}
try {
time_nanosleep(-1, 0);
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}

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