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
5ec129e
1fa524a
167421b
558148b
a372e8d
8dac772
e183741
062dd28
bb3c7f8
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 |
|---|---|---|
|
|
@@ -102,6 +102,18 @@ void CheckFunctionsImpl::functionCalledError(const Token* tok, Severity severity | |
| reportError(tok, severity, prefix + "Called", msg, CWE477, Certainty::normal); | ||
| } | ||
|
|
||
| static bool hasArgMinReadSize(const Token *ftok, int argnr, const Library &library) | ||
| { | ||
| if (library.getArgDirection(ftok, argnr) == Library::ArgumentChecks::Direction::DIR_IN) { | ||
| if (const std::vector<Library::ArgumentChecks::MinSize> *minsizes = library.argminsizes(ftok, argnr)) { | ||
| return std::any_of(minsizes->begin(), minsizes->end(), [](const Library::ArgumentChecks::MinSize &ms) { | ||
| return ms.type == Library::ArgumentChecks::MinSize::Type::ARGVALUE; | ||
| }); | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| //--------------------------------------------------------------------------- | ||
| // Check <valid>, <strz> and <not-bool> | ||
| //--------------------------------------------------------------------------- | ||
|
|
@@ -137,7 +149,7 @@ void CheckFunctionsImpl::invalidFunctionUsage() | |
| invalidFunctionArgError(argtok, functionToken->str(), argnr, nullptr, mSettings.library.validarg(functionToken, argnr)); | ||
| } | ||
| // check <strz> | ||
| if (mSettings.library.isargstrz(functionToken, argnr)) { | ||
| if (mSettings.library.isargstrz(functionToken, argnr) && !hasArgMinReadSize(functionToken, argnr, mSettings.library)) { | ||
|
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 exception also covers Two possible fixes:
|
||
| if (Token::Match(argtok, "& %var% !![") && argtok->next() && argtok->next()->valueType()) { | ||
| const ValueType * valueType = argtok->next()->valueType(); | ||
| const Variable * variable = argtok->next()->variable(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,6 +78,9 @@ void invalidFunctionArgStr_strncat(void) | |
| // No warning is expected for | ||
| strncat (str1, &src, 1); | ||
| puts (str1); | ||
| char d[] = {'a','b','c'}; | ||
| // cppcheck-suppress invalidFunctionArgStr | ||
| strncat(d, "def", 1); | ||
| } | ||
|
|
||
| char * invalidFunctionArgStr_strpbrk( const char *p ) | ||
|
|
@@ -4000,11 +4003,10 @@ void bufferAccessOutOfBounds_strxfrm(void) | |
| { | ||
| const char src[3] = "abc"; | ||
| char dest[1] = "a"; | ||
| // cppcheck-suppress invalidFunctionArgStr | ||
| (void)strxfrm(dest,src,1); | ||
|
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
|
||
| // cppcheck-suppress [bufferAccessOutOfBounds,invalidFunctionArgStr] | ||
| // cppcheck-suppress [bufferAccessOutOfBounds] | ||
| (void)strxfrm(dest,src,2); | ||
| // cppcheck-suppress [bufferAccessOutOfBounds,invalidFunctionArgStr] | ||
| // cppcheck-suppress [bufferAccessOutOfBounds] | ||
| (void)strxfrm(dest,src,3); | ||
| } | ||
|
|
||
|
|
@@ -4913,6 +4915,10 @@ void invalidFunctionArgString(char c) | |
| char d='d'; | ||
| /* cppcheck-suppress invalidFunctionArgStr */ | ||
| (void)strcat(str,&d); | ||
|
|
||
| char a[] = { 'a', 'b', 'c' }; | ||
| /* cppcheck-suppress [bufferAccessOutOfBounds,invalidFunctionArgStr] */ | ||
| (void)strcat(a, "def"); | ||
| } | ||
|
|
||
| void ignoredReturnValue_abs(int i) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.