diff options
author | Nick Clifton <nickc@redhat.com> | 2000-01-21 20:52:35 +0000 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2000-01-21 20:52:35 +0000 |
commit | 2e4bb80ea1ba3e5a4c56d6755cb5f6faf0a5a774 (patch) | |
tree | cd21e4aee484a08b4497bd5e0b4ee0ac41e30110 /bfd/libbfd.c | |
parent | 13392b77a79c3512d30ee9d6a547638eeb6fd28a (diff) | |
download | gdb-2e4bb80ea1ba3e5a4c56d6755cb5f6faf0a5a774.zip gdb-2e4bb80ea1ba3e5a4c56d6755cb5f6faf0a5a774.tar.gz gdb-2e4bb80ea1ba3e5a4c56d6755cb5f6faf0a5a774.tar.bz2 |
Fix seeks and reads past the end of a BIM
Diffstat (limited to 'bfd/libbfd.c')
-rw-r--r-- | bfd/libbfd.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/bfd/libbfd.c b/bfd/libbfd.c index b43e88c..fb833f6 100644 --- a/bfd/libbfd.c +++ b/bfd/libbfd.c @@ -274,7 +274,10 @@ bfd_read (ptr, size, nitems, abfd) get = size * nitems; if (abfd->where + get > bim->size) { - get = bim->size - abfd->where; + 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); @@ -677,10 +680,22 @@ bfd_seek (abfd, position, direction) 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 -1; + } + return 0; } |