Python: Fully disallow API::moduleImport of module with dots

Inspired by discussion about this for MaD in
https://github.com/github/codeql/pull/8883#discussion_r865858084
This commit is contained in:
Rasmus Wriedt Larsen
2022-05-12 11:19:07 +02:00
parent 597a8414d9
commit f8253f5fef
2 changed files with 7 additions and 3 deletions

View File

@@ -280,7 +280,13 @@ module API {
* you should use `.getMember` on the parent module. For example, for nodes corresponding to the module `foo.bar`,
* use `moduleImport("foo").getMember("bar")`.
*/
Node moduleImport(string m) { result = Impl::MkModuleImport(m) }
Node moduleImport(string m) {
result = Impl::MkModuleImport(m) and
// restrict `moduleImport` so it will never give results for a dotted name. Note
// that we cannot move this logic to the `MkModuleImport` construction, since we
// need the intermediate API graph nodes for the prefixes in `import foo.bar.baz`.
not m.matches("%.%")
}
/** Gets a node corresponding to the built-in with the given name, if any. */
Node builtin(string n) { result = moduleImport("builtins").getMember(n) }

View File

@@ -1,7 +1,5 @@
moduleImportWithDots
| file://:0:0:0:0 | ModuleImport moduleImport("a").getMember("b").getMember("c").getMember("d") |
doesntFullyWork
| test.py:28:10:28:17 | ControlFlowNode for method() |
works
| test.py:25:6:25:18 | ControlFlowNode for Attribute() |
| test.py:28:10:28:17 | ControlFlowNode for method() |