This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

bfd_seek on BFD_IN_MEMORY


While looking at bfd_seek in connection with PR10193, I noticed that
for BFD_IN_MEMORY it is possible to leave some allocated memory
uninitialised.  This wasn't the cause of PR10193 (BFD_IN_MEMORY not
involved), but ought to be fixed anyway.

       * bfdio.c (bfd_seek): Formatting.  Ensure newly allocated memory
       for BFD_IN_MEMORY is cleared.
       (bfd_bwrite): Zero excess memory allocated.

Index: bfd/bfdio.c
===================================================================
RCS file: /cvs/src/src/bfd/bfdio.c,v
retrieving revision 1.20
diff -u -p -r1.20 bfdio.c
--- bfd/bfdio.c	23 Feb 2009 09:28:42 -0000	1.20
+++ bfd/bfdio.c	24 May 2009 07:09:40 -0000
@@ -235,6 +235,8 @@ bfd_bwrite (const void *ptr, bfd_size_ty
 		  bim->size = 0;
 		  return 0;
 		}
+	      if (newsize > bim->size)
+		memset (bim->buffer + bim->size, 0, newsize - bim->size);
 	    }
 	}
       memcpy (bim->buffer + abfd->where, ptr, (size_t) size);
@@ -342,8 +344,8 @@ bfd_seek (bfd *abfd, file_ptr position, 
 
       if (abfd->where > bim->size)
 	{
-	  if ((abfd->direction == write_direction) ||
-	      (abfd->direction == both_direction))
+	  if (abfd->direction == write_direction
+	      || abfd->direction == both_direction)
 	    {
 	      bfd_size_type newsize, oldsize;
 
@@ -359,6 +361,7 @@ bfd_seek (bfd *abfd, file_ptr position, 
 		      bim->size = 0;
 		      return -1;
 		    }
+		  memset (bim->buffer + oldsize, 0, newsize - oldsize);
 	        }
 	    }
 	  else

-- 
Alan Modra
Australia Development Lab, IBM


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]