mirror of
https://github.com/nmap/nmap.git
synced 2026-08-04 14:49:29 +00:00
Replace repeated strcat with Snprintf
This commit is contained in:
parent
dd3a975743
commit
a600f265e1
1 changed files with 14 additions and 5 deletions
19
main.cc
19
main.cc
|
|
@ -142,13 +142,22 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
try {
|
||||
if ((cptr = getenv("NMAP_ARGS"))) {
|
||||
if (Snprintf(command, sizeof(command), "nmap %s", cptr) >= (int) sizeof(command)) {
|
||||
error("Warning: NMAP_ARGS variable is too long, truncated");
|
||||
char *tail = command;
|
||||
int rem = sizeof(command);
|
||||
int n = Snprintf(tail, rem, "nmap %s", cptr);
|
||||
if (n >= rem) {
|
||||
fatal("NMAP_ARGS variable is too long");
|
||||
}
|
||||
tail += n;
|
||||
rem -= n;
|
||||
/* copy rest of command-line arguments */
|
||||
for (i = 1; i < argc && strlen(command) + strlen(argv[i]) + 1 < sizeof(command); i++) {
|
||||
strcat(command, " ");
|
||||
strcat(command, argv[i]);
|
||||
for (i = 1; i < argc; i++) {
|
||||
n = Snprintf(tail, rem, " %s", argv[i]);
|
||||
if (n >= rem) {
|
||||
fatal("NMAP_ARGS and command line together exceed %lu bytes", sizeof(command));
|
||||
}
|
||||
tail += n;
|
||||
rem -= n;
|
||||
}
|
||||
myargc = arg_parse(command, &myargv);
|
||||
if (myargc < 1) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue