Skip to content

Commit bad88fd

Browse files
committed
Fixing review comments
-separating test cases for the tainteddiv and the dividezero checkers -simplifying taint test execution lit test invocations
1 parent c1f550a commit bad88fd

File tree

6 files changed

+47
-27
lines changed

6 files changed

+47
-27
lines changed

clang/docs/analyzer/checkers.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,25 +1295,25 @@ optin.taint.TaintedDiv (C, C++, ObjC)
12951295
This checker warns when the denominator in a division
12961296
operation is a tainted (potentially attacker controlled) value.
12971297
If the attacker can set the denominator to 0, a runtime error can
1298-
be triggered. The checker warns if the analyzer cannot prove
1299-
that the denominator is not 0 and it is a tainted value.
1300-
This warning is more pessimistic than the :ref:`core-DivideZero` checker
1298+
be triggered. The checker warns when the denominator is a tainted
1299+
value and the analyzer cannot prove that it is not 0. This warning
1300+
is more pessimistic than the :ref:`core-DivideZero` checker
13011301
which warns only when it can prove that the denominator is 0.
13021302
13031303
.. code-block:: c
13041304
13051305
int vulnerable(int n) {
13061306
size_t size = 0;
13071307
scanf("%zu", &size);
1308-
return n/size; // warn: Division by a tainted value, possibly zero
1308+
return n / size; // warn: Division by a tainted value, possibly zero
13091309
}
13101310
13111311
int not_vulnerable(int n) {
13121312
size_t size = 0;
13131313
scanf("%zu", &size);
13141314
if (!size)
13151315
return 0;
1316-
return n/size; // no warning
1316+
return n / size; // no warning
13171317
}
13181318
13191319
.. _security-checkers:

clang/include/clang/StaticAnalyzer/Checkers/Checkers.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,8 +1704,8 @@ def TaintedAllocChecker: Checker<"TaintedAlloc">,
17041704
Documentation<HasDocumentation>;
17051705

17061706
def TaintedDivChecker: Checker<"TaintedDiv">,
1707-
HelpText<"Check for divisions, where the denominator "
1708-
"might be 0 as it is a tainted (attacker controlled) value.">,
1707+
HelpText<"Check for divisions where the denominator is tainted "
1708+
"(attacker controlled) and might be 0.">,
17091709
Dependencies<[TaintPropagationChecker]>,
17101710
Documentation<HasDocumentation>;
17111711

clang/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class DivZeroChecker : public Checker<check::PreStmt<BinaryOperator>> {
3333
llvm::ArrayRef<SymbolRef> TaintedSyms) const;
3434

3535
public:
36-
/// This checker class implements multiple user facing checker
36+
/// This checker class implements several user facing checkers
3737
enum CheckKind { CK_DivideZero, CK_TaintedDivChecker, CK_NumCheckKinds };
3838
bool ChecksEnabled[CK_NumCheckKinds] = {false};
3939
CheckerNameRef CheckNames[CK_NumCheckKinds];
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %clang_analyze_cc1 -Wno-format-security -Wno-pointer-to-int-cast \
2+
// RUN: -Wno-incompatible-library-redeclaration -verify=normaldiv %s \
3+
// RUN: -analyzer-checker=optin.taint.GenericTaint \
4+
// RUN: -analyzer-checker=core
5+
6+
// RUN: %clang_analyze_cc1 -Wno-format-security -Wno-pointer-to-int-cast \
7+
// RUN: -Wno-incompatible-library-redeclaration -verify=tainteddiv %s \
8+
// RUN: -analyzer-checker=optin.taint.GenericTaint \
9+
// RUN: -analyzer-checker=optin.taint.TaintedDiv
10+
11+
int getchar(void);
12+
13+
14+
//If we are sure that we divide by zero
15+
//we emit a divide by zero warning
16+
int testDivZero(void) {
17+
int x = getchar(); // taint source
18+
if (!x)
19+
return 5 / x; // normaldiv-warning{{Division by zero}}
20+
return 8;
21+
}
22+
23+
// The attacker provided value might be 0
24+
int testDivZero2(void) {
25+
int x = getchar(); // taint source
26+
return 5 / x; // tainteddiv-warning{{Division by a tainted value}}
27+
}
28+
29+
int testDivZero3(void) {
30+
int x = getchar(); // taint source
31+
if (!x)
32+
return 0;
33+
return 5 / x; // no warning
34+
}

