From patchwork Mon Mar 6 11:46:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 64619 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1789748wrd; Mon, 6 Mar 2023 03:46:43 -0800 (PST) X-Google-Smtp-Source: AK7set+3Fwe4HaXppcWBR9r25QOnYHKOQ3T2TlPtWK+yiQztS0tpD6OybPF0KjaznpWwflKG0pCX X-Received: by 2002:a17:906:4c84:b0:8b1:e78f:598b with SMTP id q4-20020a1709064c8400b008b1e78f598bmr10775554eju.50.1678103202915; Mon, 06 Mar 2023 03:46:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678103202; cv=none; d=google.com; s=arc-20160816; b=QZzv1un87cHr8MSEqfEMpQhe4rgmZzF5+oyfv3qvuvmVcM1wA7VDoBnayLv46JNJJ9 6YCGz29c/zMa76ukUhQ57gF0uiCUaqIo2MvlFGcyLrmkZZDClVjR28nyiEqenlvM5zXw jefhXMsA74BYqUoRfDqQk+CJddOWq0VvAHRrCV01fUotz4jsjBr2lCbX6s/+denNWnWR pkfyb8EYg/DQHm2C/YhzfDUfPT69Z5otl2jqq1iuqC2c8j0zAWMF8gDb+QYlyTS8nJhc p86HK+yLQxd4kqU/pPcTCnawiWJX3cMbS7MEMMYEW+UdZiYCY7FjZH/a+IsfeoEsmgla 74jA== 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=oQJEeBLCrxwuQowRCjhrJNdCyWH7KCt+D7J35LPev+4=; b=E8dEVEUqH+qW5NW4IWu1LJQdOSglnskyielwm7VUBHPc9zWddpB7VuvwRiFZTNvgtH 9Ee9wnhurhXG7KrjJlBBg4sy33jswCth6ZkHDo3heXYxrEsbzeJS/QjwzVw1G6+Mc4L9 Nin1mWbqgTiLN2sY9QrnC7Q7CtFzIO5gyc3ttykhbKa+aZNgrTi5V/LWfevvhJ9juw9P I0FWXvBUKdIeby9Ab7j//mCuosv6wMCEx4NtYthwgzvgutIhE6/eoLPTYT95+Yx1irUS V5wTJpC3kcTV8u6BEMa/LC/vppat6UqnrsmLH2QAIM9OtE8E75N/80e8lKm2iv29EAU7 CfZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=rO6tfDTn; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ay15-20020a170906d28f00b008bedd21abe0si6735104ejb.567.2023.03.06.03.46.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 03:46:42 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=rO6tfDTn; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 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 00AF93858D39 for ; Mon, 6 Mar 2023 11:46:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 00AF93858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678103202; bh=oQJEeBLCrxwuQowRCjhrJNdCyWH7KCt+D7J35LPev+4=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=rO6tfDTnlSOpLsz7y0t4ynlmzzFEst45719haJfpCoyOzBsblyDQFp2iaAVhfoaXh Rfh7C5U6kr2sRfc174DppGdwdWSKxIkN2No1Hsm10B5F+hCcLiuX6TMixEzNPFV0MJ INlrLWWvDjGDCNejOdsp2dS3cE+bL3kCOTxuM3X4= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by sourceware.org (Postfix) with ESMTPS id 4B9793858D39 for ; Mon, 6 Mar 2023 11:46:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4B9793858D39 Received: by mail-pj1-x102b.google.com with SMTP id h17-20020a17090aea9100b0023739b10792so8586859pjz.1 for ; Mon, 06 Mar 2023 03:46:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678103190; 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=oQJEeBLCrxwuQowRCjhrJNdCyWH7KCt+D7J35LPev+4=; b=5w2aGcBJatySat2pVEg8BtEL46U/yEUXQ2s4I7U8YE2tOhVVa36s84SRsiQ4mMfyMr YLZlPiDkGPpHIH6kqOiWYRR527VF7wI0bpjbtJck/Fc37j3FVCEVa0Yq7Nc7lqQURYzO vtWnYfDz8WI9HJfa6yHi8g2+Xh14IMq6V7Qtn72/l50rxas1Ko/anI/4n/ZQHFNI5wcV rEUF78p6qDmMDGh/Zy8D7w/wCiaBm8SAYTgGU/qGzLoiqMLtML0xmnBNzmRveeQKng7m orJUyufKNVlRCP0Pp7NoiVrTvIO76m/Ga9KDoBDiaoifmERwkJ/O5VCNqE9WZcs3vmsr 0DNQ== X-Gm-Message-State: AO0yUKUFruWa2Tb+TkOWbHbZjSjO+BqqUuppkbj77CXE/nIlySVieVjH ZzbHC364cdMKRB7M57iuB2ZRbqL/LWA= X-Received: by 2002:a17:902:e80d:b0:19c:cb64:dacc with SMTP id u13-20020a170902e80d00b0019ccb64daccmr14233044plg.61.1678103190038; Mon, 06 Mar 2023 03:46:30 -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 d6-20020a170902c18600b00199025284b3sm6525442pld.151.2023.03.06.03.46.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 03:46:29 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 2A8F9114087E; Mon, 6 Mar 2023 22:16:27 +1030 (ACDT) Date: Mon, 6 Mar 2023 22:16:27 +1030 To: binutils@sourceware.org Subject: macho null dereference read Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3035.3 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?1759618744328573143?= X-GMAIL-MSGID: =?utf-8?q?1759618744328573143?= The main problem here was not returning -1 from canonicalize_symtab on an error, leaving the vector of relocs only partly initialised and one with a null sym_ptr_ptr. * mach-o.c (bfd_mach_o_canonicalize_symtab): Return -1 on error, not 0. (bfd_mach_o_pre_canonicalize_one_reloc): Init sym_ptr_ptr to undefined section sym. diff --git a/bfd/mach-o.c b/bfd/mach-o.c index a910e1146ea..0a91095a5d6 100644 --- a/bfd/mach-o.c +++ b/bfd/mach-o.c @@ -919,7 +919,7 @@ bfd_mach_o_canonicalize_symtab (bfd *abfd, asymbol **alocation) { _bfd_error_handler (_("bfd_mach_o_canonicalize_symtab: unable to load symbols")); - return 0; + return -1; } BFD_ASSERT (sym->symbols != NULL); @@ -1554,7 +1554,7 @@ bfd_mach_o_pre_canonicalize_one_reloc (bfd *abfd, bfd_vma addr; addr = bfd_get_32 (abfd, raw->r_address); - res->sym_ptr_ptr = NULL; + res->sym_ptr_ptr = bfd_und_section_ptr->symbol_ptr_ptr; res->addend = 0; if (addr & BFD_MACH_O_SR_SCATTERED) @@ -1572,7 +1572,7 @@ bfd_mach_o_pre_canonicalize_one_reloc (bfd *abfd, end of the data for the section (e.g. in a calculation of section data length). At present, the symbol will end up associated with the following section or, if it falls within alignment padding, as - null - which will assert later. */ + the undefined section symbol. */ for (j = 0; j < mdata->nsects; j++) { bfd_mach_o_section *sect = mdata->sections[j];