changeset 648:cd4aea87dbfa

common.subr: Enhance parameter check for "_get_jail_from_path()". Now checks for absolute paths are done and trailing slashes are handled.
author Franz Glasner <fzglas.hg@dom66.de>
date Fri, 27 Sep 2024 20:35:34 +0200
parents b0e8b5cf5d33
children 4ee9a8042f4a
files share/local-bsdtools/common.subr
diffstat 1 files changed, 24 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/share/local-bsdtools/common.subr	Fri Sep 27 19:17:21 2024 +0200
+++ b/share/local-bsdtools/common.subr	Fri Sep 27 20:35:34 2024 +0200
@@ -321,7 +321,30 @@
     local _name _path _dying
 
     _location="${1-}"
-    [ -z "${_location}" ] && { echo "ERROR: no mountpoint given" 1>&2; return 1; }
+    case "${_location}" in
+        '')
+            err "no mountpoint given"
+            return 1
+            ;;
+        /)
+            true
+            ;;
+        *//*)
+            err "given directory must not contain consequtive slashes"
+            return 1
+            ;;
+        /*/)
+            # Remove trailing slash
+            _location="${_location%/}"
+            ;;
+        /*)
+            true
+            ;;
+        *)
+            err "given directory path must be an absolute path"
+            return 1
+            ;;
+    esac
 
     if [ -x "${JQ}" ]; then
         /usr/sbin/jls --libxo=json,no-locale -d dying name path \