Skip to content

Fix potential OOB read in zend_dirname() on Windows #16995

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Nov 29, 2024

Only on Windows IS_SLASH_P() may read the previous byte, and so may in unlikely cases read one byte out of bounds. Since IS_SLASH_P() is in a public header (albeit not likely to be used by external extensions or SAPIs), we introduce IS_SLASH_P_EX() which accepts a second argument to prevent that OOB read.

It should be noted that the PHP userland function dirname() is not affected by this issue, since it does not call zend_dirname() on Windows.

Only on Windows `IS_SLASH_P()` may read the previous byte, and so may
in unlikely cases read one byte out of bounds.  Since `IS_SLASH_P()` is
in a public header (albeit not likely to be used by external extensions
or SAPIs), we introduce `IS_SLASH_P_EX()` which accepts a second
argument to prevent that OOB read.

It should be noted that the PHP userland function `dirname()` is not
affected by this issue, since it does not call `zend_dirname()` on
Windows.
@cmb69
Copy link
Member Author

cmb69 commented Nov 29, 2024

No ABI break here.

@cmb69 cmb69 removed the ABI break label Nov 29, 2024
Copy link
Member

@nielsdos nielsdos left a comment

Choose a reason for hiding this comment

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

Looks ok for me as discussed earlier, just one suggestion.

@cmb69 cmb69 removed the ABI break label Nov 29, 2024
@cmb69 cmb69 closed this in 94fa2a4 Nov 29, 2024
@cmb69 cmb69 deleted the cmb/is-slash branch November 29, 2024 21:20
charmitro pushed a commit to wasix-org/php that referenced this pull request Mar 13, 2025
Only on Windows `IS_SLASH_P()` may read the previous byte, and so may
in unlikely cases read one byte out of bounds.  Since `IS_SLASH_P()` is
in a public header (albeit not likely to be used by external extensions
or SAPIs), we introduce `IS_SLASH_P_EX()` which accepts a second
argument to prevent that OOB read.

It should be noted that the PHP userland function `dirname()` is not
affected by this issue, since it does not call `zend_dirname()` on
Windows.

Closes phpGH-16995.
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.

2 participants