From 9778fafba22ec67f97bb35a34980230966ebe0de Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Mon, 14 Aug 2017 14:37:20 -0400 Subject: [PATCH 191/229] editenv: handle relative symlinks Handle symlinks with targets relative to the containing dir. This ensures that the rename operation does not depend on the cwd. Resolves: rhbz#1479960 Signed-off-by: Jonathan Lebon --- util/editenv.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/util/editenv.c b/util/editenv.c index d8d1dad6ab9..41bc7cb1c9a 100644 --- a/util/editenv.c +++ b/util/editenv.c @@ -28,6 +28,7 @@ #include #include +#include #define DEFAULT_ENVBLK_SIZE 1024 @@ -87,9 +88,20 @@ grub_util_create_envblk_file (const char *name) continue; } - free (rename_target); linkbuf[retsize] = '\0'; - rename_target = linkbuf; + if (linkbuf[0] == '/') + { + free (rename_target); + rename_target = linkbuf; + } + else + { + char *dbuf = xstrdup (rename_target); + const char *dir = dirname (dbuf); + free (rename_target); + rename_target = xasprintf("%s/%s", dir, linkbuf); + free (dbuf); + } } int rc = grub_util_rename (namenew, rename_target); -- 2.15.0