Is CodeQL capable of inferring possible parameter values of a function via symbolic modeling? #19647
-
Inspired by https://github.com/github/codeql/blob/main/csharp/ql/src/Security%20Features/CWE-798/HardcodedConnectionString.ql, I wrote code to get the possible string literals that may flow into the "WriteLine" function, as shown below.
However, the string literals passed to 'WriteLine' do not determine the actual possible values of its argument. Example is below. string a = "a";
string b = "b";
Console.WriteLine(a + b); Can CodeQL infer a function's possible parameter values via modeling some key functions (e.g., string concatenation)? Since I'm a beginner, I'm not sure if CodeQL can solve this problem. I'd really appreciate any help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Thanks for your interest using CodeQL.
In general, this is not possible for a static analysis tool like CodeQL to compute precisely, since doing so would be equivalent to running the program (and so would hit theoretical limits). However, there are some ways to approximate this idea, where you can find some possible constant values if we know them from the program at compile time.
|
Beta Was this translation helpful? Give feedback.
Thanks for your interest using CodeQL.
In general, this is not possible for a static analysis tool like CodeQL to compute precisely, since doing so would be equivalent to running the program (and so would hit theoretical limits). However, there are some ways to approximate this idea, where you can find some possible constant values if we know them from the program at compile time.
Expr
type has predicateshasValue()
(which holds if the given expression has a compile-time constant value), andgetValue()
(which gets you that value if it exists). See https://codeql.git…