nalika / rpms / grub2

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