[syslinux:elflink] ldlinux: Perform chdir() before parsing config

syslinux-bot for Matt Fleming matt.fleming at intel.com
Wed Jan 16 04:27:05 PST 2013


Commit-ID:  d5e63aca6de51f9a70e9f78e2cc5ee3d32a18614
Gitweb:     http://www.syslinux.org/commit/d5e63aca6de51f9a70e9f78e2cc5ee3d32a18614
Author:     Matt Fleming <matt.fleming at intel.com>
AuthorDate: Wed, 16 Jan 2013 11:14:59 +0000
Committer:  Matt Fleming <matt.fleming at intel.com>
CommitDate: Wed, 16 Jan 2013 12:22:42 +0000

ldlinux: Perform chdir() before parsing config

The old 4.x behaviour for handling CONFIG directives of the form,

    CONFIG foo.cfg /bar

was to lookup the absolute pathname of foo.cfg, then chdir to /bar and
finally to parse foo.cfg. The 5.x behaviour reversed the chdir and
parsing steps. This meant if foo.cfg's contents were simply,

    INCLUDE say.txt

4.x would include /bar/say.txt and 5.x would include
/boot/syslinux/say.txt (assuming the current working directory was
/boot/syslinux).

What's even worse is that because of the way 'config_cwd' is used in
5.x we'd actually perform the chdir() operation after the first
INCLUDE in foo.cfg, e.g.

   INCLUDE say.txt
   INCLUDE say.txt

would include /boot/syslinux/say.txt and /bar/say.txt, respectively.

Signed-off-by: Matt Fleming <matt.fleming at intel.com>

---
 com32/elflink/ldlinux/readconfig.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/com32/elflink/ldlinux/readconfig.c b/com32/elflink/ldlinux/readconfig.c
index 156acf5..f4f599f 100644
--- a/com32/elflink/ldlinux/readconfig.c
+++ b/com32/elflink/ldlinux/readconfig.c
@@ -1356,15 +1356,15 @@ static int parse_one_config(const char *filename)
 	if (fd < 0)
 		return fd;
 
-	f = fdopen(fd, mode);
-	parse_config_file(f);
-
 	if (config_cwd[0]) {
 		if (chdir(config_cwd) < 0)
 			printf("Failed to chdir to %s\n", config_cwd);
 		config_cwd[0] = '\0';
 	}
 
+	f = fdopen(fd, mode);
+	parse_config_file(f);
+
 	return 0;
 }
 


More information about the Syslinux-commits mailing list