Index: zenmap/zenmapGUI/NmapOutputViewer.py =================================================================== --- zenmap/zenmapGUI/NmapOutputViewer.py (revision 32967) +++ zenmap/zenmapGUI/NmapOutputViewer.py (working copy) @@ -296,8 +296,11 @@ 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 @@ 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 @@ # 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 @@ 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 Index: zenmap/zenmapGUI/ScanInterface.py =================================================================== --- zenmap/zenmapGUI/ScanInterface.py (revision 32967) +++ zenmap/zenmapGUI/ScanInterface.py (working copy) @@ -654,7 +654,10 @@ warn_dialog.destroy() parsed.set_xml_is_temp(command.xml_is_temp) self.collect_umit_info(command, parsed) - parsed.nmap_output = command.get_output() + try: + parsed.nmap_output = command.get_output() + except MemoryError: + self.scan_result.scan_result_notebook.nmap_output.nmap_output.show_large_output_message(command) self.update_ui() self.scans_store.finish_running_scan(command, parsed)