diff mbox

[iproute2] Fix unterminated readlink() buffer usage

Message ID 201110131030.21723.thomas.jarosch@intra2net.com
State Accepted, archived
Delegated to: stephen hemminger
Headers show

Commit Message

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

Comments

stephen hemminger Oct. 13, 2011, 3:22 p.m. UTC | #1
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.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

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