* srec.c (srec_get_section_contents): Return immediately on
authorAlan Modra <amodra@gmail.com>
Thu, 26 Jul 2007 12:34:43 +0000 (12:34 +0000)
committerAlan Modra <amodra@gmail.com>
Thu, 26 Jul 2007 12:34:43 +0000 (12:34 +0000)
count zero.  Check that offset and count are within section.
* libbfd.c (_bfd_generic_get_section_contents): Check that
offset + count does not overflow.

bfd/ChangeLog
bfd/libbfd.c
bfd/srec.c

index 9bef708ab1610acb8bb6c2dc283bd817fc91f2dc..19a7c49b4c57f15277a85e33ace9c4c26486cec7 100644 (file)
@@ -1,5 +1,10 @@
 2007-07-26  Alan Modra  <amodra@bigpond.net.au>
 
+       * srec.c (srec_get_section_contents): Return immediately on
+       count zero.  Check that offset and count are within section.
+       * libbfd.c (_bfd_generic_get_section_contents): Check that
+       offset + count does not overflow.
+
        * srec.c (srec_canonicalize_symtab): Don't alloc when symcount
        is zero.  Correct return value on error.
        * mmo.c (mmo_canonicalize_symtab): Likewise.
index 33d9c017ab63f336f3eeb673d7caa28555763a5f..bf49a2e1db14671145790ef88433016f394f28df 100644 (file)
@@ -820,7 +820,8 @@ _bfd_generic_get_section_contents (bfd *abfd,
     return TRUE;
 
   sz = section->rawsize ? section->rawsize : section->size;
-  if (offset + count > sz)
+  if (offset + count < count
+      || offset + count > sz)
     {
       bfd_set_error (bfd_error_invalid_operation);
       return FALSE;
index a5f588c231e99c811e3f5d8990900f5218745541..ebb039bba36eb635cdc315d70d6ba49418b4e075 100644 (file)
@@ -781,10 +781,20 @@ srec_get_section_contents (bfd *abfd,
                           file_ptr offset,
                           bfd_size_type count)
 {
+  if (count == 0)
+    return TRUE;
+
+  if (offset + count < count
+      || offset + count > section->size)
+    {
+      bfd_set_error (bfd_error_invalid_operation);
+      return FALSE;
+    }
+
   if (section->used_by_bfd == NULL)
     {
       section->used_by_bfd = bfd_alloc (abfd, section->size);
-      if (section->used_by_bfd == NULL && section->size != 0)
+      if (section->used_by_bfd == NULL)
        return FALSE;
 
       if (! srec_read_section (abfd, section, section->used_by_bfd))