This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[Patch]: do not allow to read past the end of an archive member
- From: Tristan Gingold <gingold at adacore dot com>
- To: binutils <binutils at sourceware dot org>
- Date: Tue, 8 Jun 2010 16:14:33 +0200
- Subject: [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;
+ }
}