diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2024-04-04 06:37:18 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2024-04-04 15:35:48 -0700 |
commit | 0ffdc37b98964477e70bfd63ca28f374193dcdb2 (patch) | |
tree | f45a262c03413092c89a8735f34f73a064c36e65 /bfd | |
parent | 360d244b24e84c50f2c6054908cfafb370a1f13c (diff) | |
download | gdb-0ffdc37b98964477e70bfd63ca28f374193dcdb2.zip gdb-0ffdc37b98964477e70bfd63ca28f374193dcdb2.tar.gz gdb-0ffdc37b98964477e70bfd63ca28f374193dcdb2.tar.bz2 |
bfd_mmap_local: Check offset and size
Update bfd_mmap_local to return NULL if filesize < offset or filesize -
offset < rsize.
* libbfd.c (bfd_mmap_local): Validate offset and size against
the file size.
Diffstat (limited to 'bfd')
-rw-r--r-- | bfd/libbfd.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/bfd/libbfd.c b/bfd/libbfd.c index 5126ee2..86366e4 100644 --- a/bfd/libbfd.c +++ b/bfd/libbfd.c @@ -1072,18 +1072,15 @@ static void * bfd_mmap_local (bfd *abfd, size_t rsize, int prot, void **map_addr, size_t *map_size) { - if (!_bfd_constant_p (rsize)) + ufile_ptr filesize = bfd_get_file_size (abfd); + ufile_ptr offset = bfd_tell (abfd); + if (filesize < offset || filesize - offset < rsize) { - ufile_ptr filesize = bfd_get_file_size (abfd); - if (filesize != 0 && rsize > filesize) - { - bfd_set_error (bfd_error_file_truncated); - return NULL; - } + bfd_set_error (bfd_error_file_truncated); + return NULL; } void *mem; - ufile_ptr offset = bfd_tell (abfd); mem = bfd_mmap (abfd, NULL, rsize, prot, MAP_PRIVATE, offset, map_addr, map_size); return mem; |