svn commit: r279364 - head/libexec/rtld-elf
Jung-uk Kim
jkim at FreeBSD.org
Fri Feb 27 19:05:24 UTC 2015
Author: jkim
Date: Fri Feb 27 19:05:23 2015
New Revision: 279364
URL: https://svnweb.freebsd.org/changeset/base/279364
Log:
When a file is executed and the path starts with `/', AT_EXECPATH is set
without any translation. If the file is a symbolic link, $ORIGIN may not be
expanded to the actual origin. Use realpath(3) to properly expand $ORIGIN
to its absolute path.
Reviewed by: kib
MFC after: 1 week
Modified:
head/libexec/rtld-elf/rtld.c
Modified: head/libexec/rtld-elf/rtld.c
==============================================================================
--- head/libexec/rtld-elf/rtld.c Fri Feb 27 18:13:06 2015 (r279363)
+++ head/libexec/rtld-elf/rtld.c Fri Feb 27 19:05:23 2015 (r279364)
@@ -3561,17 +3561,16 @@ rtld_dirname(const char *path, char *bna
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);
}
More information about the svn-src-head
mailing list