From owner-svn-src-all@freebsd.org Thu Jan 16 10:51:32 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id A04582328E2; Thu, 16 Jan 2020 10:51:32 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47z1GD3l1Dz3KxJ; Thu, 16 Jan 2020 10:51:32 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 7B7AF1E35A; Thu, 16 Jan 2020 10:51:32 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 00GApWcu053803; Thu, 16 Jan 2020 10:51:32 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 00GApWrj053801; Thu, 16 Jan 2020 10:51:32 GMT (envelope-from kib@FreeBSD.org) Message-Id: <202001161051.00GApWrj053801@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Thu, 16 Jan 2020 10:51:32 +0000 (UTC) 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 X-SVN-Group: stable-12 X-SVN-Commit-Author: kib X-SVN-Commit-Paths: stable/12/libexec/rtld-elf X-SVN-Commit-Revision: 356787 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Jan 2020 10:51:32 -0000 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); }