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
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -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
========================================
Expand Down
8 changes: 8 additions & 0 deletions ext/posix/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions ext/posix/tests/posix_fpathconf.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
6 changes: 5 additions & 1 deletion ext/posix/tests/posix_isatty_value_errors.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 3 additions & 0 deletions ext/posix/tests/posix_ttyname_value_errors.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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