Blame SOURCES/0104-editenv-handle-relative-symlinks.patch

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