From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from forward206c.mail.yandex.net (forward206c.mail.yandex.net [178.154.239.215]) by sourceware.org (Postfix) with ESMTPS id 66337384F011 for ; Sat, 18 Mar 2023 16:51:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 66337384F011 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=yandex.ru Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=yandex.ru Received: from myt6-1289f562e823.qloud-c.yandex.net (myt6-1289f562e823.qloud-c.yandex.net [IPv6:2a02:6b8:c12:259d:0:640:1289:f562]) by forward206c.mail.yandex.net (Yandex) with ESMTP id 19F2B600FA for ; Sat, 18 Mar 2023 19:51:43 +0300 (MSK) Received: by myt6-1289f562e823.qloud-c.yandex.net (smtp/Yandex) with ESMTPSA id cpp3fcrbC8c1-uSg1Vrg4; Sat, 18 Mar 2023 19:51:42 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1679158302; bh=BkpUl4IjziF+k30QNWuSr+3VSIfaClg+Fa7lsLsF5TU=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=v6s3+5GeihUZq92Kpavs9UXKMXpifJQfzEXMHoXeu/ZxMAR6rXU//8uml7LxPm1gF a6GSl5fgRz6SWCozCB55nl/uNHWaotUTA7eNiOjtd07RcnvwquAVlbFdt7Zvd8jDn0 uvte33P7Qb2zJBOmkBCki2S/BKAqBhNyyVIgwECI= Authentication-Results: myt6-1289f562e823.qloud-c.yandex.net; dkim=pass header.i=@yandex.ru From: Stas Sergeev To: libc-alpha@sourceware.org Cc: Stas Sergeev Subject: [PATCH 01/13] elf: strdup() l_name if no realname [BZ #30100] Date: Sat, 18 Mar 2023 21:50:58 +0500 Message-Id: <20230318165110.3672749-2-stsp2@yandex.ru> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230318165110.3672749-1-stsp2@yandex.ru> References: <20230318165110.3672749-1-stsp2@yandex.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,GIT_PATCH_0,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: _dl_close_worker() has this code: /* This name always is allocated. */ free (imap->l_name); But in that particular case, while indeed being allocated, l_name doesn't point to the start of an allocation: new = (struct link_map *) calloc (sizeof (*new) + audit_space + sizeof (struct link_map *) + sizeof (*newname) + libname_len, 1); ... new->l_symbolic_searchlist.r_list = (struct link_map **) ((char *) (new + 1) + audit_space); new->l_libname = newname = (struct libname_list *) (new->l_symbolic_searchlist.r_list + 1); newname->name = (char *) memcpy (newname + 1, libname, libname_len); ... new->l_name = (char *) newname->name + libname_len - 1; It therefore cannot be freed separately. Use strdup("") as a simple fix. Signed-off-by: Stas Sergeev --- elf/dl-object.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/elf/dl-object.c b/elf/dl-object.c index f1f2ec956c..ab926cd4bf 100644 --- a/elf/dl-object.c +++ b/elf/dl-object.c @@ -122,7 +122,10 @@ _dl_new_object (char *realname, const char *libname, int type, #endif new->l_name = realname; else - new->l_name = (char *) newname->name + libname_len - 1; + /* When realname="", it is not allocated and points to the constant + string. Constness is dropped by an explicit cast. :( + So strdup() it here. */ + new->l_name = __strdup (""); new->l_type = type; /* If we set the bit now since we know it is never used we avoid -- 2.37.2