@@ -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
4646class 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
5252predicate taintingFunction ( Function f , int buf )
@@ -83,8 +83,7 @@ class TaintedArgument extends PointsToExpr
8383}
8484
8585from 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
9089select fc , "To avoid overflow, this operation should be bounded by destination-buffer size, not source-buffer size."
0 commit comments