1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-07 05:01:29 +00:00

Avoid crashing when PATH contains non-ascii/utf-8. Decode if possible

This commit is contained in:
dmiller
2018-11-15 16:23:32 +00:00
parent adfc39f4f3
commit bff7dcad4e
2 changed files with 16 additions and 9 deletions

View File

@@ -1,5 +1,8 @@
#Nmap Changelog ($Id$); -*-text-*- #Nmap Changelog ($Id$); -*-text-*-
o [Zenmap] Fix a crash when Nmap executable cannot be found and the system PATH
contains non-UTF-8 bytes, such as on Windows. [Daniel Miller]
o [Zenmap] Fix a crash in results search when using the dir: operator: o [Zenmap] Fix a crash in results search when using the dir: operator:
AttributeError: 'SearchDB' object has no attribute 'match_dir' AttributeError: 'SearchDB' object has no attribute 'match_dir'
[Daniel Miller] [Daniel Miller]

View File

@@ -131,6 +131,7 @@ import gtk
import gobject import gobject
import os import os
import time import time
import sys
# Prevent loading PyXML # Prevent loading PyXML
import xml import xml
@@ -550,30 +551,33 @@ class ScanInterface(HIGVBox):
try: try:
command_execution.run_scan() command_execution.run_scan()
except Exception, e: except Exception, e:
text = str(e) text = unicode(e)
if isinstance(e, OSError): if isinstance(e, OSError):
# Handle ENOENT specially. # Handle ENOENT specially.
if e.errno == errno.ENOENT: if e.errno == errno.ENOENT:
# nmap_command_path comes from zenmapCore.NmapCommand. # nmap_command_path comes from zenmapCore.NmapCommand.
text += "\n\n%s\n\n%s" % (
_("This means that the nmap executable was "
"not found in your system PATH, which is"),
os.getenv("PATH", _("<undefined>"))
)
path_env = os.getenv("PATH") path_env = os.getenv("PATH")
if path_env is None: if path_env is None:
default_paths = [] default_paths = []
else: else:
fsencoding = sys.getfilesystemencoding()
if fsencoding:
path_env = path_env.decode(fsencoding, 'replace')
default_paths = path_env.split(os.pathsep) default_paths = path_env.split(os.pathsep)
text += u"\n\n{}\n\n{}".format(
_("This means that the nmap executable was "
"not found in your system PATH, which is"),
path_env or _("<undefined>")
)
extra_paths = get_extra_executable_search_paths() extra_paths = get_extra_executable_search_paths()
extra_paths = [p for p in extra_paths if ( extra_paths = [p for p in extra_paths if (
p not in default_paths)] p not in default_paths)]
if len(extra_paths) > 0: if len(extra_paths) > 0:
if len(extra_paths) == 1: if len(extra_paths) == 1:
text += "\n\n" + _("plus the extra directory") text += u"\n\n" + _("plus the extra directory")
else: else:
text += "\n\n" + _("plus the extra directories") text += u"\n\n" + _("plus the extra directories")
text += "\n\n" + os.pathsep.join(extra_paths) text += u"\n\n" + os.pathsep.join(extra_paths)
warn_dialog = HIGAlertDialog( warn_dialog = HIGAlertDialog(
message_format=_("Error executing command"), message_format=_("Error executing command"),
secondary_text=text, type=gtk.MESSAGE_ERROR) secondary_text=text, type=gtk.MESSAGE_ERROR)