Skip to content

Commit 782278a

Browse files
committed
ext/standard: Refactor php_stat() API
1 parent 0bb64a7 commit 782278a

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

UPGRADING.INTERNALS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ PHP 8.5 INTERNALS UPGRADE NOTES
134134
. The php_std_date() function has been removed. Use php_format_date() with
135135
the "D, d M Y H:i:s \\G\\M\\T" format instead.
136136
. Added php_url_encode_to_smart_str() to encode a URL to a smart_str buffer.
137+
. The php_stat() function now asserts that the zend_string *filename
138+
parameter does not contain any null bytes. To ensure such strings are not
139+
provided the zend_str_has_nul_byte() API, the P ZPP specifier, or the fast
140+
ZPP Z_PARAM_PATH_STR specifier can be used to check this ahead of time.
137141

138142
========================
139143
4. OpCode changes

ext/standard/filestat.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -748,14 +748,12 @@ PHPAPI void php_stat(zend_string *filename, int type, zval *return_value)
748748
const char *local = NULL;
749749
php_stream_wrapper *wrapper = NULL;
750750

751+
ZEND_ASSERT(!zend_str_has_nul_byte(filename));
752+
/* Quick check for empty file paths */
753+
if (!ZSTR_LEN(filename)) {
754+
RETURN_FALSE;
755+
}
751756
if (IS_ACCESS_CHECK(type)) {
752-
if (!ZSTR_LEN(filename) || CHECK_NULL_PATH(ZSTR_VAL(filename), ZSTR_LEN(filename))) {
753-
if (ZSTR_LEN(filename) && !IS_EXISTS_CHECK(type)) {
754-
php_error_docref(NULL, E_WARNING, "Filename contains null byte");
755-
}
756-
RETURN_FALSE;
757-
}
758-
759757
if ((wrapper = php_stream_locate_url_wrapper(ZSTR_VAL(filename), &local, 0)) == &php_plain_files_wrapper
760758
&& php_check_open_basedir(local)) {
761759
RETURN_FALSE;
@@ -821,13 +819,6 @@ PHPAPI void php_stat(zend_string *filename, int type, zval *return_value)
821819
}
822820

823821
if (!wrapper) {
824-
if (!ZSTR_LEN(filename) || CHECK_NULL_PATH(ZSTR_VAL(filename), ZSTR_LEN(filename))) {
825-
if (ZSTR_LEN(filename) && !IS_EXISTS_CHECK(type)) {
826-
php_error_docref(NULL, E_WARNING, "Filename contains null byte");
827-
}
828-
RETURN_FALSE;
829-
}
830-
831822
if ((wrapper = php_stream_locate_url_wrapper(ZSTR_VAL(filename), &local, 0)) == &php_plain_files_wrapper
832823
&& php_check_open_basedir(local)) {
833824
RETURN_FALSE;

0 commit comments

Comments
 (0)