Fix potential crash in ObjCContainersChecker by properly validating

the number of arguments.

llvm-svn: 165838
This commit is contained in:
Ted Kremenek 2012-10-12 22:56:36 +00:00
parent bd1d7fa460
commit d0b9770399
1 changed files with 5 additions and 0 deletions

View File

@ -105,6 +105,8 @@ void WalkAST::VisitCallExpr(CallExpr *CE) {
unsigned ArgNum = InvalidArgIndex;
if (Name.equals("CFArrayCreate") || Name.equals("CFSetCreate")) {
if (CE->getNumArgs() != 4)
return;
ArgNum = 1;
Arg = CE->getArg(ArgNum)->IgnoreParenCasts();
if (hasPointerToPointerSizedType(Arg))
@ -112,6 +114,8 @@ void WalkAST::VisitCallExpr(CallExpr *CE) {
}
if (Arg == 0 && Name.equals("CFDictionaryCreate")) {
if (CE->getNumArgs() != 6)
return;
// Check first argument.
ArgNum = 1;
Arg = CE->getArg(ArgNum)->IgnoreParenCasts();
@ -127,6 +131,7 @@ void WalkAST::VisitCallExpr(CallExpr *CE) {
if (ArgNum != InvalidArgIndex) {
assert(ArgNum == 1 || ArgNum == 2);
assert(Arg);
SmallString<256> BufName;
llvm::raw_svector_ostream OsName(BufName);