[CRIU] [PATCH] proc_parse: use the static buffer to parse mountinfo

Andrei Vagin avagin at openvz.org
Tue Oct 11 15:14:43 PDT 2016


From: Andrei Vagin <avagin at virtuozzo.com>

Currently a buffer is allocated on stack and its size is 1024.
Usually we use our static buffer to read proc files and its
size is 4096 (page size).

I know that this patch doesn't fix this problem completly,
it just does it less critical.

https://github.com/opencontainers/runc/issues/1070
Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 criu/proc_parse.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/criu/proc_parse.c b/criu/proc_parse.c
index 204c31e..6eb0c13 100644
--- a/criu/proc_parse.c
+++ b/criu/proc_parse.c
@@ -1409,7 +1409,6 @@ struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid, bool for_dump)
 {
 	struct mount_info *list = NULL;
 	FILE *f;
-	char str[1024];
 
 	f = fopen_proc(pid, "mountinfo");
 	if (!f) {
@@ -1417,7 +1416,7 @@ struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid, bool for_dump)
 		return NULL;
 	}
 
-	while (fgets(str, sizeof(str), f)) {
+	while (fgets(buf, BUF_SIZE, f)) {
 		struct mount_info *new;
 		int ret = -1;
 		char *fsname = NULL;
@@ -1428,9 +1427,9 @@ struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid, bool for_dump)
 
 		new->nsid = nsid;
 
-		ret = parse_mountinfo_ent(str, new, &fsname);
+		ret = parse_mountinfo_ent(buf, new, &fsname);
 		if (ret < 0) {
-			pr_err("Bad format in %d mountinfo: '%s'\n", pid, str);
+			pr_err("Bad format in %d mountinfo: '%s'\n", pid, buf);
 			goto end;
 		}
 
-- 
2.7.4



More information about the CRIU mailing list