nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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