[PATCH 1/4] convert_abs_rel() fixups

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



- IFS was not preserved, and modified value could leak to outside functions

- the '.' relative path should be returned for arguments such as /x/y/z
  /x/y - but not for $1 == $2 ones

- $1 == $2 is self-looping link, so it returns final component of its
  name

Signed-off-by: Michal Soltys <soltys@xxxxxxxx>
---
 dracut-functions |   18 +++++++++++-------
 1 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/dracut-functions b/dracut-functions
index c4f7f61..12dfa70 100755
--- a/dracut-functions
+++ b/dracut-functions
@@ -91,20 +91,24 @@ normalize_path() {
 }
 
 convert_abs_rel() {
-    local __current __absolute __abssize __cursize __i __level __newpath
+    local __current __absolute __abssize __cursize __newpath="" __oldifs
+    local -i __i __level=0
 #    PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ';
 
-    if [[ "$1" == "$2" ]]
-    then
-        echo "."
-        return
-    fi
+    # corner case #1 - self looping link
+    [[ "$1" == "$2" ]] && { echo "${1##*/}"; return; }
+
+    # corner case #2 - own dir link
+    [[ "${1%/*}" == "$2" ]] && { echo "."; return; }
+
     __current=$(normalize_path "$1")
     __absolute=$(normalize_path "$2")
-    IFS="/"
 
+    __oldifs="$IFS"
+    IFS="/"
     __current=($__current)
     __absolute=($__absolute)
+    IFS="$__oldifs"
 
     __abssize=${#__absolute[@]}
     __cursize=${#__current[@]}
-- 
1.7.5.3

--
To unsubscribe from this list: send the line "unsubscribe initramfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux