Replies: 1 comment 1 reply
-
Hi @ayosten, Thanks for raising these issues. The problem here is that CodeQL doesn't reason about "interprocedural" barriers. That is, we don't detect that the value is overwritten in all cases when flowing through bool condition();
void setToValid(TwoIntClass *&ref)
{
TwoIntClass *valid = new TwoIntClass{1, 2};
if(condition()) {
ref = valid;
}
} so that This is also why you don't get an alert from int source();
void sink(int);
void test() {
int x = source();
x = 0;
sink(x);
} but you do get one here: int source();
void sink(int);
void set_x(int *x) {
*x = 0;
}
void test() {
int x = source();
set_x(&x);
sink(x);
} since we don't try to detect that As for your final example: void ref_good(){
TwoIntClass tic = {1,2};
TwoIntClass* ptr = nullptr;
TwoIntClass*& refptr = ptr;
refptr = &tic;
ptr->triggerSinkPtr();
} we don't realise that I will keep a link to this issue in our internal tracking for both of these issues, though. |
Beta Was this translation helpful? Give feedback.
-
Hello,
While I was writting some test file to get a better understanding of Dataflow true capabilities at tracking values with function and containers wrapping, with uses of references, pointers and other edge cases I encountered something which I cannot make sens of. An assignment to a reference is correctly detected as a source that flows to the sink, but it doesn't overwrite previous assignment. (that is to say, the value assigned before the assignment to the reference is said to flows to the sink)
This is obviously wrong (I mean I hope so otherwise I would seriously reconsider my understanding of c++), but the hard part (from a computational / algorithmic point of view) is finding the assignement to a reference hidden inside the function, not overwriting the value that was assigned before the function. So I have no idea why CodeQL says that the nullptr flows to sink. We can simply execute the program to see that indeed, nullptr doesn't flows to
triggerSinkPtr
. (or maybe my understanding of what it means to "flow" is wrong ?)Here's the code :
Here's the CodeQL request :
And here's the result for this function : (
0
correspond tonullptr
andnew
tonew TwoIntClass{1,2}
)If the new is correctly detected then why is the nullptr still here ?
I am even more confused because in this case, only nullptr is said to flow to the sink by the request (and obviously it's not)
Does this mean that Dataflow track argument references but not references ? I would've expected reference in the same scope easier to track than reference in function argument so I'm a little surprised.
Beta Was this translation helpful? Give feedback.
All reactions