lxc.rootfs: support multiple lower layers

Do it in a safe way by using strstr() to check for the substring ":/" should
':' be part of a pathname. This should be a safer implementation than the one
originally suggested in #547.

Signed-off-by: Christian Brauner <christian.brauner@mailbox.org>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
This commit is contained in:
Christian Brauner 2016-01-20 01:02:59 +01:00 committed by Stéphane Graber
parent f267d6668e
commit 9208af160e

View File

@ -309,7 +309,7 @@ char *ovl_getlower(char *p)
int ovl_mount(struct bdev *bdev)
{
char *options, *dup, *lower, *upper;
char *tmp, *options, *dup, *lower, *upper;
char *options_work, *work, *lastslash;
int lastslashidx;
int len, len2;
@ -331,9 +331,15 @@ int ovl_mount(struct bdev *bdev)
*/
dup = alloca(strlen(bdev->src) + 1);
strcpy(dup, bdev->src);
if (!(lower = strchr(dup, ':')))
return -22;
if (!(upper = strchr(++lower, ':')))
/* support multiple lower layers */
if (!(lower = strstr(dup, ":/")))
return -22;
lower++;
upper = lower;
while ((tmp = strstr(++upper, ":/"))) {
upper = tmp;
}
if (--upper == lower)
return -22;
*upper = '\0';
upper++;