-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsecure_tool.py
More file actions
55 lines (38 loc) · 1.15 KB
/
secure_tool.py
File metadata and controls
55 lines (38 loc) · 1.15 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
# Tool to give corrections for weak coding.
# FIRST OPEN C FILE AND FIND BAD PRINTS
import sys
from enum import Enum
types = ['int', 'char', 'void', 'short', 'long']
class error_type(Enum):
NOERROR = 0
PRINT = 1
STACK = 2
HEAP = 3
INTEGER = 4
DANGLING = 5
def print_correct(line):
if ('printf(' in line) and ('printf("' not in line) and ("printf('" not in line):
return error_type.PRINT
else:
return error_type.NOERROR
def check_function(function):
variables = []
for line in function:
if 'strcpy' in line:
return error_type.STACK
def read_file(file):
# print("ATTEMPTING TO FIND PRINT ERRORS.")
functions = {'name': '', 'begin': 0, 'length': 0, 'lines': []}
with open(file) as source:
for line in source:
print(line)
if ('printf(' in line) and ('printf("' not in line) and ("printf('" not in line):
print("ERROR")
def main():
print ('argument list', sys.argv)
file = sys.argv[1]
print ("Now checking file {}".format(file))
error_array_dict = []
print_correct(file)
if __name__ == "__main__":
main()