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