Skip to content

Commit 42ae5f4

Browse files
committed
Python: support / from the right
Will also support both operands being paths
1 parent d361d99 commit 42ae5f4

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

python/ql/src/semmle/python/frameworks/Stdlib.qll

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,11 @@ private module Stdlib {
946946
slash.getOp() instanceof Div and
947947
right.asCfgNode() = slash.getRight() and
948948
left.asCfgNode() = slash.getLeft() and
949-
left.getALocalSource() = pathlibPath(t2) and
949+
(
950+
left.getALocalSource() = pathlibPath(t2)
951+
or
952+
right.getALocalSource() = pathlibPath(t2)
953+
) and
950954
t2.end()
951955
|
952956
t.start() and
@@ -1030,19 +1034,24 @@ private module Stdlib {
10301034
nodeTo.getALocalSource() = pathlibPath() and
10311035
(
10321036
// Special handling of the `/` operator
1033-
exists(BinaryExprNode slash, DataFlow::Node left |
1037+
exists(BinaryExprNode slash, DataFlow::Node path_operand, DataFlow::Node data_operand |
10341038
slash.getOp() instanceof Div and
1035-
left.asCfgNode() = slash.getLeft() and
1036-
left.getALocalSource() = pathlibPath()
1037-
|
1038-
nodeTo.asCfgNode() = slash and
10391039
(
1040-
// type-preserving call
1041-
nodeFrom = left
1040+
path_operand.asCfgNode() = slash.getLeft() and
1041+
data_operand.asCfgNode() = slash.getRight()
10421042
or
1043-
// data injection
1044-
nodeFrom.asCfgNode() = slash.getRight()
1045-
)
1043+
path_operand.asCfgNode() = slash.getRight() and
1044+
data_operand.asCfgNode() = slash.getLeft()
1045+
) and
1046+
path_operand.getALocalSource() = pathlibPath()
1047+
|
1048+
nodeTo.asCfgNode() = slash and
1049+
nodeFrom in [
1050+
// type-preserving call
1051+
path_operand,
1052+
// data injection
1053+
data_operand
1054+
]
10461055
)
10471056
or
10481057
// standard case

0 commit comments

Comments
 (0)