From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ThIaAWwlZmeGDCYAWB0awg (envelope-from ) for ; Fri, 20 Dec 2024 21:18:20 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=zetier.com header.i=@zetier.com header.a=rsa-sha256 header.s=gm header.b=TCr4ks2+; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id EA7F81E097; Fri, 20 Dec 2024 21:18:19 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.8 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DATE_IN_PAST_03_06,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable 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 56B3C1E05C for ; Fri, 20 Dec 2024 21:18:19 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EACE83858C2B for ; Sat, 21 Dec 2024 02:18:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EACE83858C2B Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=zetier.com header.i=@zetier.com header.a=rsa-sha256 header.s=gm header.b=TCr4ks2+ Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) by sourceware.org (Postfix) with ESMTPS id CFF493858D26 for ; Sat, 21 Dec 2024 02:15:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CFF493858D26 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=zetier.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=zetier.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CFF493858D26 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::836 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1734747344; cv=none; b=x/X9BMpKCBuRL/1jyjoIo5F7SyIUl4rBBITELz0Py1EBwAxvOPcy18N/6k0d11ClYu7cN22LSyJTZUBfrWXBmvKI0oQIR+xOhziV2qzq3r4ZSDGva/zsJsjkmCi1TcNr+WbDpJjrApRuILWb/szkOF0CLAiDyWHVAurhL7kc464= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1734747344; c=relaxed/simple; bh=iPI+NIApyLXHmaOGHyJ+jBkXG22srT3lkabDZ5ZGoR8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=h09+hIshtjyvBda3qMazRXI1IZ9K4AuGPtrmhkctc4cjSGN3fDZ89mKYt2ETRTViHaCcA63Inue1OJASSyAqU/eg5YU4QmACecPz4X4821hXoQG6RX5H5mYxS/ebx0BbY58eABAnahbR8lF24teSqfOWn+9ZX82EOI+lTW1ZW6k= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CFF493858D26 Received: by mail-qt1-x836.google.com with SMTP id d75a77b69052e-46772a0f85bso21802601cf.3 for ; Fri, 20 Dec 2024 18:15:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zetier.com; s=gm; t=1734747343; x=1735352143; darn=sourceware.org; h=mime-version:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=RPa7+5q+RBoHq5WcQnmpVjgX/deAbwvTBepeqqH7SXI=; b=TCr4ks2+RrmRTby4Rm/PBm8tgXEwLbjZtQgk3JQyCn0HlDnBCYD62L7YsKhtuVnFyc G90hJ0Rw75RCyN8ODvhFLly+KOtpw+VkDUZcG2Z4+gz+dHdhpKpCQIy+pKrxxQFnFyJ1 d/EmVnOZ52EcdDZGUmUBjLQbmLMICeBZ9dp2cjhCO/btgpUglJBpmPa6bdja8w8Csa4i xI5XEJOQ1DZ2vSaEbmuT0BDYjMLD+/3gJFEi1/ZK7VPS8WJSfZzuC74PN+nyYH3KHSr5 qfheBYSc+AVYswxNCYjDhlk2uJd7RzxTCA6vHAeqMJXN9sobkaOcrR8dwMSsORnSq3y2 1vVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734747343; x=1735352143; h=mime-version:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=RPa7+5q+RBoHq5WcQnmpVjgX/deAbwvTBepeqqH7SXI=; b=LJALyuYaKkEi5rDUlnt6YntFLaMWcp3e+9yblb8D6bSBJWZtIBHUoDSa8ffU2/w7V4 PdnoYS/bqHaWSUTFK14h5YtjdJeDo/jWWGRt2woEq3+vXDTal7WVS11pnWtcswyvkcKC UcmAjvgMrXx20MdG2DVZ1EPSzGq4tDiqlo8ZrJ5ZmXGhhxGaLNuD67NlOrHXcVq3bkmf V7fIM8/zhwoBm+lN9IPE6HNXHteOPcDwkODxXxQFy+GfCjLfXL+Rt4EjCbjgbwUZCtSx AQ8B6MCw/3Mj/o1XaK7PsCy/Bk0JVlzjDEeldNI3xebo4iZ7bBYiHeEOU0KIG9+A3igf maWw== X-Gm-Message-State: AOJu0Yzs8TSZ3UDG1dS4hwXQJyNUBqKc7yMilRrnIgwdV1L9VZX4UKmZ /baCt8vFeFkY4+tRIoSovpb+eNacQVlS4vh9cbKQUgRC8tYw18zRQLYAbenCSKG5HO7vnji1Olu Ct/lb8w== X-Gm-Gg: ASbGnctLinFwnSrUZa//vWU/z55cYqwcJF+c22QKTN4N3QtbSk3KWb6DC+byTU0xFLJ m962GbKxt6mCl09OcAbDL4x53G71sj2MG/ra9wpW5L3K6QXMOBuzjnNol/YER2OAeXqFmZltSEV 9syfpo0jxlMV0/K+Kl/qXvBdqkbt5t7b6bRnqdEkR2K0G4QEuvhywDNIJekIIIchNqzUUAy0qps dQArVIBPAXKjbHyUql6mwCekobGi4KujFXnguJcf54oh8s/Ax0wco66lqXbEnrID54BZ0r1ew== X-Google-Smtp-Source: AGHT+IFfif7HNJ+0+e5xuN5rdFXP12AP9CgjHUhl2/OmwhevP+yEKpUr7Lu/NzmSTB8a26mTmOMRHw== X-Received: by 2002:ac8:5a09:0:b0:466:9197:b503 with SMTP id d75a77b69052e-46a4a9a33e8mr89828731cf.46.1734747343101; Fri, 20 Dec 2024 18:15:43 -0800 (PST) Received: from brandonb.zetier.com ([65.222.209.234]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46a3eb17902sm22460871cf.60.2024.12.20.18.15.42 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Dec 2024 18:15:42 -0800 (PST) From: "brandon.belew" To: gdb-patches@sourceware.org Cc: brandon.belew@zetier.com Subject: [PATCH] [PR corefiles/32441] Fix segfault if target_fileio_read_alloc fails Date: Fri, 20 Dec 2024 17:17:33 -0500 Message-ID: MIME-Version: 1.0 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 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). > 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