Nmap Development mailing list archives

[PATCH] Use memset() instead of looping when "quashing" argv


From: Kris Katterjohn <kjak () ispwest com>
Date: Fri, 15 Sep 2006 19:51:03 -0500

The attached patch uses memset() instead of looping in nmap.cc.

It's a diff against 4.20ALPHA7.

Thanks,
Kris Katterjohn
--- x/nmap.cc   2006-09-11 22:33:34.000000000 -0500
+++ y/nmap.cc   2006-09-15 19:45:10.000000000 -0500
@@ -437,7 +437,6 @@ int nmap_main(int argc, char *argv[]) {
   int i, arg;
   long l;
   unsigned int targetno;
-  size_t j, argvlen;
   FILE *inputfd = NULL, *excludefd = NULL;
   char *host_spec = NULL, *exclude_spec = NULL;
   short fastscan=0, randomize=1;
@@ -1341,16 +1340,13 @@ int nmap_main(int argc, char *argv[]) {
 
   /* more fakeargv junk, BTW malloc'ing extra space in argv[0] doesn't work */
   if (quashargv) {
-    argvlen = strlen(argv[0]);
-    if (argvlen < strlen(FAKE_ARGV))
+    size_t fakeargvlen = strlen(FAKE_ARGV), argvlen = strlen(argv[0]);
+    if (argvlen < fakeargvlen)
       fatal("If you want me to fake your argv, you need to call the program with a longer name.  Try the full 
pathname, or rename it fyodorssuperdedouperportscanner");
-    strncpy(argv[0], FAKE_ARGV, strlen(FAKE_ARGV));
-    for(j = strlen(FAKE_ARGV); j < argvlen; j++) argv[0][j] = '\0';
-    for(i=1; i < argc; i++) {
-      argvlen = strlen(argv[i]);
-      for(j=0; j <= argvlen; j++)
-       argv[i][j] = '\0';
-    }
+    strncpy(argv[0], FAKE_ARGV, fakeargvlen);
+    memset(&argv[0][fakeargvlen], '\0', strlen(&argv[0][fakeargvlen]));
+    for(i=1; i < argc; i++)
+      memset(argv[i], '\0', strlen(argv[i]));
   }
 
 #if defined(HAVE_SIGNAL) && defined(SIGPIPE)

_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://SecLists.Org

Current thread: