aboutsummaryrefslogtreecommitdiffhomepage
path: root/runtime
diff options
context:
space:
mode:
authorTimotej Kapus <tk1713@ic.ac.uk>2020-03-15 10:28:52 +0000
committerCristian Cadar <c.cadar@imperial.ac.uk>2020-04-09 10:18:39 +0100
commit55f1672a6928c2337bdb5952f049c833e21826c2 (patch)
tree10fd3da543f8475052de1f8981c481a1bf941916 /runtime
parentc78b837d24f5df92b758b27e175b079ef2f1fbc0 (diff)
downloadklee-55f1672a6928c2337bdb5952f049c833e21826c2.tar.gz
[posix-runtime] Improve model to handle full-path symbolic files
Diffstat (limited to 'runtime')
-rw-r--r--runtime/POSIX/fd.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/runtime/POSIX/fd.c b/runtime/POSIX/fd.c
index 240e589e..cfd2622f 100644
--- a/runtime/POSIX/fd.c
+++ b/runtime/POSIX/fd.c
@@ -38,6 +38,22 @@ static exe_disk_file_t *__get_sym_file(const char *pathname) {
if (!pathname)
return NULL;
+ // Handle the case where symbolic file is given as an absolute path, ie.
+ // /current/work/dir/A
+ if (pathname[0] == '/') {
+ char cwd[1024] = {0};
+ if (getcwd(cwd, 1024)) {
+ size_t cwd_len = strlen(cwd);
+ // strip trailing / if present
+ if (cwd_len > 0 && cwd[cwd_len - 1] == '/') {
+ cwd[--cwd_len] = '\0';
+ }
+ if (strncmp(pathname, cwd, cwd_len) == 0) {
+ if (pathname[cwd_len] != '\0')
+ pathname += cwd_len + 1;
+ }
+ }
+ }
char c = pathname[0];
unsigned i;