diff options
| -rw-r--r-- | core/elflink/load_env32.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/core/elflink/load_env32.c b/core/elflink/load_env32.c index 7a6b08fb..3ddbfec3 100644 --- a/core/elflink/load_env32.c +++ b/core/elflink/load_env32.c @@ -127,7 +127,7 @@ void load_env32(com32sys_t * regs __unused) PATH = malloc(strlen(CurrentDirName) + 1); if (!PATH) { printf("Couldn't allocate memory for PATH\n"); - return; + goto out; } strcpy(PATH, CurrentDirName); @@ -142,15 +142,36 @@ 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; fp = &__file_info[fd]; - if (!search_dirs(&fp->i.fd, search_directories, filenames, realname)) + if (!search_dirs(&fp->i.fd, search_directories, filenames, realname)) { + char path[FILENAME_MAX]; + + /* + * search_dirs() sets the current working directory if + * it successfully opens the file. Set PATH to the + * directory in which we found ldlinux.c32. + */ + 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; + } + + strcpy(PATH, path); + start_ldlinux(argv); + } +out: writestr("\nFailed to load ldlinux.c32"); } |
