public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* bfd_seek on BFD_IN_MEMORY
@ 2009-05-24 11:47 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2009-05-24 11:47 UTC (permalink / raw)
  To: binutils

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-05-24 11:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-24 11:47 bfd_seek on BFD_IN_MEMORY Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).