[PATCH] Fix off-by-one in nscd getservbyport call

Andreas Schwab schwab@suse.de
Mon Nov 11 11:35:00 GMT 2013


When nscd is in use, getservbyport ignores the protocol name when
looking up the key.  There are a few services where it matters, and it
also didn't return an error when the port/protocol combination isn't
defined.

Andreas.

	[BZ #16153]
	* nscd/nscd_getserv_r.c (__nscd_getservbyport_r): Don't include
	terminating NUL in key length.

diff --git a/nscd/nscd_getserv_r.c b/nscd/nscd_getserv_r.c
index c9c890c..7728258 100644
--- a/nscd/nscd_getserv_r.c
+++ b/nscd/nscd_getserv_r.c
@@ -54,7 +54,7 @@ __nscd_getservbyport_r (int port, const char *proto,
   portstr[sizeof (portstr) - 1] = '\0';
   char *cp = _itoa_word (port, portstr + sizeof (portstr) - 1, 10, 0);
 
-  return nscd_getserv_r (cp, portstr + sizeof (portstr) - cp, proto,
+  return nscd_getserv_r (cp, portstr + sizeof (portstr) - 1 - cp, proto,
 			 GETSERVBYPORT, result_buf, buf, buflen, result);
 }
 
-- 
1.8.4.3

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



More information about the Libc-alpha mailing list