mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] drop unused extra char from getnameinfo() local buffer
@ 2019-06-28  0:54 Andre McCurdy
  2019-06-28 15:13 ` Rich Felker
  0 siblings, 1 reply; 3+ messages in thread
From: Andre McCurdy @ 2019-06-28  0:54 UTC (permalink / raw)
  To: musl; +Cc: Andre McCurdy

The num local buffer is only passed to itoa(), which expects a buffer
size of 3*sizeof(int), not 3*sizeof(int)+1. Also change the data type
of the port local variable to clarify that itoa() only handles
unsigned values.
---
 src/network/getnameinfo.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/network/getnameinfo.c b/src/network/getnameinfo.c
index f77e73a..02c2c09 100644
--- a/src/network/getnameinfo.c
+++ b/src/network/getnameinfo.c
@@ -124,7 +124,7 @@ int getnameinfo(const struct sockaddr *restrict sa, socklen_t sl,
 	int flags)
 {
 	char ptr[PTR_MAX];
-	char buf[256], num[3*sizeof(int)+1];
+	char buf[256], num[3*sizeof(int)];
 	int af = sa->sa_family;
 	unsigned char *a;
 	unsigned scopeid;
@@ -184,7 +184,7 @@ int getnameinfo(const struct sockaddr *restrict sa, socklen_t sl,
 
 	if (serv && servlen) {
 		char *p = buf;
-		int port = ntohs(((struct sockaddr_in *)sa)->sin_port);
+		unsigned port = ntohs(((struct sockaddr_in *)sa)->sin_port);
 		buf[0] = 0;
 		if (!(flags & NI_NUMERICSERV))
 			reverse_services(buf, port, flags & NI_DGRAM);
-- 
1.9.1



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-06-28 19:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-28  0:54 [PATCH] drop unused extra char from getnameinfo() local buffer Andre McCurdy
2019-06-28 15:13 ` Rich Felker
2019-06-28 19:24   ` Andre McCurdy

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).