Nmap Development mailing list archives
[PATCH] Rewrite (simplify) parse_bounce_argument() in nmap.cc
From: Kris Katterjohn <kjak () ispwest com>
Date: Wed, 06 Sep 2006 21:48:23 -0500
The attached patch simplifies parse_bounce_argument() by removing duplicate code. I just sorta pulled out the duplicated things and rearranged it a bit. I had a printf at the bottom so I could check the "extracted" values and everything seemed to work fine. Running size on the nmap.o's yielded a decrease of 79 bytes in the text segment, but a slight increase of 8 in the data segment on my box. You probably have to apply the patch to a copy to really see the changes because diff kinda jumped around and the patch may look kinda confusing. It's a diff against 4.20ALPHA6. Thanks, Kris Katterjohn
--- x/nmap.cc 2006-09-02 16:50:41.000000000 -0500 +++ y/nmap.cc 2006-09-06 21:25:19.000000000 -0500 @@ -159,35 +159,29 @@ static int parse_scanflags(char *arg) { static int parse_bounce_argument(struct ftpinfo *ftp, char *url) { char *p = url,*q, *s; - if ((q = strrchr(url, '@'))) { /*we have username and/or pass */ - *(q++) = '\0'; - if ((s = strchr(q, ':'))) - { /* has portno */ - *(s++) = '\0'; - strncpy(ftp->server_name, q, MAXHOSTNAMELEN); - ftp->port = atoi(s); - } - else strncpy(ftp->server_name, q, MAXHOSTNAMELEN); - - if ((s = strchr(p, ':'))) { /* User AND pass given */ - *(s++) = '\0'; - strncpy(ftp->user, p, 63); + if ((q = strrchr(url, '@'))) { /* we have user and/or pass */ + *q++ = '\0'; + + if ((s = strchr(p, ':'))) { /* we have user AND pass */ + *s++ = '\0'; strncpy(ftp->pass, s, 255); - } - else { /* Username ONLY given */ + } else { /* we ONLY have user */ log_write(LOG_STDOUT, "Assuming %s is a username, and using the default password: %s\n", - p, ftp->pass); - strncpy(ftp->user, p, 63); + p, ftp->pass); } + + strncpy(ftp->user, p, 63); + } else { + q = url; } - else /* no username or password given */ - if ((s = strchr(url, ':'))) { /* portno is given */ - *(s++) = '\0'; - strncpy(ftp->server_name, url, MAXHOSTNAMELEN); - ftp->port = atoi(s); - } - else /* default case, no username, password, or portnumber */ - strncpy(ftp->server_name, url, MAXHOSTNAMELEN); + + /* q points to beginning of server name */ + if ((s = strchr(q, ':'))) { /* we have portno */ + *s++ = '\0'; + ftp->port = atoi(s); + } + + strncpy(ftp->server_name, q, MAXHOSTNAMELEN); ftp->user[63] = ftp->pass[255] = ftp->server_name[MAXHOSTNAMELEN] = 0;
_______________________________________________ Sent through the nmap-dev mailing list http://cgi.insecure.org/mailman/listinfo/nmap-dev Archived at http://SecLists.Org
Current thread:
- [PATCH] Rewrite (simplify) parse_bounce_argument() in nmap.cc Kris Katterjohn (Sep 06)