From owner-dev-commits-src-branches@freebsd.org Wed May 19 03:13:59 2021 Return-Path: Delivered-To: dev-commits-src-branches@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 E239C635FF5; Wed, 19 May 2021 03:13:59 +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 4FlHyb5trMz4h1Z; Wed, 19 May 2021 03:13:59 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 B2DE7372F; Wed, 19 May 2021 03:13:59 +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 14J3DxHt051266; Wed, 19 May 2021 03:13:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 14J3Dxaf051265; Wed, 19 May 2021 03:13:59 GMT (envelope-from git) Date: Wed, 19 May 2021 03:13:59 GMT Message-Id: <202105190313.14J3Dxaf051265@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: 29b896e67ddb - stable/13 - rtld: preserve the 'seen' state of the dlerror message in errmsg_save() 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: 29b896e67ddb055d0b6878ded41738b6a294db0e Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 May 2021 03:13:59 -0000 The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=29b896e67ddb055d0b6878ded41738b6a294db0e commit 29b896e67ddb055d0b6878ded41738b6a294db0e Author: Konstantin Belousov AuthorDate: 2021-05-10 19:02:19 +0000 Commit: Konstantin Belousov CommitDate: 2021-05-19 03:13:14 +0000 rtld: preserve the 'seen' state of the dlerror message in errmsg_save() PR: 255698 (cherry picked from commit 630caa95d46191220dd457c2ae2d06460cb4f71b) --- libexec/rtld-elf/rtld.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c index d50774868908..2943c1d06fa3 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -81,6 +81,10 @@ extern struct r_debug r_debug; /* For GDB */ extern int _thread_autoinit_dummy_decl; extern void (*__cleanup)(void); +struct dlerror_save { + int seen; + char *msg; +}; /* * Function declarations. @@ -100,8 +104,8 @@ static Obj_Entry *dlopen_object(const char *name, int fd, Obj_Entry *refobj, static Obj_Entry *do_load_object(int, const char *, char *, struct stat *, int); static int do_search_info(const Obj_Entry *obj, int, struct dl_serinfo *); static bool donelist_check(DoneList *, const Obj_Entry *); -static void errmsg_restore(char *); -static char *errmsg_save(void); +static void errmsg_restore(struct dlerror_save *); +static struct dlerror_save *errmsg_save(void); static void *fill_search_info(const char *, size_t, void *); static char *find_library(const char *, const Obj_Entry *, int *); static const char *gethints(bool); @@ -933,10 +937,16 @@ _rtld_error(const char *fmt, ...) /* * Return a dynamically-allocated copy of the current error message, if any. */ -static char * +static struct dlerror_save * errmsg_save(void) { - return (xstrdup(lockinfo.dlerror_loc())); + struct dlerror_save *res; + + res = xmalloc(sizeof(*res)); + res->seen = *lockinfo.dlerror_seen(); + if (res->seen == 0) + res->msg = xstrdup(lockinfo.dlerror_loc()); + return (res); } /* @@ -944,14 +954,17 @@ errmsg_save(void) * by errmsg_save(). The copy is freed. */ static void -errmsg_restore(char *saved_msg) +errmsg_restore(struct dlerror_save *saved_msg) { - if (saved_msg == NULL) - _rtld_error(""); - else { - _rtld_error("%s", saved_msg); - free(saved_msg); + if (saved_msg == NULL || saved_msg->seen == 1) { + *lockinfo.dlerror_seen() = 1; + } else { + *lockinfo.dlerror_seen() = 0; + strlcpy(lockinfo.dlerror_loc(), saved_msg->msg, + lockinfo.dlerror_loc_sz); + free(saved_msg->msg); } + free(saved_msg); } static const char * @@ -2716,7 +2729,7 @@ static void objlist_call_fini(Objlist *list, Obj_Entry *root, RtldLockState *lockstate) { Objlist_Entry *elm; - char *saved_msg; + struct dlerror_save *saved_msg; Elf_Addr *fini_addr; int index; @@ -2792,7 +2805,7 @@ objlist_call_init(Objlist *list, RtldLockState *lockstate) { Objlist_Entry *elm; Obj_Entry *obj; - char *saved_msg; + struct dlerror_save *saved_msg; Elf_Addr *init_addr; void (*reg)(void (*)(void)); int index;