summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Leigh <rleigh@debian.org>2012-10-29 20:04:10 +0000
committerRoger Leigh <rleigh@debian.org>2013-01-04 23:58:07 +0000
commit80c94fef9690476eab8dba52dd57010479594bc1 (patch)
treec060fa4d4308bc154b2eff003814ab3c92c37889
parent75634db9e080f3731486cfaf7f3bd899cf0456da (diff)
downloadschroot-80c94fef9690476eab8dba52dd57010479594bc1.tar.gz
schroot-mount: Canonicalise base path
In order to correctly compare the base path and full path, both paths require canonicalising.
-rw-r--r--bin/schroot-mount/schroot-mount-main.cc14
1 files changed, 10 insertions, 4 deletions
diff --git a/bin/schroot-mount/schroot-mount-main.cc b/bin/schroot-mount/schroot-mount-main.cc
index 0cf2eeef..52c39a02 100644
--- a/bin/schroot-mount/schroot-mount-main.cc
+++ b/bin/schroot-mount/schroot-mount-main.cc
@@ -96,9 +96,15 @@ main::resolve_path (std::string const& mountpoint)
if (absmountpoint.empty() || absmountpoint[0] != '/')
absmountpoint = std::string("/") + absmountpoint;
+ char *resolved_path = realpath(opts->mountpoint.c_str(), 0);
+ if (!resolved_path)
+ throw error(opts->mountpoint, REALPATH, strerror(errno));
+ std::string basepath(resolved_path);
+ std::free(resolved_path);
+
std::string directory(opts->mountpoint + absmountpoint);
// Canonicalise path to remove any symlinks.
- char *resolved_path = realpath(directory.c_str(), 0);
+ resolved_path = realpath(directory.c_str(), 0);
if (resolved_path == 0)
{
// The path is either not present or is an invalid link. If
@@ -137,9 +143,9 @@ main::resolve_path (std::string const& mountpoint)
// If the link was absolute (i.e. points somewhere on the host,
// outside the chroot, make sure that this is modified to be
// inside.
- if (directory.size() < opts->mountpoint.size() ||
- directory.substr(0,opts->mountpoint.size()) != opts->mountpoint)
- directory = opts->mountpoint + directory;
+ if (directory.size() < basepath.size() ||
+ directory.substr(0,basepath.size()) != basepath)
+ directory = basepath + directory;
return directory;
}