From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id hTDDM3cerWFPfQAAWB0awg (envelope-from ) for ; Sun, 05 Dec 2021 15:17:59 -0500 Received: by simark.ca (Postfix, from userid 112) id C20811F0CE; Sun, 5 Dec 2021 15:17:59 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 543AD1EDF0 for ; Sun, 5 Dec 2021 15:17:53 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9A240385800F for ; Sun, 5 Dec 2021 20:17:52 +0000 (GMT) Received: from gateway30.websitewelcome.com (gateway30.websitewelcome.com [192.185.198.26]) by sourceware.org (Postfix) with ESMTPS id E6FAD3858D28 for ; Sun, 5 Dec 2021 20:17:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E6FAD3858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tromey.com Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway30.websitewelcome.com (Postfix) with ESMTP id 5936325D06 for ; Sun, 5 Dec 2021 14:17:39 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id txx5md8r60ESotxx5mP6j6; Sun, 05 Dec 2021 14:17:39 -0600 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:References :Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=z1BCIBp2cNzwQay0f98FOP6I761CxyXOvKRTa+QYQ+o=; b=moGn2ptCgEKJwEk8qqva3ycGd9 IuD8LGhG6HU+tqn0Zml4Dh7GXU6Lcco6qhUvcAMFDqkanqtMB+0JQx9Z6D8Xz7rjEnRVD7RvwwD7C cjosadlVBRFOYGlpHvIgXRlRG; Received: from 97-122-84-67.hlrn.qwest.net ([97.122.84.67]:40442 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mtxx4-002Z3t-W9; Sun, 05 Dec 2021 13:17:39 -0700 From: Tom Tromey To: Simon Marchi Subject: Re: [PATCH 3/3] Cache the result of find_file_and_directory References: <20211130013304.4135367-1-tom@tromey.com> <20211130013304.4135367-4-tom@tromey.com> <87tufotela.fsf@tromey.com> <104bfab9-d713-1ec8-3a44-09a8403e2c3f@polymtl.ca> <87k0gju31v.fsf@tromey.com> X-Attribution: Tom Date: Sun, 05 Dec 2021 13:17:38 -0700 In-Reply-To: (Simon Marchi's message of "Sat, 4 Dec 2021 22:47:24 -0500") Message-ID: <874k7mu7q5.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.84.67 X-Source-L: No X-Exim-ID: 1mtxx4-002Z3t-W9 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-84-67.hlrn.qwest.net (localhost.localdomain) [97.122.84.67]:40442 X-Source-Auth: tom+tromey.com X-Email-Count: 3 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tom Tromey , gdb-patches@sourceware.org, Joel Brobecker Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" >> Sorry about that. I'll fix it soon. Or you can back it out if you >> prefer. Simon> I'm not personally affected so I do not mind, I can wait for the fix. Here is what I am checking in. I was able to reproduce the failure with valgrind, and confirmed that this patch fixes it. Tom commit 33af066d07d495c81c7c102125aec8dbac62c27b Author: Tom Tromey Date: Sun Dec 5 13:13:33 2021 -0700 Preserve artificial CU name in process_psymtab_comp_unit_reader This fixes a use-after-free that Simon pointed out. process_psymtab_comp_unit_reader was allocating an artificial name for a CU, and then discarding it. However, this name was preserved in the cached file_and_directory. This patch arranges for the allocated name to be preserved there. diff --git a/gdb/dwarf2/file-and-dir.h b/gdb/dwarf2/file-and-dir.h index 1a9ccf35829..c56922ff90d 100644 --- a/gdb/dwarf2/file-and-dir.h +++ b/gdb/dwarf2/file-and-dir.h @@ -84,9 +84,10 @@ struct file_and_directory } /* Set the filename. */ - void set_name (const char *name) + void set_name (gdb::unique_xmalloc_ptr name) { - m_name = name; + m_name_storage = std::move (name); + m_name = m_name_storage.get (); } private: @@ -94,6 +95,9 @@ struct file_and_directory /* The filename. */ const char *m_name; + /* Storage for the filename, if needed. */ + gdb::unique_xmalloc_ptr m_name_storage; + /* The compilation directory. NULL if not known. If we needed to compute a new string, it will be stored in the comp_dir_storage member, and this will be NULL. Otherwise, points directly to the diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index ff5758eb0a4..f2d7da7de52 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -6986,15 +6986,15 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader, prepare_one_comp_unit (cu, comp_unit_die, pretend_language); /* Allocate a new partial symbol table structure. */ - gdb::unique_xmalloc_ptr debug_filename; static const char artificial[] = ""; file_and_directory &fnd = find_file_and_directory (comp_unit_die, cu); if (strcmp (fnd.get_name (), artificial) == 0) { - debug_filename.reset (concat (artificial, "@", - sect_offset_str (per_cu->sect_off), - (char *) NULL)); - fnd.set_name (debug_filename.get ()); + gdb::unique_xmalloc_ptr debug_filename + (concat (artificial, "@", + sect_offset_str (per_cu->sect_off), + (char *) NULL)); + fnd.set_name (std::move (debug_filename)); } pst = create_partial_symtab (per_cu, per_objfile, fnd.get_name ());