From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 150BA3858D37 for ; Mon, 21 Feb 2022 11:51:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 150BA3858D37 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-599-OSGO5rM9N2Ks9oJEbXj_Jw-1; Mon, 21 Feb 2022 06:51:21 -0500 X-MC-Unique: OSGO5rM9N2Ks9oJEbXj_Jw-1 Received: by mail-wr1-f69.google.com with SMTP id g11-20020adfa48b000000b001e57dfb3c38so7274823wrb.2 for ; Mon, 21 Feb 2022 03:51:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:in-reply-to:references:date :message-id:mime-version; bh=ZIbNiPvy3JQSNP3UXNDFgywNRV6hSnP50+x9Ku70aHM=; b=NUBuWROONRRqUyt3cHuluoprFai9XW9hUPicVlw8IXkoizFRapgcS/IHzbcou+Vlkx Uas5Wes2iBmC4s8SltOKWbwTtRa4LZKyYD8cQGyZ59BcKB1kmlSnzJntQ/GGeYu6EDRj RcSEVYBINtf06Y6e6iCp86BzHo5M7086luDYKPlm6ZLaTkmzZswl9uqxwpWTwutRGGD1 tqDVmf1L/E8q26k6dGoSvBru3mBoGRrfzYED5NcAuvBbNz510AF4TR0MIstO5yZ7nfMn e4NmdBdNOflcw/hkbJtJIVRU+Gl2Qd7473LzElzRmSOEqrYRLv4hrjd5vviyfPKL0Qj3 1sYA== X-Gm-Message-State: AOAM532Cpl67Rw2HFnx7RUi33In01+XbfRpJMT3opPtyM80kQospj5i+ CrhIAMBB1kVuueXnER3cJS3KH07PTzL01Fhu6/O9c2XCCcYi8notwpeLT8j5tDGjP6YjhVByBjw oCtAXh2EcngDHiWW3FB8g4Q== X-Received: by 2002:a05:6000:22f:b0:1e3:3415:4078 with SMTP id l15-20020a056000022f00b001e334154078mr15343167wrz.69.1645444279997; Mon, 21 Feb 2022 03:51:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJxHUxm4zZeOleOsTGWQbIwCCQ44XDQAJnnAPAzQblqVQDXs3Hdfr1zG1idiibw9LAGXFZ+lrQ== X-Received: by 2002:a05:6000:22f:b0:1e3:3415:4078 with SMTP id l15-20020a056000022f00b001e334154078mr15343154wrz.69.1645444279778; Mon, 21 Feb 2022 03:51:19 -0800 (PST) Received: from localhost (host86-169-131-29.range86-169.btcentralplus.com. [86.169.131.29]) by smtp.gmail.com with ESMTPSA id u23-20020a7bcb17000000b0037bdfa1665asm8687869wmj.18.2022.02.21.03.51.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 03:51:19 -0800 (PST) From: Andrew Burgess To: Simon Marchi , gdb-patches@sourceware.org Subject: Re: [PATCH 2/2] gdb: avoid nullptr access in dbxread.c from read_dbx_symtab In-Reply-To: <1eb38e94-5132-af9a-29a8-5810cf9a5eab@polymtl.ca> References: <8febea6adac3d80d41f41a2e5e49dc98d0b934ba.1645300222.git.aburgess@redhat.com> <1eb38e94-5132-af9a-29a8-5810cf9a5eab@polymtl.ca> Date: Mon, 21 Feb 2022 11:51:18 +0000 Message-ID: <87k0docua1.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org 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: , X-List-Received-Date: Mon, 21 Feb 2022 11:51:26 -0000 Simon Marchi via Gdb-patches writes: > On 2022-02-19 14:51, Andrew Burgess via Gdb-patches wrote: >> This fixes a GDB crash reported in bug pr/28900, related to reading in >> some stabs debug information. >> >> In this commit my goal is to stop GDB crashing. I am not trying to >> ensure that GDB makes the best possible use of the available stabs >> debug information. At this point I consider stabs a legacy debug >> format, with only limited support in GDB. >> >> So, the problem appears to be that, when reading in the stabs data, we >> need to find a N_SO entry, this is the entry that defines the start of >> a compilation unit (or at least the location of a corresponding source >> file). >> >> It is while handling an N_SO that GDB creates a psymtab to hold the >> incoming debug information (symbols, etc). >> >> The problem we hit in the bug is that we encounter some symbol >> information (an N_PC entry) outside of an N_SO entry - that is we find >> some symbol information that is not associated with any source file. >> >> We already have some protection for this case, look (in >> read_dbx_symtab) at the handling of N_PC entries of type 'F' and 'f', >> if we have no psymtab (the pst variable is nullptr) then we issue a >> complaint. However, for whatever reason, in both 'f' and 'F' >> handling, there is one place where we assume that the pst >> variable (the psymtab) is not nullptr. This is a mistake. >> >> In this commit, I guard these two locations (in 'f' and 'F' handling) >> so we no longer assume pst is not nullptr. >> >> While I was at it, I audited all the other uses of pst in >> read_dbx_symtab, and in every potentially dangerous case I added a >> nullptr check, and issue a suitable complaint if pst is found to be >> nullptr. >> >> It might well be true that we could/should do something smarter if we >> see a debug symbol outside of an N_SO entry, and if anyone wanted to >> do that work, they're welcome too. But this commit is just about >> preventing the nullptr access, and the subsequent GDB crash. >> >> I don't have any tests for this change, I have no idea how to generate >> weird stabs data for testing. The original binary from the bug report >> now loads just fine without GDB crashing. >> >> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28900 > > For all I know, this looks correct. Thanks for doing this. Thanks, I pushed this patch. Andrew