[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH] whois: It is safe to tell fgets() the entire size of the buffer
From:       Xabier Oneca  --  xOneca <xoneca () gmail ! com>
Date:       2019-12-03 7:59:51
Message-ID: CACkgH70rv5-MHtn_V6sK43-CCB18jaCKkw7AjF9-EhVBJsfDzA () mail ! gmail ! com
[Download RAW message or body]

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 <xoneca@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_,,_

["0001-whois-It-is-safe-to-tell-fgets-the-entire-size-of-th.patch" (text/x-patch)]

From a7788f900f9f9de279bddcfc50bfb1fbd5cd77bb Mon Sep 17 00:00:00 2001
From: Xabier Oneca <xoneca@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 <xoneca@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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic