Skip to content

Commit 94fa4af

Browse files
committed
fixup!
1 parent 4b31027 commit 94fa4af

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

clang/docs/analyzer/checkers.rst

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,8 @@ Check for undefined results of binary operators.
213213
214214
core.VLASize (C)
215215
""""""""""""""""
216-
Check for declarations of Variable Length Arrays of undefined or zero size.
217-
218-
Check for declarations of VLA of undefined or zero size.
216+
Check for declarations of Variable Length Arrays (VLA) of undefined, zero or negative
217+
size.
219218
220219
.. code-block:: c
221220
@@ -229,6 +228,28 @@ Check for declarations of Variable Length Arrays of undefined or zero size.
229228
int vla2[x]; // warn: zero size
230229
}
231230
231+
232+
The checker also gives warning if the `TaintPropagation` checker is switched on
233+
and an unbound, attacker controlled (tainted) value is used to define
234+
the size of the VLA.
235+
236+
.. code-block:: c
237+
238+
void taintedVLA(void) {
239+
int x;
240+
scanf("%d", &x);
241+
int vla[x]; // Declared variable-length array (VLA) has a tainted (attacker controlled) size, that can be 0 or negative
242+
}
243+
244+
void taintedVerfieidVLA(void) {
245+
int x;
246+
scanf("%d", &x);
247+
if (x<1)
248+
return;
249+
int vla[x]; // no-warning. The analyzer can prove that the x can only be positive.
250+
}
251+
252+
232253
.. _core-uninitialized-ArraySubscript:
233254
234255
core.uninitialized.ArraySubscript (C)

clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ void VLASizeChecker::reportTaintBug(const Expr *SizeE, ProgramStateRef State,
220220
SmallString<256> buf;
221221
llvm::raw_svector_ostream os(buf);
222222
os << "Declared variable-length array (VLA) ";
223-
os << "has a tainted (attacker controlled) size, that can be 0 or negative";
223+
os << "has a tainted (attacker controlled) size that can be 0 or negative";
224224

225225
auto report = std::make_unique<PathSensitiveBugReport>(*TaintBT, os.str(), N);
226226
report->addRange(SizeE->getSourceRange());

clang/test/Analysis/taint-generic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ int testDivByZero(void) {
405405
void testTaintedVLASize(void) {
406406
int x;
407407
scanf("%d", &x);
408-
int vla[x]; // expected-warning{{Declared variable-length array (VLA) has a tainted (attacker controlled) size, that can be 0 or negative}}
408+
int vla[x]; // expected-warning{{Declared variable-length array (VLA) has a tainted (attacker controlled) size that can be 0 or negative}}
409409
}
410410

411411
// Tainted-sanitized VLAs.

0 commit comments

Comments
 (0)