From patchwork Fri Feb 10 14:07:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: stsp X-Patchwork-Id: 64669 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6E8ED3858025 for ; Fri, 10 Feb 2023 14:08:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6E8ED3858025 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1676038095; bh=C+nDotYE4WpQ7hGhms4TfaPahaQgwggizU7CU46d9s8=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=NvPhan6YIGCxzWKgPYXj/N6xHE9Tduwb5QfBYOobBx6TO31hY+CyrSypnXbBNJKuT 6ct6zTMVPu+rlipOKQxFiEJHdRMGcAlUR+lx6LGv82wpMdd+hhnZYJX1VOgrmzy0E0 wyGJI6sV6faGn8RDehuBna6L9oCNWdJbCzvq+F7s= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from forward105o.mail.yandex.net (forward105o.mail.yandex.net [37.140.190.183]) by sourceware.org (Postfix) with ESMTPS id 5FB063858D28 for ; Fri, 10 Feb 2023 14:07:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5FB063858D28 Received: from forward100q.mail.yandex.net (forward100q.mail.yandex.net [IPv6:2a02:6b8:c0e:4b:0:640:4012:bb97]) by forward105o.mail.yandex.net (Yandex) with ESMTP id 8381F4C3E8C for ; Fri, 10 Feb 2023 17:07:50 +0300 (MSK) Received: from vla3-aeadfdeff55e.qloud-c.yandex.net (vla3-aeadfdeff55e.qloud-c.yandex.net [IPv6:2a02:6b8:c15:341d:0:640:aead:fdef]) by forward100q.mail.yandex.net (Yandex) with ESMTP id 7F50E6F40007 for ; Fri, 10 Feb 2023 17:07:50 +0300 (MSK) Received: by vla3-aeadfdeff55e.qloud-c.yandex.net (smtp/Yandex) with ESMTPSA id l7gEnKCZhiE1-koQgyCyR; Fri, 10 Feb 2023 17:07:49 +0300 X-Yandex-Fwd: 1 To: libc-alpha@sourceware.org Cc: Stas Sergeev Subject: [PATCH 1/2] elf: strdup() l_name if no realname [BZ #30100] Date: Fri, 10 Feb 2023 19:07:43 +0500 Message-Id: <20230210140744.2828787-1-stsp2@yandex.ru> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 X-Spam-Status: No, score=-10.7 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 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Stas Sergeev via Libc-alpha From: stsp Reply-To: Stas Sergeev Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" _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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elf/dl-object.c b/elf/dl-object.c index f1f2ec956c..c92daf37d1 100644 --- a/elf/dl-object.c +++ b/elf/dl-object.c @@ -122,7 +122,7 @@ _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; + new->l_name = __strdup ((char *) newname->name + libname_len - 1); new->l_type = type; /* If we set the bit now since we know it is never used we avoid