aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-09-04 14:48:00 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2018-09-04 14:48:00 +0200
commit3d6f95ede6e98cd245cfbdc4c429a184f6c0d717 (patch)
tree5b44abec395055fc861ad07bd4f8a2a7acdb1caf
parent8f1ae256347b32057d32846f915f53f9106f00bc (diff)
downloadbusybox-w32-3d6f95ede6e98cd245cfbdc4c429a184f6c0d717.tar.gz
busybox-w32-3d6f95ede6e98cd245cfbdc4c429a184f6c0d717.tar.bz2
busybox-w32-3d6f95ede6e98cd245cfbdc4c429a184f6c0d717.zip
whois: fix a possible out-of-bounds stack access
If fgets() returns incomplete string, we replace NUL with '\n', and then trim() runs on a non-NUL-terminated buffer. Prevent that. While at it, bump buffer from 1k to 2k. function old new delta query 519 524 +5 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/whois.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/networking/whois.c b/networking/whois.c
index f0ec86301..f3da32b4e 100644
--- a/networking/whois.c
+++ b/networking/whois.c
@@ -39,20 +39,26 @@ static char *query(const char *host, int port, const char *domain)
39 bool success; 39 bool success;
40 char *redir = NULL; 40 char *redir = NULL;
41 const char *pfx = ""; 41 const char *pfx = "";
42 char linebuf[1024]; 42 /* some .io domains reported to have very long strings in whois
43 * responses, 1k was not enough:
44 */
45 char linebuf[2 * 1024];
43 char *buf = NULL; 46 char *buf = NULL;
44 unsigned bufpos = 0; 47 unsigned bufpos = 0;
45 48
46 again: 49 again:
47 printf("[Querying %s:%d '%s%s']\n", host, port, pfx, domain); 50 printf("[Querying %s:%d '%s%s']\n", host, port, pfx, domain);
48 fd = create_and_connect_stream_or_die(host, port); 51 fd = create_and_connect_stream_or_die(host, port);
49 success = 0;
50 fdprintf(fd, "%s%s\r\n", pfx, domain); 52 fdprintf(fd, "%s%s\r\n", pfx, domain);
51 fp = xfdopen_for_read(fd); 53 fp = xfdopen_for_read(fd);
52 54
53 while (fgets(linebuf, sizeof(linebuf), fp)) { 55 success = 0;
54 unsigned len = strcspn(linebuf, "\r\n"); 56 while (fgets(linebuf, sizeof(linebuf)-1, fp)) {
57 unsigned len;
58
59 len = strcspn(linebuf, "\r\n");
55 linebuf[len++] = '\n'; 60 linebuf[len++] = '\n';
61 linebuf[len] = '\0';
56 62
57 buf = xrealloc(buf, bufpos + len + 1); 63 buf = xrealloc(buf, bufpos + len + 1);
58 memcpy(buf + bufpos, linebuf, len); 64 memcpy(buf + bufpos, linebuf, len);