Date: Thu, 16 Jan 2020 10:51:32 +0000 (UTC) From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r356787 - stable/12/libexec/rtld-elf Message-ID: <202001161051.00GApWrj053801@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kib Date: Thu Jan 16 10:51:32 2020 New Revision: 356787 URL: https://svnweb.freebsd.org/changeset/base/356787 Log: MFC r356548, r356630: Resolve relative argv0 for direct exec mode to absolute path for AT_EXECPATH. Modified: stable/12/libexec/rtld-elf/rtld.c Directory Properties: stable/12/ (props changed) Modified: stable/12/libexec/rtld-elf/rtld.c ============================================================================== --- stable/12/libexec/rtld-elf/rtld.c Thu Jan 16 10:44:02 2020 (r356786) +++ stable/12/libexec/rtld-elf/rtld.c Thu Jan 16 10:51:32 2020 (r356787) @@ -5482,9 +5482,12 @@ static int open_binary_fd(const char *argv0, bool search_in_path, const char **binpath_res) { - char *pathenv, *pe, *binpath; + char *binpath, *pathenv, *pe, *res1; + const char *res; int fd; + binpath = NULL; + res = NULL; if (search_in_path && strchr(argv0, '/') == NULL) { binpath = xmalloc(PATH_MAX); pathenv = getenv("PATH"); @@ -5509,21 +5512,31 @@ open_binary_fd(const char *argv0, bool search_in_path, continue; fd = open(binpath, O_RDONLY | O_CLOEXEC | O_VERIFY); if (fd != -1 || errno != ENOENT) { - *binpath_res = binpath; + res = binpath; break; } } free(pathenv); } else { fd = open(argv0, O_RDONLY | O_CLOEXEC | O_VERIFY); - *binpath_res = argv0; + res = argv0; } - /* XXXKIB Use getcwd() to resolve relative binpath to absolute. */ if (fd == -1) { _rtld_error("Cannot open %s: %s", argv0, rtld_strerror(errno)); rtld_die(); } + if (res != NULL && res[0] != '/') { + res1 = xmalloc(PATH_MAX); + if (realpath(res, res1) != NULL) { + if (res != argv0) + free(__DECONST(char *, res)); + res = res1; + } else { + free(res1); + } + } + *binpath_res = res; return (fd); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202001161051.00GApWrj053801>