Skip to content

Commit

Permalink
V.11.4 [FIX] Securing file opening to prevent from crashes due to non…
Browse files Browse the repository at this point in the history
…-utf8 characters in files
  • Loading branch information
Just1truc committed Apr 28, 2022
1 parent 9f31786 commit 77979e5
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions brico.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self):
self.checked = True

def run(self, Norm_obj, files):
buffer = open(files, "r")
buffer = open(files, "r", encoding="utf8", errors='ignore')
line = 0
for lines in buffer:
line += 1
Expand All @@ -57,7 +57,7 @@ def __init__(self):

def run(self, Norm_obj, files):
if files.endswith(".h"):
inside = open(files, "r")
inside = open(files, "r", encoding="utf8", errors='ignore')
begin = 0
line = 0
for lines in inside:
Expand All @@ -78,7 +78,7 @@ def run(self, Norm_obj, files):
if "#define" in lines and id < len(lines.split(" ")) and not(lines.split(" ")[id].split("(")[0].isupper()):
Norm_obj.major.append(("V1", "Macros should be in Uppercases", line))
inside.close()
buffer = open(files, "r")
buffer = open(files, "r", encoding="utf8", errors='ignore')
inside = "".join(buffer.read().replace(" ", "").replace("\n", "[END]"))
get_splited = re.split("enum+.+{+.+}", inside)
if get_splited[0] == inside:
Expand All @@ -100,7 +100,7 @@ def __init__(self):
self.checked = False

def run(self, Norm_obj, files):
buffer = open(files, "r")
buffer = open(files, "r", encoding="utf8", errors='ignore')
inside = buffer.read().split("\n")
line = 0
in_function = False
Expand Down Expand Up @@ -141,7 +141,7 @@ def __init__(self):
self.checked = False

def run(self, Norm_obj, files):
inside = open(files, "r")
inside = open(files, "r", encoding="utf8", errors='ignore')
line = 0
for lines in inside:
line += 1
Expand All @@ -161,7 +161,7 @@ def __init__(self):
self.checked = True

def run(self, Norm_obj, files):
inside = open(files, "r")
inside = open(files, "r", encoding="utf8", errors='ignore')
line = 0
rest = ""
for lines in inside:
Expand All @@ -179,7 +179,7 @@ def __init__(self):
self.checked = True

def run(self, Norm_obj, files):
inside = open(files, "r")
inside = open(files, "r", encoding="utf8", errors='ignore')
line = 0
in_it = 0
for lines in inside:
Expand All @@ -198,7 +198,7 @@ def __init__(self):
self.checked = True

def run(self, Norm_obj, files):
inside = open(files, "r")
inside = open(files, "r", encoding="utf8", errors='ignore')
line = 0
two = 0
for lines in inside:
Expand All @@ -214,7 +214,7 @@ def __init__(self):

def run(self, Norm_obj, file_name):
if self.active == True:
inside = open(file_name, "r")
inside = open(file_name, "r", encoding="utf8", errors='ignore')
rest = ""
for lines in inside:
rest = lines
Expand All @@ -229,7 +229,7 @@ def __init__(self):

def run(self, Norm_obj, files):
if self.active == True:
inside = open(files, "r")
inside = open(files, "r", encoding="utf8", errors='ignore')
line = 0
in_it = 0
for lines in inside:
Expand Down Expand Up @@ -311,7 +311,7 @@ def __init__(self):

def run(self, Norm_obj, files):
if (files[-1] == 'c' and files[-2] == '.') and self.active == True:
inside = open(files, "r")
inside = open(files, "r", encoding="utf8", errors='ignore')
function_nbr = 0
for lines in inside:
if (lines.replace(" ", "").replace("\t", "").replace("\n", "") == "{" and lines[0] == '{'):
Expand All @@ -330,7 +330,7 @@ def __init__(self):

def run(self, Norm_obj, files):
if (files[-1] == 'h' and files[-2] == '.'):
buffer = open(files, "r")
buffer = open(files, "r", encoding="utf8", errors='ignore')
for lines in buffer:
if "#ifndef" in lines:
self.check_ifndef = 1
Expand Down Expand Up @@ -358,7 +358,7 @@ def run(self, Norm_obj, files):
spaces_lvl = 4
depth = 1
op_list = [ "for (", "for(", "if (", "if(", "while (", "while(", "do(", "do (" ]
inside = open(files, "r")
inside = open(files, "r", encoding="utf8", errors='ignore')
line = 0
for lines in inside:
line += 1
Expand Down Expand Up @@ -393,7 +393,7 @@ def __init__(self):

