netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [iproute2 PATCH] Fix unterminated readlink() buffer usage
@ 2011-10-13  8:30 Thomas Jarosch
  2011-10-13 15:22 ` Stephen Hemminger
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas Jarosch @ 2011-10-13  8:30 UTC (permalink / raw)
  To: netdev; +Cc: Stephen Hemminger


Signed-off-by: Thomas Jarosch <thomas.jarosch@intra2net.com>
---
 misc/ss.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/misc/ss.c b/misc/ss.c
index b00841b..1353620 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -273,13 +273,19 @@ static void user_ent_hash_build(void)
 			unsigned int ino;
 			char lnk[64];
 			int fd;
+			ssize_t link_len;
 
 			if (sscanf(d1->d_name, "%d%c", &fd, &crap) != 1)
 				continue;
 
 			sprintf(name+pos, "%d", fd);
-			if (readlink(name, lnk, sizeof(lnk)-1) < 0 ||
-			    strncmp(lnk, pattern, strlen(pattern)))
+
+			link_len = readlink(name, lnk, sizeof(lnk)-1);
+			if (link_len == -1)
+				continue;
+			lnk[link_len] = '\0';
+
+			if (strncmp(lnk, pattern, strlen(pattern)))
 				continue;
 
 			sscanf(lnk, "socket:[%u]", &ino);
-- 
1.7.4.4

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

* Re: [iproute2 PATCH] Fix unterminated readlink() buffer usage
  2011-10-13  8:30 [iproute2 PATCH] Fix unterminated readlink() buffer usage Thomas Jarosch
@ 2011-10-13 15:22 ` Stephen Hemminger
  0 siblings, 0 replies; 2+ messages in thread
From: Stephen Hemminger @ 2011-10-13 15:22 UTC (permalink / raw)
  To: Thomas Jarosch; +Cc: netdev

On Thu, 13 Oct 2011 10:30:21 +0200
Thomas Jarosch <thomas.jarosch@intra2net.com> wrote:

> 
> Signed-off-by: Thomas Jarosch <thomas.jarosch@intra2net.com>

Applied thanks.

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

end of thread, other threads:[~2011-10-13 15:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-13  8:30 [iproute2 PATCH] Fix unterminated readlink() buffer usage Thomas Jarosch
2011-10-13 15:22 ` Stephen Hemminger

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).