1
0
mirror of https://github.com/nmap/nmap.git synced 2026-02-10 23:46:34 +00:00

Remove dynamically allocated fakeargv.

This used to be used to hold the original argv before quashing with -q.
Now that -q is gone, it was just a copy of argv.

fakeargv was also causing Valgrind to complain about leaked memory. it
wasn't a real leak, but now it's out of the report anyway.
This commit is contained in:
david
2013-01-25 06:26:21 +00:00
parent e77a084790
commit 50a4817671
2 changed files with 8 additions and 21 deletions

View File

@@ -4514,7 +4514,7 @@ size_t read_host_from_file(FILE *fp, char *buf, size_t n)
/* Return next target host specification from the supplied stream.
* if parameter "random" is set to true, then the function will
* return a random, non-reserved, IP address in decimal-dot notation */
const char *grab_next_host_spec(FILE *inputfd, bool random, int argc, const char **fakeargv) {
const char *grab_next_host_spec(FILE *inputfd, bool random, int argc, const char **argv) {
static char host_spec[1024];
struct in_addr ip;
size_t n;
@@ -4525,7 +4525,7 @@ const char *grab_next_host_spec(FILE *inputfd, bool random, int argc, const char
} while (ip_is_reserved(&ip));
Strncpy(host_spec, inet_ntoa(ip), sizeof(host_spec));
} else if (!inputfd) {
return( (optind < argc)? fakeargv[optind++] : NULL);
return( (optind < argc)? argv[optind++] : NULL);
} else {
n = read_host_from_file(inputfd, host_spec, sizeof(host_spec));
if (n == 0)

25
nmap.cc
View File

@@ -1585,7 +1585,6 @@ int nmap_main(int argc, char *argv[]) {
char hostname[MAXHOSTNAMELEN + 1] = "";
struct sockaddr_storage ss;
size_t sslen;
char **fakeargv = NULL;
now = time(NULL);
local_time = localtime(&now);
@@ -1598,19 +1597,12 @@ int nmap_main(int argc, char *argv[]) {
if (argc < 2)
printusage(-1);
/* argv faking silliness */
fakeargv = (char **) safe_malloc(sizeof(char *) * (argc + 1));
for (i = 0; i < argc; i++) {
fakeargv[i] = strdup(argv[i]);
}
fakeargv[argc] = NULL;
Targets.reserve(100);
#ifdef WIN32
win_pre_init();
#endif
parse_options(argc, fakeargv);
parse_options(argc, argv);
tty_init(); // Put the keyboard in raw mode
@@ -1687,14 +1679,14 @@ int nmap_main(int argc, char *argv[]) {
std::string command;
if (argc > 0)
command += fakeargv[0];
command += argv[0];
for (i = 1; i < argc; i++) {
command += " ";
command += fakeargv[i];
command += argv[i];
}
xml_start_comment();
xml_write_escaped(" %s %s scan initiated %s as: %s ", NMAP_NAME, NMAP_VERSION, mytime, join_quoted(fakeargv, argc).c_str());
xml_write_escaped(" %s %s scan initiated %s as: %s ", NMAP_NAME, NMAP_VERSION, mytime, join_quoted(argv, argc).c_str());
xml_end_comment();
xml_newline();
@@ -1705,7 +1697,7 @@ int nmap_main(int argc, char *argv[]) {
xml_open_start_tag("nmaprun");
xml_attribute("scanner", "nmap");
xml_attribute("args", "%s", join_quoted(fakeargv, argc).c_str());
xml_attribute("args", "%s", join_quoted(argv, argc).c_str());
xml_attribute("start", "%lu", (unsigned long) timep);
xml_attribute("startstr", "%s", mytime);
xml_attribute("version", "%s", NMAP_VERSION);
@@ -1814,7 +1806,7 @@ int nmap_main(int argc, char *argv[]) {
}
#endif
HostGroupState hstate(o.ping_group_sz, o.randomize_hosts, argc, (const char **) fakeargv);
HostGroupState hstate(o.ping_group_sz, o.randomize_hosts, argc, (const char **) argv);
do {
ideal_scan_group_sz = determineScanGroupSize(o.numhosts_scanned, &ports);
@@ -2075,11 +2067,6 @@ int nmap_main(int argc, char *argv[]) {
eth_close_cached();
if (o.release_memory) {
/* Free fake argv */
for (i = 0; i < argc; i++)
free(fakeargv[i]);
free(fakeargv);
nmap_free_mem();
}
return 0;