|
11 | 11 | * external/cwe/cwe-131 |
12 | 12 | */ |
13 | 13 | import cpp |
| 14 | +import semmle.code.cpp.security.TaintTracking |
14 | 15 | import semmle.code.cpp.pointsto.PointsTo |
15 | 16 |
|
16 | 17 | /** |
@@ -49,41 +50,8 @@ class VulnerableArgument extends PointsToExpr |
49 | 50 | override predicate interesting() { sourceSized(_, this) } |
50 | 51 | } |
51 | 52 |
|
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 |
86 | 54 | where sourceSized(fc, vuln) |
87 | | - and vuln.pointsTo() = tainted.pointsTo() |
| 55 | + and tainted(taintSource, vuln.pointsTo()) |
88 | 56 | and vuln.confidence() > 0.01 |
89 | 57 | select fc, "To avoid overflow, this operation should be bounded by destination-buffer size, not source-buffer size." |
0 commit comments