-
Notifications
You must be signed in to change notification settings - Fork 243
/
inject-error
executable file
·60 lines (50 loc) · 1.55 KB
/
inject-error
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
#!/usr/bin/python3
import random
import re
import subprocess
import sys
found = {}
def do_new_cookie() -> str:
global found
cookie = hex(random.randrange(1, 2**32))
while cookie in found:
cookie = hex(random.randrange(1, 2**32))
return cookie
pipe = subprocess.Popen("git grep -n 'inject_error(0x'", shell=True,
stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True);
ch_stdout = pipe.stdout
ch_lines = [str(x.decode()).strip('\n') for x in ch_stdout.readlines()]
#print("STDOUT", "\n".join(ch_lines))
for l in ch_lines:
m = re.search(r'^([^:]+):(\d+):.*inject_error\((0x[0-9a-fA-F]+)\)', l)
if m:
fn = m.group(1)
line = m.group(2)
c = m.group(3)
#print(f"MATCH: {c}")
if not c in found:
found[c] = fn + ":" + line
else:
print(f"ERROR: cookie {c} in {fn}:{line} not unique, please fix it first")
if len(sys.argv) == 1:
cookie = do_new_cookie()
print(cookie)
if len(sys.argv) == 2:
cmd = sys.argv[1]
if cmd == 'new':
cookie = do_new_cookie()
print(cookie)
elif cmd == 'known':
for k, v in found.items():
print(f"{k}\t{v}")
else:
print(f"ERROR: unknown command {cmd} or wrong number of arguments")
if len(sys.argv) == 3:
cmd = sys.argv[1]
if cmd == 'file':
regex = sys.argv[2]
for k, v in found.items():
if re.search(r'' + regex, v):
print(f"{k}\t{v}")
else:
print(f"ERROR: unknown command {cmd} or wrong number of arguments")