Unverified Commit 3874902c by Christian Brauner Committed by Stéphane Graber

storage/overlay: do not write to invalid memory

Closes #1802. Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent c0b3869f
...@@ -109,9 +109,9 @@ int ovl_clonepaths(struct lxc_storage *orig, struct lxc_storage *new, const char ...@@ -109,9 +109,9 @@ int ovl_clonepaths(struct lxc_storage *orig, struct lxc_storage *new, const char
return -1; return -1;
} }
strncpy(delta, new->dest, lastslashidx + 1); memcpy(delta, new->dest, lastslashidx + 1);
strncpy(delta + lastslashidx, "delta0", sizeof("delta0") - 1); memcpy(delta + lastslashidx, "delta0", sizeof("delta0") - 1);
delta[lastslashidx + sizeof("delta0")] = '\0'; delta[lastslashidx + sizeof("delta0") - 1] = '\0';
ret = mkdir(delta, 0755); ret = mkdir(delta, 0755);
if (ret < 0 && errno != EEXIST) { if (ret < 0 && errno != EEXIST) {
...@@ -141,12 +141,13 @@ int ovl_clonepaths(struct lxc_storage *orig, struct lxc_storage *new, const char ...@@ -141,12 +141,13 @@ int ovl_clonepaths(struct lxc_storage *orig, struct lxc_storage *new, const char
return -1; return -1;
} }
strncpy(work, new->dest, lastslashidx + 1); memcpy(work, new->dest, lastslashidx + 1);
strncpy(work + lastslashidx, "olwork", sizeof("olwork") - 1); memcpy(work + lastslashidx, "olwork", sizeof("olwork") - 1);
work[lastslashidx + sizeof("olwork")] = '\0'; work[lastslashidx + sizeof("olwork") - 1] = '\0';
if (mkdir(work, 0755) < 0) { ret = mkdir(work, 0755);
SYSERROR("error: mkdir %s", work); if (ret < 0) {
SYSERROR("Failed to create directory \"%s\"", work);
free(delta); free(delta);
free(work); free(work);
return -1; return -1;
...@@ -253,9 +254,9 @@ int ovl_clonepaths(struct lxc_storage *orig, struct lxc_storage *new, const char ...@@ -253,9 +254,9 @@ int ovl_clonepaths(struct lxc_storage *orig, struct lxc_storage *new, const char
return -1; return -1;
} }
strncpy(work, ndelta, lastslashidx + 1); memcpy(work, ndelta, lastslashidx + 1);
strncpy(work + lastslashidx, "olwork", sizeof("olwork") - 1); memcpy(work + lastslashidx, "olwork", sizeof("olwork") - 1);
work[lastslashidx + sizeof("olwork")] = '\0'; work[lastslashidx + sizeof("olwork") - 1] = '\0';
ret = mkdir(work, 0755); ret = mkdir(work, 0755);
if (ret < 0 && errno != EEXIST) { if (ret < 0 && errno != EEXIST) {
...@@ -417,8 +418,8 @@ int ovl_create(struct lxc_storage *bdev, const char *dest, const char *n, ...@@ -417,8 +418,8 @@ int ovl_create(struct lxc_storage *bdev, const char *dest, const char *n,
return -1; return -1;
} }
strncpy(delta, dest, len); memcpy(delta, dest, len);
strncpy(delta + len - 6, "delta0", sizeof("delta0") - 1); memcpy(delta + len - 6, "delta0", sizeof("delta0") - 1);
delta[len + sizeof("delta0")] = '\0'; delta[len + sizeof("delta0")] = '\0';
ret = mkdir_p(delta, 0755); ret = mkdir_p(delta, 0755);
...@@ -575,9 +576,9 @@ int ovl_mount(struct lxc_storage *bdev) ...@@ -575,9 +576,9 @@ int ovl_mount(struct lxc_storage *bdev)
return -22; return -22;
} }
strncpy(work, upper, lastslashidx + 1); memcpy(work, upper, lastslashidx + 1);
strncpy(work + lastslashidx, "olwork", sizeof("olwork") - 1); memcpy(work + lastslashidx, "olwork", sizeof("olwork") - 1);
work[lastslashidx + sizeof("olwork")] = '\0'; work[lastslashidx + sizeof("olwork") - 1] = '\0';
ret = parse_mntopts(bdev->mntopts, &mntflags, &mntdata); ret = parse_mntopts(bdev->mntopts, &mntflags, &mntdata);
if (ret < 0) { if (ret < 0) {
...@@ -747,8 +748,9 @@ int ovl_mkdir(const struct mntent *mntent, const struct lxc_rootfs *rootfs, ...@@ -747,8 +748,9 @@ int ovl_mkdir(const struct mntent *mntent, const struct lxc_rootfs *rootfs,
char lxcpath[MAXPATHLEN]; char lxcpath[MAXPATHLEN];
char **opts; char **opts;
int ret; int ret;
size_t arrlen, dirlen, i, len, rootfslen; size_t arrlen, i, len, rootfslen;
int fret = -1; int fret = -1;
size_t dirlen = 0;
char *rootfs_dir = NULL, *rootfs_path = NULL, *upperdir = NULL, char *rootfs_dir = NULL, *rootfs_path = NULL, *upperdir = NULL,
*workdir = NULL; *workdir = NULL;
...@@ -772,8 +774,7 @@ int ovl_mkdir(const struct mntent *mntent, const struct lxc_rootfs *rootfs, ...@@ -772,8 +774,7 @@ int ovl_mkdir(const struct mntent *mntent, const struct lxc_rootfs *rootfs,
} }
if (rootfs_path) { if (rootfs_path) {
ret = ret = snprintf(lxcpath, MAXPATHLEN, "%s/%s", lxc_path, lxc_name);
snprintf(lxcpath, MAXPATHLEN, "%s/%s", lxc_path, lxc_name);
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= MAXPATHLEN)
goto err; goto err;
......
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