@@ -872,7 +872,7 @@ module InterProceduralPointsTo {
872872 )
873873 }
874874
875- predicate selfMethodCall ( MethodCallsiteRefinement def , PointsToContext caller , Function func , PointsToContext callee ) {
875+ predicate selfMethodCall ( SelfCallsiteRefinement def , PointsToContext caller , Function func , PointsToContext callee ) {
876876 def .getInput ( ) .getSourceVariable ( ) .( Variable ) .isSelf ( ) and
877877 exists ( PythonFunctionObjectInternal method , CallNode call |
878878 method .getScope ( ) = func and
@@ -1232,6 +1232,15 @@ module Expressions {
12321232 )
12331233 }
12341234
1235+ pragma [ noinline]
1236+ predicate setattr_call ( CallNode call , PointsToContext context , ControlFlowNode obj , string name , ObjectInternal val , ControlFlowNode origin ) {
1237+ exists ( ControlFlowNode arg1 , ControlFlowNode arg2 |
1238+ call_to_setattr ( call , context , obj , arg1 , arg2 ) and
1239+ PointsToInternal:: pointsTo ( arg2 , context , val , origin ) and
1240+ PointsToInternal:: pointsToString ( arg1 , context , name )
1241+ )
1242+ }
1243+
12351244 pragma [ noinline]
12361245 private predicate call_to_getattr ( ControlFlowNode call , PointsToContext context , ControlFlowNode arg0 , ControlFlowNode arg1 ) {
12371246 exists ( ControlFlowNode func |
@@ -1240,6 +1249,14 @@ module Expressions {
12401249 )
12411250 }
12421251
1252+ pragma [ noinline]
1253+ private predicate call_to_setattr ( ControlFlowNode call , PointsToContext context , ControlFlowNode arg0 , ControlFlowNode arg1 , ControlFlowNode arg2 ) {
1254+ exists ( ControlFlowNode func |
1255+ call3 ( call , func , arg0 , arg1 , arg2 ) and
1256+ PointsToInternal:: pointsTo ( func , context , ObjectInternal:: builtin ( "setattr" ) , _)
1257+ )
1258+ }
1259+
12431260 pragma [ noinline]
12441261 private boolean otherComparisonEvaluatesTo ( CompareNode comp , PointsToContext context , ControlFlowNode operand , ObjectInternal opvalue ) {
12451262 exists ( Cmpop op |
@@ -1935,6 +1952,7 @@ cached module Types {
19351952module AttributePointsTo {
19361953
19371954 predicate pointsTo ( AttrNode f , Context context , ObjectInternal value , ControlFlowNode origin ) {
1955+ f .isLoad ( ) and
19381956 exists ( EssaVariable var , string name , CfgOrigin orig |
19391957 var .getASourceUse ( ) = f .getObject ( name ) and
19401958 variableAttributePointsTo ( var , context , name , value , orig ) and
@@ -1961,6 +1979,8 @@ module AttributePointsTo {
19611979 selfParameterAttributePointsTo ( def , context , name , value , origin )
19621980 or
19631981 selfMethodCallsitePointsTo ( def , context , name , value , origin )
1982+ or
1983+ argumentRefinementPointsTo ( def , context , name , value , origin )
19641984 }
19651985
19661986 pragma [ noinline]
@@ -2002,22 +2022,41 @@ module AttributePointsTo {
20022022 }
20032023
20042024 private predicate selfParameterAttributePointsTo ( ParameterDefinition def , PointsToContext context , string name , ObjectInternal value , CfgOrigin origin ) {
2005- exists ( MethodCallsiteRefinement call , Function func , PointsToContext caller |
2025+ exists ( SelfCallsiteRefinement call , Function func , PointsToContext caller |
20062026 InterProceduralPointsTo:: selfMethodCall ( call , caller , func , context ) and
20072027 def .isSelf ( ) and def .getScope ( ) = func and
20082028 variableAttributePointsTo ( call .getInput ( ) , caller , name , value , origin )
20092029 )
20102030 }
20112031
20122032 /** Pass through for `self` for the implicit re-definition of `self` in `self.foo()`. */
2013- private predicate selfMethodCallsitePointsTo ( MethodCallsiteRefinement def , PointsToContext context , string name , ObjectInternal value , CfgOrigin origin ) {
2033+ private predicate selfMethodCallsitePointsTo ( SelfCallsiteRefinement def , PointsToContext context , string name , ObjectInternal value , CfgOrigin origin ) {
20142034 /* The value of self remains the same, only the attributes may change */
20152035 exists ( Function func , PointsToContext callee , EssaVariable exit_self |
20162036 InterProceduralPointsTo:: selfMethodCall ( def , context , func , callee ) and
20172037 exit_self .getSourceVariable ( ) .( Variable ) .isSelf ( ) and
20182038 exit_self .getScope ( ) = func and
20192039 BaseFlow:: reaches_exit ( exit_self ) and
2020- variableAttributePointsTo ( exit_self , context , name , value , origin )
2040+ variableAttributePointsTo ( exit_self , callee , name , value , origin )
2041+ )
2042+ }
2043+
2044+ private predicate argumentRefinementPointsTo ( ArgumentRefinement def , PointsToContext context , string name , ObjectInternal value , CfgOrigin origin ) {
2045+ exists ( ObjectInternal callable |
2046+ PointsToInternal:: pointsTo ( def .getCall ( ) .getFunction ( ) , context , callable , _) and
2047+ callable != ObjectInternal:: builtin ( "setattr" )
2048+ ) and
2049+ variableAttributePointsTo ( def .getInput ( ) , context , name , value , origin )
2050+ or
2051+ exists ( string othername |
2052+ Expressions:: setattr_call ( def .getCall ( ) , context , def .getInput ( ) .getASourceUse ( ) , othername , _, _) and
2053+ not othername = name
2054+ ) and
2055+ variableAttributePointsTo ( def .getInput ( ) , context , name , value , origin )
2056+ or
2057+ exists ( ControlFlowNode orig |
2058+ Expressions:: setattr_call ( def .getCall ( ) , context , def .getInput ( ) .getASourceUse ( ) , name , value , orig ) and
2059+ origin = CfgOrigin:: fromCfgNode ( orig )
20212060 )
20222061 }
20232062
0 commit comments