@@ -1429,20 +1429,51 @@ module Expressions {
14291429 }
14301430
14311431 pragma [ noinline]
1432- predicate subscriptPointsTo (
1432+ private predicate indexPointsToInt ( ControlFlowNode index , PointsToContext context , int n ) {
1433+ index = any ( SubscriptNode subscr ) .getIndex ( ) and
1434+ PointsToInternal:: pointsTo ( index , context , TInt ( n ) , _)
1435+ }
1436+
1437+ pragma [ noinline]
1438+ private predicate getItemSequenceObjectInternal (
1439+ ObjectInternal value , SequenceObjectInternal objvalue , int n
1440+ ) {
1441+ value = objvalue .getItem ( n )
1442+ }
1443+
1444+ pragma [ noinline]
1445+ private predicate subscriptObjectAndIndexPointsToInt (
1446+ SubscriptNode subscr , PointsToContext context , ControlFlowNode obj , ObjectInternal objvalue ,
1447+ int n
1448+ ) {
1449+ exists ( ControlFlowNode index |
1450+ subscriptObjectAndIndex ( subscr , context , obj , objvalue , index ) and
1451+ indexPointsToInt ( index , context , n )
1452+ )
1453+ }
1454+
1455+ deprecated predicate subscriptPointsTo (
14331456 SubscriptNode subscr , PointsToContext context , ObjectInternal value , ControlFlowNode origin ,
14341457 ControlFlowNode obj , ObjectInternal objvalue
1458+ ) {
1459+ subscriptPointsTo ( subscr , context , value , obj , objvalue ) and
1460+ origin = subscr
1461+ }
1462+
1463+ pragma [ noinline]
1464+ private predicate subscriptPointsTo (
1465+ SubscriptNode subscr , PointsToContext context , ObjectInternal value , ControlFlowNode obj ,
1466+ ObjectInternal objvalue
14351467 ) {
14361468 exists ( ControlFlowNode index | subscriptObjectAndIndex ( subscr , context , obj , objvalue , index ) |
14371469 objvalue .subscriptUnknown ( ) and
14381470 value = ObjectInternal:: unknown ( )
1439- or
1440- exists ( int n |
1441- PointsToInternal:: pointsTo ( index , context , TInt ( n ) , _) and
1442- value = objvalue .( SequenceObjectInternal ) .getItem ( n )
1443- )
1444- ) and
1445- origin = subscr
1471+ )
1472+ or
1473+ exists ( int n |
1474+ subscriptObjectAndIndexPointsToInt ( subscr , context , obj , objvalue , n ) and
1475+ getItemSequenceObjectInternal ( value , objvalue , n )
1476+ )
14461477 }
14471478
14481479 predicate subscriptPartsPointsTo (
@@ -1466,15 +1497,22 @@ module Expressions {
14661497 index = subscr .getIndex ( )
14671498 }
14681499
1500+ deprecated predicate binaryPointsTo (
1501+ BinaryExprNode b , PointsToContext context , ObjectInternal value , ControlFlowNode origin ,
1502+ ControlFlowNode operand , ObjectInternal opvalue
1503+ ) {
1504+ binaryPointsTo ( b , context , value , operand , opvalue ) and
1505+ origin = b
1506+ }
1507+
14691508 /**
14701509 * Tracking too many binary expressions is likely to kill performance, so just say anything other than addition or bitwise or is 'unknown'.
14711510 */
14721511 pragma [ noinline]
1473- predicate binaryPointsTo (
1474- BinaryExprNode b , PointsToContext context , ObjectInternal value , ControlFlowNode origin ,
1475- ControlFlowNode operand , ObjectInternal opvalue
1512+ private predicate binaryPointsTo (
1513+ BinaryExprNode b , PointsToContext context , ObjectInternal value , ControlFlowNode operand ,
1514+ ObjectInternal opvalue
14761515 ) {
1477- origin = b and
14781516 operand = genericBinaryOperand ( b ) and
14791517 PointsToInternal:: pointsTo ( operand , context , opvalue , _) and
14801518 value = ObjectInternal:: unknown ( )
@@ -1491,12 +1529,19 @@ module Expressions {
14911529 )
14921530 }
14931531
1494- pragma [ noinline]
1495- predicate addPointsTo (
1532+ deprecated predicate addPointsTo (
14961533 BinaryExprNode b , PointsToContext context , ObjectInternal value , ControlFlowNode origin ,
14971534 ControlFlowNode operand , ObjectInternal opvalue
14981535 ) {
1499- origin = b and
1536+ addPointsTo ( b , context , value , operand , opvalue ) and
1537+ origin = b
1538+ }
1539+
1540+ pragma [ noinline]
1541+ private predicate addPointsTo (
1542+ BinaryExprNode b , PointsToContext context , ObjectInternal value , ControlFlowNode operand ,
1543+ ObjectInternal opvalue
1544+ ) {
15001545 exists ( Operator op |
15011546 b .operands ( operand , op , _)
15021547 or
@@ -1508,12 +1553,19 @@ module Expressions {
15081553 )
15091554 }
15101555
1511- pragma [ noinline]
1512- predicate bitOrPointsTo (
1556+ deprecated predicate bitOrPointsTo (
15131557 BinaryExprNode b , PointsToContext context , ObjectInternal value , ControlFlowNode origin ,
15141558 ControlFlowNode operand , ObjectInternal opvalue
15151559 ) {
1516- origin = b and
1560+ bitOrPointsTo ( b , context , value , operand , opvalue ) and
1561+ origin = b
1562+ }
1563+
1564+ pragma [ noinline]
1565+ private predicate bitOrPointsTo (
1566+ BinaryExprNode b , PointsToContext context , ObjectInternal value , ControlFlowNode operand ,
1567+ ObjectInternal opvalue
1568+ ) {
15171569 exists ( Operator op , ControlFlowNode other |
15181570 b .operands ( operand , op , other )
15191571 or
@@ -1533,10 +1585,18 @@ module Expressions {
15331585 value = obj .intValue ( )
15341586 }
15351587
1536- pragma [ noinline]
1537- predicate unaryPointsTo (
1588+ deprecated predicate unaryPointsTo (
15381589 UnaryExprNode u , PointsToContext context , ObjectInternal value , ControlFlowNode origin ,
15391590 ControlFlowNode operand , ObjectInternal opvalue
1591+ ) {
1592+ unaryPointsTo ( u , context , value , operand , opvalue ) and
1593+ origin = u
1594+ }
1595+
1596+ pragma [ noinline]
1597+ private predicate unaryPointsTo (
1598+ UnaryExprNode u , PointsToContext context , ObjectInternal value , ControlFlowNode operand ,
1599+ ObjectInternal opvalue
15401600 ) {
15411601 exists ( Unaryop op |
15421602 op = u .getNode ( ) .getOp ( ) and
@@ -1548,14 +1608,21 @@ module Expressions {
15481608 op instanceof USub and value = ObjectInternal:: fromInt ( - opvalue .intValue ( ) )
15491609 or
15501610 not op instanceof Not and opvalue = ObjectInternal:: unknown ( ) and value = opvalue
1551- ) and
1552- origin = u
1611+ )
15531612 }
15541613
1555- pragma [ noinline]
1556- predicate builtinCallPointsTo (
1614+ deprecated predicate builtinCallPointsTo (
15571615 CallNode call , PointsToContext context , ObjectInternal value , ControlFlowNode origin ,
15581616 ControlFlowNode arg , ObjectInternal argvalue
1617+ ) {
1618+ builtinCallPointsTo ( call , context , value , arg , argvalue ) and
1619+ origin = call
1620+ }
1621+
1622+ pragma [ noinline]
1623+ private predicate builtinCallPointsTo (
1624+ CallNode call , PointsToContext context , ObjectInternal value , ControlFlowNode arg ,
1625+ ObjectInternal argvalue
15591626 ) {
15601627 PointsToInternal:: pointsTo ( arg , context , argvalue , _) and
15611628 arg = call .getArg ( 0 ) and
@@ -1569,8 +1636,7 @@ module Expressions {
15691636 callable != ObjectInternal:: builtin ( "hasattr" ) and
15701637 callable .isClass ( ) = false and
15711638 value = ObjectInternal:: unknown ( )
1572- ) and
1573- origin = call
1639+ )
15741640 }
15751641
15761642 pragma [ noinline]
@@ -1585,11 +1651,10 @@ module Expressions {
15851651
15861652 pragma [ noinline]
15871653 private predicate lenCallPointsTo (
1588- CallNode call , PointsToContext context , ObjectInternal value , ControlFlowNode origin ,
1589- ControlFlowNode arg , ObjectInternal argvalue
1654+ CallNode call , PointsToContext context , ObjectInternal value , ControlFlowNode arg ,
1655+ ObjectInternal argvalue
15901656 ) {
15911657 len_call ( call , arg , context , argvalue ) and
1592- origin = call and
15931658 exists ( int len | len = argvalue .length ( ) |
15941659 value = TInt ( len ) and len >= 0
15951660 or
@@ -1815,19 +1880,26 @@ module Expressions {
18151880 ) {
18161881 attributePointsTo ( expr , context , value , origin , subexpr , subvalue )
18171882 or
1818- subscriptPointsTo ( expr , context , value , origin , subexpr , subvalue )
1883+ subscriptPointsTo ( expr , context , value , subexpr , subvalue ) and
1884+ origin = expr
18191885 or
1820- addPointsTo ( expr , context , value , origin , subexpr , subvalue )
1886+ addPointsTo ( expr , context , value , subexpr , subvalue ) and
1887+ origin = expr
18211888 or
1822- bitOrPointsTo ( expr , context , value , origin , subexpr , subvalue )
1889+ bitOrPointsTo ( expr , context , value , subexpr , subvalue ) and
1890+ origin = expr
18231891 or
1824- binaryPointsTo ( expr , context , value , origin , subexpr , subvalue )
1892+ binaryPointsTo ( expr , context , value , subexpr , subvalue ) and
1893+ origin = expr
18251894 or
1826- unaryPointsTo ( expr , context , value , origin , subexpr , subvalue )
1895+ unaryPointsTo ( expr , context , value , subexpr , subvalue ) and
1896+ origin = expr
18271897 or
1828- builtinCallPointsTo ( expr , context , value , origin , subexpr , subvalue )
1898+ builtinCallPointsTo ( expr , context , value , subexpr , subvalue ) and
1899+ origin = expr
18291900 or
1830- lenCallPointsTo ( expr , context , value , origin , subexpr , subvalue )
1901+ lenCallPointsTo ( expr , context , value , subexpr , subvalue ) and
1902+ origin = expr
18311903 or
18321904 typeCallPointsTo ( expr , context , value , origin , subexpr , subvalue )
18331905 or
@@ -2068,6 +2140,12 @@ module Conditionals {
20682140 }
20692141}
20702142
2143+ /** INTERNAL: Do not use. */
2144+ predicate declaredAttributeVar ( PythonClassObjectInternal cls , string name , EssaVariable var ) {
2145+ name = var .getName ( ) and
2146+ var .getAUse ( ) = cls .getScope ( ) .getANormalExit ( )
2147+ }
2148+
20712149cached
20722150module Types {
20732151 cached
@@ -2163,8 +2241,7 @@ module Types {
21632241 or
21642242 value != ObjectInternal:: undefined ( ) and
21652243 exists ( EssaVariable var |
2166- name = var .getName ( ) and
2167- var .getAUse ( ) = cls .( PythonClassObjectInternal ) .getScope ( ) .getANormalExit ( ) and
2244+ declaredAttributeVar ( cls , name , var ) and
21682245 PointsToInternal:: variablePointsTo ( var , _, value , origin )
21692246 )
21702247 }
0 commit comments