Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: Brandon Belew <brandon.belew@zetier.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH v2] [PR corefiles/32441] Fix segfault if target_fileio_read_alloc fails
Date: Fri, 28 Feb 2025 11:03:39 +0000	[thread overview]
Message-ID: <87ikouz5ys.fsf@redhat.com> (raw)
In-Reply-To: <hwjgyazfjchuu7.fsf_-_@brandonb.zetier.com>

Brandon Belew <brandon.belew@zetier.com> 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.

LGTM.

Approved-By: Andrew Burgess <aburgess@redhat.com>

Thanks,
Andrew


> ---
>  gdb/linux-tdep.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
> index d3ab02d03e0..735d20dc050 100644
> --- a/gdb/linux-tdep.c
> +++ b/gdb/linux-tdep.c
> @@ -854,7 +854,7 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args,
>      {
>        xsnprintf (filename, sizeof filename, "/proc/%ld/cmdline", pid);
>        gdb_byte *buffer;
> -      ssize_t len = target_fileio_read_alloc (NULL, filename, &buffer);
> +      LONGEST len = target_fileio_read_alloc (nullptr, filename, &buffer);
>
>        if (len > 0)
>  	{
> @@ -2180,17 +2180,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;
> +  LONGEST buf_len = target_fileio_read_alloc (nullptr, filename, &buf);
>    gdb::unique_xmalloc_ptr<char> 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.47.1


  parent reply	other threads:[~2025-02-28 11:04 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-20 22:17 [PATCH] " brandon.belew
2025-01-16 10:27 ` Luis Machado
2025-01-16 16:28   ` Brandon Belew
2025-01-16 16:51 ` Andrew Burgess
2025-01-16 17:36   ` Brandon Belew
2025-01-20 14:44     ` Andrew Burgess
2025-01-27 20:20   ` [PATCH v2] " Brandon Belew
2025-02-18 23:44     ` Brandon Belew
2025-02-28 11:03     ` Andrew Burgess [this message]
2025-03-04 13:47       ` [PATCH v3] " Brandon Belew
2025-03-09  4:17       ` [PATCH v2] " Joel Brobecker
2025-03-01 10:23 GDB 16.3 release - 2025-03-01 update Joel Brobecker
2025-03-03 14:23 ` Luis Machado
2025-03-04  3:07   ` Joel Brobecker
2025-03-03 15:08 ` Brandon Belew
2025-03-04  3:12   ` Joel Brobecker
2025-03-07 14:07     ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ikouz5ys.fsf@redhat.com \
    --to=aburgess@redhat.com \
    --cc=brandon.belew@zetier.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox