public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug gdb/9885] field for register names too narrow
       [not found] <bug-9885-4717@http.sourceware.org/bugzilla/>
@ 2014-12-01 20:50 ` larue at cadence dot com
  2014-12-01 21:07 ` larue at cadence dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 4+ messages in thread
From: larue at cadence dot com @ 2014-12-01 20:50 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=9885

larue at cadence dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |larue at cadence dot com

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug gdb/9885] field for register names too narrow
       [not found] <bug-9885-4717@http.sourceware.org/bugzilla/>
  2014-12-01 20:50 ` [Bug gdb/9885] field for register names too narrow larue at cadence dot com
@ 2014-12-01 21:07 ` larue at cadence dot com
  2014-12-01 21:12 ` larue at cadence dot com
  2020-04-28 16:01 ` ssbssa at sourceware dot org
  3 siblings, 0 replies; 4+ messages in thread
From: larue at cadence dot com @ 2014-12-01 21:07 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=9885

--- Comment #1 from larue at cadence dot com ---
I have recently encountered this problem, and found it is much more severe than
indicated in this bug report.  If a register name is > 15 characters then a
negative value is passed to n_spaces().  This causes garbage to be printed, and
occasional crashes of gdb.

This problem still exists in gdb-7.8.1.

The function default_print_one_register_info() calls:
print_spaces_filtered (15 - strlen (name), file);

if the register length is greater than 15, then print_spaces_filtered is called
with a negative value.

The following is a snippet of code from gdb/utils.c.  Notice that if n < 0,
then n_spaces returns pointer to potentially unallocated data in the heap.
This sometimes causes a crash in gdb, and garbage is printed in other cases.

char *
n_spaces (int n)
{
  char *t;
  static char *spaces = 0;
  static int max_spaces = -1;

  if (n > max_spaces)
    {
      if (spaces)
        xfree (spaces);
      spaces = (char *) xmalloc (n + 1);
      for (t = spaces + n; t != spaces;)
        *--t = ' ';
      spaces[n] = '\0';
      max_spaces = n;
    }

  return spaces + max_spaces - n;
}

void
print_spaces_filtered (int n, struct ui_file *stream)
{
  fputs_filtered (n_spaces (n), stream);
}


Ideally, gdb should be able to nicely print with arbitrary length register
names, but at a minimum the crash and garbage output should be fixed. A simple
way to do this is to put this check in n_spaces()

char *
n_spaces (int n)
{
  char *t;
  static char *spaces = 0;
  static int max_spaces = -1;

  if (n > max_spaces)
    {
      if (spaces)
        xfree (spaces);
      spaces = (char *) xmalloc (n + 1);
      for (t = spaces + n; t != spaces;)
        *--t = ' ';
      spaces[n] = '\0';
      max_spaces = n;
    }

  return spaces + max_spaces - n;
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug gdb/9885] field for register names too narrow
       [not found] <bug-9885-4717@http.sourceware.org/bugzilla/>
  2014-12-01 20:50 ` [Bug gdb/9885] field for register names too narrow larue at cadence dot com
  2014-12-01 21:07 ` larue at cadence dot com
@ 2014-12-01 21:12 ` larue at cadence dot com
  2020-04-28 16:01 ` ssbssa at sourceware dot org
  3 siblings, 0 replies; 4+ messages in thread
From: larue at cadence dot com @ 2014-12-01 21:12 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=9885

--- Comment #2 from larue at cadence dot com ---
Oops, accidentally saved before pasting in the patch (shown below):

char *
n_spaces (int n)
{
  char *t;
  static char *spaces = 0;
  static int max_spaces = -1;
  /* Prevent heap corruption if n is negative (which occurs if
default_print_one_register_info is called with a register whose name
is > 15 characters long */
  if (n < 0)
     n = 0;
  if (n > max_spaces)
    {
      if (spaces)
        xfree (spaces);
      spaces = (char *) xmalloc (n + 1);
      for (t = spaces + n; t != spaces;)
        *--t = ' ';
      spaces[n] = '\0';
      max_spaces = n;
    }

  return spaces + max_spaces - n;
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug gdb/9885] field for register names too narrow
       [not found] <bug-9885-4717@http.sourceware.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2014-12-01 21:12 ` larue at cadence dot com
@ 2020-04-28 16:01 ` ssbssa at sourceware dot org
  3 siblings, 0 replies; 4+ messages in thread
From: ssbssa at sourceware dot org @ 2020-04-28 16:01 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=9885

Hannes Domani <ssbssa at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|6.8                         |8.2
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED
                 CC|                            |ssbssa at sourceware dot org

--- Comment #3 from Hannes Domani <ssbssa at sourceware dot org> ---
Fixed since version 8.2, with this commit:
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=e813d34aaabee0ca034fa5ddd50e76ade80318bc

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-04-28 16:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-9885-4717@http.sourceware.org/bugzilla/>
2014-12-01 20:50 ` [Bug gdb/9885] field for register names too narrow larue at cadence dot com
2014-12-01 21:07 ` larue at cadence dot com
2014-12-01 21:12 ` larue at cadence dot com
2020-04-28 16:01 ` ssbssa at sourceware dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).