summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Leigh <rleigh@debian.org>2012-10-29 20:04:10 +0000
committerRoger Leigh <rleigh@debian.org>2012-10-29 20:11:35 +0000
commit8e7001d539dfe6e9d34f7ab4e46b96eb87d8e766 (patch)
tree2baf5a9faeaad33854839542bbef98337d6fc676
parent55c2e9c48d203b0a576768b01498b306694d7813 (diff)
downloadschroot-8e7001d539dfe6e9d34f7ab4e46b96eb87d8e766.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 2cce127f..d2b24b39 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;
}