Skip to content

Remove broken check in var_unserializer #13852

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

Merged
merged 1 commit into from
Apr 3, 2024

Conversation

nielsdos
Copy link
Member

end = *p+maxlen, and pointer overflow is UB, so that means that a check of the form end < *p will always be false because it can only be true on pointer overflow. In particular, the compiler simplifies this to maxlen < 0 which is always false because maxlen is unsigned.

`end = *p+maxlen`, and pointer overflow is UB, so that means that a check
of the form `end < *p` will always be false because it can only be true
on pointer overflow. In particular, the compiler simplifies this to
`maxlen < 0` which is always false because maxlen is unsigned.
@TimWolla
Copy link
Member

TimWolla commented Apr 1, 2024

Somewhat related: #10214 which previously removed a pointer overflow in the unserializer.

Comment on lines -329 to -332
if (end < *p) {
zend_string_efree(str);
return NULL;
}
Copy link
Member

@arnaud-lb arnaud-lb Apr 2, 2024

Choose a reason for hiding this comment

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

This may not break anything that wasn't already broken because this was optimized out by the compiler, but I would prefer if we fixed this check instead of simply removing it

Copy link
Member Author

@nielsdos nielsdos Apr 2, 2024

Choose a reason for hiding this comment

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

The intention of the check seems to be to see if maxlen wraps around the address space.
I don't think that's possible, given that maxlen = max - YYCURSOR; and the fact that max is the pointer to the end of the input string.
So I'm not sure what you want me to replace this check with?

Copy link
Member

Choose a reason for hiding this comment

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

You are right. I was blindly assuming that maxlen was possibly user-controlled. Looking at the history this check made more sense at some point, but now it can be removed.

Copy link
Member

Choose a reason for hiding this comment

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

This is out of scope, but we could pass max directly to this function, maybe via UNSERIALIZE_PASSTHRU/UNSERIALIZE_PARAMETER.

Comment on lines -329 to -332
if (end < *p) {
zend_string_efree(str);
return NULL;
}
Copy link
Member

Choose a reason for hiding this comment

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

You are right. I was blindly assuming that maxlen was possibly user-controlled. Looking at the history this check made more sense at some point, but now it can be removed.

@nielsdos nielsdos merged commit 5ca72ec into php:master Apr 3, 2024
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