PR25745, powerpc64-ld overflows string buffer in --stats mode

PR 25745
	* elf64-ppc.c (ppc64_elf_build_stubs): Use asprintf to form
	statistics message.
This commit is contained in:
Alan Modra
2020-03-30 09:28:02 +10:30
parent 69b037c30c
commit 988b7300bc
2 changed files with 46 additions and 36 deletions

View File

@ -1,3 +1,9 @@
2020-03-30 Alan Modra <amodra@gmail.com>
PR 25745
* elf64-ppc.c (ppc64_elf_build_stubs): Use asprintf to form
statistics message.
2020-03-26 Nick Clifton <nickc@redhat.com> 2020-03-26 Nick Clifton <nickc@redhat.com>
* cofflink.c (bfd_coff_get_internal_extra_pe_aouthdr): Delete. * cofflink.c (bfd_coff_get_internal_extra_pe_aouthdr): Delete.

View File

@ -14557,17 +14557,17 @@ ppc64_elf_build_stubs (struct bfd_link_info *info,
if (stats != NULL) if (stats != NULL)
{ {
size_t len; char *groupmsg;
*stats = bfd_malloc (500); if (asprintf (&groupmsg,
if (*stats == NULL)
return FALSE;
len = sprintf (*stats,
ngettext ("linker stubs in %u group\n", ngettext ("linker stubs in %u group\n",
"linker stubs in %u groups\n", "linker stubs in %u groups\n",
stub_sec_count), stub_sec_count),
stub_sec_count); stub_sec_count) < 0)
sprintf (*stats + len, _(" branch %lu\n" *stats = NULL;
else
{
if (asprintf (stats, _("%s"
" branch %lu\n"
" branch toc adj %lu\n" " branch toc adj %lu\n"
" branch notoc %lu\n" " branch notoc %lu\n"
" branch both %lu\n" " branch both %lu\n"
@ -14580,6 +14580,7 @@ ppc64_elf_build_stubs (struct bfd_link_info *info,
" plt call notoc %lu\n" " plt call notoc %lu\n"
" plt call both %lu\n" " plt call both %lu\n"
" global entry %lu"), " global entry %lu"),
groupmsg,
htab->stub_count[ppc_stub_long_branch - 1], htab->stub_count[ppc_stub_long_branch - 1],
htab->stub_count[ppc_stub_long_branch_r2off - 1], htab->stub_count[ppc_stub_long_branch_r2off - 1],
htab->stub_count[ppc_stub_long_branch_notoc - 1], htab->stub_count[ppc_stub_long_branch_notoc - 1],
@ -14592,7 +14593,10 @@ ppc64_elf_build_stubs (struct bfd_link_info *info,
htab->stub_count[ppc_stub_plt_call_r2save - 1], htab->stub_count[ppc_stub_plt_call_r2save - 1],
htab->stub_count[ppc_stub_plt_call_notoc - 1], htab->stub_count[ppc_stub_plt_call_notoc - 1],
htab->stub_count[ppc_stub_plt_call_both - 1], htab->stub_count[ppc_stub_plt_call_both - 1],
htab->stub_count[ppc_stub_global_entry - 1]); htab->stub_count[ppc_stub_global_entry - 1]) < 0)
*stats = NULL;
free (groupmsg);
}
} }
return TRUE; return TRUE;
} }