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 55e1de9..ee575a4 100644 --- a/networking/whois.c +++ b/networking/whois.c @@ -53,7 +53,7 @@ static char *query(const char *host, int port, const char *domain) fp = xfdopen_for_read(fd); success = 0; - while (fgets(linebuf, sizeof(linebuf)-1, fp)) { + while (fgets(linebuf, sizeof(linebuf), fp)) { unsigned len; len = strcspn(linebuf, "\r\n"); -- 2.7.4 Cheers, Xabier Oneca_,,_
From a7788f900f9f9de279bddcfc50bfb1fbd5cd77bb Mon Sep 17 00:00:00 2001 From: Xabier Oneca <xon...@mugicloud.com> Date: Tue, 3 Dec 2019 08:50:39 +0100 Subject: [PATCH] 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 55e1de9..ee575a4 100644 --- a/networking/whois.c +++ b/networking/whois.c @@ -53,7 +53,7 @@ static char *query(const char *host, int port, const char *domain) fp = xfdopen_for_read(fd); success = 0; - while (fgets(linebuf, sizeof(linebuf)-1, fp)) { + while (fgets(linebuf, sizeof(linebuf), fp)) { unsigned len; len = strcspn(linebuf, "\r\n"); -- 2.7.4
_______________________________________________ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox