From patchwork Thu Mar 30 04:50:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 76887 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp873406vqo; Wed, 29 Mar 2023 21:51:09 -0700 (PDT) X-Google-Smtp-Source: AKy350ZkHP9dDELjeLzHZJ61ymR7dRhQbf75BenPBfGjriJU4w1v2x4MUULRN16jSbwJhVrUv/V4 X-Received: by 2002:aa7:cc04:0:b0:4fd:2a29:ceac with SMTP id q4-20020aa7cc04000000b004fd2a29ceacmr19171725edt.14.1680151869126; Wed, 29 Mar 2023 21:51:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680151869; cv=none; d=google.com; s=arc-20160816; b=Yzp0Hw0YnrbW5BkIvgvkSShiMDcPXUOiYFFWfbmX1IRTNGIyxtkG2hYoQEgXWjhSAS ZbutatopemSA63jBuME04uQr0LcpA5+iy8HmNtHqznBGBNxewzRAgZZMWglsctUF9k94 wzG0uQauqbqag9TXgrmnVhLYZQaeK51G3R2to+d9yXjkqn2wiAe6eY5ph7ixso5jyu2M Y25pyKhNfy9SDFDcFXgnxR+K4w4RdnXD01TI4i6tTOnPjtTEHI7rUL5CTPayaEBppjWw Egy6oOClOHXtSbTrGRn4GM6Q30+lpZNwNKBOKxi1zOMEewCWib1CMiTlHTpV+L/ck62m gOjg== 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=7sdL4hiGT90+ket4CtbGTQSduevHBZG9QZCFxEOOP44=; b=meUIzk52wR1gQXSOz3+zmDIpi49U8MtD1FUgg+Vbl0kqqBIhXgrahgCVtbYh02tOEd 36o8eRFhavRXytEnr6VJY7Msa4A017xU9vQiW86R4QZ8xSHMJRThgE295uhw9TzcT2f+ x2+RhRJduxtzYIrAt35xANkjwopiJy7vkRjEUcnS9/C8DMGmFlUxS6DxYHIKwFVmizOG 4HzPWyW4HoyMmV6hlOljnpZpY27VPxyp2TziDbRe5XNnwlvyzi9tWje5LWZZ+hrBaPXJ lsLxCPFuJW/ORSu+UQNXxUpsgG1tHY5FVLYr3G32PdZJW5gW18gwq9McKiz5C74si8tc XuGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=Rq2bzFAO; 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 f23-20020a056402069700b004ace62d6ea3si37449510edy.519.2023.03.29.21.51.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 21:51:09 -0700 (PDT) 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=Rq2bzFAO; 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 C52323858C1F for ; Thu, 30 Mar 2023 04:51:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C52323858C1F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680151867; bh=7sdL4hiGT90+ket4CtbGTQSduevHBZG9QZCFxEOOP44=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Rq2bzFAOlT+3TzHT/cocn+3cv8pIxCT2jzeNuW7kMqwnswVJKWARD1xzd2yv/nT7i vV+rnDZTzXtEAdDQnJik7Tpucal8BRXhjVp7FG+fibnwxZ+VRvddiK0NRDEHrpGgvZ DTi12T/olDzKwAcU3OnmJbEeK7mjXL5wOpe9Vgt8= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by sourceware.org (Postfix) with ESMTPS id 689CC3858C30 for ; Thu, 30 Mar 2023 04:50:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 689CC3858C30 Received: by mail-pj1-x102d.google.com with SMTP id c4so147449pjs.4 for ; Wed, 29 Mar 2023 21:50:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680151813; 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=7sdL4hiGT90+ket4CtbGTQSduevHBZG9QZCFxEOOP44=; b=FxoH0rCIMHtMjke5KPrRtC7oVEu+ESP4vBvgdS3FeTvKVCMlRXZFsZvFoUyhx/9ClF UHZLE4M9pIZeTFRVV6IumdJAk7JcOJ8QErtwqc9KA1yT4zc2iC62MZWTWYQ2M+F0mdw3 SPamE7zkxh5V45rvuXNLV726wMWHLPQRXSDNv9Uo12xu1glS7wtIawpnY+h55Agyl8kJ mBOiU1rwy6Hws1d4ochjMia1lDlgwh6jXcEosvzal7Arv4PViFBfIu+1gcKQzb2ZQV8R OCyuUVABndfzbzukTCK5uEumAW84u4Y6K+7LwPAQQ/KwcShCt1f+B5TVdMAo9/IbCveQ L6fw== X-Gm-Message-State: AAQBX9fZ4LiBKY4zybnyZM0X6Pu1FVkQM/C1WBD4RItkN9BEwGze0R8h NAxxgCWlNgrqUiOGZoBB88743YlVWm8= X-Received: by 2002:a17:902:f550:b0:1a1:d70f:7114 with SMTP id h16-20020a170902f55000b001a1d70f7114mr26859164plf.14.1680151813031; Wed, 29 Mar 2023 21:50:13 -0700 (PDT) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:5286:655c:8aca:de7f]) by smtp.gmail.com with ESMTPSA id g6-20020a1709026b4600b001a19cf1b37esm23783412plt.40.2023.03.29.21.50.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 21:50:12 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 155711142E2D; Thu, 30 Mar 2023 15:20:10 +1030 (ACDT) Date: Thu, 30 Mar 2023 15:20:10 +1030 To: binutils@sourceware.org Subject: Fix memory leak in bfd_get_debug_link_info_1 Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3034.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_NUMSUBJECT, 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?1761766926597235159?= X-GMAIL-MSGID: =?utf-8?q?1761766926597235159?= * opncls.c (bfd_get_alt_debug_link_info): Don't bother freeing after bfd_malloc_and_get_section failure. (get_build_id): Likewise. (bfd_get_debug_link_info_1): Likewise. Free section contents when crc not present. * section.c (bfd_malloc_and_get_section): Document that the buffer is NULL on error return. diff --git a/bfd/opncls.c b/bfd/opncls.c index abea464baa4..81e124457e9 100644 --- a/bfd/opncls.c +++ b/bfd/opncls.c @@ -1211,10 +1211,7 @@ bfd_get_debug_link_info_1 (bfd *abfd, void *crc32_out) return NULL; if (!bfd_malloc_and_get_section (abfd, sect, &contents)) - { - free (contents); - return NULL; - } + return NULL; /* CRC value is stored after the filename, aligned up to 4 bytes. */ name = (char *) contents; @@ -1222,7 +1219,10 @@ bfd_get_debug_link_info_1 (bfd *abfd, void *crc32_out) crc_offset = strnlen (name, size) + 1; crc_offset = (crc_offset + 3) & ~3; if (crc_offset + 4 > size) - return NULL; + { + free (name); + return NULL; + } *crc32 = bfd_get_32 (abfd, contents + crc_offset); return name; @@ -1297,10 +1297,7 @@ bfd_get_alt_debug_link_info (bfd * abfd, bfd_size_type *buildid_len, return NULL; if (!bfd_malloc_and_get_section (abfd, sect, & contents)) - { - free (contents); - return NULL; - } + return NULL; /* BuildID value is stored after the filename. */ name = (char *) contents; @@ -1817,10 +1814,7 @@ get_build_id (bfd *abfd) } if (!bfd_malloc_and_get_section (abfd, sect, & contents)) - { - free (contents); - return NULL; - } + return NULL; /* FIXME: Paranoia - allow for compressed build-id sections. Maybe we should complain if this size is different from diff --git a/bfd/section.c b/bfd/section.c index 3b1993b60a5..1e7e8ac7522 100644 --- a/bfd/section.c +++ b/bfd/section.c @@ -1600,6 +1600,8 @@ SYNOPSIS DESCRIPTION Read all data from @var{section} in BFD @var{abfd} into a buffer, *@var{buf}, malloc'd by this function. + Return @code{true} on success, @code{false} on failure in which + case *@var{buf} will be NULL. */ bool