Blame SOURCES/libcgroup-0.41-prevent-buffer-overflow.patch

1c5b3f
From 9c80e2cb4bca26993a12027c46a274bb43645630 Mon Sep 17 00:00:00 2001
1c5b3f
From: =?UTF-8?q?Nikola=20Forr=C3=B3?= <nforro@redhat.com>
1c5b3f
Date: Wed, 22 Jun 2016 14:12:46 +0200
1c5b3f
Subject: [PATCH 3/6] api.c: fix potential buffer overflow
1c5b3f
MIME-Version: 1.0
1c5b3f
Content-Type: text/plain; charset=UTF-8
1c5b3f
Content-Transfer-Encoding: 8bit
1c5b3f
1c5b3f
It is assumed that arguments read from /proc/<pid>/cmdline don't exceed
1c5b3f
buf_pname buffer size, which is FILENAME_MAX - 1 characters, but that's
1c5b3f
not always the case.
1c5b3f
1c5b3f
Add check to prevent buffer overflow and discard the excessive part of
1c5b3f
an argument.
1c5b3f
1c5b3f
Signed-off-by: Nikola Forró <nforro@redhat.com>
1c5b3f
---
1c5b3f
 src/api.c | 6 +++++-
1c5b3f
 1 file changed, 5 insertions(+), 1 deletion(-)
1c5b3f
1c5b3f
diff --git a/src/api.c b/src/api.c
1c5b3f
index 217d6c9..4d98081 100644
1c5b3f
--- a/src/api.c
1c5b3f
+++ b/src/api.c
1c5b3f
@@ -4065,13 +4065,17 @@ static int cg_get_procname_from_proc_cmdline(pid_t pid,
1c5b3f
 
1c5b3f
 	while (c != EOF) {
1c5b3f
 		c = fgetc(f);
1c5b3f
-		if ((c != EOF) && (c != '\0')) {
1c5b3f
+		if ((c != EOF) && (c != '\0') && (len < FILENAME_MAX - 1)) {
1c5b3f
 			buf_pname[len] = c;
1c5b3f
 			len++;
1c5b3f
 			continue;
1c5b3f
 		}
1c5b3f
 		buf_pname[len] = '\0';
1c5b3f
 
1c5b3f
+		if (len == FILENAME_MAX - 1)
1c5b3f
+			while ((c != EOF) && (c != '\0'))
1c5b3f
+				c = fgetc(f);
1c5b3f
+
1c5b3f
 		/*
1c5b3f
 		 * The taken process name from /proc/<pid>/status is
1c5b3f
 		 * shortened to 15 characters if it is over. So the
1c5b3f
-- 
1c5b3f
2.17.0
1c5b3f