-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathUndefinedGlobal.py
More file actions
176 lines (136 loc) · 3 KB
/
UndefinedGlobal.py
File metadata and controls
176 lines (136 loc) · 3 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
from ud_helper import d
import ud_helper as helper
from ud_helper import *
try:
import __builtin__ as B
except:
import builtins as B
defined = 2
#Monkey patch some builtins
B.__dict__["monkey1"] = 1
setattr(B, "monkey2", 2)
B.monkey3 = 3
def f(parameter):
parameter
local = 3
local
d # Explicitly from ud_helper
helper # Explicitly as import
a # Imlicitly from ud_helper
defined
ug2 # ERROR
e # ERROR Defined in ud_helper, but not in __all__
int
float
__file__ #OK all files have __file__ defined
__path__ #ERROR only modules have __path__ defined
len #Ok defined in builtins
monkey1 #Ok monkey-patched builtins
monkey2 #Ok monkey-patched builtins
monkey3 #Ok monkey-patched builtins
import sys
if __name__ == '__main__':
if len(sys.argv) == 1:
print('usage')
sys.exit(0)
elif ('-s' in sys.argv):
server = sys.argv[2]
else:
server = '127.0.0.1'
server
#Check that builtins are always defined even if conditionally shadowed.
bool
if d:
bool = int
bool
def t2():
return bool
def f():
global local_global
local_global = 1
local_global
#ODASA-2021
from elsewhere import gflags, a_function
def usage_and_quit():
print("Usage: unusable")
sys.exit(1)
def main():
global from_hdb
try:
# Because of from_hdb, get_mp_hashes.py has a lot of extra unique flags
gflags.DEFINE_bool("from_hdb", False, "")
from_hdb = gflags.FLAGS.from_hdb
except Exception as ex:
usage_and_quit(str(ex))
if not from_hdb:
a_function()
#ODASA-2432
def globals_guard():
if 'varname' in globals():
f(varname)
#Example taken from logging module
try:
import module1
import module2
except ImportError:
module1 = None
if module1:
inst = module2.Class()
#Some possible false positives, observed in ERP5.
if 1:
pfp1 = 1
pfp1
def outer():
global pfp2
pfp2 = 2
def inner():
global pfp2
pfp2 += 1
class Cls(object):
global pfp3
pfp3 = 3
def inner():
global pfp3
pfp3 += 1
def only_report_once():
ug3
ug3
ug3
ug3
#ODASA-5381
from _ast import *
try:
NameConstant
except NameError:
NameConstant = Name
#ODASA-5486
class modinit:
global _time
import time
_time = time
try:
import datetime
_pydatetime = datetime.datetime
except ImportError:
# Set them to (), so that isinstance() works with them
_pydatetime = ()
del modinit
# FP occurs in line below
def _isstring(arg, isinstance=isinstance, t=_time):
pass
#ODASA-4688
def outer():
def inner():
global glob
glob = 'asdf'
print(glob[2])
def otherInner():
print(glob[3])
inner()
#ODASA-5896
guesses_made = 0
while guesses_made < 6: # This loop is guaranteed to execute at least once.
guess = int(input('Take a guess: '))
guesses_made += 1
if guess == 1017: # FP here
pass