Skip to content

Fix potential crash when setting invalid declare value #2395

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 1 commit into from

Conversation

sgolemon
Copy link
Member

Using a non-literal expression in a declare value can cause the
compiler to crash trying to turn that AST node into a usable zval.

There was an existing test for such values using 'encoding',
but that didn't crash because it's handled by the lexer
rather than being compiled.

Trying to use a non-literal with ticks reproduces the crash.

@krakjoe krakjoe added the Bug label Feb 22, 2017
@krakjoe
Copy link
Member

krakjoe commented Feb 22, 2017

@sgolemon other declare tests are failing

@sgolemon
Copy link
Member Author

Ah, yeah. Those tests skipped on my build because I don't have mbstring. Will update.

Using a non-literal expression in a declare value can cause the
compiler to crash trying to turn that AST node into a usable zval.

There was an existing test for such values using 'encoding',
but that didn't crash because it's handled by the lexer
rather than being compiled.

Trying to use a non-literal with ticks reproduces the crash.
@nikic
Copy link
Member

nikic commented Feb 22, 2017

This should be handled in the compiler, either by checking whether you have an AST_ZVAL or whether the result of evaluation is a zval. The latter will allow constant expressions. It probably best not to allow constant expressions, as this would make it opcache-dependent (whether constants can be substituted or not).

@sgolemon
Copy link
Member Author

Yeah, that was the other half of my email: http://news.php.net/php.internals/98335

I'm fine either way, and the compiler check for ZEND_AST_ZVAL will certainly be less likely to break existing code, but I think we should look at something like this PR for future PHP versions (target 7.3 maybe?) . I really don't think we need to support constant expressions in declares.

@sgolemon
Copy link
Member Author

Compiler-only version of this patch is at: #2396

@nikic
Copy link
Member

nikic commented Feb 22, 2017

@sgolemon Even for 7.3, what is the advantage of handling this in the parser? The implementation looks more complicated, and additionally generates a lower-quality diagnostic.

@sgolemon
Copy link
Member Author

Correctness? We don't want anything other than integers and quoted strings so we shouldn't accept them. Again, don't actually care much, and I do agree the error message in #2396 is way more clear.

@php-pulls
Copy link

Comment on behalf of pollita at php.net:

Closed in favor of #2396

@php-pulls php-pulls closed this Mar 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants