[CRIU] [PATCH] mnt: Devpts options get corrupted on dump

Pavel Emelyanov xemul at parallels.com
Fri May 30 04:30:37 PDT 2014


The memcpy() in devpts_dump() just overwrites part of them.
Fix this and move the whole code into sub-routine for future.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>

---

 mount.c | 35 +++++++++++++++++++++++------------
 1 file changed, 23 insertions(+), 12 deletions(-)

diff --git a/mount.c b/mount.c
index 1d960ae..f347f1e 100644
--- a/mount.c
+++ b/mount.c
@@ -559,15 +559,34 @@ out:
 	return -1;
 }
 
+static int attach_option(struct mount_info *pm, char *opt)
+{
+	char *buf;
+	int len, olen;
+
+	len = strlen(pm->options);
+	olen = strlen(opt);
+	buf = xrealloc(pm->options, len + olen + 2);
+	if (buf == NULL)
+		return -1;
+
+	if (len && buf[len - 1] != ',') {
+		buf[len] = ',';
+		len++;
+	}
+
+	memcpy(buf + len, opt, olen);
+	pm->options = buf;
+
+	return 0;
+}
+
 /* Is it mounted w or w/o the newinstance option */
 static int devpts_dump(struct mount_info *pm)
 {
-	static const char newinstance[] = ",newinstance";
 	struct stat *host_st;
 	struct stat st;
 	int fdir;
-	char *buf;
-	int len;
 
 	host_st = kerndat_get_devpts_stat();
 	if (host_st == NULL)
@@ -588,15 +607,7 @@ static int devpts_dump(struct mount_info *pm)
 	if (host_st->st_dev == st.st_dev)
 		return 0;
 
-	len = strlen(pm->options);
-	buf = xrealloc(pm->options, len + sizeof(newinstance));
-	if (buf == NULL)
-		return -1;
-	memcpy(buf, newinstance, sizeof(newinstance));
-
-	pm->options = buf;
-
-	return 0;
+	return attach_option(pm, "newinstance");
 }
 
 static int tmpfs_dump(struct mount_info *pm)
-- 
1.8.4.2


More information about the CRIU mailing list