forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.py
More file actions
59 lines (36 loc) · 777 Bytes
/
examples.py
File metadata and controls
59 lines (36 loc) · 777 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from python.ql.test.experimental.dataflow.testDefinitions import *
# Preamble
class MyObj(object):
def __init__(self, foo):
self.foo = foo
class NestedObj(object):
def __init__(self):
self.obj = MyObj("OK")
def getObj(self):
return self.obj
# Example 1
def setFoo(obj, x):
SINK_F(obj.foo)
obj.foo = x
myobj = MyObj("OK")
setFoo(myobj, SOURCE)
SINK(myobj.foo)
# Example 2
x = SOURCE
a = NestedObj()
a.obj.foo = x
SINK(a.obj.foo)
# Example 2 with method call
x = SOURCE
a = NestedObj()
a.getObj().foo = x
SINK(a.obj.foo) # Flow missing
# Example 3
obj = MyObj(SOURCE)
SINK(obj.foo)
# Local flow
def fields_with_local_flow(x):
obj = MyObj(x)
a = obj.foo
return a
SINK(fields_with_local_flow(SOURCE))