-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchecker8.py
executable file
·129 lines (87 loc) · 3.93 KB
/
checker8.py
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
#!/usr/bin/python3
'''SOSP23-Paper21: '''
'''Checker8: F_start --> S_P(p0) --> S_D(p0) --> F_end'''
import os
import configparser
import json
from utils import *
g_record_file = 'checker8.log'
def checker8(func_str, apis, file_name, g_logger):
ast_f = build_ast_from_str(func_str)
if ast_f=='': return
bug_lines = []
for api in apis:
api = api.strip()
for n in ast_f.node_set.keys():
cur_node = ast_f.node_set[n]
src = cur_node.dot_src
if cur_node.type == AST_NODE_TYPE_REAL_METHOD:
if src.find(api)!=-1:
pointer = src.split(',')[1].split(')')[0].split('(')[1]
if pointer.find('->')!=-1:
continue
has_return = 0
for nb in cur_node.parent[0].nb:
#print(nb.dot_src)
if nb.line>cur_node.line:
if nb.dot_src.find('return')!=-1:
#print('Find Return!!!!')
has_return = 1
break
if has_return == 1:
continue
#print(file_name)
#print('Find: %s'%(src))
#print('Pointer: %s'%(pointer))
root_node = cur_node
while root_node.type!=AST_NODE_TYPE_METHOD:
root_node = root_node.parent[0]
node_set = [root_node]
goto_nodes = []
while len(node_set)!=0:
t = node_set.pop()
for nb in t.nb:
node_set.append(nb)
if t.line>cur_node.line and (not (t.line in bug_lines)):
if t.dot_src.find('%s->'%(pointer))!=-1:
print('%s %s %s'%('+'*10, file_name, '+'*10))
g_logger.write('%s %s %s\n'%('+'*10, file_name, '+'*10))
print('Find Bug: %s'%(t.dot_src))
g_logger.write('Find Bug: %s\n'%(t.dot_src))
g_logger.flush()
bug_lines.append(t.line)
def run_checker():
g_logger = open(g_record_file, 'w')
config = configparser.ConfigParser()
config.read('checkers.ini', encoding='utf-8')
#secs = config.sections()
#print(secs)
apis = ''
ast_kernel_functions_file = config.get('global', 'ast_kernel_functions')
if config.has_section('future_put'):
#print('yes')
apis = config.get('future_put', 'apis')[1:-1].split(',')
else:
print('no section *future_put* for checker8')
return -1
i = 0
with open(ast_kernel_functions_file) as f:
while True:
l = f.readline()
if l=='': break
l = l.strip()
if l=='': continue
dot_file = l.split(' ')[0].split(':')[1]
#dot_file = '/data1/linux-ast/0/+data1+struck-linux+arch+powerpc+platforms+powernv+opal.c+outdir/45-ast.dot'
#print('Process --- %s'%dot_file)
with open(dot_file) as df:
file_str = df.read()
checker8(file_str, apis, l, g_logger)
#break
i+=1
if i%10000==0:
print(i)
#if i>50000: break
g_logger.close()
if __name__ == '__main__':
run_checker()