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

Skip to content

Commit 4cc13d3

Browse files
committed
Fixes #3680
1 parent 0322440 commit 4cc13d3

5 files changed

Lines changed: 28 additions & 20 deletions

File tree

lib/core/common.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
from lib.core.convert import getText
5959
from lib.core.convert import getUnicode
6060
from lib.core.convert import htmlunescape
61-
from lib.core.convert import stdoutencode
61+
from lib.core.convert import stdoutEncode
6262
from lib.core.data import conf
6363
from lib.core.data import kb
6464
from lib.core.data import logger
@@ -968,9 +968,9 @@ def dataToStdout(data, forceOutput=False, bold=False, content_type=None, status=
968968

969969
try:
970970
if conf.get("api"):
971-
sys.stdout.write(stdoutencode(clearColors(data)), status, content_type)
971+
sys.stdout.write(stdoutEncode(clearColors(data)), status, content_type)
972972
else:
973-
sys.stdout.write(stdoutencode(setColor(data, bold=bold)))
973+
sys.stdout.write(stdoutEncode(setColor(data, bold=bold)))
974974

975975
sys.stdout.flush()
976976
except IOError:

lib/core/convert.py

100644100755
Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from lib.core.settings import IS_WIN
2424
from lib.core.settings import NULL
2525
from lib.core.settings import PICKLE_PROTOCOL
26+
from lib.core.settings import PYVERSION
2627
from lib.core.settings import SAFE_HEX_MARKER
2728
from lib.core.settings import UNICODE_ENCODING
2829
from thirdparty import six
@@ -100,27 +101,34 @@ def filterNone(values): # Cross-referenced function
100101
def isListLike(value): # Cross-referenced function
101102
raise NotImplementedError
102103

103-
def stdoutencode(data):
104-
retVal = data
104+
def stdoutEncode(value):
105+
value = value or ""
105106

106-
if six.PY2:
107-
try:
108-
retVal = getBytes(data or "", sys.stdout.encoding, unsafe=False)
107+
if isinstance(value, six.text_type) and PYVERSION < "3.6":
108+
encoding = sys.stdout.encoding or UNICODE_ENCODING
109+
110+
while True:
111+
try:
112+
retVal = value.encode(encoding)
113+
break
114+
except UnicodeEncodeError as ex:
115+
value = value[:ex.start] + "?" + value[ex.end:]
109116

110-
# Reference: http://bugs.python.org/issue1602
111-
if IS_WIN:
112-
if '?' in retVal and '?' not in retVal:
113-
warnMsg = "cannot properly display Unicode characters "
117+
if IS_WIN and PYVERSION < "3.6":
118+
warnMsg = "cannot properly display (some) Unicode characters "
114119
warnMsg += "inside Windows OS command prompt "
115-
warnMsg += "(http://bugs.python.org/issue1602). All "
120+
warnMsg += "(https://bugs.python.org/issue1602). All "
116121
warnMsg += "unhandled occurrences will result in "
117122
warnMsg += "replacement with '?' character. Please, find "
118123
warnMsg += "proper character representation inside "
119124
warnMsg += "corresponding output files. "
120125
singleTimeWarnMessage(warnMsg)
121126

122-
except:
123-
retVal = getBytes(data or "", unsafe=False)
127+
if six.PY3:
128+
retVal = getUnicode(retVal, encoding)
129+
130+
else:
131+
retVal = value
124132

125133
return retVal
126134

lib/core/patch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from lib.core.common import isListLike
2525
from lib.core.common import singleTimeWarnMessage
2626
from lib.core.common import readInput
27-
from lib.core.convert import stdoutencode
27+
from lib.core.convert import stdoutEncode
2828
from lib.core.option import _setHTTPHandlers
2929
from lib.core.option import setVerbosity
3030
from lib.core.option import _setWafFunctions
@@ -70,7 +70,7 @@ def resolveCrossReferences():
7070
lib.controller.checks.setVerbosity = setVerbosity
7171
lib.controller.checks.setWafFunctions = _setWafFunctions
7272
lib.utils.sqlalchemy.getSafeExString = getSafeExString
73-
thirdparty.ansistrm.ansistrm.stdoutencode = stdoutencode
73+
thirdparty.ansistrm.ansistrm.stdoutEncode = stdoutEncode
7474

7575
def pympTempLeakPatch(tempDir):
7676
"""

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from thirdparty.six import unichr as _unichr
1919

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

thirdparty/ansistrm/ansistrm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
ctypes.windll.kernel32.SetConsoleTextAttribute.argtypes = [ctypes.wintypes.HANDLE, ctypes.wintypes.WORD]
2121
ctypes.windll.kernel32.SetConsoleTextAttribute.restype = ctypes.wintypes.BOOL
2222

23-
def stdoutencode(data): # Cross-referenced function
23+
def stdoutEncode(data): # Cross-referenced function
2424
raise NotImplementedError
2525

2626
class ColorizingStreamHandler(logging.StreamHandler):
@@ -56,7 +56,7 @@ def is_tty(self):
5656

5757
def emit(self, record):
5858
try:
59-
message = stdoutencode(self.format(record))
59+
message = stdoutEncode(self.format(record))
6060
stream = self.stream
6161

6262
if not self.is_tty:

0 commit comments

Comments
 (0)