aboutsummaryrefslogtreecommitdiff
path: root/gdb/dbxread.c
diff options
context:
space:
mode:
authorFred Fish <fnf@specifix.com>1993-03-04 00:01:32 +0000
committerFred Fish <fnf@specifix.com>1993-03-04 00:01:32 +0000
commit69a272c4f6b452de40e6994c55f8941f957ff8f2 (patch)
tree4e3852958441a716e83cef4f24caed30f372cef6 /gdb/dbxread.c
parent350e711979f38198d99fc90194b1d4fe44b00048 (diff)
downloadgdb-69a272c4f6b452de40e6994c55f8941f957ff8f2.zip
gdb-69a272c4f6b452de40e6994c55f8941f957ff8f2.tar.gz
gdb-69a272c4f6b452de40e6994c55f8941f957ff8f2.tar.bz2
* dbxread.c (dbx_symfile_init): Make size of the string table
size field a define (DBX_STRINGTAB_SIZE_SIZE). Ensure that the offset to the string table is nonzero and handle the nonexistant string table case, should it occur. Ensure that the string table size read from the file is reasonable, with a minimum lower bound of DBX_STRINGTAB_SIZE_SIZE instead of zero.
Diffstat (limited to 'gdb/dbxread.c')
-rw-r--r--gdb/dbxread.c79
1 files changed, 44 insertions, 35 deletions
diff --git a/gdb/dbxread.c b/gdb/dbxread.c
index 3cb4bcd..3f9334b 100644
--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -515,6 +515,8 @@ dbx_new_init (ignore)
be called unless this is an a.out (or very similar) file.
FIXME, there should be a cleaner peephole into the BFD environment here. */
+#define DBX_STRINGTAB_SIZE_SIZE sizeof(long) /* FIXME */
+
static void
dbx_symfile_init (objfile)
struct objfile *objfile;
@@ -522,7 +524,7 @@ dbx_symfile_init (objfile)
int val;
bfd *sym_bfd = objfile->obfd;
char *name = bfd_get_filename (sym_bfd);
- unsigned char size_temp[sizeof(long)];
+ unsigned char size_temp[DBX_STRINGTAB_SIZE_SIZE];
/* Allocate struct to keep track of the symfile */
objfile->sym_private = (PTR)
@@ -552,41 +554,48 @@ dbx_symfile_init (objfile)
table size would be so totally bogus that the malloc would fail. Now
that we put in on the psymbol_obstack, we can't do this since gdb gets
a fatal error (out of virtual memory) if the size is bogus. We can
- however at least check to see if the size is zero or some negative
- value. */
-
- val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET);
- if (val < 0)
- perror_with_name (name);
-
- memset (size_temp, 0, sizeof (size_temp));
- val = bfd_read ((PTR)size_temp, sizeof (long), 1, sym_bfd);
- if (val < 0)
- perror_with_name (name);
+ however at least check to see if the size is less than the size of
+ the size field itself, or larger than the size of the entire file.
+ Note that all valid string tables have a size greater than zero, since
+ the bytes used to hold the size are included in the count. */
- DBX_STRINGTAB_SIZE (objfile) = bfd_h_get_32 (sym_bfd, size_temp);
-
- if (DBX_STRINGTAB_SIZE (objfile) == 0)
- error ("%s has no string table.", name);
-
- if (DBX_STRINGTAB_SIZE (objfile) < 0
- || DBX_STRINGTAB_SIZE (objfile) > bfd_get_size (sym_bfd))
- error ("ridiculous string table size (%d bytes).",
- DBX_STRINGTAB_SIZE (objfile));
-
- DBX_STRINGTAB (objfile) =
- (char *) obstack_alloc (&objfile -> psymbol_obstack,
- DBX_STRINGTAB_SIZE (objfile));
-
- /* Now read in the string table in one big gulp. */
-
- val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET);
- if (val < 0)
- perror_with_name (name);
- val = bfd_read (DBX_STRINGTAB (objfile), DBX_STRINGTAB_SIZE (objfile), 1,
- sym_bfd);
- if (val != DBX_STRINGTAB_SIZE (objfile))
- perror_with_name (name);
+ if (STRING_TABLE_OFFSET == 0)
+ {
+ DBX_STRINGTAB_SIZE (objfile) = 0;
+ DBX_STRINGTAB (objfile) = NULL;
+ }
+ else
+ {
+ val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET);
+ if (val < 0)
+ perror_with_name (name);
+
+ memset ((PTR) size_temp, 0, sizeof (size_temp));
+ val = bfd_read ((PTR) size_temp, sizeof (size_temp), 1, sym_bfd);
+ if (val < 0)
+ perror_with_name (name);
+
+ DBX_STRINGTAB_SIZE (objfile) = bfd_h_get_32 (sym_bfd, size_temp);
+
+ if (DBX_STRINGTAB_SIZE (objfile) < sizeof (size_temp)
+ || DBX_STRINGTAB_SIZE (objfile) > bfd_get_size (sym_bfd))
+ error ("ridiculous string table size (%d bytes).",
+ DBX_STRINGTAB_SIZE (objfile));
+
+ DBX_STRINGTAB (objfile) =
+ (char *) obstack_alloc (&objfile -> psymbol_obstack,
+ DBX_STRINGTAB_SIZE (objfile));
+
+ /* Now read in the string table in one big gulp. */
+
+ val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET);
+ if (val < 0)
+ perror_with_name (name);
+ val = bfd_read (DBX_STRINGTAB (objfile), DBX_STRINGTAB_SIZE (objfile), 1,
+ sym_bfd);
+ if (val != DBX_STRINGTAB_SIZE (objfile))
+ perror_with_name (name);
+ }
}
/* Perform any local cleanups required when we are done with a particular