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

Check for invalid output file. Fixes #3066

This commit is contained in:
dmiller
2025-05-15 20:36:03 +00:00
parent f22bd4b91b
commit 86e055a251

View File

@@ -236,7 +236,7 @@ class NmapOutputViewer(Gtk.Box):
self.text_view.get_buffer().set_text(output)
self.apply_highlighting()
except MemoryError:
self.show_large_output_message(self.command_execution)
self.show_large_output_message()
def set_command_execution(self, command):
"""Set the live running command whose output is shown by this display.
@@ -249,8 +249,9 @@ class NmapOutputViewer(Gtk.Box):
self.output_file_pointer = None
self.refresh_output()
def show_large_output_message(self, command=None):
def replace_buffer_warning_message(self, message):
buf = self.text_view.get_buffer()
command = self.command_execution
try:
running = (command is not None and command.scan_state() is True)
except Exception:
@@ -259,20 +260,22 @@ class NmapOutputViewer(Gtk.Box):
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"
buf.set_text(_("Warning: %s \n"
"Zenmap will continue to run the scan to completion. However,"
" some features of Zenmap might not work as expected.")
" 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"
buf.set_text(_("Warning: %s \n"
"The scan has completed. However, some features of Zenmap "
"might not work as expected.")
"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"
buf.set_text(_("Warning: %s \n"
"The scan has been stopped. Some features of Zenmap might not "
"work as expected.")
"work as expected."))
def show_large_output_message(self):
self.replace_buffer_warning_message(
_("You have insufficient resources for Zenmap to be able to "
"display the complete output from Nmap here. \n"))
def refresh_output(self, widget=None):
"""Update the output from the latest output of the command associated
@@ -284,12 +287,17 @@ class NmapOutputViewer(Gtk.Box):
return
# Seek to the end of the most recent read.
self.command_execution.stdout_file.seek(self.output_file_pointer)
try:
self.command_execution.stdout_file.seek(self.output_file_pointer)
except ValueError:
self.replace_buffer_warning_message(
_("The Nmap output file has been closed unexpectedly."))
return
try:
new_output = self.command_execution.stdout_file.read()
except MemoryError:
self.show_large_output_message(self.command_execution)
self.show_large_output_message()
return
self.output_file_pointer = self.command_execution.stdout_file.tell()
@@ -309,7 +317,7 @@ class NmapOutputViewer(Gtk.Box):
buf.get_iter_at_mark(prev_end_mark),
buf.get_end_iter())
except MemoryError:
self.show_large_output_message(self.command_execution)
self.show_large_output_message()
return
if at_end: