aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrandon Belew <brandon.belew@zetier.com>2025-03-09 08:15:07 +0400
committerJoel Brobecker <brobecker@adacore.com>2025-03-09 08:15:07 +0400
commitcbc6950a6603e184ebc6671f2c252a56013b07c2 (patch)
treeeab8155efdf2d397981fa367040952967c0aa2e2
parentfb2f3876d90af66a084a50f84c7da3c8b96c309b (diff)
downloadbinutils-cbc6950a6603e184ebc6671f2c252a56013b07c2.zip
binutils-cbc6950a6603e184ebc6671f2c252a56013b07c2.tar.gz
binutils-cbc6950a6603e184ebc6671f2c252a56013b07c2.tar.bz2
Fix segfault if target_fileio_read_alloc fails
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. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32441 Approved-By: Andrew Burgess <aburgess@redhat.com>
-rw-r--r--gdb/linux-tdep.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index d3ab02d..735d20d 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. */