Commit c75b7ab6 authored by Pavel Emelyanov's avatar Pavel Emelyanov

mnt: Devpts options get corrupted on dump (v2)

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

v2: Fix off-by-one error spotted by Filipe.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
Acked-by: 's avatarFilipe Brandenburger <filbranden@google.com>
parent 06f559fc
...@@ -559,15 +559,34 @@ out: ...@@ -559,15 +559,34 @@ out:
return -1; 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 + 1);
pm->options = buf;
return 0;
}
/* Is it mounted w or w/o the newinstance option */ /* Is it mounted w or w/o the newinstance option */
static int devpts_dump(struct mount_info *pm) static int devpts_dump(struct mount_info *pm)
{ {
static const char newinstance[] = ",newinstance";
struct stat *host_st; struct stat *host_st;
struct stat st; struct stat st;
int fdir; int fdir;
char *buf;
int len;
host_st = kerndat_get_devpts_stat(); host_st = kerndat_get_devpts_stat();
if (host_st == NULL) if (host_st == NULL)
...@@ -588,15 +607,7 @@ static int devpts_dump(struct mount_info *pm) ...@@ -588,15 +607,7 @@ static int devpts_dump(struct mount_info *pm)
if (host_st->st_dev == st.st_dev) if (host_st->st_dev == st.st_dev)
return 0; return 0;
len = strlen(pm->options); return attach_option(pm, "newinstance");
buf = xrealloc(pm->options, len + sizeof(newinstance));
if (buf == NULL)
return -1;
memcpy(buf, newinstance, sizeof(newinstance));
pm->options = buf;
return 0;
} }
static int tmpfs_dump(struct mount_info *pm) static int tmpfs_dump(struct mount_info *pm)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment