-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
Internal exceptions may misinterpret the null byte \0 #10810
Comments
As I've noted on phpc.social, the issue is with <?php
$e = new \Exception("Hello\0World");
var_dump(strlen($e->getMessage()));
var_dump($e->getMessage() === "Hello\0World");
var_dump($e->getMessage()); |
@TimWolla you're right, I didn't spot this issue with But it's similar, when an exception is converted to string, the message is transmitted as a php-src/Zend/zend_exceptions.c Line 682 in afd8695
|
userland |
This is actually relatively annoying to fix. |
I missed that there's already an |
PHP supports
I would not recommend using the octal |
Description
The following code:
Resulted in this output:
But I expected this output instead:
or
Notes
Thanks to this strange behavior, I discovered that Zend strings are perfectly able to handle the
\0
character.But to call the function
zend_throw_exception(zend_class_entry *exception_ce, const char *message, zend_long code)
, some callers may convert a zend string to a raw C string, losing the actual size. Then, the newly created zend string will stop at the first\0
, loosing the end of the string.I didn't found any risk with this bug, since sensitive functions seem to look explicitly for this kind of abuse. Just to notice that some error messages may be truncated if they contain this null byte.
Here are some other examples:
💡 It may be relevant to prefer the function
zend_throw_exception_zstr
when possible, to prevent to lose the actual length of the zend string.Thanks for your amazing work 🙂 👍
PHP Version
PHP 8.0, 8.1, 8.2
Operating System
No response
The text was updated successfully, but these errors were encountered: