diff options
author | Matt Fleming <matt.fleming@intel.com> | 2013-02-07 17:56:24 +0000 |
---|---|---|
committer | Matt Fleming <matt.fleming@intel.com> | 2013-02-07 18:09:13 +0000 |
commit | 282fe9da42ebb0c34cf4256972a8c07ba5542e23 (patch) | |
tree | 2ff13c2e116199fce488499032f8ee14db6eb572 | |
parent | 04f40bc55ed4f39d6c625b017bb16907f7d50c05 (diff) | |
download | syslinux-282fe9da42ebb0c34cf4256972a8c07ba5542e23.tar.gz syslinux-282fe9da42ebb0c34cf4256972a8c07ba5542e23.tar.xz syslinux-282fe9da42ebb0c34cf4256972a8c07ba5542e23.zip |
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@intel.com>
-rw-r--r-- | com32/lib/Makefile | 4 | ||||
-rw-r--r-- | core/elflink/load_env32.c | 31 |
2 files changed, 23 insertions, 12 deletions
diff --git a/com32/lib/Makefile b/com32/lib/Makefile index 49a3aafe..a225f6f5 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 3ddbfec3..c84582de 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"); } |