proc_parse: use the static buffer to parse mountinfo

Submitted by Andrei Vagin on Oct. 11, 2016, 10:14 p.m.

Details

Message ID 1476224083-3549-1-git-send-email-avagin@openvz.org
State Superseded
Series "proc_parse: use the static buffer to parse mountinfo"
Headers show

Commit Message

Andrei Vagin Oct. 11, 2016, 10:14 p.m.
From: Andrei Vagin <avagin@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@virtuozzo.com>
---
 criu/proc_parse.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

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

Comments

Pavel Emelianov Oct. 13, 2016, 12:09 p.m.
Applied, thanks