Home page logo
/

nmap-dev logo Nmap Development mailing list archives

ncat minor patches
From: ithilgore <ithilgore.ryu.l () gmail com>
Date: Fri, 24 Apr 2009 21:12:00 +0300

Hello nmap-dev.
I 've been reading through the ncat code and made some minor fixes
on some things that I stumbled upon. 


1. Replaced all instances of sys_wrap's Malloc with nbase's safe_malloc,
since safe_malloc does essentially the same thing and is used throughout
all of nmap's codebase.

2. Replaced all instances of strdup with sys_wrap's Strdup for consistency.

3. Removed a redundant check in ncat_main.c 

    /* Set the default to IPv4 if not explicitly specified. */
    if (o.af != AF_INET && o.af != AF_INET6)
        o.af = AF_INET;

o.af is initialized to AF_INET with options_init() which is called in the
beginning of main()



In addition, I think all atoi instances should be replaced with something
like strtol since atoi is deprecated and doesn't do any error-checking for
input that is not actually a digit.


--
ithilgore
sock-raw.org
diff -urNb nmap/ncat/ncat_main.c nmap-working3/ncat/ncat_main.c
--- nmap/ncat/ncat_main.c       2009-04-24 20:44:33.000000000 +0300
+++ nmap-working3/ncat/ncat_main.c      2009-04-24 20:50:36.000000000 +0300
@@ -408,10 +408,6 @@
     if (o.verbose)
         print_banner(stderr);
 
-    /* Set the default to IPv4 if not explicitly specified. */
-    if (o.af != AF_INET && o.af != AF_INET6)
-        o.af = AF_INET;
-
     /* Will be AF_INET or AF_INET6 when valid */
     memset(&targetss, 0, sizeof(targetss));
     targetss.ss_family = AF_UNSPEC;
diff -urNb nmap/ncat/ncat_connect.c nmap-working/ncat/ncat_connect.c
--- nmap/ncat/ncat_connect.c    2009-04-24 20:44:33.000000000 +0300
+++ nmap-working/ncat/ncat_connect.c    2009-04-24 20:45:34.000000000 +0300
@@ -212,7 +212,7 @@
                         char *tmp = NULL;
 
                         if (o.crlf && buf[nbytes - 1] == '\n' && buf[nbytes - 2] != '\r') {
-                            tmp = (char *) Malloc(nbytes + 1);
+                            tmp = (char *) safe_malloc(nbytes + 1);
                             memcpy(tmp, buf, nbytes - 1);
                             memcpy(tmp + nbytes - 1, "\r\n", 2);
                             buf = tmp;
diff -urNb nmap/ncat/ncat_exec.c nmap-working/ncat/ncat_exec.c
--- nmap/ncat/ncat_exec.c       2009-04-24 20:44:33.000000000 +0300
+++ nmap-working/ncat/ncat_exec.c       2009-04-24 20:45:48.000000000 +0300
@@ -85,8 +85,8 @@
     }
 
     /* malloc space based on supplied command/arguments */
-    cmdbin = (char *)Malloc((path_count + 2) * sizeof(cmdbin));
-    cmdargs = (char **)Malloc((arg_count + 2) * sizeof(cmdargs));
+    cmdbin = (char *)safe_malloc((path_count + 2) * sizeof(cmdbin));
+    cmdargs = (char **)safe_malloc((arg_count + 2) * sizeof(cmdargs));
     newtoken = (char *)Calloc(((maxlen + arg_count + path_count) * 4), sizeof(char));
 
     /* assemble arg vector */
diff -urNb nmap/ncat/sys_wrap.c nmap-working/ncat/sys_wrap.c
--- nmap/ncat/sys_wrap.c        2009-04-24 20:44:33.000000000 +0300
+++ nmap-working/ncat/sys_wrap.c        2009-04-24 20:46:06.000000000 +0300
@@ -84,17 +84,6 @@
     return 0;
 }
 
-void * Malloc(size_t size)
-{
-    void    *ret;
-
-    ret = malloc(size);
-    if(ret == NULL)
-        die("malloc");
-
-    return ret;
-}
-
 int Open(const char *pathname, int flags, mode_t mode)
 {
     int ret;
diff -urNb nmap/ncat/sys_wrap.h nmap-working/ncat/sys_wrap.h
--- nmap/ncat/sys_wrap.h        2009-04-24 20:44:33.000000000 +0300
+++ nmap-working/ncat/sys_wrap.h        2009-04-24 20:46:37.000000000 +0300
@@ -48,7 +48,6 @@
 int Dup2(int oldfd, int newfd);
 pid_t Fork(void);
 int Listen(int s, int backlog);
-void * Malloc(size_t size);
 int Open(const char *pathname, int flags, mode_t mode);
 ssize_t Read(int fd, void *buf, size_t count);
 ssize_t Recv(int s, void *buf, size_t len, int flags);
diff -urNb nmap/ncat/util.c nmap-working/ncat/util.c
--- nmap/ncat/util.c    2009-04-24 20:44:33.000000000 +0300
+++ nmap-working/ncat/util.c    2009-04-24 20:46:15.000000000 +0300
@@ -308,7 +308,7 @@
     if (numroutes > 8)
         bye("Bad number of routes passed to buildsrcrte().");
 
-    opts = (char *) Malloc(*len);
+    opts = (char *) safe_malloc(*len);
     p = opts;
 
     zmem(opts, *len);
diff -urNb nmap/ncat/ncat_hostmatch.c nmap-working2/ncat/ncat_hostmatch.c
--- nmap/ncat/ncat_hostmatch.c  2009-04-24 20:44:33.000000000 +0300
+++ nmap-working2/ncat/ncat_hostmatch.c 2009-04-24 20:48:28.000000000 +0300
@@ -137,7 +137,7 @@
     int rc;
 
     /* Make a copy of the spec to mess with. */
-    local_spec = strdup(spec);
+    local_spec = Strdup(spec);
     if (local_spec == NULL)
         return 0;
 
diff -urNb nmap/ncat/ncat_main.c nmap-working2/ncat/ncat_main.c
--- nmap/ncat/ncat_main.c       2009-04-24 20:44:33.000000000 +0300
+++ nmap-working2/ncat/ncat_main.c      2009-04-24 20:48:10.000000000 +0300
@@ -296,19 +296,19 @@
             {
                 if (proxyaddr)
                     bye("You can't specify more than one --proxy.");
-                proxyaddr = strdup(optarg);
+                proxyaddr = Strdup(optarg);
             }
             else if (strcmp(long_options[option_index].name, "proxy-type") == 0)
             {
                 if (o.proxytype)
                         bye("You can't specify more than one --proxy-type.");
-                o.proxytype = strdup(optarg);
+                o.proxytype = Strdup(optarg);
             }
             else if (strcmp(long_options[option_index].name, "proxy-auth") == 0)
             {
                 if (o.proxy_auth)
                         bye("You can't specify more than one --proxy-auth.");
-                o.proxy_auth = strdup(optarg);
+                o.proxy_auth = Strdup(optarg);
             }
             else if (strcmp(long_options[option_index].name, "chat") == 0
                      || strcmp(long_options[option_index].name, "talk") == 0)
@@ -419,7 +419,7 @@
 
     if (proxyaddr) {
       if (!o.proxytype)
-          o.proxytype = strdup("http");
+          o.proxytype = Strdup("http");
 
       if (!strcmp(o.proxytype, "http")) {
           /* Parse HTTP proxy address and temporarily store it in httpconnect.  If

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

  By Date           By Thread  

Current thread:
[ Nmap | Sec Tools | Mailing Lists | Site News | About/Contact | Advertising | Privacy ]