Skip to content

Python: Call analysis fails in some scenarios #19288

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

Open
mckirk opened this issue Apr 11, 2025 · 1 comment
Open

Python: Call analysis fails in some scenarios #19288

mckirk opened this issue Apr 11, 2025 · 1 comment
Labels
question Further information is requested

Comments

@mckirk
Copy link

mckirk commented Apr 11, 2025

While trying to use the 'pointsTo' approach for some basic control-flow-based queries (please let me know if there's a better approach to find 'all statements reachable from a function entry-point'), I've noticed that currently, some calls are incorrectly picked up without any value to point to.

MWE:

import sys

def mwe_callable():
    print("Hello, World!") # works

def mwe_broken():
    if herp := sys.argv[1]:
        raise Exception("merp") # broken
    
    mwe_callable() # broken

def mwe_broken2():
    if herp := "derp":
        print("merp") # broken
    
    mwe_callable() # works

def mwe_works():
    if sys.argv[1] == "derp":
        raise Exception("merp") # works
    
    mwe_callable() # works

def mwe_works2():
    print("merp") # works
    mwe_callable() # works

Test query:

import python

from Function f, Call c, Expr e
where
  f.contains(c) and
  e = c.getFunc() and
  not exists(Value v | e.pointsTo() = v)
select f, c, e

Every call I've marked here as 'broken' is returned by the query as not having any Value to point to, whereas the other calls are correctly identified and associated with their target.

I am using:

  • CodeQL CLI 2.21.0
  • CodeQL VSCode extension 1.17.2
  • codeql/python-all@4.0.4
  • Python extractor 1.22.1
@mckirk mckirk added the question Further information is requested label Apr 11, 2025
@joefarebrother
Copy link
Contributor

Hello @mckirk
The pointsTo analysis API is not really supported or maintained any more.
For function call resolution, unfortunately the new call graph does not yet have a stable public-facing API, partly because direct call resolution is rarely needed; in favor of data flow / taint tracking. But if you do need it, this comment shows how to dig out the new call resolution predicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants