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:04:10 +0000
commit4fcfb7141e45a5e7ca8a9b1f6297ad9885efe16d (patch)
tree7b9b779c26272cc611024460ca34f121b48ffc38
parent5fbab5b020922a454a1a8824ee6920e0ea26e088 (diff)
downloadschroot-4fcfb7141e45a5e7ca8a9b1f6297ad9885efe16d.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;
}