[CRIU] [PATCH 02/14] namespace: append a null byte after readlink

Andrey Vagin avagin at openvz.org
Tue Oct 14 04:38:16 PDT 2014


readlink() does not append a null byte to buf.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 namespaces.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/namespaces.c b/namespaces.c
index bd7d86e..8b45f5d 100644
--- a/namespaces.c
+++ b/namespaces.c
@@ -228,7 +228,7 @@ static unsigned int __get_ns_id(int pid, struct ns_desc *nd, struct ns_id **ns)
 		return 0;
 
 	sprintf(ns_path, "ns/%s", nd->str);
-	ret = readlinkat(proc_dir, ns_path, ns_id, sizeof(ns_id));
+	ret = readlinkat(proc_dir, ns_path, ns_id, sizeof(ns_id) - 1);
 	if (ret < 0) {
 		if (errno == ENOENT) {
 			/* The namespace is unsupported */
@@ -238,6 +238,7 @@ static unsigned int __get_ns_id(int pid, struct ns_desc *nd, struct ns_id **ns)
 		pr_perror("Can't readlink ns link");
 		return 0;
 	}
+	ns_id[ret] = '\0';
 
 	kid = parse_ns_link(ns_id, ret, nd);
 	BUG_ON(!kid);
-- 
1.9.3



More information about the CRIU mailing list