From nobody Fri Feb 11 18:01:56 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 9A77A19BD8BF; Fri, 11 Feb 2022 18:01:56 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JwLzS3yRJz3H0V; Fri, 11 Feb 2022 18:01:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644602516; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=lC+IcFsAcJ+dp2p7xIyTZdsJeJAUbwdRKMtiCOsJcSM=; b=C4HpkNgCfAjFOx/iW21nzgL0bb0PwYqiRQ+RGpnuNZJcfxH2COK2a/eqBmeFhqtdEk2608 M6GPneQ9Ydyu67XPQnBp/uzf0WxumiRy7W/N6jFkhoAuTtM0D/e92Ds81XTrKhlLWW6Ph8 irI/m6igHL2dAhSaQmiJUIWLvWVBzD4QVa3ZUieS9ODCuuipLpcgk/0jgAHmaSbzPfzBsb cW+YcmBYdlMOS2fF7UhXU6OxYeTdhTYFT4KZUkkcK1YEMF8ox6564pOCk+auYL3UYbfv1K KrFwBudNcJDsibNWWyk+JVVnNPkWCHsNF4uhfrG2eK45cQ2B/tgKAoYT7K/b8Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 67948188F3; Fri, 11 Feb 2022 18:01:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 21BI1uRm025535; Fri, 11 Feb 2022 18:01:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21BI1uGZ025534; Fri, 11 Feb 2022 18:01:56 GMT (envelope-from git) Date: Fri, 11 Feb 2022 18:01:56 GMT Message-Id: <202202111801.21BI1uGZ025534@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 55abf23dd36b - main - rtld: make token substitution table-driven List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 55abf23dd36b2fa1499bd6806ce4c9510f7a4ee5 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644602516; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=lC+IcFsAcJ+dp2p7xIyTZdsJeJAUbwdRKMtiCOsJcSM=; b=LcDhXgkL6VeugNhwXMUZ3Rj8x49uvEb3Zlw2rOvmpMizzTF2TY0Dn0xv09T/XByPqrqiMK Z2ipk9afRLnJa/SBI8xU3RnGM8lOWtWl1MQJaPqwgbWsWtNBMH1/7ooUA4kd5+X+3wtb3W YVKHl3nu72Fd2JTSp9JU7csdkFoOs8uKQ6Ec/pZD95vsvrYsSuUO+33qegIAk82XrQc1gr SgMqDnx67bmwy4AsyIpHw8DRQWM0tuEaTEhorwGMhJNjHUL13Ougj3p7rLMpB3GefGTbKL PiuifTlS0OhYreksKsN/K5KQtucGZ0l84AubG1r5WdQbMQuLY1AfKus3BWnytg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1644602516; a=rsa-sha256; cv=none; b=guKe10GeDcrowwT4Xr+9kn3Da/hbFGRAhH3nZHIXTWvk2nhtkwzAuMhHw8B5Rw9kCGzP9y PG1LeogmD1ceXLasLW7JTWX63AZca8E2ZML70Sl7hY7I0Zm0jw53Nzb29IEpS/ebK2La4O 2OKZ3yn3yw5Sut5HND8+vfigWmS/5YjeZNIxR687SZFjqk2HHIUSd9Z2BzImNiJvAqwnRK mPpTUiRZFqsDJk3oURmC4Au57REIe48a8eSY9s/pldeQSBYUKAkUGzn3Rhue8zpP9pmR3K abGuMoyzSbx6yBfGjvVoLKzcszTfWnYFVis7KpylsO6N2HpvY8g4ebeCwLYkag== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=55abf23dd36b2fa1499bd6806ce4c9510f7a4ee5 commit 55abf23dd36b2fa1499bd6806ce4c9510f7a4ee5 Author: Konstantin Belousov AuthorDate: 2022-02-11 13:44:36 +0000 Commit: Konstantin Belousov CommitDate: 2022-02-11 18:00:47 +0000 rtld: make token substitution table-driven Reviewed by: emaste, markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D34247 --- libexec/rtld-elf/rtld.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c index 4327b598db58..63b921ff2503 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -1175,10 +1175,22 @@ origin_subst_one(Obj_Entry *obj, char *real, const char *kw, return (res); } +static const struct { + const char *kw; + bool pass_obj; + const char *subst; +} tokens[] = { + { .kw = "$ORIGIN", .pass_obj = true, .subst = NULL }, + { .kw = "$OSNAME", .pass_obj = false, .subst = uts.sysname }, + { .kw = "$OSREL", .pass_obj = false, .subst = uts.release }, + { .kw = "$PLATFORM", .pass_obj = false, .subst = uts.machine }, +}; + static char * origin_subst(Obj_Entry *obj, const char *real) { - char *res1, *res2, *res3, *res4; + char *res; + int i; if (obj == NULL || !trust) return (xstrdup(real)); @@ -1188,13 +1200,14 @@ origin_subst(Obj_Entry *obj, const char *real) return (NULL); } } + /* __DECONST is safe here since without may_free real is unchanged */ - res1 = origin_subst_one(obj, __DECONST(char *, real), "$ORIGIN", NULL, - false); - res2 = origin_subst_one(NULL, res1, "$OSNAME", uts.sysname, true); - res3 = origin_subst_one(NULL, res2, "$OSREL", uts.release, true); - res4 = origin_subst_one(NULL, res3, "$PLATFORM", uts.machine, true); - return (res4); + res = __DECONST(char *, real); + for (i = 0; i < (int)nitems(tokens); i++) { + res = origin_subst_one(tokens[i].pass_obj ? obj : NULL, + res, tokens[i].kw, tokens[i].subst, i == 0); + } + return (res); } void