main: Allow escaped colons in directory paths

Allow directory paths specified for lowerdir, upperdir and workdir to
contain colon characters.

Previously, colons were unconditionally treated as separators,
making it impossible to use directories with colons in their names.

Closes: https://github.com/containers/fuse-overlayfs/issues/440

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2025-04-28 14:32:58 +02:00
parent b31d82ff8e
commit 27cabd561b
No known key found for this signature in database
GPG Key ID: 67E38F7A8BA21772
2 changed files with 58 additions and 5 deletions

55
main.c
View File

@ -1924,6 +1924,58 @@ cleanup_layerp (struct ovl_layer **p)
#define cleanup_layer __attribute__ ((cleanup (cleanup_layerp)))
static void
unescape (char *input)
{
char *dest = input;
if (input == NULL)
return;
for (; *input; input++)
{
if (*input == '\\')
continue;
*dest++ = *input;
}
*dest = '\0';
}
static char *
get_next_path (char *it, char **saveptr)
{
char *ret;
if (*saveptr == NULL)
*saveptr = it;
ret = *saveptr;
if (*ret == '\0')
return NULL;
while (1)
{
if (**saveptr == '\0')
break;
if (**saveptr == ':')
{
**saveptr = '\0';
(*saveptr)++;
break;
}
else if (**saveptr == '\\')
{
memmove (*saveptr, *saveptr + 1, strlen (*saveptr) + 1);
}
(*saveptr)++;
}
return ret;
}
static struct ovl_layer *
read_dirs (struct ovl_data *lo, char *path, bool low, struct ovl_layer *layers)
{
@ -1942,7 +1994,7 @@ read_dirs (struct ovl_data *lo, char *path, bool low, struct ovl_layer *layers)
while (last && last->next)
last = last->next;
for (it = strtok_r (buf, ":", &saveptr); it; it = strtok_r (NULL, ":", &saveptr))
for (it = get_next_path (buf, &saveptr); it; it = get_next_path (NULL, &saveptr))
{
char *name, *data;
char *it_path = it;
@ -5755,6 +5807,7 @@ main (int argc, char *argv[])
if (lo.mountpoint == NULL)
error (EXIT_FAILURE, 0, "no mountpoint specified");
unescape (lo.workdir);
set_limits ();
check_can_mknod (&lo);

View File

@ -2,17 +2,17 @@
set -xeuo pipefail
mkdir lower upper workdir merged
mkdir lower:1 upper:2 workdir:3 merged
fuse-overlayfs -o sync=0,lowerdir=lower,upperdir=upper,workdir=workdir,suid,dev merged
fuse-overlayfs -o 'sync=0,lowerdir=lower\\:1,upperdir=upper\\:2,workdir=workdir\\:3,suid,dev' merged
docker run --rm -v $(pwd)/merged:/merged fedora dnf --use-host-config --installroot /merged --releasever 41 install -y glibc-common gedit
umount merged
# Make sure workdir is empty, and move the upper layer down
rm -rf workdir lower
mv upper lower
rm -rf lower:1 workdir:3
mv upper:2 lower
mkdir upper workdir
gcc -static -o suid-test $(dirname $0)/suid-test.c