diff --git a/clang/lib/StaticAnalyzer/Checkers/BoolAssignmentChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/BoolAssignmentChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/BoolAssignmentChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/BoolAssignmentChecker.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h" +#include "clang/StaticAnalyzer/Checkers/Taint.h" #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h" #include "clang/StaticAnalyzer/Core/Checker.h" #include "clang/StaticAnalyzer/Core/CheckerManager.h" @@ -23,20 +24,23 @@ namespace { class BoolAssignmentChecker : public Checker< check::Bind > { mutable std::unique_ptr BT; - void emitReport(ProgramStateRef state, CheckerContext &C) const; + void emitReport(ProgramStateRef state, CheckerContext &C, + bool IsTainted = false) const; + public: void checkBind(SVal loc, SVal val, const Stmt *S, CheckerContext &C) const; }; } // end anonymous namespace -void BoolAssignmentChecker::emitReport(ProgramStateRef state, - CheckerContext &C) const { +void BoolAssignmentChecker::emitReport(ProgramStateRef state, CheckerContext &C, + bool IsTainted) const { if (ExplodedNode *N = C.generateNonFatalErrorNode(state)) { if (!BT) BT.reset(new BuiltinBug(this, "Assignment of a non-Boolean value")); - C.emitReport( - std::make_unique(*BT, BT->getDescription(), N)); + StringRef Msg = IsTainted ? "Might assign a tainted non-Boolean value" + : "Assignment of a non-Boolean value"; + C.emitReport(std::make_unique(*BT, Msg, N)); } } @@ -90,6 +94,8 @@ if (!StIn) emitReport(StOut, C); + if (StIn && StOut && taint::isTainted(state, *NV)) + emitReport(StOut, C, /*IsTainted=*/true); } void ento::registerBoolAssignmentChecker(CheckerManager &mgr) { diff --git a/clang/test/Analysis/bool-assignment.c b/clang/test/Analysis/bool-assignment.c --- a/clang/test/Analysis/bool-assignment.c +++ b/clang/test/Analysis/bool-assignment.c @@ -1,5 +1,5 @@ -// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core.BoolAssignment -analyzer-store=region -verify -std=c99 -Dbool=_Bool %s -// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core.BoolAssignment -analyzer-store=region -verify -x c++ %s +// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core.BoolAssignment,alpha.security.taint -analyzer-store=region -verify -std=c99 -Dbool=_Bool %s +// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core.BoolAssignment,alpha.security.taint -analyzer-store=region -verify -x c++ %s // Test C++'s bool and C's _Bool. // FIXME: We stopped warning on these when SValBuilder got smarter about @@ -104,3 +104,10 @@ } x = y; // no-warning } + +int scanf(const char *format, ...); +void test_tainted_Boolean() { + int n; + scanf("%d", &n); + Boolean copy = n; // expected-warning {{Might assign a tainted non-Boolean value}} +}