asan: buffer overflow in mmo_get_symbols
authorAlan Modra <amodra@gmail.com>
Fri, 17 Dec 2021 02:11:28 +0000 (12:41 +1030)
committerAlan Modra <amodra@gmail.com>
Fri, 17 Dec 2021 05:31:14 +0000 (16:01 +1030)
* mmo.c (mmo_get_symbols): Error on symbol name exceeding max length.

bfd/mmo.c

index 2ee386662a425cc2d071e6d453c2e0ecddd7985c..d80cb06f74627bb2d6e408d85e02adf6c820a9a0 100644 (file)
--- a/bfd/mmo.c
+++ b/bfd/mmo.c
@@ -1411,6 +1411,16 @@ SUBSECTION
            c = c2;
        }
 
+      if (abfd->tdata.mmo_data->symbol_position
+         >= abfd->tdata.mmo_data->max_symbol_length)
+       {
+         _bfd_error_handler
+           /* xgettext:c-format */
+           (_("%pB: symbol name exceeds given max length of %d"),
+            abfd, abfd->tdata.mmo_data->max_symbol_length);
+         abfd->tdata.mmo_data->have_error = true;
+         return false;
+       }
       abfd->tdata.mmo_data->lop_stab_symbol[abfd->tdata.mmo_data->symbol_position++] = c;
       abfd->tdata.mmo_data->lop_stab_symbol[abfd->tdata.mmo_data->symbol_position] = 0;