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

Close an open start tag before a fatal error.

This is part of the error handler that attempts to close open XML tags
at a fatal error. The case wasn't handled where a fatal error happened
while a start tag was still open (didn't have its '>' written yet). This
came from a bug report from David Hingos.

http://seclists.org/nmap-dev/2012/q1/514
This commit is contained in:
david
2012-03-09 00:16:39 +00:00
parent e1576d1d14
commit fa0713e041
3 changed files with 10 additions and 0 deletions

View File

@@ -122,6 +122,8 @@ void fatal(const char *fmt, ...) {
}
log_write(o.log_errors? LOG_NORMAL|LOG_STDERR : LOG_STDERR, "\nQUITTING!\n");
if (xml_tag_open())
xml_close_start_tag();
if (!xml_root_written())
xml_start_tag("nmaprun");
/* Close all open XML elements but one. */
@@ -198,6 +200,8 @@ void pfatal(const char *fmt, ...) {
log_write(o.log_errors? LOG_NORMAL|LOG_STDERR : LOG_STDERR, "%s: %s (%d)\n",
errbuf, strerror_s, error_number);
if (xml_tag_open())
xml_close_start_tag();
if (!xml_root_written())
xml_start_tag("nmaprun");
/* Close all open XML elements but one. */

5
xml.cc
View File

@@ -412,6 +412,11 @@ int xml_depth() {
return xml.element_stack.size();
}
/* Return true iff a root element has been started. */
bool xml_tag_open() {
return xml.tag_open;
}
/* Return true iff a root element has been started. */
bool xml_root_written() {
return xml.root_written;

1
xml.h
View File

@@ -118,6 +118,7 @@ int xml_attribute(const char *name, const char *fmt, ...) __attribute__ ((format
int xml_newline();
int xml_depth();
bool xml_tag_open();
bool xml_root_written();
#endif