Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA/HPUX] somread.c: avoid stack overflow
@ 2006-10-04 18:25 Joel Brobecker
  2006-10-04 19:32 ` Mark Kettenis
  0 siblings, 1 reply; 3+ messages in thread
From: Joel Brobecker @ 2006-10-04 18:25 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 572 bytes --]

Hello,

A customer of ours ran into a GDB crash that was caused by a stack
overflow. Their executables are very large, and it turned out when
we started debugging that the overflow happened during an alloca
besides which there already was a FIXME:.

We replace the calls to alloca by a call to xmalloc followed by
make_cleanup and the problem was gone.

2006-10-04  Joel Brobecker  <brobecker@adacore.com>

        * somread.c (som_symtab_read): Avoid using alloca for potentially
        large buffers.

Tested on pa-hpux, no regression.

OK to commit?

Thanks,
-- 
Joel

[-- Attachment #2: som.diff --]
[-- Type: text/plain, Size: 1525 bytes --]

Index: somread.c
===================================================================
RCS file: /cvs/src/src/gdb/somread.c,v
retrieving revision 1.30
diff -u -p -r1.30 somread.c
--- somread.c	1 Mar 2006 05:47:46 -0000	1.30
+++ somread.c	4 Oct 2006 18:20:41 -0000
@@ -88,15 +88,22 @@ som_symtab_read (bfd *abfd, struct objfi
 
   number_of_symbols = bfd_get_symcount (abfd);
 
-  /* FIXME (alloca): could be quite large. */
-  buf = alloca (symsize * number_of_symbols);
+  /* Allocate a buffer to read in the debug info.
+     We avoid using alloca because the memory size could be so large
+     that we could hit the stack size limit.  */
+  buf = xmalloc (symsize * number_of_symbols);
+  make_cleanup (xfree, buf);
   bfd_seek (abfd, obj_som_sym_filepos (abfd), SEEK_SET);
   val = bfd_bread (buf, symsize * number_of_symbols, abfd);
   if (val != symsize * number_of_symbols)
     error (_("Couldn't read symbol dictionary!"));
 
-  /* FIXME (alloca): could be quite large. */
-  stringtab = alloca (obj_som_stringtab_size (abfd));
+  /* Allocate a buffer to read in the som stringtab section of
+     the debugging info.  Again, we avoid using alloca because
+     the data could be so large that we could potentially hit
+     the stack size limitat.  */
+  stringtab = xmalloc (obj_som_stringtab_size (abfd));
+  make_cleanup (xfree, stringtab);
   bfd_seek (abfd, obj_som_str_filepos (abfd), SEEK_SET);
   val = bfd_bread (stringtab, obj_som_stringtab_size (abfd), abfd);
   if (val != obj_som_stringtab_size (abfd))

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

end of thread, other threads:[~2006-10-04 21:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-04 18:25 [RFA/HPUX] somread.c: avoid stack overflow Joel Brobecker
2006-10-04 19:32 ` Mark Kettenis
2006-10-04 21:38   ` Joel Brobecker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox