Skip to content

Commit ccfdf54

Browse files
committed
Fixed multiple potential file leak points
1 parent d214ea5 commit ccfdf54

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

searchsploit.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,12 @@ def scrapeRC():
8686
larray = len(files_array)
8787
for i in range(larray - 1, 0, -1):
8888
try:
89-
open(path_array[i] + "/" + files_array[i],
90-
"r", encoding="utf8").read()
89+
tempRead = open(os.path.abspath(path_array[i] + "/" + files_array[i]),
90+
"r", encoding="utf8")
91+
tempRead.read()
92+
tempRead.close()
9193
except:
94+
tempRead.close()
9295
files_array.pop(i)
9396
name_array.pop(i)
9497
path_array.pop(i)
@@ -301,10 +304,13 @@ def cpFromDb(path, id):
301304
path: absolute path of database\n
302305
id: the EDBID that is searched for in database
303306
"""
304-
db = open(path, "r", encoding="utf8").read().split('\n')
307+
dbFile = open(path, "r", encoding="utf8")
308+
db = dbFile.read().split('\n')
305309
for lines in db:
306310
if lines.split(",")[0] == str(id):
311+
dbFile.close()
307312
return lines.split(",")
313+
dbFile.close()
308314
return []
309315

310316

@@ -372,7 +378,8 @@ def searchdb(path="", terms=[], cols=[], lim=-1):
372378
tmpstr += " " + terms[i]
373379
terms.clear()
374380
terms.append(tmpstr)
375-
db = open(path, "r", encoding="utf8").read().split('\n')
381+
dbFile = open(path, "r", encoding="utf8")
382+
db = dbFile.read().split('\n')
376383
for lines in db:
377384
if (lines != ""):
378385
for term in terms:
@@ -396,6 +403,7 @@ def searchdb(path="", terms=[], cols=[], lim=-1):
396403
tmphold = []
397404
if(lim != -1 and len(searchTerms) >= lim):
398405
break
406+
dbFile.close()
399407
return searchTerms
400408

401409

@@ -482,7 +490,9 @@ def nmapxml(file=""):
482490

483491
# First check whether file exists or use stdin
484492
try:
485-
content = open(file, "r").read()
493+
contentFile = open(file, "r")
494+
content = contentFile.read()
495+
contentFile.close()
486496
except:
487497
if(not os.sys.stdin.isatty()):
488498
content = os.sys.stdin.read()
@@ -547,7 +557,9 @@ def nmapgrep(file=""):
547557

548558
# First check whether file exists or use stdin
549559
try:
550-
content = open(file, "r").read()
560+
contentFile = open(file, "r")
561+
content = contentFile.read()
562+
contentFile.close()
551563
except:
552564
if(not os.sys.stdin.isatty()):
553565
content = os.sys.stdin.read()
@@ -619,9 +631,11 @@ def mirror(id):
619631
absfile = path_array[ind]
620632

621633
currDir = os.getcwd()
622-
inp = open(absfile + "/" + exploit[1], "rb").read()
634+
inp = open(absfile + "/" + exploit[1], "rb")
623635
out = open(currDir + "/" + exploit[1].split("/")[-1], "wb")
624-
out.write(inp)
636+
out.write(inp.read())
637+
inp.close()
638+
out.close()
625639
return
626640

627641

0 commit comments

Comments
 (0)