Patch for an Issue #896

This commit is contained in:
Miroslav Stampar 2014-11-04 00:34:35 +01:00
parent 6f45596f28
commit 4d5b48b2ae
3 changed files with 17 additions and 23 deletions

View File

@ -923,7 +923,7 @@ def readInput(message, default=None, checkBatch=True):
try: try:
retVal = raw_input() or default retVal = raw_input() or default
retVal = getUnicode(retVal, system=True) if retVal else retVal retVal = getUnicode(retVal, encoding=sys.stdin.encoding) if retVal else retVal
except: except:
time.sleep(0.05) # Reference: http://www.gossamer-threads.com/lists/python/python/781893 time.sleep(0.05) # Reference: http://www.gossamer-threads.com/lists/python/python/781893
kb.prependFlag = True kb.prependFlag = True
@ -1064,7 +1064,7 @@ def setPaths():
paths.SQLMAP_XML_BANNER_PATH = os.path.join(paths.SQLMAP_XML_PATH, "banner") paths.SQLMAP_XML_BANNER_PATH = os.path.join(paths.SQLMAP_XML_PATH, "banner")
_ = os.path.join(os.path.expanduser("~"), ".sqlmap") _ = os.path.join(os.path.expanduser("~"), ".sqlmap")
paths.SQLMAP_OUTPUT_PATH = getUnicode(paths.get("SQLMAP_OUTPUT_PATH", os.path.join(_, "output")), system=True) paths.SQLMAP_OUTPUT_PATH = getUnicode(paths.get("SQLMAP_OUTPUT_PATH", os.path.join(_, "output")), encoding=sys.getfilesystemencoding())
paths.SQLMAP_DUMP_PATH = os.path.join(paths.SQLMAP_OUTPUT_PATH, "%s", "dump") paths.SQLMAP_DUMP_PATH = os.path.join(paths.SQLMAP_OUTPUT_PATH, "%s", "dump")
paths.SQLMAP_FILES_PATH = os.path.join(paths.SQLMAP_OUTPUT_PATH, "%s", "files") paths.SQLMAP_FILES_PATH = os.path.join(paths.SQLMAP_OUTPUT_PATH, "%s", "files")
@ -2009,7 +2009,7 @@ def getPartRun(alias=True):
else: else:
return retVal return retVal
def getUnicode(value, encoding=None, system=False, noneToNull=False): def getUnicode(value, encoding=None, noneToNull=False):
""" """
Return the unicode representation of the supplied value: Return the unicode representation of the supplied value:
@ -2028,25 +2028,19 @@ def getUnicode(value, encoding=None, system=False, noneToNull=False):
value = list(getUnicode(_, encoding, system, noneToNull) for _ in value) value = list(getUnicode(_, encoding, system, noneToNull) for _ in value)
return value return value
if not system: if isinstance(value, unicode):
if isinstance(value, unicode): return value
return value elif isinstance(value, basestring):
elif isinstance(value, basestring): while True:
while True:
try:
return unicode(value, encoding or kb.get("pageEncoding") or UNICODE_ENCODING)
except UnicodeDecodeError, ex:
value = value[:ex.start] + "".join(INVALID_UNICODE_CHAR_FORMAT % ord(_) for _ in value[ex.start:ex.end]) + value[ex.end:]
else:
try: try:
return unicode(value) return unicode(value, encoding or kb.get("pageEncoding") or UNICODE_ENCODING)
except UnicodeDecodeError: except UnicodeDecodeError, ex:
return unicode(str(value), errors="ignore") # encoding ignored for non-basestring instances value = value[:ex.start] + "".join(INVALID_UNICODE_CHAR_FORMAT % ord(_) for _ in value[ex.start:ex.end]) + value[ex.end:]
else: else:
try: try:
return getUnicode(value, sys.getfilesystemencoding() or sys.stdin.encoding) return unicode(value)
except: except UnicodeDecodeError:
return getUnicode(value, UNICODE_ENCODING) return unicode(str(value), errors="ignore") # encoding ignored for non-basestring instances
def longestCommonPrefix(*sequences): def longestCommonPrefix(*sequences):
""" """

View File

@ -285,7 +285,7 @@ def runCase(parse):
elif result is False: # this means no SQL injection has been detected - if None, ignore elif result is False: # this means no SQL injection has been detected - if None, ignore
retVal = False retVal = False
console = getUnicode(console, system=True) console = getUnicode(console, encoding=sys.stdin.encoding)
if parse and retVal: if parse and retVal:
with codecs.open(conf.dumper.getOutputFile(), "rb", UNICODE_ENCODING) as f: with codecs.open(conf.dumper.getOutputFile(), "rb", UNICODE_ENCODING) as f:

View File

@ -41,7 +41,7 @@ def cmdLineParser():
checkSystemEncoding() checkSystemEncoding()
_ = getUnicode(os.path.normpath(sys.argv[0]), system=True) _ = getUnicode(os.path.normpath(sys.argv[0]), encoding=sys.getfilesystemencoding())
usage = "%s%s [options]" % ("python " if not IS_WIN else "", \ usage = "%s%s [options]" % ("python " if not IS_WIN else "", \
"\"%s\"" % _ if " " in _ else _) "\"%s\"" % _ if " " in _ else _)
@ -788,7 +788,7 @@ def cmdLineParser():
advancedHelp = True advancedHelp = True
for arg in sys.argv: for arg in sys.argv:
argv.append(getUnicode(arg, system=True)) argv.append(getUnicode(arg, encoding=sys.stdin.encoding))
checkDeprecatedOptions(argv) checkDeprecatedOptions(argv)
@ -837,7 +837,7 @@ def cmdLineParser():
break break
for arg in shlex.split(command): for arg in shlex.split(command):
argv.append(getUnicode(arg, system=True)) argv.append(getUnicode(arg, encoding=sys.stdin.encoding))
# Hide non-basic options in basic help case # Hide non-basic options in basic help case
for i in xrange(len(argv)): for i in xrange(len(argv)):