Date: Fri, 27 Feb 2015 19:05:24 +0000 (UTC) From: Jung-uk Kim <jkim@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r279364 - head/libexec/rtld-elf Message-ID: <201502271905.t1RJ5OYn044113@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
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); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201502271905.t1RJ5OYn044113>