From c0274f2f8d471c66c519f23758f358e6643de997 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Wed, 9 Jun 2010 13:28:31 +0000 Subject: 2010-06-09 Tristan Gingold * bfdio.c (bfd_bread): Fix the code to prevent reading past the end of archive members. --- bfd/bfdio.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'bfd/bfdio.c') diff --git a/bfd/bfdio.c b/bfd/bfdio.c index 4c13a76738..ce92781d50 100644 --- 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; + } } if (abfd->iovec) -- cgit v1.2.1