-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix #7570: Support address-of operator on variables in getBufferSize()
#7767
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
base: main
Are you sure you want to change the base?
Conversation
Thanks for your contribution. |
This patch didn't consider that because
Should we remove |
Ok, so maybe we should add a negative test/TODO for that case?
Ideally we would say 'Variable' for &i and just mention |
I mean something like this, it's not triggered now.
And also, there is a
|
lib/checkbufferoverrun.cpp
Outdated
if (!tok->isUnaryOp("&")) | ||
return tok; | ||
|
||
const auto* op = tok->astOperand1(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use Token
here since it's not much longer than auto
.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you run the tools/test-my-pr.py script please? to see what warnings this will produce and then we can see if there are false positives.
@@ -553,6 +561,8 @@ ValueFlow::Value CheckBufferOverrun::getBufferSize(const Token *bufTok) const | |||
{ | |||
if (!bufTok->valueType()) | |||
return ValueFlow::Value(-1); | |||
if (bufTok->isUnaryOp("&")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just skipping the address of like this feels dangerous spontanously to me. It feels like there could be false positives.
try to run it yourself first. if you have trouble to run it maybe we can run it on some vm.. maybe you can run on 1000 packages or something like that.. |
Detect address-of token in
getBufferSize()
and get the underlying variable's corresponding buffer size.stringNotZeroTerminated()
also callsgetBuffersize()
, so it will also benefit.