]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
loongson buffer overflow
authorAlan Modra <amodra@gmail.com>
Sun, 26 Jan 2025 02:42:45 +0000 (13:12 +1030)
committerAlan Modra <amodra@gmail.com>
Mon, 27 Jan 2025 21:04:43 +0000 (07:34 +1030)
bfd_elfNN_loongarch_set_data_segment_info can be called from the target
after_allocation function with a non-ELF hash table.  This is seen in
the ld-elf pr21884 testcase.  Fix the problem by first checking the
hash table type before writing to a loongarch_elf_hash_table field.

(cherry picked from commit 59ba00f21f7d48780e92a9fb66ed4abbedc3bd28)

bfd/elfnn-loongarch.c

index 80d2c445d034bb5b74314c7d48d553b0c3e80bda..fc1cbbea71a365e3bbc8f6bc6f6f72fb1c9e35cf 100644 (file)
@@ -5264,8 +5264,9 @@ void
 bfd_elfNN_loongarch_set_data_segment_info (struct bfd_link_info *info,
                                     int *data_segment_phase)
 {
-  struct loongarch_elf_link_hash_table *htab = loongarch_elf_hash_table (info);
-  htab->data_segment_phase = data_segment_phase;
+  if (is_elf_hash_table (info->hash)
+      && elf_hash_table_id (elf_hash_table (info)) == LARCH_ELF_DATA)
+    loongarch_elf_hash_table (info)->data_segment_phase = data_segment_phase;
 }
 
 /* Implement R_LARCH_ALIGN by deleting excess alignment NOPs.