Skip to content

Commit e77f3eb

Browse files
committed
CPP: Simplify slightly.
1 parent 939a836 commit e77f3eb

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

cpp/ql/src/Critical/OverflowDestination.ql

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ import semmle.code.cpp.pointsto.PointsTo
2020
* memcpy(dest, src, sizeof(src));
2121
* ```
2222
*/
23-
predicate sourceSized(FunctionCall fc)
23+
predicate sourceSized(FunctionCall fc, Expr src)
2424
{
2525
exists(string name |
2626
(name = "strncpy" or name = "strncat" or name = "memcpy" or name = "memmove") and
2727
fc.getTarget().hasQualifiedName(name))
2828
and
29-
exists(Expr dest, Expr src, Expr size, Variable v |
29+
exists(Expr dest, Expr size, Variable v |
3030
fc.getArgument(0) = dest and fc.getArgument(1) = src and fc.getArgument(2) = size and
3131
src = v.getAnAccess() and size.getAChild+() = v.getAnAccess() and
3232

@@ -45,8 +45,8 @@ predicate sourceSized(FunctionCall fc)
4545

4646
class VulnerableArgument extends PointsToExpr
4747
{
48-
VulnerableArgument() { sourceSized(this.getParent()) }
49-
override predicate interesting() { sourceSized(this.getParent()) }
48+
VulnerableArgument() { sourceSized(_, this) }
49+
override predicate interesting() { sourceSized(_, this) }
5050
}
5151

5252
predicate taintingFunction(Function f, int buf)
@@ -83,8 +83,7 @@ class TaintedArgument extends PointsToExpr
8383
}
8484

8585
from FunctionCall fc, VulnerableArgument vuln, TaintedArgument tainted
86-
where sourceSized(fc)
87-
and fc.getArgument(1) = vuln
86+
where sourceSized(fc, vuln)
8887
and vuln.pointsTo() = tainted.pointsTo()
8988
and vuln.confidence() > 0.01
9089
select fc, "To avoid overflow, this operation should be bounded by destination-buffer size, not source-buffer size."

0 commit comments

Comments
 (0)