diff --git a/ext/posix/posix.c b/ext/posix/posix.c index f6e028f9a96e3..787b18ae28126 100644 --- a/ext/posix/posix.c +++ b/ext/posix/posix.c @@ -521,11 +521,13 @@ PHP_FUNCTION(posix_isatty) /* A valid file descriptor must fit in an int and be positive */ if (fd < 0 || fd > INT_MAX) { + POSIX_G(last_error) = EBADF; RETURN_FALSE; } if (isatty(fd)) { RETURN_TRUE; } else { + POSIX_G(last_error) = errno; RETURN_FALSE; } } diff --git a/ext/posix/tests/posix_isatty_value_errors.phpt b/ext/posix/tests/posix_isatty_value_errors.phpt index 19dfe62c93019..e57564e7eacd7 100644 --- a/ext/posix/tests/posix_isatty_value_errors.phpt +++ b/ext/posix/tests/posix_isatty_value_errors.phpt @@ -11,13 +11,19 @@ if (PHP_INT_SIZE != 8) die('skip C int is same size as zend_long'); $values = [ -1, + 10024, 2**50+1, ]; foreach ($values as $value) { var_dump(posix_isatty($value)); + var_dump(posix_strerror(posix_get_last_error())); } ?> --EXPECT-- bool(false) +string(19) "Bad file descriptor" bool(false) +string(19) "Bad file descriptor" +bool(false) +string(19) "Bad file descriptor"