This commit is contained in:
Miroslav Štampar
2026-09-18 00:53:16 +02:00
parent bda62dcf28
commit 7eb06ce635
3 changed files with 46 additions and 2 deletions
+1 -1
View File
@@ -997,7 +997,7 @@ def setColor(message, color=None, bold=False, level=None, istty=None):
if bold or color:
retVal = colored(message, color=color, on_color=None, attrs=("bold",) if bold else None)
elif level:
elif level and hasattr(LOGGER_HANDLER, "colorize"):
try:
level = getattr(logging, level, None)
except:
+1 -1
View File
@@ -20,7 +20,7 @@ from lib.core.enums import OS
from thirdparty import six
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
VERSION = "1.10.9.13"
VERSION = "1.10.9.14"
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)
+44
View File
@@ -113,6 +113,7 @@ from lib.core.common import (
safeSQLIdentificatorNaming,
saveConfig,
serializeObject,
setColor,
setTechnique,
splitFields,
trimAlphaNum,
@@ -1784,6 +1785,49 @@ class TestCheckOldOptions(unittest.TestCase):
self.assertIsNone(checkOldOptions(["-u", "http://test.invalid/?id=1", "--banner"]))
class TestSetColorHandlerMismatch(unittest.TestCase):
"""
Regression test for issue #6122: setColor() decided whether to colorize purely from
conf.disableColoring/IS_TTY, independent of whether the installed LOGGER_HANDLER actually
supports colorize() (a plain logging.StreamHandler - installed for --disable-coloring, or as
the ansistrm-unavailable fallback - never defines it). A multiprocessing hash-cracking worker
hit exactly this mismatch (conf.disableColoring not carried over into the worker) and crashed
with an AttributeError that got misreported as "there was a problem while hashing entry".
"""
def setUp(self):
import lib.core.common as common_mod
self._common_mod = common_mod
self._saved_handler = common_mod.LOGGER_HANDLER
self._saved_disableColoring = conf.get("disableColoring")
def tearDown(self):
self._common_mod.LOGGER_HANDLER = self._saved_handler
conf.disableColoring = self._saved_disableColoring
def test_plain_handler_without_colorize_does_not_raise(self):
import logging
self._common_mod.LOGGER_HANDLER = logging.StreamHandler() # no .colorize(), like the --disable-coloring handler
conf.disableColoring = False # the desync: coloring "should" apply, but handler can't
result = setColor("[INFO] current status: abcde", istty=True) # must not raise
self.assertIsInstance(result, str)
def test_colorizing_handler_still_used(self):
# sanity check: a handler that DOES define colorize() is unaffected by the guard
calls = []
class _FakeColorizingHandler(object):
def colorize(self, message, levelno, force=False):
calls.append((message, levelno, force))
return "COLORIZED"
self._common_mod.LOGGER_HANDLER = _FakeColorizingHandler()
conf.disableColoring = False
result = setColor("[INFO] current status: abcde", istty=True)
self.assertEqual(result, "COLORIZED")
self.assertEqual(len(calls), 1)
if __name__ == "__main__":
unittest.main(verbosity=2)