Skip to content

Support compile_string passing parsing state #7462

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

Conversation

huanghantao
Copy link
Contributor

@huanghantao huanghantao commented Sep 4, 2021

I'm not sure if this revision is good.

I have a requirement to execute encrypted PHP code.

Currently, I read the encrypted code into memory, then decrypt it, and write the decrypted content to a temporary file. Then call compile_file to fetch op_array.

Perhaps we can fetch op_array directly from compile_string. But it will report the problem:

Parse error: syntax error, unexpected token "<", expecting end of file

So, I need to remove T_OPEN_TAG myself. So I think it's fine if compile_string can skip T_OPEN_TAG.

@nikic
Copy link
Member

nikic commented Sep 6, 2021

I think the feature is reasonable, but I really don't like having a global flag control this. Can we make it a function argument instead?

@huanghantao huanghantao force-pushed the support-compile-string-skip-initial branch 2 times, most recently from c931840 to 2867959 Compare September 6, 2021 15:38
@huanghantao
Copy link
Contributor Author

huanghantao commented Sep 6, 2021

Maybe we should call the parameter skip_end_of_file (or begin_initial) instead of skip_initial?

@huanghantao huanghantao changed the title Support compile_string skip INITIAL Support compile_string parsing OPEN_TAG Sep 7, 2021
@nikic
Copy link
Member

nikic commented Sep 7, 2021

I wonder whether it would make sense to accept the starting state (as unsigned to avoid include)? That way you could start at yycST_IN_SCRIPTING, yycINITIAL or yycSHEBANG. This leaks internal details a bit though.

@huanghantao
Copy link
Contributor Author

I think this is a good suggestion, and it will facilitate further extensions of this function. Maybe someone really needs to start in another state.

@huanghantao huanghantao force-pushed the support-compile-string-skip-initial branch from f7556db to 8b26bb1 Compare September 8, 2021 03:22
@huanghantao huanghantao changed the title Support compile_string parsing OPEN_TAG Support compile_string passing parsing state Sep 8, 2021
@huanghantao
Copy link
Contributor Author

Whether zend_lex_begin_state should be moved from zend_compile.h to zend_language_scanner.h?

@huanghantao huanghantao force-pushed the support-compile-string-skip-initial branch from d621ffc to 668fd57 Compare September 22, 2021 02:37
@nikic nikic closed this in 5bda4cd Sep 30, 2021
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