svn commit: r356787 - stable/12/libexec/rtld-elf
Konstantin Belousov
kib at FreeBSD.org
Thu Jan 16 10:51:32 UTC 2020
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);
}
More information about the svn-src-stable
mailing list