Skip to content

Commit 797eccc

Browse files
pfultz2danmar
authored andcommitted
Fix possible out of bounds access on arguments (#1652)
* Fix possible outbounds access on arguments * Log a warning when the arguments mismatch * Format
1 parent 155e4ce commit 797eccc

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

lib/valueflow.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2980,7 +2980,18 @@ static void valueFlowLifetimeFunction(Token *tok, TokenList *tokenlist, ErrorLog
29802980
int n = getArgumentPos(var, f);
29812981
if (n < 0)
29822982
continue;
2983-
const Token *argtok = getArguments(tok).at(n);
2983+
std::vector<const Token *> args = getArguments(tok);
2984+
if (n >= args.size()) {
2985+
if (tokenlist->getSettings()->debugwarnings)
2986+
bailout(tokenlist,
2987+
errorLogger,
2988+
tok,
2989+
"Argument mismatch: Function '" + tok->str() + "' returning lifetime from argument index " +
2990+
std::to_string(n) + " but only " + std::to_string(args.size()) +
2991+
" arguments are available.");
2992+
continue;
2993+
}
2994+
const Token *argtok = args[n];
29842995
LifetimeStore ls{argtok, "Passed to '" + tok->str() + "'.", ValueFlow::Value::Object};
29852996
ls.errorPath = v.errorPath;
29862997
ls.errorPath.emplace_front(returnTok, "Return " + lifetimeType(returnTok, &v) + ".");

0 commit comments

Comments
 (0)