]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
inst_dir: fix handling of relative symlinks outside the current dir
authorWill Woods <wwoods@redhat.com>
Tue, 8 Mar 2011 23:35:12 +0000 (18:35 -0500)
committerHarald Hoyer <harald@redhat.com>
Wed, 9 Mar 2011 11:09:10 +0000 (12:09 +0100)
inst_dir used the following to try to resolve a relative path:
  [[ $target = ${target##*/} ]] && target="${file%/*}/$target"
  inst_dir $target

This will only match if $target has no slashes, so something like
/usr/bin -> ../sbin would result in: inst_dir ../sbin, or
/usr/share -> local/share would result in: inst_dir local/share
which is not going to do the right thing.

Instead, we resolve any non-absolute link, like so:
  [[ $target == ${target#/} ]] && target=$(dirname "$file")/$target
Thus /usr/bin -> ../sbin results in: inst_dir /usr/../sbin, and
/usr/share -> local/share results in: inst_dir /usr/local/share
which is what you would expect.

dracut-functions

index 594cc0e281fd397f353e473a10192f515da6ae7e..e321dc98e6089d222475990ceb76c42b5204b4ee 100755 (executable)
@@ -240,8 +240,8 @@ inst_dir() {
             # create link as the original
             local target=$(readlink "$file")
             ln -sfn "$target" "${initdir}$file" || return 1
-            # resolve relative path and recursively install destionation
-            [[ $target = ${target##*/} ]] && target="${file%/*}/$target"
+            # resolve relative path and recursively install destination
+            [[ $target == ${target#/} ]] && target=$(dirname "$file")/$target
             inst_dir "$target"
         else
             # create directory