From 922b9be90ccce8f5b01339864f499f6d77505c5f Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Fri, 13 Dec 2013 12:31:00 -0500 Subject: [PATCH] chroot: sanitize path path was not being sanitized if it started with '/' causing chroot calls to fail when path ended with '/'. Signed-off-by: Andrew Gregory --- src/chroot.c | 3 +++ test/t/chroot.t | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/chroot.c b/src/chroot.c index 9e15ff5..7917a9a 100644 --- src/chroot.c +++ src/chroot.c @@ -76,6 +76,9 @@ else { if (*path == '/') { expand_chroot_rel_path(path); + strlcpy(tmp, path, FAKECHROOT_PATH_MAX); + dedotdot(tmpptr); + path = tmpptr; } else { snprintf(tmp, FAKECHROOT_PATH_MAX, "%s/%s", cwd, path); diff --git a/test/t/chroot.t b/test/t/chroot.t index e532a6f..286b863 100755 --- test/t/chroot.t +++ test/t/chroot.t @@ -14,7 +14,7 @@ for chroot in chroot fakechroot; do skip $(( $tap_plan / 2 )) "not root" else - for testtree in testtree2 /testtree2 ./testtree2 /./testtree2 testtree2/. testtree2/./.; do + for testtree in testtree2 /testtree2 ./testtree2 /./testtree2 testtree2/. testtree2/./. testtree2/; do t=`$srcdir/$chroot.sh testtree /usr/sbin/chroot $testtree /bin/cat /CHROOT 2>&1` test "$t" = "testtree/testtree2" || not ok "$chroot chroot $testtree:" $t -- 1.8.5.1