public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@bigpond.net.au>
To: binutils@sourceware.org
Subject: bfd_seek on BFD_IN_MEMORY
Date: Sun, 24 May 2009 11:47:00 -0000	[thread overview]
Message-ID: <20090524114738.GM3704@bubble.grove.modra.org> (raw)

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

                 reply	other threads:[~2009-05-24 11:47 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090524114738.GM3704@bubble.grove.modra.org \
    --to=amodra@bigpond.net.au \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).