clang/test/Analysis/taint-diagnostic-visitor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -analyze -analyzer-checker=optin.taint,core,alpha.security.ArrayBoundV2,optin.taint.TaintedAlloc,optin.taint.TaintedDiv -analyzer-output=text -verify %s
1+
// RUN: %clang_cc1 -analyze -analyzer-checker=optin.taint,core,alpha.security.ArrayBoundV2 -analyzer-output=text -verify %s
22

33
// This file is for testing enhanced diagnostics produced by the GenericTaintChecker
44

clang/test/Analysis/taint-generic.c

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@
1919
// RUN: -analyzer-config \
2020
// RUN: optin.taint.TaintPropagation:Config=%S/Inputs/taint-generic-config.yaml
2121

22-
// RUN: not %clang_analyze_cc1 -Wno-pointer-to-int-cast \
23-
// RUN: -Wno-incompatible-library-redeclaration -verify %s \
22+
// RUN: not %clang_analyze_cc1 \
23+
// RUN: -verify %s \
2424
// RUN: -analyzer-checker=optin.taint.GenericTaint \
25-
// RUN: -analyzer-checker=optin.taint.TaintedDiv \
26-
// RUN: -analyzer-checker=debug.ExprInspection \
2725
// RUN: -analyzer-config \
2826
// RUN: optin.taint.TaintPropagation:Config=justguessit \
2927
// RUN: 2>&1 | FileCheck %s -check-prefix=CHECK-INVALID-FILE
@@ -33,10 +31,9 @@
3331
// CHECK-INVALID-FILE-SAME: that expects a valid filename instead of
3432
// CHECK-INVALID-FILE-SAME: 'justguessit'
3533

36-
// RUN: not %clang_analyze_cc1 -Wno-incompatible-library-redeclaration \
34+
// RUN: not %clang_analyze_cc1 \
3735
// RUN: -verify %s \
3836
// RUN: -analyzer-checker=optin.taint.GenericTaint \
39-
// RUN: -analyzer-checker=debug.ExprInspection \
4037
// RUN: -analyzer-config \
4138
// RUN: optin.taint.TaintPropagation:Config=%S/Inputs/taint-generic-config-ill-formed.yaml \
4239
// RUN: 2>&1 | FileCheck -DMSG=%errc_EINVAL %s -check-prefix=CHECK-ILL-FORMED
@@ -45,10 +42,9 @@
4542
// CHECK-ILL-FORMED-SAME: 'optin.taint.TaintPropagation:Config',
4643
// CHECK-ILL-FORMED-SAME: that expects a valid yaml file: [[MSG]]
4744

48-
// RUN: not %clang_analyze_cc1 -Wno-incompatible-library-redeclaration \
45+
// RUN: not %clang_analyze_cc1 \
4946
// RUN: -verify %s \
5047
// RUN: -analyzer-checker=optin.taint.GenericTaint \
51-
// RUN: -analyzer-checker=debug.ExprInspection \
5248
// RUN: -analyzer-config \
5349
// RUN: optin.taint.TaintPropagation:Config=%S/Inputs/taint-generic-config-invalid-arg.yaml \
5450
// RUN: 2>&1 | FileCheck %s -check-prefix=CHECK-INVALID-ARG
@@ -419,16 +415,6 @@ int testTaintedDivFP(void) {
419415
return 5/x; // x cannot be 0, so no tainted warning either
420416
}
421417

422-
423-
//If we are sure that we divide by zero
424-
//we emit a divide by zero warning
425-
int testDivZero(void) {
426-
int x = getchar(); // taint source
427-
if (!x)
428-
return 5 / x; // expected-warning{{Division by zero}}
429-
return 8;
430-
}
431-
432418
// Zero-sized VLAs.
433419
void testTaintedVLASize(void) {
434420
int x;

0 commit comments

Comments
 (0)