forked from joernio/joern
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pysrc2cpg] Model Field-like Behaviour of Module Variables (joernio#3750
) * [pysrc2cpg] Model Field-like Behaviour of Module Variables The motivation for this PR is that module-level variables in Python can be accessed by other files by some implicit global scope. This behaviour is more akin to fields rather than identifiers, and should be modelled closer to that direction. Given the caveat that the data-flow engine sees fields a bit differently, especially if the flow goes across closures, this aims to be the least intrusive change to achieve this result. ### Main changes * Create a module-level identifier assigned to the module's type ref to be used as the base of module-level member field accesses. * At module-level identifier STOREs, create a block that writes to the module field, then aliases the result to the identifier, e.g., `x = 1` becomes ```python x = { <module>.x = 1 tmp = <module>.x tmp } ``` * Added helper methods, e.g., `isModuleContext` to `ContextStack` * Separated `VariableReference` class into `Reference` trait shared between `VariableReference` and `FieldReference` * During `createMemberLinks`, `FieldReference` calls will have a `REF` edge to their referencing member. TODO: Recover these `REF` edges during the type recovery pass. * ## Misc Changes * Fix `pysrc2cpg/ImportResolver` bug when an `__init__.py` entity is imported from a non-sibling module. * Added shortcut in `PythonTypeRecovery.visitStatementsInBlock` to detect these strong-update blocks and "re-sugar" them to skip propagating the type via member * Removed Python slicer tests, I would rather be intentional in how I support Python usage slicing at a later stage * Added member traversal handling for recovered base types * Fixed JSSRC import * Added test for data-flow, found some bug about how starting points are handled for members * Removed desugaring being part of the flows so that the flows are the same as before and give no fluctuations * Fixed assignment code from being `<module>.<module>.x`
- Loading branch information
1 parent
9717b71
commit 4d58f8f
Showing
17 changed files
with
381 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.