readelf looping in process_archive
Alan Modra
amodra@gmail.com
Wed Mar 25 12:02:12 GMT 2020
With a crafted "negative" ar_hdr.ar_size it is possible to make
readelf loop. This patch catches the overflow in a file offset
calculation.
* readelf.c (process_archive): Prevent endless loop.
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 1f0f49222f..9bc15e4d0b 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -20505,11 +20505,13 @@ process_archive (Filedata * filedata, bfd_boolean is_thin_archive)
{
free (name);
archive_file_offset = arch.next_arhdr_offset;
- arch.next_arhdr_offset += archive_file_size;
-
filedata->file_name = qualified_name;
if (! process_object (filedata))
ret = FALSE;
+ arch.next_arhdr_offset += archive_file_size;
+ /* Stop looping with "negative" archive_file_size. */
+ if (arch.next_arhdr_offset < archive_file_size)
+ break;
}
free (qualified_name);
--
Alan Modra
Australia Development Lab, IBM
More information about the Binutils
mailing list