From nobody Fri Feb 18 02:01:29 2022 X-Original-To: dev-commits-src-all@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 2AA2619C426F; Fri, 18 Feb 2022 02:01:30 +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 4K0FL20lcYz4dt3; Fri, 18 Feb 2022 02:01:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645149690; 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=h070ZAMFEay0bHfT741jSjDMIz1jeNvrRptCctPKZgA=; b=LWIwRZIxKbS9Uhs/bG71YIAHTC3m6Zti+vOwc4LJYiF1yBYBbPAJ8obCdzvszKbq2ZW/1S hMGAs2poml+GBA9ccz4PHzsJszkxgxcaFpf1VNa8lgrB3imD2cecBC1tjXhdBglj+iBnqc jPxNlXLhD/SbPfc/Vw9Pj7kegUIA0T6H1yNesCykWx+9e2g7xrgXTdKUK+lPRyzf7oCIne b624f28Lmt4cu56aj5zkZUp/3aWGkKISkjQFyFsoU8ooMF6fQEoWQN+lJq32imbMU+mdax I9EhvjMy8pnMYikWkTfFvshyNLEcYd7235nZzMLgEPj/3gD63e3yTtzXN9KsHQ== 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 EEB5115305; Fri, 18 Feb 2022 02:01:29 +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 21I21ToE039396; Fri, 18 Feb 2022 02:01:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21I21TYL039395; Fri, 18 Feb 2022 02:01:29 GMT (envelope-from git) Date: Fri, 18 Feb 2022 02:01:29 GMT Message-Id: <202202180201.21I21TYL039395@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 1bce4afb06a9 - stable/13 - rtld: make token substitution table-driven List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 1bce4afb06a9c82a0d41dbbd5f6784cb273540e3 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645149690; 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=h070ZAMFEay0bHfT741jSjDMIz1jeNvrRptCctPKZgA=; b=fajnhnFh4zlBXv3za8hFg9+4jsLcMkJQynIFImAvhWl7bgVh+9o5wyydY7sXeGenVzsyLO F04cQuVFiY0zTJLmROvu5oePKxFyi6jvEu9z6Ae6JGV9zeUJzMOT9+Fm46mx5FyU9eOBtJ 0VJG2RKPJ+14/mFKB2CRQWZHZ+obUwq1BZIjIjyp6Mn6JhpjbbvBLEG/a0xXutry1FAJsN EcQxaDVHsxni4inG4MLRD/gJlwo5mc0gshT40Ft5iOq/ubS6z0vRmY/9VRHLBnixRaqQ7Y jPKeQ+M8+XFL+jroVoJt7CaAepT7k1+gc7vJ6oImpbImu2r5OLBJDA6/PtcFsw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1645149690; a=rsa-sha256; cv=none; b=FVJ4QB2jC0GWMUHh1NXOgfiEJ4+r5I6/rP/1rlfnVWkE+sJH96AbIwN34JvQyxK30iPlGc bjLiWX/FzmKUblZmGj6PMYFfIU/hwop4nvF3ODZalHANfN/gORxt1Z+g53nifQP2TVWMwJ GgioJH4BvvaEGyAEbUHPMqeP5ralfBNvuGsPFBz6FNgcUdKD9PGV33csWTbQiKm8ba2MUv Lm6Vjvz6kwz3G1c6lLguV753JDqcsiZqhQo8V5iPPeESRMALLSlS0zZ58gezIbAk2uXdRG wKcV+2/U4NDTXiy4JQx4Qmy1h1VtUgdCifGaEhrnonGg1DXD8wQ/66X4Qv/iEg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=1bce4afb06a9c82a0d41dbbd5f6784cb273540e3 commit 1bce4afb06a9c82a0d41dbbd5f6784cb273540e3 Author: Konstantin Belousov AuthorDate: 2022-02-11 13:44:36 +0000 Commit: Konstantin Belousov CommitDate: 2022-02-18 02:01:24 +0000 rtld: make token substitution table-driven (cherry picked from commit 55abf23dd36b2fa1499bd6806ce4c9510f7a4ee5) --- 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 5819bf18e4b5..c2fa85a27224 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -1179,10 +1179,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)); @@ -1192,13 +1204,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