Skip to content

Fixes #64936 : doc comments picked up from previous scanner run #350

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

JonathanO
Copy link

Under some circumstances it was possible for doc comments to be
associated with the wrong thing, as the doc_comment compiler global
was carried over between scanner runs.

This patch adds the doc_comment (and doc_comment_len) to
zend_lex_state, so they're saved/restored when changing contexts,
and then resets them whenever we start scanning a new file/string.

Under some circumstances it was possible for doc comments to be
associated with the wrong thing, as the doc_comment compiler global
was carried over between scanner runs.

This patch adds the doc_comment (and doc_comment_len) to
zend_lex_state, so they're saved/restored when changing contexts,
and then resets them whenever we start scanning a new file/string.
@JonathanO
Copy link
Author

Ah, obvious bug, RESET_DOC_COMMENT() is going to free doc_comment, so the stored lex state isn't actually valid. This is less than ideal.

I'm not actually sure that I need to store the doc_comments in the lex state, is there any situation under which it's useful? I'm not sure how the scanner might be reinvoked in a situation where resetting doc_comment isn't the right thing to do anyway.

I'll add a fix for the obvious bug to this pull request shortly.

doc_comment needs to be duplicated into the lex_state, otherwise
it gets freed next time someone calls RESET_DOC_COMMENT().
@@ -226,6 +226,12 @@ ZEND_API void zend_save_lexical_state(zend_lex_state *lex_state TSRMLS_DC)
lex_state->input_filter = SCNG(input_filter);
lex_state->output_filter = SCNG(output_filter);
lex_state->script_encoding = SCNG(script_encoding);

lex_state->doc_comment = NULL;
Copy link
Contributor

Choose a reason for hiding this comment

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

why put it as null if you're going to override it 2 lines below?

@smalyshev
Copy link
Contributor

Do we really need to preserve the doc_comment state? Wouldn't resetting it in restore_lexical_state and at the beginning of the scan solve it? I can't imagine situation where you need to preserve it. And not adding new struct would also preserve BC.

@smalyshev
Copy link
Contributor

I think commit 2208447 fixes it. Please reopen the bug if you see a case where it is not enough.

@php-pulls
Copy link

Comment on behalf of stas at php.net:

fixed

@php-pulls php-pulls closed this Jun 17, 2013
@JonathanO JonathanO deleted the fix-bug64936 branch June 17, 2013 08:14
@JonathanO
Copy link
Author

Cool. I didn't want to make the decision not to store/restore it, as I wasn't sure that I wouldn't be missing something (see my second commit comment.) If you're happy that resetting it is not going to have unexpected side effects, then I'm also happy with that as the solution.

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants