Skip to content

Commit 2416cac

Browse files
committed
Python: Modernise StringKind files
1 parent 3ae1aad commit 2416cac

File tree

3 files changed

+15
-19
lines changed

3 files changed

+15
-19
lines changed

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ private predicate str_format(ControlFlowNode fromnode, CallNode tonode) {
7474
(
7575
tonode.getAnArg() = fromnode
7676
or
77+
// TODO: if this case is not covered by tonode.getAnArg(), we should change it so it is :\
7778
tonode.getNode().getAKeyword().getValue() = fromnode.getNode()
7879
)
7980
}
@@ -93,10 +94,13 @@ private predicate encode_decode(ControlFlowNode fromnode, CallNode tonode) {
9394
/* tonode = str(fromnode)*/
9495
private predicate to_str(ControlFlowNode fromnode, CallNode tonode) {
9596
tonode.getAnArg() = fromnode and
96-
exists(ClassObject str |
97-
tonode.getFunction().refersTo(str) |
98-
str = theUnicodeType() or str = theBytesType()
99-
)
97+
tonode = ClassValue::str().getACall()
98+
// TODO: should it instead be this?
99+
// (
100+
// tonode = ClassValue::bytes().getACall()
101+
// or
102+
// tonode = ClassValue::unicode().getACall()
103+
// )
100104
}
101105

102106
/* tonode = fromnode[:] */
@@ -110,11 +114,8 @@ private predicate slice(ControlFlowNode fromnode, SubscriptNode tonode) {
110114

111115
/* tonode = os.path.join(..., fromnode, ...) */
112116
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-
)
117+
tonode = Value::named("os.path.join").getACall()
118+
and tonode.getAnArg() = fromnode
118119
}
119120

120121
/** A kind of "taint", representing a dictionary mapping str->"taint" */
@@ -125,5 +126,3 @@ class StringDictKind extends DictKind {
125126
}
126127

127128
}
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)