Skip to content

Commit 2f10c30

Browse files
committed
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: #440 Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
1 parent 5dd4a01 commit 2f10c30

File tree

2 files changed

+54
-5
lines changed

2 files changed

+54
-5
lines changed

main.c

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1924,6 +1924,54 @@ cleanup_layerp (struct ovl_layer **p)
19241924

19251925
#define cleanup_layer __attribute__ ((cleanup (cleanup_layerp)))
19261926

1927+
static void
1928+
unescape (char *input)
1929+
{
1930+
char *dest = input;
1931+
for (; *input; input++)
1932+
{
1933+
if (*input == '\\')
1934+
continue;
1935+
1936+
*dest++ = *input;
1937+
}
1938+
*dest = '\0';
1939+
}
1940+
1941+
static char *
1942+
get_next_path (char *it, char **saveptr)
1943+
{
1944+
char *ret;
1945+
1946+
if (*saveptr == NULL)
1947+
*saveptr = it;
1948+
1949+
ret = *saveptr;
1950+
1951+
if (*ret == '\0')
1952+
return NULL;
1953+
1954+
while (1)
1955+
{
1956+
if (**saveptr == '\0')
1957+
break;
1958+
1959+
if (**saveptr == ':')
1960+
{
1961+
**saveptr = '\0';
1962+
(*saveptr)++;
1963+
break;
1964+
}
1965+
else if (**saveptr == '\\')
1966+
{
1967+
memmove (*saveptr, *saveptr + 1, strlen (*saveptr) + 1);
1968+
}
1969+
1970+
(*saveptr)++;
1971+
}
1972+
return ret;
1973+
}
1974+
19271975
static struct ovl_layer *
19281976
read_dirs (struct ovl_data *lo, char *path, bool low, struct ovl_layer *layers)
19291977
{
@@ -1942,7 +1990,7 @@ read_dirs (struct ovl_data *lo, char *path, bool low, struct ovl_layer *layers)
19421990
while (last && last->next)
19431991
last = last->next;
19441992

1945-
for (it = strtok_r (buf, ":", &saveptr); it; it = strtok_r (NULL, ":", &saveptr))
1993+
for (it = get_next_path (buf, &saveptr); it; it = get_next_path (NULL, &saveptr))
19461994
{
19471995
char *name, *data;
19481996
char *it_path = it;
@@ -5755,6 +5803,7 @@ main (int argc, char *argv[])
57555803
if (lo.mountpoint == NULL)
57565804
error (EXIT_FAILURE, 0, "no mountpoint specified");
57575805

5806+
unescape (lo.workdir);
57585807

57595808
set_limits ();
57605809
check_can_mknod (&lo);

tests/fedora-installs.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
set -xeuo pipefail
44

5-
mkdir lower upper workdir merged
5+
mkdir lower:1 upper:2 workdir:3 merged
66

7-
fuse-overlayfs -o sync=0,lowerdir=lower,upperdir=upper,workdir=workdir,suid,dev merged
7+
fuse-overlayfs -o 'sync=0,lowerdir=lower\\:1,upperdir=upper\\:2,workdir=workdir\\:3,suid,dev' merged
88

99
docker run --rm -v $(pwd)/merged:/merged fedora dnf --use-host-config --installroot /merged --releasever 41 install -y glibc-common gedit
1010

1111
umount merged
1212

1313
# Make sure workdir is empty, and move the upper layer down
14-
rm -rf workdir lower
15-
mv upper lower
14+
rm -rf lower:1 workdir:3
15+
mv upper:2 lower
1616
mkdir upper workdir
1717

1818
gcc -static -o suid-test $(dirname $0)/suid-test.c

0 commit comments

Comments
 (0)