From patchwork Tue Mar 21 22:47:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 73101 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp2047835wrt; Tue, 21 Mar 2023 15:47:23 -0700 (PDT) X-Google-Smtp-Source: AK7set9Je+maLYc13m/MZ01jsaeN+BIpQhjcSOngjyV75gOJDOfPgv87lIzrZu+o38zJY1QnRmwR X-Received: by 2002:a17:906:86d2:b0:933:444a:bbee with SMTP id j18-20020a17090686d200b00933444abbeemr4505138ejy.50.1679438843293; Tue, 21 Mar 2023 15:47:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679438843; cv=none; d=google.com; s=arc-20160816; b=itv3n5YFEiNs5MUMzV812B49pEcaOMXHeuy3PSXZDrE/BezcuLfw0zSEh2Mmuz976k x2Q2yVGKaYzTGp2qfE+Fag6X2brMHInYYHcWA54wjFXtGkmQ6zyv2ie2NM1Upn10GPUR wnqOIRezBlLF1eihJoLDrZUg6zWY6VLjaptgjQsyomsK9vmIBdz0rhBMZYFNfjYMsyKe eDSzpY5IKNp2+bEFT9n51M/JRt5aA0VJ3THxii2hqiwvp2XMBlVkzqvoOKlR/wDn/Vij hz79qdx1c4Hxqj4i12MBCEzCRYKrZP2Rzt/gNHOBEppMhv1w7TZQJ9na2LmXDtijKNaT 8LXQ== 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=m3TB1WvjZQicwL22l42UsrFO/BlR4tL0bSRS0ZMVMxc=; b=GnZKp3zJVUoETHRUn8UkacdLGLq9e1G+TbgwohIGYxnZAm1Cf6R99Z3CfDdplqm8nE wlqpC4/c8/tsuorjn7z4SVHHTpEC2H7qzydCfgvfOFiZ7cq8B2+nLsa+8spu96Zsor3v WlYPDgV9Ht1Hd6Td2hlzkLt7QFB2iddc85eyn65i3wnsRt/bkjZ4bQbOCcDzP2WKXQ// Jz0S2uZaMmyNGepSlWzGWIXMOflKLk7Sx86vN+3OziljXi+VOjgnoLLAT3sBSm1Okc24 RD5OsZn1PR96wsN/OZA66SYWsVdvKmoeMyHI+YFiohT0fr4ddqfZir/rubWVrA7tb4gz hasg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=TsN6UCb0; 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 d18-20020a170906175200b00923655882d3si13322284eje.718.2023.03.21.15.47.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Mar 2023 15:47:23 -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=TsN6UCb0; 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 1CFFE3858433 for ; Tue, 21 Mar 2023 22:47:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1CFFE3858433 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1679438842; bh=m3TB1WvjZQicwL22l42UsrFO/BlR4tL0bSRS0ZMVMxc=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=TsN6UCb0NVN+otk4TsuFFTAdxBmrq3PAVjuJyI7eAXspLlo2Gd7Sm2mAFhHWnffK0 rLSaR+fHxeDHdOKD8tBJT5BOvDoU8rXj86Tl/g/cwbPoWnc2crsizIdFEO8wCNxxsg ke2eAI/1luAN7jmZfdO+CkSxz0qVQAj1CT1gwKLY= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by sourceware.org (Postfix) with ESMTPS id 61D663858C52 for ; Tue, 21 Mar 2023 22:47:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 61D663858C52 Received: by mail-pl1-x62e.google.com with SMTP id kq3so5223574plb.13 for ; Tue, 21 Mar 2023 15:47:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679438832; 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=m3TB1WvjZQicwL22l42UsrFO/BlR4tL0bSRS0ZMVMxc=; b=Pb274cBB0s0RyvOc49Rw0fQ27jGNPkQL3C6W6sPJBQEbsGIrbetIWWDgar8G5IBlSP EmPquFe5YwxczyVXRaYyKl6+J4gji9vgr/vkTC310EDYB3mgYE4+eLQkE7sQa4UVherC qjLgNJeuCGJk4LiCtggKHtAukoDk+5cXIJxob555Fc+Okat8KkZyQMyIMSK1WbE0kmwE EMwGyyzDy60O/zMs1jJg/nrzJktm9laNs7tU2eABSbtKXzcO7ahTNxfTDv5/Srbm/Zi2 67MInU/SWp/O697AKbzwsnkCoo6OcV9aMpCpfVMDzIKEjJOh+xfkqIBlZmWKpg8/GEgu cAGg== X-Gm-Message-State: AO0yUKX0rsMJ1011rnyjJRS2T4nPqH5TTGR98U4edxvMn8SEeL/g7GUO BbmkH+7k7YTXSTuU/AvuVsl9Mldlg7I= X-Received: by 2002:a17:902:db10:b0:1a1:db10:7ba3 with SMTP id m16-20020a170902db1000b001a1db107ba3mr814320plx.2.1679438832213; Tue, 21 Mar 2023 15:47:12 -0700 (PDT) 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 l4-20020a170902eb0400b001a051eb014bsm9162574plb.219.2023.03.21.15.47.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Mar 2023 15:47:11 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id BB1C51140A26; Wed, 22 Mar 2023 09:17:09 +1030 (ACDT) Date: Wed, 22 Mar 2023 09:17:09 +1030 To: binutils@sourceware.org Subject: PR17910 sym string offset check Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3035.2 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?1761019264247470697?= X-GMAIL-MSGID: =?utf-8?q?1761019264247470697?= As far as I can see the only place that sets obj_coff_strings without setting obj_coff_strings_len is pe_ILF_build_a_bfd. Fix that and we can simplify the sym string offset check. This is just a tidy. pe_ILF_build_a_bfd doesn't create bad symbols and _bfd_coff_read_string_table will always result in non-zero obj_coff_strings_len when obj_coff_strings is non-NULL. This patch came about because I was trying to track down an uninitialised memory access and wondered if in some cases _bfd_coff_internal_syment_name was allowing wild string offsets by omitting the check. It turns out it wasn't, but this way someone looking at the code won't need to check further. PR 17910 * coffgen.c (_bfd_coff_internal_syment_name): Always sanity check sym string offset. * peicode.h (pe_ILF_build_a_bfd): Set obj_coff_strings_len. diff --git a/bfd/coffgen.c b/bfd/coffgen.c index f21cf2ca523..774edf76f24 100644 --- a/bfd/coffgen.c +++ b/bfd/coffgen.c @@ -443,10 +443,7 @@ _bfd_coff_internal_syment_name (bfd *abfd, if (strings == NULL) return NULL; } - /* PR 17910: Only check for string overflow if the length has been set. - Some DLLs, eg those produced by Visual Studio, may not set the length field. */ - if (obj_coff_strings_len (abfd) > 0 - && sym->_n._n_n._n_offset >= obj_coff_strings_len (abfd)) + if (sym->_n._n_n._n_offset >= obj_coff_strings_len (abfd)) return NULL; return strings + sym->_n._n_n._n_offset; } diff --git a/bfd/peicode.h b/bfd/peicode.h index b7b4f4abbb9..f1f3ce81533 100644 --- a/bfd/peicode.h +++ b/bfd/peicode.h @@ -1147,6 +1147,7 @@ pe_ILF_build_a_bfd (bfd * abfd, obj_conv_table_size (abfd) = vars.sym_index; obj_coff_strings (abfd) = vars.string_table; + obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table; obj_coff_keep_strings (abfd) = true; return true;