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:
I-am-Krish 2026-08-24 17:38:56 +05:30
parent 003949d4ba
commit fd59ddfd7f
2 changed files with 5 additions and 3 deletions

View file

@ -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();

View file

@ -481,6 +481,7 @@ bool HostGroupState::get_next_host(struct sockaddr_storage *ss, size_t *sslen, s
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();