dcavalca / rpms / grub2

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