| Summary: | Whois using a non working host for queries by default | ||
|---|---|---|---|
| Product: | Busybox | Reporter: | Vito Mule <mulevito> |
| Component: | Networking | Assignee: | unassigned |
| Status: | RESOLVED FIXED | ||
| Severity: | normal | CC: | busybox-cvs, mulevito |
| Priority: | P2 | ||
| Version: | 1.24.x | ||
| Target Milestone: | --- | ||
| Hardware: | All | ||
| OS: | Linux | ||
| Host: | Target: | ||
| Build: | |||
| Attachments: |
patch to use a working whois default server
patch V2 to use a working whois default server patch V3 to use a working whois default server whois_fix_default_server_V4 whois_fix_default_server_V5 whois_fix_default_server_V6 whois_fix_default_server_V7 whois_fix_default_server_V8 whois_fix_default_server_V9 |
||
|
Description
Vito Mule
2016-07-04 16:23:09 UTC
Disregard my previous patch, this should work better.
I added some logic to use $domain.whois-servers.net as server based on the query's domain.
diff --git a/networking/whois.c b/networking/whois.c
index bf33033..9a73bbc 100644
--- a/networking/whois.c
+++ b/networking/whois.c
@@ -47,13 +47,32 @@ static void pipe_out(int fd)
int whois_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int whois_main(int argc UNUSED_PARAM, char **argv)
{
+
+ char *host = malloc(67 * sizeof(char));
+ char domain[49];
+ char* token;
+
int port = 43;
- const char *host = "whois-servers.net";
+ const char *unqualified_host = ".whois-servers.net";
opt_complementary = "-1:p+";
getopt32(argv, "h:p:", &host, &port);
-
argv += optind;
+
+ if (strlen(host) < 1) {
+ size_t query_len = strlen(*argv);
+ char *str_token = malloc(query_len * sizeof(char));
+ strncpy(str_token, *argv, query_len);
+
+ token = strtok(str_token, ".");
+ while (token != NULL) {
+ strcpy(domain, token);
+ token = strtok(NULL, ".");
+ }
+ strncpy(host, domain, strlen(domain));
+ strncat(host, unqualified_host, 18);
+ }
+
do {
int fd = create_and_connect_stream_or_die(host, port);
fdprintf(fd, "%s\r\n", *argv);
Created attachment 6506 [details]
patch V2 to use a working whois default server
fixed typos, stopped using strcpy, added a separate function to create the name for the whois server and also supporting, as it was before, more than one query at the time. Signed-off-by: vmule <mulevito@gmail.com> diff --git a/networking/whois.c b/networking/whois.c index bf33033..908a032 100644 --- a/networking/whois.c +++ b/networking/whois.c @@ -44,22 +44,56 @@ static void pipe_out(int fd) fclose(fp); /* closes fd too */ } +void whois_host(char* host, char *argv_host, const char *unqualified_host) +{ + char domain[49]; + char* token; + size_t query_len = strlen(argv_host); + char *str_token = malloc(query_len+1 * sizeof(char)); + + if (strlen(host) >= 1) { + memset(&host[0], 0, strlen(host)); + } + + strncpy(str_token, argv_host, query_len+1); + + token = strtok(str_token, "."); + while (token != NULL) { + strncpy(domain, token, strlen(token)+1); + token = strtok(NULL, "."); + } + strncpy(host, domain, strlen(domain)); + strncat(host, unqualified_host, 19); +} + int whois_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int whois_main(int argc UNUSED_PARAM, char **argv) { + + char *host = malloc(67 * sizeof(char)); int port = 43; - const char *host = "whois-servers.net"; + const char *unqualified_host = ".whois-servers.net"; opt_complementary = "-1:p+"; getopt32(argv, "h:p:", &host, &port); - argv += optind; - do { - int fd = create_and_connect_stream_or_die(host, port); - fdprintf(fd, "%s\r\n", *argv); - pipe_out(fd); + + if (strlen(host) < 1) { + do { + whois_host(host, *argv, unqualified_host); + int fd = create_and_connect_stream_or_die(host, port); + fdprintf(fd, "%s\r\n", *argv); + pipe_out(fd); + } + while (*++argv); + } else { + do { + int fd = create_and_connect_stream_or_die(host, port); + fdprintf(fd, "%s\r\n", *argv); + pipe_out(fd); + } + while (*++argv); } - while (*++argv); return EXIT_SUCCESS; } Created attachment 6511 [details]
patch V3 to use a working whois default server
Created attachment 6516 [details]
whois_fix_default_server_V4
Final Patch:
Dealing with names that are too long, respecting the length used by original whois, to avoid segfaults.
Created attachment 6521 [details]
whois_fix_default_server_V5
removed sizeof(char) and shorter code using strdup.
Thanks
Created attachment 6526 [details]
whois_fix_default_server_V6
minor fixes, added comment for func whois_host()
Created attachment 6531 [details]
whois_fix_default_server_V7
added bloat-o-meter output and name to the initial comments
Created attachment 6536 [details]
whois_fix_default_server_V8
Now whois server hostname is requested to "whois.iana.org" querying the tld.
This will improve toll resilience.
Created attachment 6546 [details]
whois_fix_default_server_V9
function old new delta
whois_server - 225 +225
whois_main 133 242 +109
WHOIS_HOST - 15 +15
pipe_out 85 - -85
------------------------------------------------------------------------------
(add/remove: 2/1 grow/shrink: 1/0 up/down: 349/-85) Total: 264 bytes
|