diff options
| author | Ted Kremenek <kremenek@apple.com> | 2010-09-07 20:45:26 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2010-09-07 20:45:26 +0000 |
| commit | aba4958db2e6aa92b1bdbd097e68d131304fa17b (patch) | |
| tree | 866e4284ae427d27e1e4e7cbb79181c62e044028 /clang/lib/Checker | |
| parent | 420c8a604ff275c1316e7fb248aa72a21854f28a (diff) | |
| download | bcm5719-llvm-aba4958db2e6aa92b1bdbd097e68d131304fa17b.tar.gz bcm5719-llvm-aba4958db2e6aa92b1bdbd097e68d131304fa17b.zip | |
Fix null pointer dereference in StreamChecker::Fseek (reported in PR 8081) and simplify surrounding checking logic.
llvm-svn: 113282
Diffstat (limited to 'clang/lib/Checker')
| -rw-r--r-- | clang/lib/Checker/StreamChecker.cpp | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/clang/lib/Checker/StreamChecker.cpp b/clang/lib/Checker/StreamChecker.cpp index 8553875a24f..fb1937933d5 100644 --- a/clang/lib/Checker/StreamChecker.cpp +++ b/clang/lib/Checker/StreamChecker.cpp @@ -271,29 +271,24 @@ void StreamChecker::Fseek(CheckerContext &C, const CallExpr *CE) { return; // Check the legality of the 'whence' argument of 'fseek'. SVal Whence = state->getSVal(CE->getArg(2)); - bool WhenceIsLegal = true; const nonloc::ConcreteInt *CI = dyn_cast<nonloc::ConcreteInt>(&Whence); + if (!CI) - WhenceIsLegal = false; + return; int64_t x = CI->getValue().getSExtValue(); - if (!(x == 0 || x == 1 || x == 2)) - WhenceIsLegal = false; - - if (!WhenceIsLegal) { - if (ExplodedNode *N = C.GenerateSink(state)) { - if (!BT_illegalwhence) - BT_illegalwhence = new BuiltinBug("Illegal whence argument", - "The whence argument to fseek() should be " - "SEEK_SET, SEEK_END, or SEEK_CUR."); - BugReport *R = new BugReport(*BT_illegalwhence, - BT_illegalwhence->getDescription(), N); - C.EmitReport(R); - } + if (x >= 0 && x <= 2) return; - } - C.addTransition(state); + if (ExplodedNode *N = C.GenerateNode(state)) { + if (!BT_illegalwhence) + BT_illegalwhence = new BuiltinBug("Illegal whence argument", + "The whence argument to fseek() should be " + "SEEK_SET, SEEK_END, or SEEK_CUR."); + BugReport *R = new BugReport(*BT_illegalwhence, + BT_illegalwhence->getDescription(), N); + C.EmitReport(R); + } } void StreamChecker::Ftell(CheckerContext &C, const CallExpr *CE) { |

