Skip to content

Commit 0999970

Browse files
authored
Merge pull request github#3005 from RasmusWL/python-modernise-string-taint
Python: Modernise StringKind files
2 parents 917b984 + e52fec0 commit 0999970

File tree

3 files changed

+12
-23
lines changed

3 files changed

+12
-23
lines changed

python/ql/src/semmle/python/security/strings/Basic.qll

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,7 @@ private predicate str_method_call(ControlFlowNode fromnode, CallNode tonode) {
7171
/* tonode = ....format(fromnode) */
7272
private predicate str_format(ControlFlowNode fromnode, CallNode tonode) {
7373
tonode.getFunction().(AttrNode).getName() = "format" and
74-
(
75-
tonode.getAnArg() = fromnode
76-
or
77-
tonode.getNode().getAKeyword().getValue() = fromnode.getNode()
78-
)
74+
tonode.getAnArg() = fromnode
7975
}
8076

8177
/* tonode = codec.[en|de]code(fromnode)*/
@@ -93,9 +89,10 @@ private predicate encode_decode(ControlFlowNode fromnode, CallNode tonode) {
9389
/* tonode = str(fromnode)*/
9490
private predicate to_str(ControlFlowNode fromnode, CallNode tonode) {
9591
tonode.getAnArg() = fromnode and
96-
exists(ClassObject str |
97-
tonode.getFunction().refersTo(str) |
98-
str = theUnicodeType() or str = theBytesType()
92+
(
93+
tonode = ClassValue::bytes().getACall()
94+
or
95+
tonode = ClassValue::unicode().getACall()
9996
)
10097
}
10198

@@ -110,11 +107,8 @@ private predicate slice(ControlFlowNode fromnode, SubscriptNode tonode) {
110107

111108
/* tonode = os.path.join(..., fromnode, ...) */
112109
private predicate os_path_join(ControlFlowNode fromnode, CallNode tonode) {
113-
exists(FunctionObject path_join |
114-
path_join = ModuleObject::named("os").attr("path").(ModuleObject).attr("join")
115-
and
116-
tonode = path_join.getACall() and tonode.getAnArg() = fromnode
117-
)
110+
tonode = Value::named("os.path.join").getACall()
111+
and tonode.getAnArg() = fromnode
118112
}
119113

120114
/** A kind of "taint", representing a dictionary mapping str->"taint" */
@@ -125,5 +119,3 @@ class StringDictKind extends DictKind {
125119
}
126120

127121
}
128-
129-

python/ql/src/semmle/python/security/strings/Common.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import python
55
predicate copy_call(ControlFlowNode fromnode, CallNode tonode) {
66
tonode.getFunction().(AttrNode).getObject("copy") = fromnode
77
or
8-
exists(ModuleObject copy, string name |
8+
exists(ModuleValue copy, string name |
99
name = "copy" or name = "deepcopy" |
10-
copy.attr(name).(FunctionObject).getACall() = tonode and
10+
copy.attr(name).(FunctionValue).getACall() = tonode and
1111
tonode.getArg(0) = fromnode
1212
)
1313
or
14-
tonode.getFunction().refersTo(Object::builtin("reversed")) and
14+
tonode.getFunction().pointsTo(Value::named("reversed")) and
1515
tonode.getArg(0) = fromnode
1616
}

python/ql/src/semmle/python/security/strings/External.qll

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,8 @@ private predicate json_subscript_taint(
139139
}
140140

141141
private predicate json_load(ControlFlowNode fromnode, CallNode tonode) {
142-
exists(FunctionObject json_loads |
143-
ModuleObject::named("json").attr("loads") = json_loads and
144-
json_loads.getACall() = tonode and
145-
tonode.getArg(0) = fromnode
146-
)
142+
tonode = Value::named("json.loads").getACall() and
143+
tonode.getArg(0) = fromnode
147144
}
148145

149146
private predicate urlsplit(ControlFlowNode fromnode, CallNode tonode) {

0 commit comments

Comments
 (0)