Skip to content

/ext/standard: Check for empty string in linkinfo()#21793

Open
LamentXU123 wants to merge 1 commit intophp:masterfrom
LamentXU123:refactor
Open

/ext/standard: Check for empty string in linkinfo()#21793
LamentXU123 wants to merge 1 commit intophp:masterfrom
LamentXU123:refactor

Conversation

@LamentXU123
Copy link
Copy Markdown
Contributor

If link_len == 0, it now emits the same warning style as the existing filesystem error path and returns -1 immediately, avoiding the later estrndup() / zend_dirname() work on an empty input as per the TODO message.

Comment thread ext/standard/link.c
@@ -84,7 +84,11 @@ PHP_FUNCTION(linkinfo)
Z_PARAM_PATH(link, link_len)
ZEND_PARSE_PARAMETERS_END();

// TODO Check for empty string
if (UNEXPECTED(link_len == 0)) {
php_error_docref(NULL, E_WARNING, "%s", strerror(ENOENT));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would go for a ValueError exception, i.e. zend_argument_must_not_be_empty_error(1). Also you might need at least one test.

Copy link
Copy Markdown
Contributor Author

@LamentXU123 LamentXU123 Apr 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are existing tests, see https://github.com/php/php-src/blob/master/ext/standard/tests/file/symlink_link_linkinfo_is_link_error1.phpt#L30

Originally it raise a warning and return int(-1), and I don't have strong opinions on whether we should change the behavior here. The initial idea is just to add a fast guard explicitly for the case as per the TODO message.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a valid point, it is just the direction most of extensions lean towards but I ll leave the decision to @bukka on this one :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new Policy RFC allows to just emit a ValueError. Ideally we'd be able to audit all the call sites and basically just mandate that the path passed to zend_dirname() must not be empty nor contain null bytes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants