Nmap Development mailing list archives

Re: [nmap-svn] r34420 - nmap


From: Paulino Calderon Pale <paulino () calderonpale com>
Date: Thu, 16 Apr 2015 17:17:28 -0500

Hey Daniel,

I will implement it as suggested. I almost did it that way but then I thought it was OK to include the check there 
since it was in main.cc <http://main.cc/> already. 

I’ll post the patch soon!


On Apr 16, 2015, at 3:28 PM, Daniel Miller <bonsaiviking () gmail com> wrote:

On Thu, Apr 16, 2015 at 11:20 AM,  <commit-mailer () nmap org <mailto:commit-mailer () nmap org>> wrote:
Author: paulino
Date: Thu Apr 16 16:20:18 2015
New Revision: 34420

Log:
Prints a friendly error message when --resume is used with other options. Fixes #84

Modified:
   nmap/main.cc

Modified: nmap/main.cc
==============================================================================
--- nmap/main.cc        (original)
+++ nmap/main.cc        Thu Apr 16 16:20:18 2015
@@ -175,6 +175,7 @@
   char *cptr;
   int ret;
   int i;
+  int resume;

   set_program_name(argv[0]);

@@ -216,14 +217,22 @@
     return ret;
   }

-  if (argc == 3 && strcmp("--resume", argv[1]) == 0) {
-    /* OK, they want to resume an aborted scan given the log file specified.
-       Lets gather our state from the log file */
-    if (gather_logfile_resumption_state(argv[2], &myargc, &myargv) == -1) {
-      fatal("Cannot resume from (supposed) log file %s", argv[2]);
+  /* Don't allow users to use --resume with other options */
+  for (i=0; i<argc; i++) {
+    if ( strcmp("--resume", argv[i]) == 0) {
+      resume = 1;
+      if(argc!=3) {
+        fatal("Cannot use --resume with other options. Usage: nmap --resume <filename>");
+      }
+      if (gather_logfile_resumption_state(argv[i+1], &myargc, &myargv) == -1) {
+        fatal("Cannot resume from (supposed) log file %s", argv[i+1]);
+      }
     }
-    return nmap_main(myargc, myargv);
   }

-  return nmap_main(argc, argv);
+  if (resume == 1) {
+    return nmap_main(myargc, myargv);
+  } else {
+    return nmap_main(argc, argv);
+  }
 }


Paulino,

While this meets the intent of the bug report, it would be a lot cleaner to just add '--resume' as a valid option in 
the getopt parsing in nmap.cc <http://nmap.cc/>, and then perform the fatal() call there. That way it's clear to 
anyone trying to determine what '--resume' does by looking at the option parsing code; we could even have a comment 
that mentions that the actual implementation is in nmap_main.cc

Dan

_______________________________________________
Sent through the dev mailing list
https://nmap.org/mailman/listinfo/dev
Archived at http://seclists.org/nmap-dev/

Current thread: