@@ -1429,20 +1429,51 @@ module Expressions {
1429
1429
}
1430
1430
1431
1431
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 (
1433
1456
SubscriptNode subscr , PointsToContext context , ObjectInternal value , ControlFlowNode origin ,
1434
1457
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
1435
1467
) {
1436
1468
exists ( ControlFlowNode index | subscriptObjectAndIndex ( subscr , context , obj , objvalue , index ) |
1437
1469
objvalue .subscriptUnknown ( ) and
1438
1470
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
+ )
1446
1477
}
1447
1478
1448
1479
predicate subscriptPartsPointsTo (
@@ -1466,15 +1497,22 @@ module Expressions {
1466
1497
index = subscr .getIndex ( )
1467
1498
}
1468
1499
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
+
1469
1508
/**
1470
1509
* Tracking too many binary expressions is likely to kill performance, so just say anything other than addition or bitwise or is 'unknown'.
1471
1510
*/
1472
1511
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
1476
1515
) {
1477
- origin = b and
1478
1516
operand = genericBinaryOperand ( b ) and
1479
1517
PointsToInternal:: pointsTo ( operand , context , opvalue , _) and
1480
1518
value = ObjectInternal:: unknown ( )
@@ -1491,12 +1529,19 @@ module Expressions {
1491
1529
)
1492
1530
}
1493
1531
1494
- pragma [ noinline]
1495
- predicate addPointsTo (
1532
+ deprecated predicate addPointsTo (
1496
1533
BinaryExprNode b , PointsToContext context , ObjectInternal value , ControlFlowNode origin ,
1497
1534
ControlFlowNode operand , ObjectInternal opvalue
1498
1535
) {
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
+ ) {
1500
1545
exists ( Operator op |
1501
1546
b .operands ( operand , op , _)
1502
1547
or
@@ -1508,12 +1553,19 @@ module Expressions {
1508
1553
)
1509
1554
}
1510
1555
1511
- pragma [ noinline]
1512
- predicate bitOrPointsTo (
1556
+ deprecated predicate bitOrPointsTo (
1513
1557
BinaryExprNode b , PointsToContext context , ObjectInternal value , ControlFlowNode origin ,
1514
1558
ControlFlowNode operand , ObjectInternal opvalue
1515
1559
) {
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
+ ) {
1517
1569
exists ( Operator op , ControlFlowNode other |
1518
1570
b .operands ( operand , op , other )
1519
1571
or
@@ -1533,10 +1585,18 @@ module Expressions {
1533
1585
value = obj .intValue ( )
1534
1586
}
1535
1587
1536
- pragma [ noinline]
1537
- predicate unaryPointsTo (
1588
+ deprecated predicate unaryPointsTo (
1538
1589
UnaryExprNode u , PointsToContext context , ObjectInternal value , ControlFlowNode origin ,
1539
1590
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
1540
1600
) {
1541
1601
exists ( Unaryop op |
1542
1602
op = u .getNode ( ) .getOp ( ) and
@@ -1548,14 +1608,21 @@ module Expressions {
1548
1608
op instanceof USub and value = ObjectInternal:: fromInt ( - opvalue .intValue ( ) )
1549
1609
or
1550
1610
not op instanceof Not and opvalue = ObjectInternal:: unknown ( ) and value = opvalue
1551
- ) and
1552
- origin = u
1611
+ )
1553
1612
}
1554
1613
1555
- pragma [ noinline]
1556
- predicate builtinCallPointsTo (
1614
+ deprecated predicate builtinCallPointsTo (
1557
1615
CallNode call , PointsToContext context , ObjectInternal value , ControlFlowNode origin ,
1558
1616
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
1559
1626
) {
1560
1627
PointsToInternal:: pointsTo ( arg , context , argvalue , _) and
1561
1628
arg = call .getArg ( 0 ) and
@@ -1569,8 +1636,7 @@ module Expressions {
1569
1636
callable != ObjectInternal:: builtin ( "hasattr" ) and
1570
1637
callable .isClass ( ) = false and
1571
1638
value = ObjectInternal:: unknown ( )
1572
- ) and
1573
- origin = call
1639
+ )
1574
1640
}
1575
1641
1576
1642
pragma [ noinline]
@@ -1585,11 +1651,10 @@ module Expressions {
1585
1651
1586
1652
pragma [ noinline]
1587
1653
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
1590
1656
) {
1591
1657
len_call ( call , arg , context , argvalue ) and
1592
- origin = call and
1593
1658
exists ( int len | len = argvalue .length ( ) |
1594
1659
value = TInt ( len ) and len >= 0
1595
1660
or
@@ -1815,19 +1880,26 @@ module Expressions {
1815
1880
) {
1816
1881
attributePointsTo ( expr , context , value , origin , subexpr , subvalue )
1817
1882
or
1818
- subscriptPointsTo ( expr , context , value , origin , subexpr , subvalue )
1883
+ subscriptPointsTo ( expr , context , value , subexpr , subvalue ) and
1884
+ origin = expr
1819
1885
or
1820
- addPointsTo ( expr , context , value , origin , subexpr , subvalue )
1886
+ addPointsTo ( expr , context , value , subexpr , subvalue ) and
1887
+ origin = expr
1821
1888
or
1822
- bitOrPointsTo ( expr , context , value , origin , subexpr , subvalue )
1889
+ bitOrPointsTo ( expr , context , value , subexpr , subvalue ) and
1890
+ origin = expr
1823
1891
or
1824
- binaryPointsTo ( expr , context , value , origin , subexpr , subvalue )
1892
+ binaryPointsTo ( expr , context , value , subexpr , subvalue ) and
1893
+ origin = expr
1825
1894
or
1826
- unaryPointsTo ( expr , context , value , origin , subexpr , subvalue )
1895
+ unaryPointsTo ( expr , context , value , subexpr , subvalue ) and
1896
+ origin = expr
1827
1897
or
1828
- builtinCallPointsTo ( expr , context , value , origin , subexpr , subvalue )
1898
+ builtinCallPointsTo ( expr , context , value , subexpr , subvalue ) and
1899
+ origin = expr
1829
1900
or
1830
- lenCallPointsTo ( expr , context , value , origin , subexpr , subvalue )
1901
+ lenCallPointsTo ( expr , context , value , subexpr , subvalue ) and
1902
+ origin = expr
1831
1903
or
1832
1904
typeCallPointsTo ( expr , context , value , origin , subexpr , subvalue )
1833
1905
or
@@ -2068,6 +2140,12 @@ module Conditionals {
2068
2140
}
2069
2141
}
2070
2142
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
+
2071
2149
cached
2072
2150
module Types {
2073
2151
cached
@@ -2163,8 +2241,7 @@ module Types {
2163
2241
or
2164
2242
value != ObjectInternal:: undefined ( ) and
2165
2243
exists ( EssaVariable var |
2166
- name = var .getName ( ) and
2167
- var .getAUse ( ) = cls .( PythonClassObjectInternal ) .getScope ( ) .getANormalExit ( ) and
2244
+ declaredAttributeVar ( cls , name , var ) and
2168
2245
PointsToInternal:: variablePointsTo ( var , _, value , origin )
2169
2246
)
2170
2247
}
0 commit comments