asan: segfault in coff_mangle_symbols

The testcase managed to trigger creation of a wild pointer in
coff_slurp_symbol_table.  Stop that happening, and fix an unrelated
problem I happened to see in bfd_coff_get_syment.

	* coff-bfd.c (bfd_coff_get_syment): Clear fix_value after
	converting n_value from a pointer to an index.
	* coffcode.h (coff_slurp_symbol_table <C_BSTAT>): Sanity check
	symbol value before converting to a pointer.
This commit is contained in:
Alan Modra 2023-04-24 11:19:15 +09:30
parent c1eb3cd205
commit 2043ddb218
2 changed files with 18 additions and 10 deletions

View File

@ -45,9 +45,12 @@ bfd_coff_get_syment (bfd *abfd,
*psyment = csym->native->u.syment; *psyment = csym->native->u.syment;
if (csym->native->fix_value) if (csym->native->fix_value)
psyment->n_value = {
((psyment->n_value - (uintptr_t) obj_raw_syments (abfd)) psyment->n_value =
/ sizeof (combined_entry_type)); ((psyment->n_value - (uintptr_t) obj_raw_syments (abfd))
/ sizeof (combined_entry_type));
csym->native->fix_value = 0;
}
/* FIXME: We should handle fix_line here. */ /* FIXME: We should handle fix_line here. */

View File

@ -4852,13 +4852,18 @@ coff_slurp_symbol_table (bfd * abfd)
case C_BSTAT: case C_BSTAT:
dst->symbol.flags = BSF_DEBUGGING; dst->symbol.flags = BSF_DEBUGGING;
/* The value is actually a symbol index. Save a pointer if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
to the symbol instead of the index. FIXME: This dst->symbol.value = 0;
should use a union. */ else
src->u.syment.n_value {
= (uintptr_t) (native_symbols + src->u.syment.n_value); /* The value is actually a symbol index. Save a pointer
dst->symbol.value = src->u.syment.n_value; to the symbol instead of the index. FIXME: This
src->fix_value = 1; should use a union. */
src->u.syment.n_value
= (uintptr_t) (native_symbols + src->u.syment.n_value);
dst->symbol.value = src->u.syment.n_value;
src->fix_value = 1;
}
break; break;
#endif #endif