mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
ext/posix posix_ttyname/posix_isatty fd error handling update.
Set to `EBADF` errno for posix_ttyname when out of ranges. posix_fpathconf now returns false on out of range file descriptors. close GH-17209
This commit is contained in:
parent
8aac6987c2
commit
fb2443ac5c
6 changed files with 31 additions and 1 deletions
3
NEWS
3
NEWS
|
@ -54,6 +54,9 @@ PHP NEWS
|
|||
- POSIX:
|
||||
. Added POSIX_SC_OPEN_MAX constant to get the number of file descriptors
|
||||
a process can handle. (David Carlier)
|
||||
. posix_ttyname() sets last_error to EBADF on invalid file descriptors,
|
||||
posix_isatty() raises E_WARNING on invalid file descriptors,
|
||||
posix_fpathconf checks invalid file descriptors. (David Carlier)
|
||||
|
||||
- Random:
|
||||
. Moves from /dev/urandom usage to arc4random_buf on Haiku. (David Carlier)
|
||||
|
|
|
@ -115,6 +115,14 @@ PHP 8.5 UPGRADE NOTES
|
|||
- PGSQL:
|
||||
. pg_copy_from also supports inputs as Iterable.
|
||||
|
||||
- POSIX:
|
||||
. posix_ttyname sets last_error to EBADF when encountering
|
||||
an invalid file descriptor.
|
||||
. posix_isatty raises an E_WARNING message when encountering
|
||||
an invalid file descriptor.
|
||||
. posix_fpathconf checks invalid file descriptors and sets
|
||||
last_error to EBADF and raises an E_WARNING message.
|
||||
|
||||
========================================
|
||||
6. New Functions
|
||||
========================================
|
||||
|
|
|
@ -470,6 +470,7 @@ PHP_FUNCTION(posix_ttyname)
|
|||
/* fd must fit in an int and be positive */
|
||||
if (fd < 0 || fd > INT_MAX) {
|
||||
php_error_docref(NULL, E_WARNING, "Argument #1 ($file_descriptor) must be between 0 and %d", INT_MAX);
|
||||
POSIX_G(last_error) = EBADF;
|
||||
RETURN_FALSE;
|
||||
}
|
||||
}
|
||||
|
@ -532,6 +533,7 @@ PHP_FUNCTION(posix_isatty)
|
|||
|
||||
/* A valid file descriptor must fit in an int and be positive */
|
||||
if (fd < 0 || fd > INT_MAX) {
|
||||
php_error_docref(NULL, E_WARNING, "Argument #1 ($file_descriptor) must be between 0 and %d", INT_MAX);
|
||||
POSIX_G(last_error) = EBADF;
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
@ -1325,6 +1327,12 @@ PHP_FUNCTION(posix_fpathconf)
|
|||
RETURN_THROWS();
|
||||
}
|
||||
}
|
||||
/* fd must fit in an int and be positive */
|
||||
if (fd < 0 || fd > INT_MAX) {
|
||||
php_error_docref(NULL, E_WARNING, "Argument #1 ($file_descriptor) must be between 0 and %d", INT_MAX);
|
||||
POSIX_G(last_error) = EBADF;
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
ret = fpathconf(fd, name);
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ if (!function_exists("posix_pathconf")) die("skip only platforms with posix_path
|
|||
<?php
|
||||
var_dump(posix_fpathconf(-1, POSIX_PC_PATH_MAX));
|
||||
var_dump(posix_errno() != 0);
|
||||
var_dump(posix_strerror(posix_errno()));
|
||||
try {
|
||||
posix_fpathconf("string arg", POSIX_PC_PATH_MAX);
|
||||
} catch (\TypeError $e) {
|
||||
|
@ -20,7 +21,10 @@ var_dump(posix_fpathconf($fd, POSIX_PC_PATH_MAX));
|
|||
fclose($fd);
|
||||
?>
|
||||
--EXPECTF--
|
||||
|
||||
Warning: posix_fpathconf(): Argument #1 ($file_descriptor) must be between 0 and %d in %s on line %d
|
||||
bool(false)
|
||||
bool(true)
|
||||
string(19) "Bad file descriptor"
|
||||
posix_fpathconf(): Argument #1 ($file_descriptor) must be of type int|resource, string given
|
||||
int(%d)
|
||||
|
|
|
@ -20,10 +20,14 @@ foreach ($values as $value) {
|
|||
var_dump(posix_strerror(posix_get_last_error()));
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
--EXPECTF--
|
||||
|
||||
Warning: posix_isatty(): Argument #1 ($file_descriptor) must be between 0 and %d in %s on line %d
|
||||
bool(false)
|
||||
string(19) "Bad file descriptor"
|
||||
bool(false)
|
||||
string(19) "Bad file descriptor"
|
||||
|
||||
Warning: posix_isatty(): Argument #1 ($file_descriptor) must be between 0 and %d in %s on line %d
|
||||
bool(false)
|
||||
string(19) "Bad file descriptor"
|
||||
|
|
|
@ -16,11 +16,14 @@ $values = [
|
|||
|
||||
foreach ($values as $value) {
|
||||
var_dump(posix_ttyname($value));
|
||||
var_dump(posix_strerror(posix_get_last_error()));
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: posix_ttyname(): Argument #1 ($file_descriptor) must be between 0 and %d in %s on line %d
|
||||
bool(false)
|
||||
string(19) "Bad file descriptor"
|
||||
|
||||
Warning: posix_ttyname(): Argument #1 ($file_descriptor) must be between 0 and %d in %s on line %d
|
||||
bool(false)
|
||||
string(19) "Bad file descriptor"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue