This is the mail archive of the
binutils@sourceware.cygnus.com
mailing list for the binutils project.
Re: Fix bfd_read to cope with bad BIMs
- To: ian at zembu dot com
- Subject: Re: Fix bfd_read to cope with bad BIMs
- From: Nick Clifton <nickc at cygnus dot com>
- Date: Fri, 21 Jan 2000 12:19:18 -0800
- Cc: binutils at sourceware dot cygnus dot com
Hi Ian
: I think bfd_seek should return an error on an attempt to seek past
: the end of the file, rather than silently truncating abfd->where.
No sooner said than done:
Index: libbfd.c
===================================================================
RCS file: /cvs/binutils/binutils/bfd/libbfd.c,v
retrieving revision 1.7
diff -p -r1.7 libbfd.c
*** libbfd.c 1999/11/09 19:13:21 1.7
--- libbfd.c 2000/01/21 20:18:24
*************** bfd_read (ptr, size, nitems, abfd)
*** 274,280 ****
get = size * nitems;
if (abfd->where + get > bim->size)
{
! get = bim->size - abfd->where;
bfd_set_error (bfd_error_file_truncated);
}
memcpy (ptr, bim->buffer + abfd->where, get);
--- 274,283 ----
get = size * nitems;
if (abfd->where + get > bim->size)
{
! if (bim->size < abfd->where)
! get = 0;
! else
! get = bim->size - abfd->where;
bfd_set_error (bfd_error_file_truncated);
}
memcpy (ptr, bim->buffer + abfd->where, get);
*************** bfd_seek (abfd, position, direction)
*** 677,686 ****
--- 680,700 ----
if ((abfd->flags & BFD_IN_MEMORY) != 0)
{
+ struct bfd_in_memory *bim;
+
+ bim = (struct bfd_in_memory *) abfd->iostream;
+
if (direction == SEEK_SET)
abfd->where = position;
else
abfd->where += position;
+
+ if (abfd->where > bim->size)
+ {
+ abfd->where = bim->size;
+ bfd_set_error (bfd_error_file_truncated);
+ }
+
return 0;
}