binutils/binutils-detect-corrupt-sym-version-info.patch
2018-08-28 13:05:02 +01:00

53 lines
1.9 KiB
Diff

diff -rup binutils,orig/bfd/elf.c binutils-2.31.1/bfd/elf.c
--- binutils,orig/bfd/elf.c 2018-08-28 12:38:29.987511521 +0100
+++ binutils-2.31.1/bfd/elf.c 2018-08-28 12:39:35.010036349 +0100
@@ -1877,7 +1877,7 @@ _bfd_elf_get_symbol_version_string (bfd
{
Elf_Internal_Verneed *t;
- version_string = "";
+ version_string = _("<corrupt>");
for (t = elf_tdata (abfd)->verref;
t != NULL;
t = t->vn_nextref)
diff -rup binutils,orig/binutils/readelf.c binutils-2.31.1/binutils/readelf.c
--- binutils,orig/binutils/readelf.c 2018-08-28 12:38:30.552507392 +0100
+++ binutils-2.31.1/binutils/readelf.c 2018-08-28 12:42:04.625942967 +0100
@@ -11263,6 +11263,7 @@ get_symbol_version_string (Filedata *
unsigned char data[2];
unsigned short vers_data;
unsigned long offset;
+ unsigned short max_vd_ndx;
if (!is_dynsym
|| version_info[DT_VERSIONTAGIDX (DT_VERSYM)] == 0)
@@ -11280,6 +11281,8 @@ get_symbol_version_string (Filedata *
if ((vers_data & VERSYM_HIDDEN) == 0 && vers_data == 0)
return NULL;
+ max_vd_ndx = 0;
+
/* Usually we'd only see verdef for defined symbols, and verneed for
undefined symbols. However, symbols defined by the linker in
.dynbss for variables copied from a shared library in order to
@@ -11322,6 +11325,9 @@ get_symbol_version_string (Filedata *
ivd.vd_flags = BYTE_GET (evd.vd_flags);
}
+ if ((ivd.vd_ndx & VERSYM_VERSION) > max_vd_ndx)
+ max_vd_ndx = ivd.vd_ndx & VERSYM_VERSION;
+
off += ivd.vd_next;
}
while (ivd.vd_ndx != (vers_data & VERSYM_VERSION) && ivd.vd_next != 0);
@@ -11413,6 +11419,9 @@ get_symbol_version_string (Filedata *
return (ivna.vna_name < strtab_size
? strtab + ivna.vna_name : _("<corrupt>"));
}
+ else if ((max_vd_ndx || (vers_data & VERSYM_VERSION) != 1)
+ && (vers_data & VERSYM_VERSION) > max_vd_ndx)
+ return _("<corrupt>");
}
return NULL;
}