def run(self, Norm_obj, files):
if self.active == True and files.endswith(".c"):
inside = open(files, "r")
inside = open(files, "r", encoding="utf8", errors='ignore')
line = 0
counter = 0
last_char = 'p'
Expand Down Expand Up @@ -421,7 +421,7 @@ def __init__(self):

def run(self, Norm_obj, files):
if self.active == True:
inside = open(files, "r")
inside = open(files, "r", encoding="utf8", errors='ignore')
counter = 0
begin_line = 0
line = 0
Expand All @@ -445,7 +445,7 @@ def __init__(self):
self.checked = True

def check_c_files(self, Norm_obj, files):
inside = open(files, "r")
inside = open(files, "r", encoding="utf8", errors='ignore')
line = 0
prev_line = "02"
for lines in inside:
Expand All @@ -460,7 +460,7 @@ def check_c_files(self, Norm_obj, files):
inside.close()

def check_h_files(self, Norm_obj, files):
inside = open(files, "r")
inside = open(files, "r", encoding="utf8", errors='ignore')
line = 0
prev_line = "02"
for lines in inside:
Expand All @@ -484,7 +484,7 @@ def __init__(self):

def run(self, Norm_obj, files):
if self.active == True:
inside = open(files, "r")
inside = open(files, "r", encoding="utf8", errors='ignore')
test = 0
for lines in inside:
nbr = 0
Expand All @@ -506,7 +506,7 @@ def __init__(self):

def run(self, Norm_obj, files):
if self.active == True:
inside = open(files, "r")
inside = open(files, "r", encoding="utf8", errors='ignore')
line = 0
for lines in inside:
line += 1
Expand Down Expand Up @@ -544,7 +544,7 @@ def __init__(self):

def run(self, Norm_obj, files):
if ".c" in files and self.active == True:
inside = open(files, "r")
inside = open(files, "r", encoding="utf8", errors='ignore')
line = 0
for lines in inside:
ids = []
Expand All @@ -567,7 +567,7 @@ def __init__(self):
def run(self, Norm_obj, files):
start=0
line = 0
inside = open(files, "r")
inside = open(files, "r", encoding="utf8", errors='ignore')
if (".h" in files and files[-1] == 'h') and self.active == True:
for lines in inside:
line += 1
Expand All @@ -592,7 +592,7 @@ def __init__(self):
self.checked = True

def run(self, Norm_obj, files):
inside = open(files, "r")
inside = open(files, "r", encoding="utf8", errors='ignore')
trailling_lines = 0
line_nbr = 0
if (".c" in files or "Makefile" in files) and self.active == True:
Expand All @@ -606,7 +606,7 @@ def run(self, Norm_obj, files):
trailling_lines = 0
Norm_obj.minor.append(('G2', "There should be only one empty_line each time.", line_nbr))
inside.close()
inside = open(files, "r")
inside = open(files, "r", encoding="utf8", errors='ignore')
prev_line = "\n"
line = 0
if (".c" in files) and self.active == True:
Expand All @@ -627,7 +627,7 @@ def __init__(self):

def run(self, Norm_obj, files):
if self.active == True:
inside = open(files, "r")
inside = open(files, "r", encoding="utf8", errors='ignore')
line_nbr = 0
result = ""
mid_res = ""
Expand Down Expand Up @@ -701,7 +701,7 @@ def __init__(self):

def run(self, Norm_obj, files):
if self.active == True:
inside = open(files, "r")
inside = open(files, "r", encoding="utf8", errors='ignore')
line = 0
for lines in inside:
line += 1
Expand Down Expand Up @@ -775,7 +775,7 @@ def get_struct(self, direct, paths):
self.get_struct(os.listdir(test), test)
else:
if (test[-1] == 'h' and test[-2] == '.'):
inside = open(test, "r")
inside = open(test, "r", encoding="utf8", errors='ignore')
begin = 0
for lines in inside:
if "typedef" in lines:
Expand Down

0 comments on commit 77979e5

Please sign in to comment.