From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 9qkxITQ5iWchShEAWB0awg (envelope-from ) for ; Thu, 16 Jan 2025 11:52:04 -0500 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=QkOOjSwf; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 709FE1E100; Thu, 16 Jan 2025 11:52:04 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.0 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id BE4D61E05C for ; Thu, 16 Jan 2025 11:52:03 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E06B5384DD00 for ; Thu, 16 Jan 2025 16:52:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E06B5384DD00 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=QkOOjSwf Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 11F10384DEF1 for ; Thu, 16 Jan 2025 16:51:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 11F10384DEF1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 11F10384DEF1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737046277; cv=none; b=hKQX40mGvxzM4P686KLa9BwSUZv8k6+Mg+odcVPF13lYWCl2UPVSGdMFqmTYUdgsaxwg1ededXRth3xwiR5MbrId4F/6oiJMK3XSCnT+2MGBQz2cKIc0SBIRTh/vzBdApHB64NDBePMPsOoTmKTjLaKhO5lEzfgAVLXDTLs2X2M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737046277; c=relaxed/simple; bh=saoAcTjmC7n4X8JscW2QL4YPakhUathDvxEYoflLxeg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=BgzwqGyMW/hQQZoMrviNnfm+5r9bCEHUnsxqW3vLfzpf04m/hWIBPK+sQ3iX5kcBahVutDMHXL0eTbfwAu2IV/ySh4gRaeYyPoL36AmJEfd1tHwP4uheBiMKflcd02QgNp3yhgfBUuJCqDFSFF5X5qyQLI0SqD6cgEutVbk+JMI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 11F10384DEF1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737046276; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=gTfXoQeWkdAwEKO0K6tg9kruZD7F0cP8kpWDOiiyjHg=; b=QkOOjSwfSZw0WRGTELFlpLZmtklOAUjbnDJ3yIezx64uYXT8PlP+j/aAvvQy6Oc5bHUlJe zLYIgxpYcPRWPendGJdmhkiT+42e9pMDLSaz4keNOxAKOeczXGGRGnJhPnYxHRPnD4TABQ 4GNo08IC9zoBbVHt8DqNKmNN8RB4Boc= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-572-hFbaPs5UPY6S2_ugsAUC9Q-1; Thu, 16 Jan 2025 11:51:15 -0500 X-MC-Unique: hFbaPs5UPY6S2_ugsAUC9Q-1 X-Mimecast-MFC-AGG-ID: hFbaPs5UPY6S2_ugsAUC9Q Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4361efc9d1fso7998145e9.2 for ; Thu, 16 Jan 2025 08:51:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737046273; x=1737651073; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gTfXoQeWkdAwEKO0K6tg9kruZD7F0cP8kpWDOiiyjHg=; b=ptqmMYGsQg0CEqpDHl9BOovtP4JjeAPe1VJYGm/5kLqcOEq1cnbc/4SjD/W8KPsv37 +9b3l8HANLPLJPU/eFm23O0IpbUFE3nfq/acspqadAbq+4Y991PfNIUxHtJvkBG3vrPA Q4fTUa+zePXKtp0SttZ7aqvcoMKXJ6ywjFAE0WBD20hs3lcwJ8tMdnjCl6o1+BjAuq6X 3p1FQiKedLDQGvj9XV/ECtu383BEQGKb5t1dohPQh5xWLfLxjXDC9FPH3YXHiVqY4cv2 4bEaLmv6cDXcXDpOi6Da3PfZ95uCO5iRGYL3dwcSQonDvBvYSrz6cpCLe1dOoy8FqxYL ZizA== X-Forwarded-Encrypted: i=1; AJvYcCW1Y0259fdyxKfKtS2mjnAuWf14M60c3aN4hFJmQu73iTZELrVoUBrlO4DVSwZtq/Ony0cwthcMEY4AIA==@sourceware.org X-Gm-Message-State: AOJu0Yx7OpBr65VNdfAo6YXaY5u8FVWxjywZOqkfJVRF7iJJ3aBlpaqL fBefmLHXmb+iNIdrFzicFIRwuVBWXkOoql1i1LQye7fnP82nJp/KFp4XAUg+C69p76umJqxeLoj /PVKVJfmwNUN62Q3t4PCIQkFiUJoNiBrJE33M86gzDlCHa0CDqTOQ20MgdMW9zS30U1I= X-Gm-Gg: ASbGncsn9Xwo199JKuUBsGl0uOQavjmATo8sZ6C/LdeY0KeKWh+W3+sFZHOcgf0FwEa m1FotM6H1OFOJn8m/w0YNvFCZ9o2H3Wvwc1HKeW7mmk4IJrG/pv6wY+ePiNqtMrtx2KGHWfCQnR e1Q+y0bgfEoYt1upnJQ7bWn1cuGMY3bqzVTw95JB4Nlbu9v6crdlQeCDbrr2JE+gVDzyxPClBsN /rNZeIamIAA7zD8OjuYHHc5QaTGstzHQreXes+cp2CJ9hcOlbI1sXLY0I6u1sRqsJbd3Bxo/2Bg gbODFA== X-Received: by 2002:a5d:598d:0:b0:386:3711:ff8c with SMTP id ffacd0b85a97d-38a873067b9mr33929268f8f.23.1737046273471; Thu, 16 Jan 2025 08:51:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IEA/wmq3ZzKLd+n83p7skgZ3ixpeTSx0vT/9og5LmZL8Xcuu0WU+gPEAPg9baSq7JR44RWnKw== X-Received: by 2002:a5d:598d:0:b0:386:3711:ff8c with SMTP id ffacd0b85a97d-38a873067b9mr33929242f8f.23.1737046273042; Thu, 16 Jan 2025 08:51:13 -0800 (PST) Received: from localhost (44.226.159.143.dyn.plus.net. [143.159.226.44]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38bf3222bebsm324688f8f.30.2025.01.16.08.51.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 08:51:12 -0800 (PST) From: Andrew Burgess To: "brandon.belew" , gdb-patches@sourceware.org Cc: brandon.belew@zetier.com Subject: Re: [PATCH] [PR corefiles/32441] Fix segfault if target_fileio_read_alloc fails In-Reply-To: References: Date: Thu, 16 Jan 2025 16:51:12 +0000 Message-ID: <87v7ueog73.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: zgGa4hAkL_i7G55JDcJwPo4jS9ifhOAj5v5D1O7tnxI_1737046274 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org "brandon.belew" writes: > Check for target_fileio_read_alloc failure in linux_fill_prpsinfo > before dereferencing buffer. This fixes a segfault in the 'gcore' > command when attached to certain remote targets. > --- > This is my first contribution to GDB, and my first use of > git-send-email, so please let me know if this is formatted > incorrectly! I initially submitted the bug and a v1 patch at > https://sourceware.org/bugzilla/show_bug.cgi?id=32441 and received the > following from Thiago Bauermann: > >> Thank you for the patch. In general it looks good to me, just a couple of minor >> comments: >> >> 1. Since target_fileio_read_alloc () returns LONGEST, I think it's better if >> the buf_len variable also has that type. > > I decided to stick with ssize_t for the variable, as this matches the > usage elsewhere in linux-tdep.c in linux_info_proc (which already was > correctly checking the length). I think you should reconsider here. The function returns LONGEST, so that's what should be used. GDB's general policy is to fix little bugs like this as the code gets touched for other reasons. Otherwise, I agree with Luis, this looks great. If you repost with the description in the commit message we can get this merged. Thanks, Andrew > >> 2. GDB is (very) slowly transitioning from C to C++. We currently prefer to use >> nullptr rather than NULL, so I suggest using this patch as an opportunity to >> change NULL to nullptr in lines 1876, 1877 and 1879. > > I made the requested NULL -> nullptr changes. > > Let me know if this is good or if I need to make any changes in my > workflow to adhere to GNU or gdb project conventions. > > gdb/linux-tdep.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c > index d3452059ce2..c10c4c76451 100644 > --- a/gdb/linux-tdep.c > +++ b/gdb/linux-tdep.c > @@ -1867,17 +1867,17 @@ linux_fill_prpsinfo (struct elf_internal_linux_prpsinfo *p) > /* The number of fields read by `sscanf'. */ > int n_fields = 0; > > - gdb_assert (p != NULL); > + gdb_assert (p != nullptr); > > /* Obtaining PID and filename. */ > pid = inferior_ptid.pid (); > xsnprintf (filename, sizeof (filename), "/proc/%d/cmdline", (int) pid); > /* The full name of the program which generated the corefile. */ > - gdb_byte *buf = NULL; > - size_t buf_len = target_fileio_read_alloc (NULL, filename, &buf); > + gdb_byte *buf = nullptr; > + ssize_t buf_len = target_fileio_read_alloc (nullptr, filename, &buf); > gdb::unique_xmalloc_ptr fname ((char *)buf); > > - if (buf_len < 1 || fname.get ()[0] == '\0') > + if (buf_len < 1 || fname.get () == nullptr || fname.get ()[0] == '\0') > { > /* No program name was read, so we won't be able to retrieve more > information about the process. */ > -- > 2.46.0