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

133: Visit functions in while test #186

Merged
merged 5 commits into from
Nov 21, 2018

Conversation

adrianbn
Copy link
Contributor

Hi!

I've tried to resolve #133 with this PR. I hope I understood what the issue described, but this is my first foray into pyt (and contributions to static analysis tools) so take it with a grain of salt. In particular I'm not 100% convinced about the generated CFG and I'd appreciate a keen eye on the unit test's node relationships.

Let me know if you want me to make changes or if I completely missed the mark!

Regards,
Adrian

Copy link
Collaborator

@bcaller bcaller left a comment

Choose a reason for hiding this comment

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

Looks great and the tests are passing 👍. I think we just need the extra test cases for the comment I made. Thanks

pyt/cfg/stmt_visitor.py Outdated Show resolved Hide resolved
@adrianbn
Copy link
Contributor Author

@bcaller let me know if this looks good to you. I think I covered all the cases you mentioned :)

pyt/cfg/stmt_visitor.py Outdated Show resolved Hide resolved
:param loop_node: The loop node itself to connect to the new function nodes if any
:return: None
"""
if isinstance(comp_n, ast.Call) and get_call_names_as_string(comp_n.func) in self.function_names:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know this was already here, but I don't understand why get_call_names_as_string(comp_n.func) in self.function_names is there. It means that range is ignored for instance. I'd be tempted to remove it, but maybe in a later PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't pay much mind to this detail but if removed, 4 of the test cases or for fail due to functions in the iter node being ignored (e.g. range).

I think the rationale here is to only link the while / for node to the function node if we've visited the function before, but I'm not sure why that would matter since we're immediately visiting the call node.

That said, we don't have a visit_Call method, so the default visitor will be invoked, which will in turn call visit_Name (which we don't have, so default again), then I think a call to visit_Load which will be default again, etc. I wonder if we'd need a visit_Call to handle this case before we can safely remove the in self.function_names.

@bcaller
Copy link
Collaborator

bcaller commented Nov 21, 2018

@adrianbn If you make that change avoiding mutating the AST I'm happy to merge.

@bcaller bcaller merged commit 4b495ad into python-security:master Nov 21, 2018
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.

[cfg] We don't visit functions in while loops
2 participants