Minor stability patch for multi-threading console output (#3284)

This commit is contained in:
Miroslav Stampar
2019-01-22 13:45:16 +01:00
parent ae6235ce20
commit ba356baab0
7 changed files with 23 additions and 15 deletions

View File

@@ -913,7 +913,8 @@ def dataToStdout(data, forceOutput=False, bold=False, content_type=None, status=
if not kb.get("threadException"):
if forceOutput or not (getCurrentThreadData().disableStdOut or kb.get("wizardMode")):
if kb.get("multiThreadMode"):
multiThreadMode = isMultiThreadMode()
if multiThreadMode:
logging._acquireLock()
if isinstance(data, unicode):
@@ -931,7 +932,7 @@ def dataToStdout(data, forceOutput=False, bold=False, content_type=None, status=
except IOError:
pass
if kb.get("multiThreadMode"):
if multiThreadMode:
logging._releaseLock()
kb.prependFlag = isinstance(data, basestring) and (len(data) == 1 and data not in ('\n', '\r') or len(data) > 2 and data[0] == '\r' and data[-1] != '\n')
@@ -1982,6 +1983,13 @@ def isHexEncodedString(subject):
return re.match(r"\A[0-9a-fA-Fx]+\Z", subject) is not None
def isMultiThreadMode():
"""
Checks if running in multi-thread(ing) mode
"""
return threading.activeCount() > 1
@cachedmethod
def getConsoleWidth(default=80):
"""

View File

@@ -20,6 +20,7 @@ from lib.core.common import dataToStdout
from lib.core.common import getSafeExString
from lib.core.common import getUnicode
from lib.core.common import isListLike
from lib.core.common import isMultiThreadMode
from lib.core.common import normalizeUnicode
from lib.core.common import openFile
from lib.core.common import prioritySortColumns
@@ -74,7 +75,8 @@ class Dump(object):
if console:
dataToStdout(text)
if kb.get("multiThreadMode"):
multiThreadMode = isMultiThreadMode()
if multiThreadMode:
self._lock.acquire()
try:
@@ -83,7 +85,7 @@ class Dump(object):
errMsg = "error occurred while writing to log file ('%s')" % getSafeExString(ex)
raise SqlmapGenericException(errMsg)
if kb.get("multiThreadMode"):
if multiThreadMode:
self._lock.release()
kb.dataOutputFlag = True

View File

@@ -1829,7 +1829,6 @@ def _setKnowledgeBaseAttributes(flushAll=True):
kb.matchRatio = None
kb.maxConnectionsFlag = False
kb.mergeCookies = None
kb.multiThreadMode = False
kb.negativeLogic = False
kb.nullConnection = None
kb.oldMsf = None

View File

@@ -19,7 +19,7 @@ from lib.core.enums import DBMS_DIRECTORY_NAME
from lib.core.enums import OS
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
VERSION = "1.3.1.70"
VERSION = "1.3.1.71"
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

View File

@@ -110,7 +110,6 @@ def setDaemon(thread):
def runThreads(numThreads, threadFunction, cleanupFunction=None, forwardException=True, threadChoice=False, startThreadMsg=True):
threads = []
kb.multiThreadMode = True
kb.threadContinue = True
kb.threadException = False
@@ -204,7 +203,6 @@ def runThreads(numThreads, threadFunction, cleanupFunction=None, forwardExceptio
traceback.print_exc()
finally:
kb.multiThreadMode = False
kb.bruteMode = False
kb.threadContinue = True
kb.threadException = False