Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 73b33ed

Browse files
committed
fix for a bug reported by Ulisses Castro (Too many open files) - also, added an important caching mechanism with thread safe logic
1 parent 720e235 commit 73b33ed

4 files changed

Lines changed: 19 additions & 5 deletions

File tree

doc/THANKS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ Velky Brat <[email protected]>
2727
Jack Butler <[email protected]>
2828
for providing me with the sqlmap site favicon
2929

30+
Ulisses Castro <[email protected]>
31+
for reporting a bug
32+
3033
Roberto Castrogiovanni <[email protected]>
3134
for reporting a minor bug
3235

lib/core/common.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,13 +1239,20 @@ def getConsoleWidth(default=80):
12391239
return width if width else default
12401240

12411241
def parseXmlFile(xmlFile, handler):
1242-
checkFile(xmlFile)
1243-
xfile = codecs.open(xmlFile, 'rb', conf.dataEncoding)
1244-
content = xfile.read()
1245-
stream = StringIO(content)
1242+
if xmlFile not in kb.cache.content:
1243+
if conf.parseLock:
1244+
conf.parseLock.acquire()
1245+
if xmlFile not in kb.cache.content:
1246+
checkFile(xmlFile)
1247+
xfile = codecs.open(xmlFile, 'rb', conf.dataEncoding)
1248+
content = xfile.read()
1249+
kb.cache.content[xmlFile] = content
1250+
xfile.close()
1251+
if conf.parseLock:
1252+
conf.parseLock.release()
1253+
stream = StringIO(kb.cache.content[xmlFile])
12461254
parse(stream, handler)
12471255
stream.close()
1248-
xfile.close()
12491256

12501257
def readXmlFile(xmlFile):
12511258
checkFile(xmlFile)

lib/core/option.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,7 @@ def __setConfAttributes():
993993
conf.outputPath = None
994994
conf.paramDict = {}
995995
conf.parameters = {}
996+
conf.parseLock = None
996997
conf.path = None
997998
conf.port = None
998999
conf.redirectHandled = False
@@ -1022,6 +1023,7 @@ def __setKnowledgeBaseAttributes():
10221023
kb.bannerFp = advancedDict()
10231024

10241025
kb.cache = advancedDict()
1026+
kb.cache.content = {}
10251027
kb.cache.regex = {}
10261028

10271029
kb.commonOutputs = None

lib/techniques/blind/inference.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ def etaProgressUpdate(charTime, index):
252252
iolock = threading.Lock()
253253
valuelock = threading.Lock()
254254
conf.seqLock = threading.Lock()
255+
conf.parseLock = threading.Lock()
255256
conf.threadContinue = True
256257

257258
def downloadThread():
@@ -416,6 +417,7 @@ def downloadThread():
416417
dataToStdout(infoMsg)
417418

418419
conf.seqLock = None
420+
conf.parseLock = None
419421

420422
# No multi-threading (--threads = 1)
421423
else:

0 commit comments

Comments
 (0)