bfd/
[deliverable/binutils-gdb.git] / bfd / peXXigen.c
index 6597312adb0b767a7917e448289d86d9c178faa8..d7a2991690b9b2aab8397babca1909ac44095add 100644 (file)
@@ -1,6 +1,6 @@
 /* Support for the generic parts of PE/PEI; the common executable parts.
    Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-   2005 Free Software Foundation, Inc.
+   2005, 2006 Free Software Foundation, Inc.
    Written by Cygnus Solutions.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -147,6 +147,7 @@ _bfd_XXi_swap_sym_in (bfd * abfd, void * ext1, void * in1)
          int unused_section_number = 0;
          asection *sec;
          char *name;
+         flagword flags;
 
          for (sec = abfd->sections; sec; sec = sec->next)
            if (unused_section_number <= sec->target_index)
@@ -156,7 +157,8 @@ _bfd_XXi_swap_sym_in (bfd * abfd, void * ext1, void * in1)
          if (name == NULL)
            return;
          strcpy (name, in->n_name);
-         sec = bfd_make_section_anyway (abfd, name);
+         flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_DATA | SEC_LOAD;
+         sec = bfd_make_section_anyway_with_flags (abfd, name, flags);
 
          sec->vma = 0;
          sec->lma = 0;
@@ -169,7 +171,6 @@ _bfd_XXi_swap_sym_in (bfd * abfd, void * ext1, void * in1)
          sec->userdata = NULL;
          sec->next = NULL;
          sec->alignment_power = 2;
-         sec->flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_DATA | SEC_LOAD;
 
          sec->target_index = unused_section_number;
 
@@ -1103,7 +1104,7 @@ pe_print_idata (bfd * abfd, void * vfile)
       bfd_vma toc_address;
       bfd_vma start_address;
       bfd_byte *data;
-      int offset;
+      bfd_vma offset;
 
       if (!bfd_malloc_and_get_section (abfd, rel_section, &data))
        {
@@ -1114,6 +1115,13 @@ pe_print_idata (bfd * abfd, void * vfile)
 
       offset = abfd->start_address - rel_section->vma;
 
+      if (offset >= rel_section->size || offset + 8 > rel_section->size)
+        {
+          if (data != NULL)
+            free (data);
+          return FALSE;
+        }
+
       start_address = bfd_get_32 (abfd, data + offset);
       loadable_toc_address = bfd_get_32 (abfd, data + offset + 4);
       toc_address = loadable_toc_address - 32768;
@@ -1182,6 +1190,9 @@ pe_print_idata (bfd * abfd, void * vfile)
       if (hint_addr == 0 && first_thunk == 0)
        break;
 
+      if (dll_name - adj >= section->size)
+        break;
+
       dll = (char *) data + dll_name - adj;
       fprintf (file, _("\n\tDLL Name: %s\n"), dll);
 
@@ -1336,6 +1347,7 @@ pe_print_edata (bfd * abfd, void * vfile)
        return TRUE;
 
       addr = section->vma;
+      dataoff = 0;
       datasize = section->size;
       if (datasize == 0)
        return TRUE;
@@ -1345,12 +1357,8 @@ pe_print_edata (bfd * abfd, void * vfile)
       addr += extra->ImageBase;
 
       for (section = abfd->sections; section != NULL; section = section->next)
-       {
-         datasize = section->size;
-
-         if (addr >= section->vma && addr < section->vma + datasize)
-           break;
-       }
+       if (addr >= section->vma && addr < section->vma + section->size)
+         break;
 
       if (section == NULL)
        {
@@ -1358,14 +1366,21 @@ pe_print_edata (bfd * abfd, void * vfile)
                   _("\nThere is an export table, but the section containing it could not be found\n"));
          return TRUE;
        }
+
+      dataoff = addr - section->vma;
+      datasize = extra->DataDirectory[0].Size;
+      if (datasize > section->size - dataoff)
+       {
+         fprintf (file,
+                  _("\nThere is an export table in %s, but it does not fit into that section\n"),
+                  section->name);
+         return TRUE;
+       }
     }
 
   fprintf (file, _("\nThere is an export table in %s at 0x%lx\n"),
           section->name, (unsigned long) addr);
 
-  dataoff = addr - section->vma;
-  datasize -= dataoff;
-
   data = bfd_malloc (datasize);
   if (data == NULL)
     return FALSE;
@@ -1654,7 +1669,7 @@ static const char * const tbl[] =
   "RESERVED1",
   "MIPS_JMPADDR16",
   "DIR64",
-  "HIGH3ADJ"
+  "HIGH3ADJ",
   "UNKNOWN",   /* MUST be last.  */
 };
 
This page took 0.031349 seconds and 4 git commands to generate.