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

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