Skip to content

Commit 9937430

Browse files
committed
CPP: Use taint library.
1 parent e77f3eb commit 9937430

File tree

1 file changed

+3
-35
lines changed

1 file changed

+3
-35
lines changed

cpp/ql/src/Critical/OverflowDestination.ql

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* external/cwe/cwe-131
1212
*/
1313
import cpp
14+
import semmle.code.cpp.security.TaintTracking
1415
import semmle.code.cpp.pointsto.PointsTo
1516

1617
/**
@@ -49,41 +50,8 @@ class VulnerableArgument extends PointsToExpr
4950
override predicate interesting() { sourceSized(_, this) }
5051
}
5152

52-
predicate taintingFunction(Function f, int buf)
53-
{
54-
(f.hasQualifiedName("read") and buf = 1) or
55-
(f.hasQualifiedName("fgets") and buf = 0) or
56-
(f.hasQualifiedName("fread") and buf = 0)
57-
}
58-
59-
// Taint `argv[i]`, for all i, but also `*argv`, etc.
60-
predicate commandLineArg(Expr e)
61-
{
62-
exists(Function f, Parameter argv, VariableAccess access |
63-
f.hasQualifiedName("main") and f.getParameter(1) = argv and
64-
argv.getAnAccess() = access and access.isRValue() and
65-
pointer(access, e))
66-
}
67-
68-
predicate tainted(Expr e)
69-
{
70-
exists(FunctionCall fc, int arg |
71-
taintingFunction(fc.getTarget(), arg) and
72-
e = fc.getArgument(arg))
73-
or
74-
e.(FunctionCall).getTarget().hasQualifiedName("getenv")
75-
or
76-
commandLineArg(e)
77-
}
78-
79-
class TaintedArgument extends PointsToExpr
80-
{
81-
TaintedArgument() { tainted(this) }
82-
override predicate interesting() { tainted(this) }
83-
}
84-
85-
from FunctionCall fc, VulnerableArgument vuln, TaintedArgument tainted
53+
from FunctionCall fc, VulnerableArgument vuln, Expr taintSource
8654
where sourceSized(fc, vuln)
87-
and vuln.pointsTo() = tainted.pointsTo()
55+
and tainted(taintSource, vuln.pointsTo())
8856
and vuln.confidence() > 0.01
8957
select fc, "To avoid overflow, this operation should be bounded by destination-buffer size, not source-buffer size."

0 commit comments

Comments
 (0)