aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2022-11-04 13:25:05 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2022-11-04 13:25:05 +0200
commit3f10635c2118b447453f431220a268929d6be393 (patch)
tree8de06561ee7a0a3ca16136956ee3e6994565c5d5
parentf29ad5d44e952ea47916e8cbf5a75296346327f6 (diff)
Detect in build.sh if installation directory is inside source
-rw-r--r--build.sh.in29
1 files changed, 20 insertions, 9 deletions
diff --git a/build.sh.in b/build.sh.in
index f9279b7..3dfb5be 100644
--- a/build.sh.in
+++ b/build.sh.in
@@ -461,19 +461,30 @@ if test -z "$idir"; then
if test -z "$sudo"; then
sudo="sudo"
fi
-elif test -n "$(echo "$idir" | sed -n 's#^[^/].*$#true#p')"; then
+else
+ if test -n "$(echo "$idir" | sed -n 's#^[^/].*$#true#p')"; then
+ if ! command -v realpath >/dev/null 2>&1; then
+ diag "error: unable to execute realpath: command not found"
+ diag " info: specify absolute installation directory path"
+ exit 1
+ fi
- if ! command -v realpath >/dev/null 2>&1; then
- diag "error: unable to execute realpath: command not found"
- diag " info: specify absolute installation directory path"
- exit 1
+ # Don't resolve symlinks and allow non-existent path components.
+ #
+ if ! idir="$(realpath -s -m "$idir" 2>/dev/null)"; then
+ diag "error: realpath does not recognize -s -m"
+ diag " info: specify absolute installation directory path"
+ exit 1
+ fi
fi
- # Don't resolve symlinks and allow non-existent path components.
+ # Check that it's not inside the build directory (we assume nobody
+ # is going to specify a path containing `#` or other special sed
+ # characters).
#
- if ! idir="$(realpath -s -m "$idir" 2>/dev/null)"; then
- diag "error: realpath does not recognize -s -m"
- diag " info: specify absolute installation directory path"
+ eowd="$(echo "$owd" | sed 's%\([#.*^$\\[\]]\)%\\\1%g')"
+ if test -n "$(echo "$idir/" | sed -n "s#^$eowd/.*#true#p")"; then
+ diag "error: installation directory is inside current directory"
exit 1
fi
fi