-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Java: Call Graph #17457
Comments
Hi again @KylerKatz 👋🏻 Queries of type To then understand where your query goes wrong, the first step would be to identify where the problem is by starting with the smallest components involved and then working your way up. For example, if you query all instances of Also, query metadata should normally be at the very top of the file, above the import statements. |
Hello @mbg, Thank you for all your help. I have broken the problem down and done some quick evaluations. Using this example,
SensitiveMethodCallI get these results Which lines up with the data that I have in my YML file
So ControlFlowPathLooking at this, it seems to almost be alright
4 & 5 correspond to their own self use, however, there should be one starting at Also, I am still looking for a way to get the actual path. Something like this. Is this possible for control flow? Also, here is my updated query for reference
Thank you once again for your help. |
After some more research, I believe I was referring to the wrong thing, instead of wanting the control-flow paths. I believe it's actually the call graph that I am looking for. Sorry for the confusion. I found this discussion That talks about doing it using Methods. However, if I use this on my previous example,
This is going in the right direction because I am finally getting the path that I have been trying to get. However, it is missing the paths from
I believe the reason for this is because they are MethodCalls. Does anyone know of a way of making something like this work with MethodCalls instead? The issue is that MethodCall doesn't have a call predicate, which allows for the path to be generated.
Thank you. |
These are getting filtered out because the first column, here Change the final line to
Then you'll get alerts whenever the start point is in user code, and so you will indeed see paths like Note that you will not see a path |
Hello @smowton, Thank you for your response, I updated the query with your suggestion, and it is now working. However, I am noticing a few limitations of this query. Just to make sure that we're on the same page here is my current version.
There are two main limitations, the first being the one that you pointed out at the end of your response concerning seeing a path The second is that if we have a standard method such as To test this, I went back to trying dataflow, I have a helper class
Running a quick eval on this results in these
This checks out and corresponds to the sinks that I have in my YML file. So, I decided to integrate this class into my dataflow query as the sink.
However, running a quick eval on this predicate, I only get these paths
This excludes I know if I do something like this,
The I can get a result like this which is used by
Lastly, here is the full query for reference, I am mostly considering almost everything as a source and just want to see what flows into my methods.
Thank you for your help. |
A few points about this:
from Method finalCallee
...
exists(MethodCall mc | sink.getNode().asExpr() = mc.getAnArgument() | finalCallee = mc.getCallee())
...
select
sink.getNode().getEnclosingCallable(),
source,
sink,
"Dataflow from $@ to $@",
source,
source.toString(),
finalCallee,
finalCallee.toString() Note that each of the |
Hi @KylerKatz, Were you able to use @smowton suggestions to improve your query. |
Hello,
I am trying to use CodeQL to get the control flow of a program. More specifically I want to get the control flow into methods that I have marked as sensitive in a classes named
SensitiveMethodCall
. The goal is to parse the results to get the path. However, right now I am not generating a path. It is hard to tell if a path isn't being generated because of the query itself (I am used to using dataflow, so this is new to me) or if it has to do with this errorAll of the examples I see on this link have to deal with dataflow and not control flow, so I am having trouble figuring out what I am doing wrong to get the correct output. Here is my query.
Any help would be greatly appreciated. Thank you.
The text was updated successfully, but these errors were encountered: