[syslinux:elflink] elflink: Use CurrentDirName for initial PATH if valid

syslinux-bot for Matt Fleming matt.fleming at intel.com
Thu Feb 7 10:57:02 PST 2013


Commit-ID:  282fe9da42ebb0c34cf4256972a8c07ba5542e23
Gitweb:     http://www.syslinux.org/commit/282fe9da42ebb0c34cf4256972a8c07ba5542e23
Author:     Matt Fleming <matt.fleming at intel.com>
AuthorDate: Thu, 7 Feb 2013 17:56:24 +0000
Committer:  Matt Fleming <matt.fleming at intel.com>
CommitDate: Thu, 7 Feb 2013 18:09:13 +0000

elflink: Use CurrentDirName for initial PATH if valid

commit c250a42263c8 ("elflink: Set PATH to the directory containing
ldlinux.c32") made the mistake of thinking that CurrentDirName doesn't
contain useful data for PXELINUX, it may do. If a user specifies a
Path Prefix (DHCP option 210) we enter load_env32() with that path as
the current working directory. If that path is thrown away instead of
being used for PATH we may fail to load a config file as specified
with Configuration File Option (DHCP option 209).

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

---
 com32/lib/Makefile        |  4 ++--
 core/elflink/load_env32.c | 31 +++++++++++++++++++++----------
 2 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/com32/lib/Makefile b/com32/lib/Makefile
index 49a3aaf..a225f6f 100644
--- a/com32/lib/Makefile
+++ b/com32/lib/Makefile
@@ -120,7 +120,7 @@ LIBOTHER_OBJS = \
 	lrand48.o stack.o memccpy.o memchr.o 		\
 	mempcpy.o memmem.o memmove.o memswap.o	\
 	perror.o qsort.o seed48.o \
-	srand48.o sscanf.o strcasecmp.o strcat.o	\
+	srand48.o sscanf.o strcasecmp.o 				\
 	strerror.o errlist.o		\
 	strnlen.o							\
 	strncat.o strndup.o		\
@@ -171,7 +171,7 @@ CORELIBOBJS = \
 	fputs.o fwrite2.o fwrite.o fgetc.o fclose.o errno.o lmalloc.o 	\
 	sys/err_read.o sys/err_write.o sys/null_read.o 			\
 	sys/stdcon_write.o						\
-	syslinux/memscan.o strrchr.o					\
+	syslinux/memscan.o strrchr.o strcat.o				\
 	libgcc/__ashldi3.o libgcc/__udivdi3.o				\
 	libgcc/__negdi2.o libgcc/__ashrdi3.o libgcc/__lshrdi3.o		\
 	libgcc/__muldi3.o libgcc/__udivmoddi4.o libgcc/__umoddi3.o	\
diff --git a/core/elflink/load_env32.c b/core/elflink/load_env32.c
index 3ddbfec..c84582d 100644
--- a/core/elflink/load_env32.c
+++ b/core/elflink/load_env32.c
@@ -142,10 +142,9 @@ void load_env32(com32sys_t * regs __unused)
 	 * a bit harder to find LDLINUX. If search_dirs() succeeds
 	 * in finding LDLINUX it will set the cwd.
 	 */
-	free(PATH);
 	fd = opendev(&__file_dev, NULL, O_RDONLY);
 	if (fd < 0)
-		return;
+		goto out;
 
 	fp = &__file_info[fd];
 
@@ -154,24 +153,36 @@ void load_env32(com32sys_t * regs __unused)
 
 		/*
 		 * search_dirs() sets the current working directory if
-		 * it successfully opens the file. Set PATH to the
-		 * directory in which we found ldlinux.c32.
+		 * it successfully opens the file. Add the directory
+		 * in which we found ldlinux.c32 to PATH.
 		 */
 		if (!core_getcwd(path, sizeof(path)))
 			goto out;
 
-		PATH = malloc(strlen(path) + 1);
-		if (!PATH) {
-			printf("Couldn't allocate memory for PATH\n");
-			goto out;
+		if (!strlen(PATH)) {
+			PATH = realloc(PATH, strlen(path) + 1);
+			if (!PATH) {
+				printf("Couldn't allocate memory for PATH\n");
+				goto out;
+			}
+
+			strcpy(PATH, path);
+		} else {
+			PATH = realloc(PATH, strlen(path) + strlen(PATH) + 2);
+			if (!PATH) {
+				printf("Couldn't allocate memory for PATH\n");
+				goto out;
+			}
+
+			strcat(PATH, ":");
+			strcat(PATH, path);
 		}
 
-		strcpy(PATH, path);
-
 		start_ldlinux(argv);
 	}
 
 out:
+	free(PATH);
 	writestr("\nFailed to load ldlinux.c32");
 }
 


More information about the Syslinux-commits mailing list