Skip to content

Commit 7eb06ce

Browse files
committed
Fixes #6122
1 parent bda62dc commit 7eb06ce

3 files changed

Lines changed: 46 additions & 2 deletions

File tree

lib/core/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ def setColor(message, color=None, bold=False, level=None, istty=None):
997997

998998
if bold or color:
999999
retVal = colored(message, color=color, on_color=None, attrs=("bold",) if bold else None)
1000-
elif level:
1000+
elif level and hasattr(LOGGER_HANDLER, "colorize"):
10011001
try:
10021002
level = getattr(logging, level, None)
10031003
except:

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from thirdparty import six
2121

2222
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
23-
VERSION = "1.10.9.13"
23+
VERSION = "1.10.9.14"
2424
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2525
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2626
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

tests/test_common.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
safeSQLIdentificatorNaming,
114114
saveConfig,
115115
serializeObject,
116+
setColor,
116117
setTechnique,
117118
splitFields,
118119
trimAlphaNum,
@@ -1784,6 +1785,49 @@ def test_no_old_options_is_noop(self):
17841785
self.assertIsNone(checkOldOptions(["-u", "http://test.invalid/?id=1", "--banner"]))
17851786

17861787

1788+
class TestSetColorHandlerMismatch(unittest.TestCase):
1789+
"""
1790+
Regression test for issue #6122: setColor() decided whether to colorize purely from
1791+
conf.disableColoring/IS_TTY, independent of whether the installed LOGGER_HANDLER actually
1792+
supports colorize() (a plain logging.StreamHandler - installed for --disable-coloring, or as
1793+
the ansistrm-unavailable fallback - never defines it). A multiprocessing hash-cracking worker
1794+
hit exactly this mismatch (conf.disableColoring not carried over into the worker) and crashed
1795+
with an AttributeError that got misreported as "there was a problem while hashing entry".
1796+
"""
1797+
1798+
def setUp(self):
1799+
import lib.core.common as common_mod
1800+
self._common_mod = common_mod
1801+
self._saved_handler = common_mod.LOGGER_HANDLER
1802+
self._saved_disableColoring = conf.get("disableColoring")
1803+
1804+
def tearDown(self):
1805+
self._common_mod.LOGGER_HANDLER = self._saved_handler
1806+
conf.disableColoring = self._saved_disableColoring
1807+
1808+
def test_plain_handler_without_colorize_does_not_raise(self):
1809+
import logging
1810+
self._common_mod.LOGGER_HANDLER = logging.StreamHandler() # no .colorize(), like the --disable-coloring handler
1811+
conf.disableColoring = False # the desync: coloring "should" apply, but handler can't
1812+
result = setColor("[INFO] current status: abcde", istty=True) # must not raise
1813+
self.assertIsInstance(result, str)
1814+
1815+
def test_colorizing_handler_still_used(self):
1816+
# sanity check: a handler that DOES define colorize() is unaffected by the guard
1817+
calls = []
1818+
1819+
class _FakeColorizingHandler(object):
1820+
def colorize(self, message, levelno, force=False):
1821+
calls.append((message, levelno, force))
1822+
return "COLORIZED"
1823+
1824+
self._common_mod.LOGGER_HANDLER = _FakeColorizingHandler()
1825+
conf.disableColoring = False
1826+
result = setColor("[INFO] current status: abcde", istty=True)
1827+
self.assertEqual(result, "COLORIZED")
1828+
self.assertEqual(len(calls), 1)
1829+
1830+
17871831
if __name__ == "__main__":
17881832
unittest.main(verbosity=2)
17891833

0 commit comments

Comments
 (0)