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]

[Patch]: do not allow to read past the end of an archive member


Hi,

the bfd_bread() code to prevent from reading past of an archive member is buggy: it worked only
if the current position is the start of the member.  This patch fixes this issue.

Ok to commit ?
(no regressions on i386 gnu/linux)

Tristan.


bfd/
2010-06-08  Tristan Gingold  <gingold@adacore.com>

	* bfdio.c (bfd_bread): Fix the code to prevent reading past the
	end of archive members.


--- a/bfd/bfdio.c
+++ b/bfd/bfdio.c
@@ -180,8 +180,12 @@ bfd_bread (void *ptr, bfd_size_type size, bfd *abfd)
   if (abfd->arelt_data != NULL)
     {
       size_t maxbytes = ((struct areltdata *) abfd->arelt_data)->parsed_size;
-      if (size > maxbytes)
-       size = maxbytes;
+      if (abfd->where + size > maxbytes)
+        {
+          if (abfd->where >= maxbytes)
+            return 0;
+          size = maxbytes - abfd->where;
+        }
     }
 


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