diff options
author | jkim <jkim@FreeBSD.org> | 2015-03-06 22:31:35 +0000 |
---|---|---|
committer | jkim <jkim@FreeBSD.org> | 2015-03-06 22:31:35 +0000 |
commit | 88fa6bbce5dc15cc47f7a7500c86953b559e66f2 (patch) | |
tree | 03040211045d8124a1663bb6a4a45cf9313adb82 /libexec | |
parent | b6bec41c3d0a922602a7593f30d29f22621fb3aa (diff) | |
download | FreeBSD-src-88fa6bbce5dc15cc47f7a7500c86953b559e66f2.zip FreeBSD-src-88fa6bbce5dc15cc47f7a7500c86953b559e66f2.tar.gz |
MFC: r279364
Use realpath(3) to properly expand $ORIGIN to its absolute path.
Diffstat (limited to 'libexec')
-rw-r--r-- | libexec/rtld-elf/rtld.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c index 0d1a738..f5a6a17 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -3420,17 +3420,16 @@ rtld_dirname(const char *path, char *bname) static int rtld_dirname_abs(const char *path, char *base) { - char base_rel[PATH_MAX]; + char *last; - if (rtld_dirname(path, base) == -1) + if (realpath(path, base) == NULL) return (-1); - if (base[0] == '/') - return (0); - if (getcwd(base_rel, sizeof(base_rel)) == NULL || - strlcat(base_rel, "/", sizeof(base_rel)) >= sizeof(base_rel) || - strlcat(base_rel, base, sizeof(base_rel)) >= sizeof(base_rel)) + dbg("%s -> %s", path, base); + last = strrchr(base, '/'); + if (last == NULL) return (-1); - strcpy(base, base_rel); + if (last != base) + *last = '\0'; return (0); } |