mirror of
https://github.com/nmap/nmap.git
synced 2026-08-27 11:55:27 +00:00
Address code review feedback on PR #3448
1. Used C++98 const_iterator for range loop in output.cc 2. Added missing guard condition for empty aliases in output.cc 3. Added is_resolved_address(ss) check in targets.cc to prevent netmask addresses from applying as names 4. Added architectural comment explaining why cross-batch aliases cannot be appended due to streaming XML constraints
This commit is contained in:
parent
5d8a4cc56b
commit
c99f43f8b7
2 changed files with 11 additions and 5 deletions
|
|
@ -1271,7 +1271,7 @@ static void write_xml_initial_hostinfo(const Target *currenths,
|
|||
print_MAC_XML_Info(currenths);
|
||||
/* Output a hostnames element whenever we have a name to write or the target
|
||||
is up. */
|
||||
if (currenths->TargetName() != NULL || *currenths->HostName() || strcmp(status, "up") == 0) {
|
||||
if (currenths->TargetName() != NULL || *currenths->HostName() || strcmp(status, "up") == 0 || !currenths->getTargetNameAliases().empty()) {
|
||||
xml_start_tag("hostnames");
|
||||
xml_newline();
|
||||
if (currenths->TargetName() != NULL) {
|
||||
|
|
@ -1282,9 +1282,10 @@ static void write_xml_initial_hostinfo(const Target *currenths,
|
|||
xml_newline();
|
||||
}
|
||||
/* Print additional names collected when --unique suppressed duplicate scanning. */
|
||||
for (const std::string &alias : currenths->getTargetNameAliases()) {
|
||||
for (std::vector<std::string>::const_iterator alias = currenths->getTargetNameAliases().begin();
|
||||
alias != currenths->getTargetNameAliases().end(); ++alias) {
|
||||
xml_open_start_tag("hostname");
|
||||
xml_attribute("name", "%s", alias.c_str());
|
||||
xml_attribute("name", "%s", alias->c_str());
|
||||
xml_attribute("type", "user");
|
||||
xml_close_empty_tag();
|
||||
xml_newline();
|
||||
|
|
|
|||
|
|
@ -470,8 +470,13 @@ bool HostGroupState::get_next_host(struct sockaddr_storage *ss, size_t *sslen, s
|
|||
/* This IP is already in the exclude list (a --unique duplicate).
|
||||
At this point *ss holds the excluded IP. If it came from a named
|
||||
host, attach that name as an alias on the existing Target in the
|
||||
current batch so it appears in XML output. */
|
||||
if (o.unique && current_group.get_namedhost()) {
|
||||
current batch so it appears in XML output.
|
||||
|
||||
Note: Nmap's streaming XML architecture finalizes and closes <host> blocks
|
||||
after each batch. Therefore, it is impossible to attach aliases to duplicates
|
||||
that occur in a later batch than the original target without buffering
|
||||
all XML in memory. We restrict our search to the current batch. */
|
||||
if (o.unique && current_group.get_namedhost() && current_group.is_resolved_address(ss)) {
|
||||
const char *skipped_name = current_group.get_resolved_name();
|
||||
if (skipped_name) {
|
||||
for (int i = 0; i < current_batch_sz; i++) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue