fgets() reads in at most one less than size characters from stream, so no need
to account for the extra byte needed for the final '\0'. In fact, it was never
set to '\0' if fgets() did not do it.

Signed-off-by: Xabier Oneca <xon...@gmail.com>
---
 networking/whois.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/networking/whois.c b/networking/whois.c
index caa71ac..813b34f 100644
--- a/networking/whois.c
+++ b/networking/whois.c
@@ -54,7 +54,7 @@ static char *query(const char *host, int port, const
char *domain)

     success = 0;
     while (bufpos < 32*1024 /* paranoia */
-     && fgets(linebuf, sizeof(linebuf)-1, fp)
+     && fgets(linebuf, sizeof(linebuf), fp)
     ) {
         unsigned len;

-- 
2.7.4
From 54e0e60444e193e9d9cb3f6809188c03e0ac9d39 Mon Sep 17 00:00:00 2001
From: Xabier Oneca <xon...@gmail.com>
Date: Tue, 3 Dec 2019 15:36:24 +0100
Subject: [PATCH v2] whois: It is safe to tell fgets() the entire size of the buffer

fgets() reads in at most one less than size characters from stream, so no need
to account for the extra byte needed for the final '\0'. In fact, it was never
set to '\0' if fgets() did not do it.

Signed-off-by: Xabier Oneca <xon...@gmail.com>
---
 networking/whois.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/networking/whois.c b/networking/whois.c
index caa71ac..813b34f 100644
--- a/networking/whois.c
+++ b/networking/whois.c
@@ -54,7 +54,7 @@ static char *query(const char *host, int port, const char *domain)
 
 	success = 0;
 	while (bufpos < 32*1024 /* paranoia */
-	 && fgets(linebuf, sizeof(linebuf)-1, fp)
+	 && fgets(linebuf, sizeof(linebuf), fp)
 	) {
 		unsigned len;
 
-- 
2.7.4

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to