1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 04:31:29 +00:00

Catch Zenmap's MemoryError (caused by large Nmap Output) and provide the user a more useful error message so that we get less of the out-of-memory "crash reports"

This commit is contained in:
jay
2014-07-01 16:53:10 +00:00
parent 0066d3b24e
commit 2b30085d90
4 changed files with 57 additions and 15 deletions

View File

@@ -296,8 +296,11 @@ class NmapOutputViewer (gtk.VBox):
def show_nmap_output(self, output):
"""Show the string (or unicode) output in the output display."""
self.text_view.get_buffer().set_text(output)
self.apply_highlighting()
try:
self.text_view.get_buffer().set_text(output)
self.apply_highlighting()
except MemoryError:
self.show_large_output_message(self.command_execution)
def set_command_execution(self, command):
"""Set the live running command whose output is shown by this display.
@@ -310,6 +313,31 @@ class NmapOutputViewer (gtk.VBox):
self.output_file_pointer = None
self.refresh_output()
def show_large_output_message(self, command=None):
buf = self.text_view.get_buffer()
try:
running = (command is not None and command.scan_state() is True)
except:
running = False
complete = False
else:
complete = not running
if running:
buf.set_text("Warning: You have insufficient resources for Zenmap "
"to be able to display the complete output from Nmap here. \n"
"Zenmap will continue to run the scan to completion. However,"
" some features of Zenmap might not work as expected.")
elif complete:
buf.set_text("Warning: You have insufficient resources for Zenmap "
"to be able to display the complete output from Nmap here. \n"
"The scan has completed. However, some features of Zenmap "
"might not work as expected.")
else:
buf.set_text("Warning: You have insufficient resources for Zenmap "
"to be able to display the complete output from Nmap here. \n"
"The scan has been stopped. Some features of Zenmap might not "
"work as expected.")
def refresh_output(self, widget=None):
"""Update the output from the latest output of the command associated
with this view, as set by set_command_execution. It has no effect if no
@@ -322,7 +350,13 @@ class NmapOutputViewer (gtk.VBox):
# Seek to the end of the most recent read.
self.command_execution.stdout_file.seek(self.output_file_pointer)
pos = self.command_execution.stdout_file.tell()
new_output = self.command_execution.stdout_file.read()
try:
new_output = self.command_execution.stdout_file.read()
except MemoryError:
self.show_large_output_message(self.command_execution)
return
self.output_file_pointer = self.command_execution.stdout_file.tell()
# print "read %d -> %d %d" % (
# pos, self.output_file_pointer, len(new_output))
@@ -335,10 +369,14 @@ class NmapOutputViewer (gtk.VBox):
buf = self.text_view.get_buffer()
prev_end_mark = buf.create_mark(
None, buf.get_end_iter(), left_gravity=True)
buf.insert(buf.get_end_iter(), new_output)
# Highlight the new text.
self.apply_highlighting(
buf.get_iter_at_mark(prev_end_mark), buf.get_end_iter())
try:
buf.insert(buf.get_end_iter(), new_output)
# Highlight the new text.
self.apply_highlighting(
buf.get_iter_at_mark(prev_end_mark), buf.get_end_iter())
except MemoryError:
self.show_large_output_message(self.command_execution)
return
if at_end:
# If we were already scrolled to the bottom, scroll back to the