zshenv: avoid placing empty components in PATH; reorder root's PATH
authorDr. András Korn <korn-github.com@elan.rulez.org>
Mon, 1 Jun 2015 09:12:40 +0000 (11:12 +0200)
committerMichael Prokop <mika@grml.org>
Wed, 3 Jun 2015 22:07:21 +0000 (00:07 +0200)
zsh treats an empty PATH component ("::") as ".", which creates a
security hole. Sanitize PATH by explicitly removing empty
components.

As agreed on #grml, root's PATH should also list /usr/local/sbin
and /usr/local/bin before /sbin, /bin, /usr/sbin and /usr/bin;
and there is no harm in adding $HOME/bin unconditionally as the
first PATH component.

etc/zsh/zshenv

index 954ca38..d696b56 100644 (file)
@@ -90,17 +90,21 @@ if (( EUID != 0 )); then
   )
 else
   path=(
+    $HOME/bin
+    /usr/local/sbin
+    /usr/local/bin
     /sbin
     /bin
     /usr/sbin
     /usr/bin
-    /usr/local/sbin
-    /usr/local/bin
     "${ADDONS}"
     "${path[@]}"
   )
 fi
 
+# remove empty components to avoid '::' ending up + resulting in './' being in $PATH
+path=( "${path[@]:#}" )
+
 typeset -U path
 
 # less (:=pager) options: