[CRIU] [PATCH 4/9] read_ns_sys_file(): check if buf is long enough

Kir Kolyshkin kir at openvz.org
Wed Oct 7 02:44:19 PDT 2015


In case buf size is not adequate, report and return an error.
This is modelled after commit 1ead3d7.

Signed-off-by: Kir Kolyshkin <kir at openvz.org>
---
 net.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/net.c b/net.c
index 08ef865..ef73d0b 100644
--- a/net.c
+++ b/net.c
@@ -45,6 +45,11 @@ int read_ns_sys_file(char *path, char *buf, int len)
 	rlen = read(fd, buf, len);
 	close(fd);
 
+	if (rlen == len) {
+		pr_err("Too small buffer to read ns sys file %s\n", path);
+		return -1;
+	}
+
 	if (rlen > 0)
 		buf[rlen - 1] = '\0';
 
-- 
2.4.3



More information about the CRIU mailing list