From: Alan Modra Date: Thu, 3 Dec 2020 05:40:37 +0000 (+1030) Subject: asan: readelf: memory leaks X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=288f0ba26478ec3a8926d54319b9c899e64e26a7;p=binutils-gdb.git asan: readelf: memory leaks This tidies some code used by readelf, hopefully fixing some intermittent oss-fuzz bug reports that likely could only be reproduced by feeding readelf two or more object files on the command line. The second and subsequent file may see non-zero state in .bss variables, and non-initial values in .data variables. This patch fixes some of those, and moves some .data variables to .rodata. * dwarf.c (frame_display_row): Do without static variable "sloc". (cu_tu_indexes_read): Move to file scope. (free_debug_memory): Reset it here, along with level_type_signed. Free and clear a number of other static variables. * readelf.c (arm_attr_public_tag ): Constify, updating.. (arm_attr_tag_*): ..all these uses. (process_mips_specific): Free "rels" on error path. --- diff --git a/binutils/ChangeLog b/binutils/ChangeLog index fbd14f19e15..ccb9da5ef87 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,13 @@ +2020-12-04 Alan Modra + + * dwarf.c (frame_display_row): Do without static variable "sloc". + (cu_tu_indexes_read): Move to file scope. + (free_debug_memory): Reset it here, along with level_type_signed. + Free and clear a number of other static variables. + * readelf.c (arm_attr_public_tag
): Constify, updating.. + (arm_attr_tag_*): ..all these uses. + (process_mips_specific): Free "rels" on error path. + 2020-11-27 Nick Clifton PR 26865 diff --git a/binutils/dwarf.c b/binutils/dwarf.c index 149755da1d0..96b7a57f061 100644 --- a/binutils/dwarf.c +++ b/binutils/dwarf.c @@ -8187,11 +8187,9 @@ frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_reg if (*need_col_headers) { - static const char *sloc = " LOC"; - *need_col_headers = 0; - printf ("%-*s CFA ", eh_addr_size * 2, sloc); + printf ("%-*s CFA ", eh_addr_size * 2, " LOC"); for (r = 0; r < *max_regs; r++) if (fc->col_type[r] != DW_CFA_unreferenced) @@ -10467,6 +10465,8 @@ process_cu_tu_index (struct dwarf_section *section, int do_display) return 1; } +static int cu_tu_indexes_read = -1; /* Tri-state variable. */ + /* Load the CU and TU indexes if present. This will build a list of section sets that we can use to associate a .debug_info.dwo section with its associated .debug_abbrev.dwo section in a .dwp file. */ @@ -10474,8 +10474,6 @@ process_cu_tu_index (struct dwarf_section *section, int do_display) static bfd_boolean load_cu_tu_indexes (void *file) { - static int cu_tu_indexes_read = -1; /* Tri-state variable. */ - /* If we have already loaded (or tried to load) the CU and TU indexes then do not bother to repeat the task. */ if (cu_tu_indexes_read == -1) @@ -11249,6 +11247,20 @@ free_debug_memory (void) cu_abbrev_map = NULL; next_free_abbrev_map_entry = 0; + free (shndx_pool); + shndx_pool = NULL; + shndx_pool_size = 0; + shndx_pool_used = 0; + free (cu_sets); + cu_sets = NULL; + cu_count = 0; + free (tu_sets); + tu_sets = NULL; + tu_count = 0; + + memset (level_type_signed, 0, sizeof level_type_signed); + cu_tu_indexes_read = -1; + for (i = 0; i < max; i++) free_debug_section ((enum dwarf_section_display_enum) i); diff --git a/binutils/readelf.c b/binutils/readelf.c index 57e0f1de459..7f634d94bf3 100644 --- a/binutils/readelf.c +++ b/binutils/readelf.c @@ -15570,77 +15570,77 @@ typedef struct const char * name; /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */ unsigned int type; - const char ** table; + const char *const *table; } arm_attr_public_tag; -static const char * arm_attr_tag_CPU_arch[] = +static const char *const arm_attr_tag_CPU_arch[] = {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2", "v6K", "v7", "v6-M", "v6S-M", "v7E-M", "v8", "v8-R", "v8-M.baseline", "v8-M.mainline", "", "", "", "v8.1-M.mainline"}; -static const char * arm_attr_tag_ARM_ISA_use[] = {"No", "Yes"}; -static const char * arm_attr_tag_THUMB_ISA_use[] = +static const char *const arm_attr_tag_ARM_ISA_use[] = {"No", "Yes"}; +static const char *const arm_attr_tag_THUMB_ISA_use[] = {"No", "Thumb-1", "Thumb-2", "Yes"}; -static const char * arm_attr_tag_FP_arch[] = +static const char *const arm_attr_tag_FP_arch[] = {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", "VFPv4-D16", "FP for ARMv8", "FPv5/FP-D16 for ARMv8"}; -static const char * arm_attr_tag_WMMX_arch[] = {"No", "WMMXv1", "WMMXv2"}; -static const char * arm_attr_tag_Advanced_SIMD_arch[] = +static const char *const arm_attr_tag_WMMX_arch[] = {"No", "WMMXv1", "WMMXv2"}; +static const char *const arm_attr_tag_Advanced_SIMD_arch[] = {"No", "NEONv1", "NEONv1 with Fused-MAC", "NEON for ARMv8", "NEON for ARMv8.1"}; -static const char * arm_attr_tag_PCS_config[] = +static const char *const arm_attr_tag_PCS_config[] = {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004", "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"}; -static const char * arm_attr_tag_ABI_PCS_R9_use[] = +static const char *const arm_attr_tag_ABI_PCS_R9_use[] = {"V6", "SB", "TLS", "Unused"}; -static const char * arm_attr_tag_ABI_PCS_RW_data[] = +static const char *const arm_attr_tag_ABI_PCS_RW_data[] = {"Absolute", "PC-relative", "SB-relative", "None"}; -static const char * arm_attr_tag_ABI_PCS_RO_data[] = +static const char *const arm_attr_tag_ABI_PCS_RO_data[] = {"Absolute", "PC-relative", "None"}; -static const char * arm_attr_tag_ABI_PCS_GOT_use[] = +static const char *const arm_attr_tag_ABI_PCS_GOT_use[] = {"None", "direct", "GOT-indirect"}; -static const char * arm_attr_tag_ABI_PCS_wchar_t[] = +static const char *const arm_attr_tag_ABI_PCS_wchar_t[] = {"None", "??? 1", "2", "??? 3", "4"}; -static const char * arm_attr_tag_ABI_FP_rounding[] = {"Unused", "Needed"}; -static const char * arm_attr_tag_ABI_FP_denormal[] = +static const char *const arm_attr_tag_ABI_FP_rounding[] = {"Unused", "Needed"}; +static const char *const arm_attr_tag_ABI_FP_denormal[] = {"Unused", "Needed", "Sign only"}; -static const char * arm_attr_tag_ABI_FP_exceptions[] = {"Unused", "Needed"}; -static const char * arm_attr_tag_ABI_FP_user_exceptions[] = {"Unused", "Needed"}; -static const char * arm_attr_tag_ABI_FP_number_model[] = +static const char *const arm_attr_tag_ABI_FP_exceptions[] = {"Unused", "Needed"}; +static const char *const arm_attr_tag_ABI_FP_user_exceptions[] = {"Unused", "Needed"}; +static const char *const arm_attr_tag_ABI_FP_number_model[] = {"Unused", "Finite", "RTABI", "IEEE 754"}; -static const char * arm_attr_tag_ABI_enum_size[] = +static const char *const arm_attr_tag_ABI_enum_size[] = {"Unused", "small", "int", "forced to int"}; -static const char * arm_attr_tag_ABI_HardFP_use[] = +static const char *const arm_attr_tag_ABI_HardFP_use[] = {"As Tag_FP_arch", "SP only", "Reserved", "Deprecated"}; -static const char * arm_attr_tag_ABI_VFP_args[] = +static const char *const arm_attr_tag_ABI_VFP_args[] = {"AAPCS", "VFP registers", "custom", "compatible"}; -static const char * arm_attr_tag_ABI_WMMX_args[] = +static const char *const arm_attr_tag_ABI_WMMX_args[] = {"AAPCS", "WMMX registers", "custom"}; -static const char * arm_attr_tag_ABI_optimization_goals[] = +static const char *const arm_attr_tag_ABI_optimization_goals[] = {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size", "Aggressive Size", "Prefer Debug", "Aggressive Debug"}; -static const char * arm_attr_tag_ABI_FP_optimization_goals[] = +static const char *const arm_attr_tag_ABI_FP_optimization_goals[] = {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size", "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"}; -static const char * arm_attr_tag_CPU_unaligned_access[] = {"None", "v6"}; -static const char * arm_attr_tag_FP_HP_extension[] = +static const char *const arm_attr_tag_CPU_unaligned_access[] = {"None", "v6"}; +static const char *const arm_attr_tag_FP_HP_extension[] = {"Not Allowed", "Allowed"}; -static const char * arm_attr_tag_ABI_FP_16bit_format[] = +static const char *const arm_attr_tag_ABI_FP_16bit_format[] = {"None", "IEEE 754", "Alternative Format"}; -static const char * arm_attr_tag_DSP_extension[] = +static const char *const arm_attr_tag_DSP_extension[] = {"Follow architecture", "Allowed"}; -static const char * arm_attr_tag_MPextension_use[] = +static const char *const arm_attr_tag_MPextension_use[] = {"Not Allowed", "Allowed"}; -static const char * arm_attr_tag_DIV_use[] = +static const char *const arm_attr_tag_DIV_use[] = {"Allowed in Thumb-ISA, v7-R or v7-M", "Not allowed", "Allowed in v7-A with integer division extension"}; -static const char * arm_attr_tag_T2EE_use[] = {"Not Allowed", "Allowed"}; -static const char * arm_attr_tag_Virtualization_use[] = +static const char *const arm_attr_tag_T2EE_use[] = {"Not Allowed", "Allowed"}; +static const char *const arm_attr_tag_Virtualization_use[] = {"Not Allowed", "TrustZone", "Virtualization Extensions", "TrustZone and Virtualization Extensions"}; -static const char * arm_attr_tag_MPextension_use_legacy[] = +static const char *const arm_attr_tag_MPextension_use_legacy[] = {"Not Allowed", "Allowed"}; -static const char * arm_attr_tag_MVE_arch[] = +static const char *const arm_attr_tag_MVE_arch[] = {"No MVE", "MVE Integer only", "MVE Integer and FP"}; #define LOOKUP(id, name) \ @@ -18038,7 +18038,10 @@ process_mips_specific (Filedata * filedata) data = (unsigned char *) get_data (NULL, filedata, offset, end - mips_pltgot, 1, _("Procedure Linkage Table data")); if (data == NULL) - return FALSE; + { + free (rels); + return FALSE; + } printf ("\nPLT GOT:\n\n"); printf (_(" Reserved entries:\n"));