2010-06-16 13:38:05 +08:00
|
|
|
//===-- StreamChecker.cpp -----------------------------------------*- C++ -*--//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-06-16 13:38:05 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines checkers that model and check stream handling functions.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
[analyzer][NFC] Move CheckerRegistry from the Core directory to Frontend
ClangCheckerRegistry is a very non-obvious, poorly documented, weird concept.
It derives from CheckerRegistry, and is placed in lib/StaticAnalyzer/Frontend,
whereas it's base is located in lib/StaticAnalyzer/Core. It was, from what I can
imagine, used to circumvent the problem that the registry functions of the
checkers are located in the clangStaticAnalyzerCheckers library, but that
library depends on clangStaticAnalyzerCore. However, clangStaticAnalyzerFrontend
depends on both of those libraries.
One can make the observation however, that CheckerRegistry has no place in Core,
it isn't used there at all! The only place where it is used is Frontend, which
is where it ultimately belongs.
This move implies that since
include/clang/StaticAnalyzer/Checkers/ClangCheckers.h only contained a single function:
class CheckerRegistry;
void registerBuiltinCheckers(CheckerRegistry ®istry);
it had to re purposed, as CheckerRegistry is no longer available to
clangStaticAnalyzerCheckers. It was renamed to BuiltinCheckerRegistration.h,
which actually describes it a lot better -- it does not contain the registration
functions for checkers, but only those generated by the tblgen files.
Differential Revision: https://reviews.llvm.org/D54436
llvm-svn: 349275
2018-12-16 00:23:51 +08:00
|
|
|
#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
|
2011-03-01 09:16:21 +08:00
|
|
|
#include "clang/StaticAnalyzer/Core/Checker.h"
|
2011-02-18 05:39:17 +08:00
|
|
|
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
|
2019-06-20 07:33:42 +08:00
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
|
2011-02-24 09:05:33 +08:00
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
|
2011-08-16 06:09:50 +08:00
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
|
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
|
2011-02-10 09:03:03 +08:00
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h"
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
#include <functional>
|
2010-06-16 13:38:05 +08:00
|
|
|
|
|
|
|
using namespace clang;
|
2010-12-23 15:20:52 +08:00
|
|
|
using namespace ento;
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
using namespace std::placeholders;
|
2010-06-16 13:38:05 +08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2010-07-19 09:52:29 +08:00
|
|
|
struct StreamState {
|
2010-07-23 22:14:59 +08:00
|
|
|
enum Kind { Opened, Closed, OpenFailed, Escaped } K;
|
2010-07-19 09:52:29 +08:00
|
|
|
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
StreamState(Kind k) : K(k) {}
|
2010-07-19 09:52:29 +08:00
|
|
|
|
|
|
|
bool isOpened() const { return K == Opened; }
|
|
|
|
bool isClosed() const { return K == Closed; }
|
2010-09-03 12:34:38 +08:00
|
|
|
//bool isOpenFailed() const { return K == OpenFailed; }
|
|
|
|
//bool isEscaped() const { return K == Escaped; }
|
2010-07-19 09:52:29 +08:00
|
|
|
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
bool operator==(const StreamState &X) const { return K == X.K; }
|
2010-07-19 09:52:29 +08:00
|
|
|
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
static StreamState getOpened() { return StreamState(Opened); }
|
|
|
|
static StreamState getClosed() { return StreamState(Closed); }
|
|
|
|
static StreamState getOpenFailed() { return StreamState(OpenFailed); }
|
|
|
|
static StreamState getEscaped() { return StreamState(Escaped); }
|
2010-07-19 09:52:29 +08:00
|
|
|
|
|
|
|
void Profile(llvm::FoldingSetNodeID &ID) const {
|
|
|
|
ID.AddInteger(K);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-03-01 09:16:21 +08:00
|
|
|
class StreamChecker : public Checker<eval::Call,
|
2012-11-16 03:11:38 +08:00
|
|
|
check::DeadSymbols > {
|
2014-03-08 04:03:18 +08:00
|
|
|
mutable std::unique_ptr<BuiltinBug> BT_nullfp, BT_illegalwhence,
|
|
|
|
BT_doubleclose, BT_ResourceLeak;
|
2010-06-16 13:38:05 +08:00
|
|
|
|
|
|
|
public:
|
2019-06-20 07:33:42 +08:00
|
|
|
bool evalCall(const CallEvent &Call, CheckerContext &C) const;
|
2011-02-24 09:05:33 +08:00
|
|
|
void checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const;
|
2010-06-16 13:38:05 +08:00
|
|
|
|
|
|
|
private:
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
using FnCheck = std::function<void(const StreamChecker *, const CallEvent &,
|
|
|
|
CheckerContext &)>;
|
|
|
|
|
|
|
|
CallDescriptionMap<FnCheck> Callbacks = {
|
|
|
|
{{"fopen"}, &StreamChecker::evalFopen},
|
2019-12-05 00:15:03 +08:00
|
|
|
{{"freopen", 3}, &StreamChecker::evalFreopen},
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
{{"tmpfile"}, &StreamChecker::evalFopen},
|
|
|
|
{{"fclose", 1}, &StreamChecker::evalFclose},
|
|
|
|
{{"fread", 4},
|
|
|
|
std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 3)},
|
|
|
|
{{"fwrite", 4},
|
|
|
|
std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 3)},
|
|
|
|
{{"fseek", 3}, &StreamChecker::evalFseek},
|
|
|
|
{{"ftell", 1},
|
|
|
|
std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
|
|
|
|
{{"rewind", 1},
|
|
|
|
std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
|
|
|
|
{{"fgetpos", 2},
|
|
|
|
std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
|
|
|
|
{{"fsetpos", 2},
|
|
|
|
std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
|
|
|
|
{{"clearerr", 1},
|
|
|
|
std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
|
|
|
|
{{"feof", 1},
|
|
|
|
std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
|
|
|
|
{{"ferror", 1},
|
|
|
|
std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
|
|
|
|
{{"fileno", 1},
|
|
|
|
std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
|
|
|
|
};
|
|
|
|
|
|
|
|
void evalFopen(const CallEvent &Call, CheckerContext &C) const;
|
2019-12-05 00:15:03 +08:00
|
|
|
void evalFreopen(const CallEvent &Call, CheckerContext &C) const;
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
void evalFclose(const CallEvent &Call, CheckerContext &C) const;
|
|
|
|
void evalFseek(const CallEvent &Call, CheckerContext &C) const;
|
|
|
|
void checkArgNullStream(const CallEvent &Call, CheckerContext &C,
|
|
|
|
unsigned ArgI) const;
|
[analyzer]StreamChecker refactoring (NFC).
Reviewers: Szelethus
Reviewed By: Szelethus
Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73359
2020-02-12 18:26:38 +08:00
|
|
|
|
|
|
|
ProgramStateRef checkNullStream(SVal SV, CheckerContext &C,
|
|
|
|
ProgramStateRef State) const;
|
|
|
|
ProgramStateRef checkFseekWhence(SVal SV, CheckerContext &C,
|
|
|
|
ProgramStateRef State) const;
|
|
|
|
ProgramStateRef checkDoubleClose(const CallEvent &Call, CheckerContext &C,
|
|
|
|
ProgramStateRef State) const;
|
2010-06-16 13:38:05 +08:00
|
|
|
};
|
|
|
|
|
2010-06-18 10:47:46 +08:00
|
|
|
} // end anonymous namespace
|
2010-06-16 13:38:05 +08:00
|
|
|
|
2012-11-02 09:54:42 +08:00
|
|
|
REGISTER_MAP_WITH_PROGRAMSTATE(StreamMap, SymbolRef, StreamState)
|
|
|
|
|
2010-07-19 09:52:29 +08:00
|
|
|
|
2019-06-20 07:33:42 +08:00
|
|
|
bool StreamChecker::evalCall(const CallEvent &Call, CheckerContext &C) const {
|
|
|
|
const auto *FD = dyn_cast_or_null<FunctionDecl>(Call.getDecl());
|
2012-07-11 07:13:01 +08:00
|
|
|
if (!FD || FD->getKind() != Decl::Function)
|
2010-06-16 13:38:05 +08:00
|
|
|
return false;
|
|
|
|
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
// Recognize "global C functions" with only integral or pointer arguments
|
|
|
|
// (and matching name) as stream functions.
|
|
|
|
if (!Call.isGlobalCFunction())
|
2019-06-20 07:33:42 +08:00
|
|
|
return false;
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
for (auto P : Call.parameters()) {
|
|
|
|
QualType T = P->getType();
|
|
|
|
if (!T->isIntegralOrEnumerationType() && !T->isPointerType())
|
|
|
|
return false;
|
2010-06-22 15:50:21 +08:00
|
|
|
}
|
2010-06-18 10:47:46 +08:00
|
|
|
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
const FnCheck *Callback = Callbacks.lookup(Call);
|
|
|
|
if (!Callback)
|
|
|
|
return false;
|
2010-06-16 13:38:05 +08:00
|
|
|
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
(*Callback)(this, Call, C);
|
2010-07-22 22:01:01 +08:00
|
|
|
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
return C.isDifferent();
|
2010-07-22 22:01:01 +08:00
|
|
|
}
|
|
|
|
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
void StreamChecker::evalFopen(const CallEvent &Call, CheckerContext &C) const {
|
[analyzer] Small StreamChecker refactoring (NFC).
Reviewers: Szelethus
Reviewed By: Szelethus
Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73350
2020-02-07 16:09:45 +08:00
|
|
|
ProgramStateRef State = C.getState();
|
|
|
|
SValBuilder &SVB = C.getSValBuilder();
|
2012-02-18 07:13:45 +08:00
|
|
|
const LocationContext *LCtx = C.getPredecessor()->getLocationContext();
|
[analyzer] Small StreamChecker refactoring (NFC).
Reviewers: Szelethus
Reviewed By: Szelethus
Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73350
2020-02-07 16:09:45 +08:00
|
|
|
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
auto *CE = dyn_cast_or_null<CallExpr>(Call.getOriginExpr());
|
|
|
|
if (!CE)
|
|
|
|
return;
|
|
|
|
|
[analyzer] Small StreamChecker refactoring (NFC).
Reviewers: Szelethus
Reviewed By: Szelethus
Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73350
2020-02-07 16:09:45 +08:00
|
|
|
DefinedSVal RetVal = SVB.conjureSymbolVal(nullptr, CE, LCtx, C.blockCount())
|
|
|
|
.castAs<DefinedSVal>();
|
|
|
|
SymbolRef RetSym = RetVal.getAsSymbol();
|
|
|
|
assert(RetSym && "RetVal must be a symbol here.");
|
|
|
|
|
|
|
|
State = State->BindExpr(CE, C.getLocationContext(), RetVal);
|
2015-09-08 11:50:52 +08:00
|
|
|
|
2010-06-16 13:38:05 +08:00
|
|
|
// Bifurcate the state into two: one with a valid FILE* pointer, the other
|
|
|
|
// with a NULL.
|
[analyzer] Small StreamChecker refactoring (NFC).
Reviewers: Szelethus
Reviewed By: Szelethus
Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73350
2020-02-07 16:09:45 +08:00
|
|
|
ProgramStateRef StateNotNull, StateNull;
|
|
|
|
std::tie(StateNotNull, StateNull) =
|
|
|
|
C.getConstraintManager().assumeDual(State, RetVal);
|
2015-09-08 11:50:52 +08:00
|
|
|
|
[analyzer] Small StreamChecker refactoring (NFC).
Reviewers: Szelethus
Reviewed By: Szelethus
Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73350
2020-02-07 16:09:45 +08:00
|
|
|
StateNotNull = StateNotNull->set<StreamMap>(RetSym, StreamState::getOpened());
|
|
|
|
StateNull = StateNull->set<StreamMap>(RetSym, StreamState::getOpenFailed());
|
2010-06-24 21:36:41 +08:00
|
|
|
|
[analyzer] Small StreamChecker refactoring (NFC).
Reviewers: Szelethus
Reviewed By: Szelethus
Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73350
2020-02-07 16:09:45 +08:00
|
|
|
C.addTransition(StateNotNull);
|
|
|
|
C.addTransition(StateNull);
|
2010-06-18 10:47:46 +08:00
|
|
|
}
|
|
|
|
|
2019-12-05 00:15:03 +08:00
|
|
|
void StreamChecker::evalFreopen(const CallEvent &Call,
|
|
|
|
CheckerContext &C) const {
|
|
|
|
ProgramStateRef State = C.getState();
|
|
|
|
|
|
|
|
auto *CE = dyn_cast_or_null<CallExpr>(Call.getOriginExpr());
|
|
|
|
if (!CE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Optional<DefinedSVal> StreamVal = Call.getArgSVal(2).getAs<DefinedSVal>();
|
|
|
|
if (!StreamVal)
|
|
|
|
return;
|
|
|
|
// Do not allow NULL as passed stream pointer.
|
|
|
|
// This is not specified in the man page but may crash on some system.
|
[analyzer]StreamChecker refactoring (NFC).
Reviewers: Szelethus
Reviewed By: Szelethus
Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73359
2020-02-12 18:26:38 +08:00
|
|
|
State = checkNullStream(*StreamVal, C, State);
|
|
|
|
if (!State)
|
2019-12-05 00:15:03 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
SymbolRef StreamSym = StreamVal->getAsSymbol();
|
|
|
|
// Do not care about special values for stream ("(FILE *)0x12345"?).
|
|
|
|
if (!StreamSym)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Generate state for non-failed case.
|
|
|
|
// Return value is the passed stream pointer.
|
|
|
|
// According to the documentations, the stream is closed first
|
|
|
|
// but any close error is ignored. The state changes to (or remains) opened.
|
|
|
|
ProgramStateRef StateRetNotNull =
|
|
|
|
State->BindExpr(CE, C.getLocationContext(), *StreamVal);
|
|
|
|
// Generate state for NULL return value.
|
|
|
|
// Stream switches to OpenFailed state.
|
|
|
|
ProgramStateRef StateRetNull = State->BindExpr(CE, C.getLocationContext(),
|
|
|
|
C.getSValBuilder().makeNull());
|
|
|
|
|
|
|
|
StateRetNotNull =
|
|
|
|
StateRetNotNull->set<StreamMap>(StreamSym, StreamState::getOpened());
|
|
|
|
StateRetNull =
|
|
|
|
StateRetNull->set<StreamMap>(StreamSym, StreamState::getOpenFailed());
|
|
|
|
|
|
|
|
C.addTransition(StateRetNotNull);
|
|
|
|
C.addTransition(StateRetNull);
|
|
|
|
}
|
|
|
|
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
void StreamChecker::evalFclose(const CallEvent &Call, CheckerContext &C) const {
|
|
|
|
ProgramStateRef State = C.getState();
|
[analyzer]StreamChecker refactoring (NFC).
Reviewers: Szelethus
Reviewed By: Szelethus
Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73359
2020-02-12 18:26:38 +08:00
|
|
|
State = checkDoubleClose(Call, C, State);
|
|
|
|
if (State)
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
C.addTransition(State);
|
2010-06-18 10:47:46 +08:00
|
|
|
}
|
|
|
|
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
void StreamChecker::evalFseek(const CallEvent &Call, CheckerContext &C) const {
|
|
|
|
const Expr *AE2 = Call.getArgExpr(2);
|
|
|
|
if (!AE2)
|
2010-06-18 10:47:46 +08:00
|
|
|
return;
|
2010-06-16 13:38:05 +08:00
|
|
|
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
ProgramStateRef State = C.getState();
|
2010-06-22 15:50:21 +08:00
|
|
|
|
[analyzer]StreamChecker refactoring (NFC).
Reviewers: Szelethus
Reviewed By: Szelethus
Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73359
2020-02-12 18:26:38 +08:00
|
|
|
State = checkNullStream(Call.getArgSVal(0), C, State);
|
|
|
|
if (!State)
|
2010-06-22 15:50:21 +08:00
|
|
|
return;
|
|
|
|
|
[analyzer]StreamChecker refactoring (NFC).
Reviewers: Szelethus
Reviewed By: Szelethus
Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73359
2020-02-12 18:26:38 +08:00
|
|
|
State =
|
|
|
|
checkFseekWhence(State->getSVal(AE2, C.getLocationContext()), C, State);
|
|
|
|
if (!State)
|
|
|
|
return;
|
2010-06-22 15:50:21 +08:00
|
|
|
|
[analyzer]StreamChecker refactoring (NFC).
Reviewers: Szelethus
Reviewed By: Szelethus
Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73359
2020-02-12 18:26:38 +08:00
|
|
|
C.addTransition(State);
|
2010-06-22 15:50:21 +08:00
|
|
|
}
|
|
|
|
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
void StreamChecker::checkArgNullStream(const CallEvent &Call, CheckerContext &C,
|
|
|
|
unsigned ArgI) const {
|
|
|
|
ProgramStateRef State = C.getState();
|
[analyzer]StreamChecker refactoring (NFC).
Reviewers: Szelethus
Reviewed By: Szelethus
Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73359
2020-02-12 18:26:38 +08:00
|
|
|
State = checkNullStream(Call.getArgSVal(ArgI), C, State);
|
|
|
|
if (State)
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
C.addTransition(State);
|
2010-06-22 15:50:21 +08:00
|
|
|
}
|
|
|
|
|
[analyzer]StreamChecker refactoring (NFC).
Reviewers: Szelethus
Reviewed By: Szelethus
Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73359
2020-02-12 18:26:38 +08:00
|
|
|
ProgramStateRef StreamChecker::checkNullStream(SVal SV, CheckerContext &C,
|
|
|
|
ProgramStateRef State) const {
|
2013-02-21 06:23:23 +08:00
|
|
|
Optional<DefinedSVal> DV = SV.getAs<DefinedSVal>();
|
2010-06-18 10:47:46 +08:00
|
|
|
if (!DV)
|
[analyzer]StreamChecker refactoring (NFC).
Reviewers: Szelethus
Reviewed By: Szelethus
Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73359
2020-02-12 18:26:38 +08:00
|
|
|
return State;
|
2010-06-16 13:56:39 +08:00
|
|
|
|
2010-06-18 10:47:46 +08:00
|
|
|
ConstraintManager &CM = C.getConstraintManager();
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
ProgramStateRef StateNotNull, StateNull;
|
|
|
|
std::tie(StateNotNull, StateNull) = CM.assumeDual(C.getState(), *DV);
|
2010-06-16 13:56:39 +08:00
|
|
|
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
if (!StateNotNull && StateNull) {
|
|
|
|
if (ExplodedNode *N = C.generateErrorNode(StateNull)) {
|
2010-06-18 10:47:46 +08:00
|
|
|
if (!BT_nullfp)
|
2014-02-12 05:49:21 +08:00
|
|
|
BT_nullfp.reset(new BuiltinBug(this, "NULL stream pointer",
|
|
|
|
"Stream pointer might be NULL."));
|
2019-09-10 04:34:40 +08:00
|
|
|
C.emitReport(std::make_unique<PathSensitiveBugReport>(
|
2015-06-23 21:15:32 +08:00
|
|
|
*BT_nullfp, BT_nullfp->getDescription(), N));
|
2010-06-16 13:38:05 +08:00
|
|
|
}
|
[analyzer]StreamChecker refactoring (NFC).
Reviewers: Szelethus
Reviewed By: Szelethus
Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73359
2020-02-12 18:26:38 +08:00
|
|
|
return nullptr;
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
}
|
|
|
|
|
[analyzer]StreamChecker refactoring (NFC).
Reviewers: Szelethus
Reviewed By: Szelethus
Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73359
2020-02-12 18:26:38 +08:00
|
|
|
return StateNotNull;
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
}
|
|
|
|
|
[analyzer]StreamChecker refactoring (NFC).
Reviewers: Szelethus
Reviewed By: Szelethus
Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73359
2020-02-12 18:26:38 +08:00
|
|
|
// Check the legality of the 'whence' argument of 'fseek'.
|
|
|
|
ProgramStateRef StreamChecker::checkFseekWhence(SVal SV, CheckerContext &C,
|
|
|
|
ProgramStateRef State) const {
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
Optional<nonloc::ConcreteInt> CI = SV.getAs<nonloc::ConcreteInt>();
|
|
|
|
if (!CI)
|
[analyzer]StreamChecker refactoring (NFC).
Reviewers: Szelethus
Reviewed By: Szelethus
Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73359
2020-02-12 18:26:38 +08:00
|
|
|
return State;
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
|
|
|
|
int64_t X = CI->getValue().getSExtValue();
|
|
|
|
if (X >= 0 && X <= 2)
|
[analyzer]StreamChecker refactoring (NFC).
Reviewers: Szelethus
Reviewed By: Szelethus
Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73359
2020-02-12 18:26:38 +08:00
|
|
|
return State;
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
|
|
|
|
if (ExplodedNode *N = C.generateNonFatalErrorNode(State)) {
|
|
|
|
if (!BT_illegalwhence)
|
|
|
|
BT_illegalwhence.reset(
|
|
|
|
new BuiltinBug(this, "Illegal whence argument",
|
|
|
|
"The whence argument to fseek() should be "
|
|
|
|
"SEEK_SET, SEEK_END, or SEEK_CUR."));
|
|
|
|
C.emitReport(std::make_unique<PathSensitiveBugReport>(
|
|
|
|
*BT_illegalwhence, BT_illegalwhence->getDescription(), N));
|
[analyzer]StreamChecker refactoring (NFC).
Reviewers: Szelethus
Reviewed By: Szelethus
Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73359
2020-02-12 18:26:38 +08:00
|
|
|
return nullptr;
|
2010-06-16 13:38:05 +08:00
|
|
|
}
|
[analyzer]StreamChecker refactoring (NFC).
Reviewers: Szelethus
Reviewed By: Szelethus
Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73359
2020-02-12 18:26:38 +08:00
|
|
|
|
|
|
|
return State;
|
2010-06-16 13:38:05 +08:00
|
|
|
}
|
2010-07-19 09:52:29 +08:00
|
|
|
|
[analyzer]StreamChecker refactoring (NFC).
Reviewers: Szelethus
Reviewed By: Szelethus
Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73359
2020-02-12 18:26:38 +08:00
|
|
|
ProgramStateRef StreamChecker::checkDoubleClose(const CallEvent &Call,
|
|
|
|
CheckerContext &C,
|
|
|
|
ProgramStateRef State) const {
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
SymbolRef Sym = Call.getArgSVal(0).getAsSymbol();
|
2010-09-03 09:07:04 +08:00
|
|
|
if (!Sym)
|
[analyzer]StreamChecker refactoring (NFC).
Reviewers: Szelethus
Reviewed By: Szelethus
Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73359
2020-02-12 18:26:38 +08:00
|
|
|
return State;
|
2015-09-08 11:50:52 +08:00
|
|
|
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
const StreamState *SS = State->get<StreamMap>(Sym);
|
2010-08-06 07:24:13 +08:00
|
|
|
|
|
|
|
// If the file stream is not tracked, return.
|
|
|
|
if (!SS)
|
[analyzer]StreamChecker refactoring (NFC).
Reviewers: Szelethus
Reviewed By: Szelethus
Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73359
2020-02-12 18:26:38 +08:00
|
|
|
return State;
|
2015-09-08 11:50:52 +08:00
|
|
|
|
2010-07-19 09:52:29 +08:00
|
|
|
// Check: Double close a File Descriptor could cause undefined behaviour.
|
|
|
|
// Conforming to man-pages
|
|
|
|
if (SS->isClosed()) {
|
2015-09-17 06:03:05 +08:00
|
|
|
ExplodedNode *N = C.generateErrorNode();
|
2010-07-19 09:52:29 +08:00
|
|
|
if (N) {
|
|
|
|
if (!BT_doubleclose)
|
2014-02-12 05:49:21 +08:00
|
|
|
BT_doubleclose.reset(new BuiltinBug(
|
|
|
|
this, "Double fclose", "Try to close a file Descriptor already"
|
|
|
|
" closed. Cause undefined behaviour."));
|
2019-09-10 04:34:40 +08:00
|
|
|
C.emitReport(std::make_unique<PathSensitiveBugReport>(
|
2015-06-23 21:15:32 +08:00
|
|
|
*BT_doubleclose, BT_doubleclose->getDescription(), N));
|
[analyzer]StreamChecker refactoring (NFC).
Reviewers: Szelethus
Reviewed By: Szelethus
Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73359
2020-02-12 18:26:38 +08:00
|
|
|
return nullptr;
|
2010-07-19 09:52:29 +08:00
|
|
|
}
|
[analyzer]StreamChecker refactoring (NFC).
Reviewers: Szelethus
Reviewed By: Szelethus
Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73359
2020-02-12 18:26:38 +08:00
|
|
|
|
|
|
|
return State;
|
2010-07-19 09:52:29 +08:00
|
|
|
}
|
2015-09-08 11:50:52 +08:00
|
|
|
|
2010-07-19 09:52:29 +08:00
|
|
|
// Close the File Descriptor.
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
State = State->set<StreamMap>(Sym, StreamState::getClosed());
|
|
|
|
|
[analyzer]StreamChecker refactoring (NFC).
Reviewers: Szelethus
Reviewed By: Szelethus
Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73359
2020-02-12 18:26:38 +08:00
|
|
|
return State;
|
2010-07-19 09:52:29 +08:00
|
|
|
}
|
2010-07-23 22:14:59 +08:00
|
|
|
|
2011-02-24 09:05:33 +08:00
|
|
|
void StreamChecker::checkDeadSymbols(SymbolReaper &SymReaper,
|
|
|
|
CheckerContext &C) const {
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
ProgramStateRef State = C.getState();
|
2018-11-30 11:27:50 +08:00
|
|
|
|
2012-10-30 06:51:44 +08:00
|
|
|
// TODO: Clean up the state.
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
const StreamMapTy &Map = State->get<StreamMap>();
|
2018-11-30 11:27:50 +08:00
|
|
|
for (const auto &I: Map) {
|
|
|
|
SymbolRef Sym = I.first;
|
|
|
|
const StreamState &SS = I.second;
|
|
|
|
if (!SymReaper.isDead(Sym) || !SS.isOpened())
|
2013-03-16 07:34:31 +08:00
|
|
|
continue;
|
2010-07-23 22:14:59 +08:00
|
|
|
|
2018-11-30 11:27:50 +08:00
|
|
|
ExplodedNode *N = C.generateErrorNode();
|
|
|
|
if (!N)
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
continue;
|
2018-11-30 11:27:50 +08:00
|
|
|
|
|
|
|
if (!BT_ResourceLeak)
|
|
|
|
BT_ResourceLeak.reset(
|
|
|
|
new BuiltinBug(this, "Resource Leak",
|
|
|
|
"Opened File never closed. Potential Resource leak."));
|
2019-09-10 04:34:40 +08:00
|
|
|
C.emitReport(std::make_unique<PathSensitiveBugReport>(
|
2018-11-30 11:27:50 +08:00
|
|
|
*BT_ResourceLeak, BT_ResourceLeak->getDescription(), N));
|
2010-07-23 22:14:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-24 09:05:33 +08:00
|
|
|
void ento::registerStreamChecker(CheckerManager &mgr) {
|
|
|
|
mgr.registerChecker<StreamChecker>();
|
|
|
|
}
|
2019-01-26 22:23:08 +08:00
|
|
|
|
|
|
|
bool ento::shouldRegisterStreamChecker(const LangOptions &LO) {
|
|
|
|
return true;
|
|
|
|
}
|