Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: gdb-patches@sourceware.org
Cc: Joost van der Sluis <joost@cnoc.nl>
Subject: [patch] Fix crash on reading stabs
Date: Tue, 17 Nov 2009 16:31:00 -0000	[thread overview]
Message-ID: <20091117162958.GA827@host0.dyn.jankratochvil.net> (raw)

Hi,

there is a crash on reading stabs fpc binary:
	https://bugzilla.redhat.com/show_bug.cgi?id=537837

Program received signal SIGSEGV, Segmentation fault.
0x000000000069db3d in read_dbx_symtab (objfile=0x1daf5f0) at dbxread.c:1369
1369              if ((namestring[0] == '-' && namestring[1] == 'l')

(gdb) p/x nlist.n_strx
$7 = 0xfffffff8
(gdb) p sizeof(nlist.n_strx)
$10 = 8

Below the patch context is:
    namestring = (nlist->n_strx + file_string_table_offset
                  + DBX_STRINGTAB (objfile));

so IMO the `(unsigned)' cast is excessive as it does not match the expression
below.  Such cast is there since the GDB "Initial revision" (1999).

`n_strx' type:
struct internal_nlist
{
  unsigned long n_strx;                 /* Index into string table of name.  */
...
};

Regression tested on {x86_64,x86_64-m32,i686}-fedora12-linux-gnu which does not
mean anything with the default DWARF debug info.  It was hanging for stabs so
tried just a large part of gdb.base/*.exp on x86_64-m32 - `unix/-gstabs+/-m32'.

If it isn't obviously approved please feel free to drop it as one should not
use STABS in the first place.


Regards,
Jan


gdb/
2009-11-17  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* dbxread.c (set_namestring): Remove cast to unsigned.  Check N_STRX
	overflow.

--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -965,8 +965,9 @@ set_namestring (struct objfile *objfile, const struct internal_nlist *nlist)
 {
   char *namestring;
 
-  if (((unsigned) nlist->n_strx + file_string_table_offset)
-      >= DBX_STRINGTAB_SIZE (objfile))
+  if (nlist->n_strx + file_string_table_offset
+      >= DBX_STRINGTAB_SIZE (objfile)
+      || nlist->n_strx + file_string_table_offset < nlist->n_strx)
     {
       complaint (&symfile_complaints, _("bad string table offset in symbol %d"),
 		 symnum);


             reply	other threads:[~2009-11-17 16:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-17 16:31 Jan Kratochvil [this message]
2009-11-17 19:40 ` Joel Brobecker
2009-11-17 20:50   ` Jan Kratochvil

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=20091117162958.GA827@host0.dyn.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=joost@cnoc.nl \
    /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