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
This commit is contained in:
Jung-uk Kim 2015-02-27 19:05:23 +00:00
parent 726b99f9f9
commit 0461326c01

View File

@ -3561,17 +3561,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);
}