From 7f53c2cc9603c89ba6ef576847151695789a2a93 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Thu, 21 Jul 2005 23:51:02 +0000 Subject: [PATCH] We now make sure, that images always have absolute paths, otherwise their path could be invalid in other contexts (e.g. the debug server might be unabled to find them). This seems to be what BeOS does, too. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13796 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/runtime_loader/rldelf.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/system/runtime_loader/rldelf.c b/src/system/runtime_loader/rldelf.c index 5902bc510f..123e921a13 100644 --- a/src/system/runtime_loader/rldelf.c +++ b/src/system/runtime_loader/rldelf.c @@ -878,6 +878,22 @@ load_container(char const *name, image_type type, const char *rpath) fd = open_executable(path, type, rpath); FATAL((fd < 0), fd, "cannot open file %s\n", path); + // If the path is not absolute, we prepend the CWD to make it one. + if (path[0] != '/') { + char relativePath[PATH_MAX]; + strcpy(relativePath, path); + + // get the CWD + status = _kern_getcwd(path, sizeof(path)); + FATAL((status != B_OK), status, "_kern_getcwd() failed\n"); + + if (strlcat(path, "/", sizeof(path)) >= sizeof(path) + || strlcat(path, relativePath, sizeof(path)) >= sizeof(path)) { + FATAL(true, B_NAME_TOO_LONG, "Absolute path of image %s is too " + "long!\n", relativePath); + } + } + len = _kern_read(fd, 0, &eheader, sizeof(eheader)); FATAL((len != sizeof(eheader)), B_BAD_DATA, "troubles reading ELF header\n");