Repository navigation
Fix #11765 FN: minsize not checked for string literal, buffer access out of bounds not found #8944
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?
Changes from all commits
0383f66
c6eab5f
dcee57b
a387948
cd753bf
775b826
778cb2e
ecee9f7
9527653
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -604,6 +604,14 @@ ValueFlow::Value CheckBufferOverrunImpl::getBufferSize(const Token *bufTok, cons | |
| return bufSizeVal; | ||
| } | ||
| } | ||
| } else if (bufTok->tokType() == Token::Type::eString && bufTok->valueType()) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AI review This still causes false positives for bounded string functions whose library entries keep
All three now give |
||
| ValueFlow::Value strSizeVal; | ||
| strSizeVal.valueType = ValueFlow::Value::ValueType::BUFFER_SIZE; | ||
| const size_t charSize = bufTok->valueType()->getSizeOf(settings, ValueType::Accuracy::ExactOrZero, ValueType::SizeOf::Pointee); | ||
| if (charSize > 0) { | ||
| strSizeVal.intvalue = Token::getStrArraySize(bufTok) * charSize; | ||
| return strSizeVal; | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -717,8 +717,9 @@ size_t bufferAccessOutOfBounds_strnlen(const char *s, size_t maxlen) | |
| { | ||
| const char buf[2]={'4','2'}; | ||
| size_t len = strnlen(buf,2); | ||
| // cppcheck-suppress bufferAccessOutOfBounds | ||
| // TODO cppcheck-suppress bufferAccessOutOfBounds | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AI review This is a regression. |
||
| len+=strnlen(buf,3); | ||
| len+=strnlen("ab",3); | ||
| return len; | ||
| } | ||
|
|
||
|
|
@@ -1606,4 +1607,4 @@ void pthread_define_test() | |
| (void)rwlock; | ||
| PTHREAD_SCOPE_PROCESS; | ||
| PTHREAD_SCOPE_SYSTEM; | ||
| } | ||
| } | ||
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.
AI review
With this branch, every input-argument
minsize type="argvalue"in the library configs is now checked against string literals. That is wrong for bounded string functions, which stop reading at the NUL. Valid code now getsbufferAccessOutOfBounds, and base did not warn on any of these:The same pattern is also in
wcsncasecmp,wcsnlenandwcswidth(posix.cfg),_strncpy_s_l/_mbsncpy_s(windows.cfg) andsqlite3_stricmp(sqlite3.cfg). These configs need the same cleanup as std.cfg. The other option is to not use the literal size forstrzarguments.