Skip to content
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

CTracer_handle_return() reads byte code blindly #375

Closed
nedbat opened this issue Jun 9, 2015 · 3 comments
Closed

CTracer_handle_return() reads byte code blindly #375

nedbat opened this issue Jun 9, 2015 · 3 comments
Labels
bug Something isn't working run

Comments

@nedbat
Copy link
Owner

nedbat commented Jun 9, 2015

Originally reported by sbehnel (Bitbucket: sbehnel, GitHub: Unknown)


CTracer_handle_return() currently tries to read the byte code of the return statement as follows:

        int bytecode = MyBytes_AS_STRING(frame->f_code->co_code)[frame->f_lasti];

It would be better to not rely blindly on its existence, even though the current code should not crash with Cython where f_lasti should currently be 0 and co_code points to the empty string, so the read will return 0 (the C string terminator) as byte code instruction. That means that it only accidentally works due to the "!=" test.


@nedbat
Copy link
Owner Author

nedbat commented Jun 14, 2015

@sbehnel Can you explain more about why co_code could point to an empty string?

@nedbat
Copy link
Owner Author

nedbat commented Jun 16, 2015

Original comment by sbehnel (Bitbucket: sbehnel, GitHub: Unknown)


co_code is empty in Cython because it doesn't have bytecode, only native
code. It uses CodeObjects to provide introspection information for its
native functions. The way it emulates (or fakes) the Python function
interface may evolve over time, but I doubt that it will ever try to mimic
the byte code interface.

@nedbat
Copy link
Owner Author

nedbat commented Jun 16, 2015

@nedbat nedbat closed this as completed Jun 16, 2015
@nedbat nedbat added minor bug Something isn't working run labels Jun 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working run
Projects
None yet
Development

No branches or pull requests

1 participant