From patchwork Wed Dec 14 03:35:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 33035 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp515331wrn; Tue, 13 Dec 2022 19:35:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf5pVi51Hh6c2AJjNFbzbNyxx+YgYQS/pZSU21s1uuSwdd/THDGhNfENEtdUhp4p4GohygRh X-Received: by 2002:a05:6402:1219:b0:46c:dc40:5482 with SMTP id c25-20020a056402121900b0046cdc405482mr19467465edw.29.1670988940341; Tue, 13 Dec 2022 19:35:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670988940; cv=none; d=google.com; s=arc-20160816; b=z2qzbMKDlwJaHromzascfrlVTi1GQbjsy44EYH4/H4OjsOjupuJ3SYXesUU5tM00w6 p19dB0bUACila2RkTZ2f8gLMftSHmNnfSCZMMeL2sxWWOgPW+JYTpR8/uj/v/Io/StUN lMc+8aZNyrD8mhU1Mb1+V/pPwrL6NkWQ/IjAz8/mzvyzzaQ0nVNuO70HZznEACJugLtw kxdZ0QY98qD6CL9uYnlrPlFJqgU+hRD/6wdNOMQN5JgSNb9G80W5EY5xkTUWM+xMlm/7 yd0NHkPirq+Nz+kvWcIC/OVHd70eifU4+UD4K0U/+hex0PqQu7J7Tw7cntRvn3eWjbwK PUCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=SlSeh4WlDYbAtbJHyWW1ztV8tyyyQtKfOeSZE/1JtiI=; b=qoFPxKFb5fTW7gEpBqFdRwtIwCZoRoEFO1Etd9nDQZ7WOc9PKvRvpsQ8N/kT54UN+v br/5jKrANbCuv/xEX/DLfo4NYrCpwY3d8mALOcyQC/Cgj5/2D59rCQ/foWMX8b5fbpgr zQR2sN+141xFpcsYu3tIcqI2Ro8FUFy0VKwziw5GLZ2m/tpToVjm110LBQs2yDsstnUV HN3aGs0UFnxkyH743VZ4w0HNYeaj4o7DZoRBKumiNkTKtJ+YIMiv1zBIhsP0CMdSYVsB cJjdMzD3oARnRzxOMG3bMtVVtSC3d1RQK6dl1S5RHBYhp/y2kd2Gxesyj3+TvR/OcMw+ KVeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=O1hEydmU; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id eb7-20020a0564020d0700b0046b14f9e2fbsi13763590edb.430.2022.12.13.19.35.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Dec 2022 19:35:40 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=O1hEydmU; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3977138533C9 for ; Wed, 14 Dec 2022 03:35:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3977138533C9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1670988931; bh=SlSeh4WlDYbAtbJHyWW1ztV8tyyyQtKfOeSZE/1JtiI=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=O1hEydmUwUbRyg29DZsDwri2028Vf/FRzLWknruaBZMCRVL2sMz4f8+fLSkpjFE4/ TKIVFuwOWggAZDxw40Yvzl09CLHy6f8UXGX7IZjPjKNAtBGuWQIgQGSjZk5tGWrb6O sGKTNqDNXSdjvtwgfF1EfPRJas+52Qa4qROypEDM= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by sourceware.org (Postfix) with ESMTPS id C39603836D1C for ; Wed, 14 Dec 2022 03:35:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C39603836D1C Received: by mail-pj1-x102e.google.com with SMTP id b13-20020a17090a5a0d00b0021906102d05so5670911pjd.5 for ; Tue, 13 Dec 2022 19:35:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SlSeh4WlDYbAtbJHyWW1ztV8tyyyQtKfOeSZE/1JtiI=; b=vytfTQluu7sDxq1p/ReJ9ZdBmr0dhSW75x9Kuszx1FzimW9JJadha6rPoJuMb+hdbt 22g5ArDkgsqttMFAqcWFidg/iioZTBb+BtMVUfpqpTWxR+yy++Y0QTpXoc/HybUfYfXm 3PwUH5jyEutpWP204V0IOjmU4xg47mc5Hj19GfdTLJ5tZ8skGE0ch+hjfZkM4k1nN1Ar FoaTU35ZX/MM3IoAd3G5ymUhp7AaxYxFGE1250grIWPkEaRTdgmr92xhHyOcEAkJsO4k 4zxt+L7BIfUOugmLoo4eOBRmkI3G03UVvOxDDi68e7s3M4BHu0cYxl0CbjF55bYlS4Ya HO/A== X-Gm-Message-State: ANoB5pkB8lCWS8vdxzTK89ucIGQUNpoq1SM+hcp11yOdkv2Lu/d+4Aem kBeXjfWJOXPFK93PUWVTWiTTqVMzOlA= X-Received: by 2002:a17:90a:aa94:b0:218:d638:1628 with SMTP id l20-20020a17090aaa9400b00218d6381628mr26072759pjq.42.1670988915332; Tue, 13 Dec 2022 19:35:15 -0800 (PST) Received: from squeak.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id rm10-20020a17090b3eca00b00218fba260e2sm253392pjb.43.2022.12.13.19.35.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Dec 2022 19:35:14 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 0D9D41143017; Wed, 14 Dec 2022 14:05:12 +1030 (ACDT) Date: Wed, 14 Dec 2022 14:05:12 +1030 To: binutils@sourceware.org Subject: Don't access freed memory printing objcopy warning Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3036.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alan Modra via Binutils From: Alan Modra Reply-To: Alan Modra Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752158899326963158?= X-GMAIL-MSGID: =?utf-8?q?1752158899326963158?= abfd->filename will be freed if bfd_close gets far enough to delete the bfd. It's possible to have an error from fclose at this point. * objcopy.c (copy_archive): Dup filename before closing bfd for potential use in bfd_nonfatal_message. diff --git a/binutils/objcopy.c b/binutils/objcopy.c index be08f7bd0f9..289b62355af 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -3543,7 +3543,7 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target, bfd **ptr = &obfd->archive_head; bfd *this_element; char *dir; - const char *filename; + char *filename; /* PR 24281: It is not clear what should happen when copying a thin archive. One part is straight forward - if the output archive is in a different @@ -3720,19 +3720,21 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target, } *ptr = NULL; - filename = bfd_get_filename (obfd); + filename = xstrdup (bfd_get_filename (obfd)); if (!(status == 0 ? bfd_close : bfd_close_all_done) (obfd)) { status = 1; bfd_nonfatal_message (filename, NULL, NULL, NULL); } + free (filename); - filename = bfd_get_filename (ibfd); + filename = xstrdup (bfd_get_filename (ibfd)); if (!bfd_close (ibfd)) { status = 1; bfd_nonfatal_message (filename, NULL, NULL, NULL); } + free (filename); cleanup_and_exit: /* Delete all the files that we opened. */