From a5e0be5cb29bcbcfee6f1ead2daed9889a2a6ac6 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Mon, 20 Apr 2020 11:01:47 +0930 Subject: [PATCH] readelf: segfault at readelf.c:12227 This is another one where not cleaning up sufficiently after processing one file can lead to errors when processing the next file. We have ngnuchains non-zero but gnuchains NULL in the following: off < ngnuchains && (gnuchains[off] & 1) == 0 * readelf.c (process_symbol_table): Clear ngnuchains, ngnubuckets and nbuckets. --- binutils/ChangeLog | 5 +++++ binutils/readelf.c | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/binutils/ChangeLog b/binutils/ChangeLog index 86eb578140..6280eb7c37 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,8 @@ +2020-04-20 Alan Modra + + * readelf.c (process_symbol_table): Clear ngnuchains, ngnubuckets + and nbuckets. + 2020-04-20 Alan Modra * readelf.c (process_section_headers): Free dynamic symbols etc. diff --git a/binutils/readelf.c b/binutils/readelf.c index d9c9b7ea0c..ea30f883c5 100644 --- a/binutils/readelf.c +++ b/binutils/readelf.c @@ -12188,6 +12188,7 @@ process_symbol_table (Filedata * filedata) free (buckets); buckets = NULL; + nbuckets = 0; free (chains); chains = NULL; @@ -12263,8 +12264,10 @@ process_symbol_table (Filedata * filedata) } free (gnubuckets); gnubuckets = NULL; + ngnubuckets = 0; free (gnuchains); gnuchains = NULL; + ngnuchains = 0; free (mipsxlat); mipsxlat = NULL; return TRUE; @@ -12272,12 +12275,15 @@ process_symbol_table (Filedata * filedata) err_out: free (gnubuckets); gnubuckets = NULL; + ngnubuckets = 0; free (gnuchains); gnuchains = NULL; + ngnuchains = 0 free (mipsxlat); mipsxlat = NULL; free (buckets); buckets = NULL; + nbuckets = 0; free (chains); chains = NULL; return FALSE; -- 2.34.1