From 9f2f979bcf7bfd6cef08c17b5a432444ac8603dc Mon Sep 17 00:00:00 2001 From: Andrey Borzenkov Date: Tue, 10 Dec 2013 09:55:27 +0400 Subject: [PATCH] always define config_directory and config_file as full pathname If configfile is relative pathname, extend it with current ($root) so its interpretation does not change if $root is changed later. Suggested by Vladimir Serbienko. --- grub-core/normal/main.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c index 991a59524..84df3601f 100644 --- a/grub-core/normal/main.c +++ b/grub-core/normal/main.c @@ -190,14 +190,26 @@ read_config_file (const char *config) ctmp = grub_env_get ("config_directory"); if (ctmp) old_dir = grub_strdup (ctmp); - grub_env_set ("config_file", config); - config_dir = grub_strdup (config); + if (*config == '(') + { + grub_env_set ("config_file", config); + config_dir = grub_strdup (config); + } + else + { + /* $root is guranteed to be defined, otherwise open above would fail */ + config_dir = grub_xasprintf ("(%s)%s", grub_env_get ("root"), config); + if (config_dir) + grub_env_set ("config_file", config_dir); + } if (config_dir) - ptr = grub_strrchr (config_dir, '/'); - if (ptr) - *ptr = 0; - grub_env_set ("config_directory", config_dir); - grub_free (config_dir); + { + ptr = grub_strrchr (config_dir, '/'); + if (ptr) + *ptr = 0; + grub_env_set ("config_directory", config_dir); + grub_free (config_dir); + } grub_env_export ("config_file"); grub_env_export ("config_directory");