diff options
author | Nick Clifton <nickc@redhat.com> | 2020-01-09 16:51:04 +0000 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2020-01-09 16:51:04 +0000 |
commit | ffebb0bbde7deae978ab3e4d3d3d90acf52b7d69 (patch) | |
tree | 946ffa070c8a85a538d86c3576a6e7fab0eedd22 /binutils | |
parent | b899eb3bb807be1094fde9a2f1c8628232bc0743 (diff) | |
download | fsf-binutils-gdb-ffebb0bbde7deae978ab3e4d3d3d90acf52b7d69.zip fsf-binutils-gdb-ffebb0bbde7deae978ab3e4d3d3d90acf52b7d69.tar.gz fsf-binutils-gdb-ffebb0bbde7deae978ab3e4d3d3d90acf52b7d69.tar.bz2 |
Fix an attempt to free a static pointer when using objcopy's symbol addition feature.
PR 25220
* objcopy.c (empty_name): New variable.
(need_sym_before): Prevent an attempt to free a static variable.
(filter_symbols): Avoid strcmp test by checking for pointer
equality.
Diffstat (limited to 'binutils')
-rw-r--r-- | binutils/ChangeLog | 8 | ||||
-rw-r--r-- | binutils/objcopy.c | 15 |
2 files changed, 18 insertions, 5 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog index 792b978..b3c499d 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,5 +1,13 @@ 2020-01-09 Nick Clifton <nickc@redhat.com> + PR 25220 + * objcopy.c (empty_name): New variable. + (need_sym_before): Prevent an attempt to free a static variable. + (filter_symbols): Avoid strcmp test by checking for pointer + equality. + +2020-01-09 Nick Clifton <nickc@redhat.com> + * po/zh_TW.po: Updated Traditional Chinese translation. 2020-01-09 Aaron Merey <amerey@redhat.com> diff --git a/binutils/objcopy.c b/binutils/objcopy.c index 61b33c7..ef3b693 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -68,7 +68,7 @@ struct addsym_node long symval; flagword flags; char * section; - char * othersym; + const char * othersym; }; typedef struct section_rename @@ -808,7 +808,7 @@ parse_flags (const char *s) string can't be parsed. */ static flagword -parse_symflags (const char *s, char **other) +parse_symflags (const char *s, const char **other) { flagword ret; const char *snext; @@ -1453,6 +1453,9 @@ is_hidden_symbol (asymbol *sym) return FALSE; } +/* Empty name is hopefully never a valid symbol name. */ +static const char * empty_name = ""; + static bfd_boolean need_sym_before (struct addsym_node **node, const char *sym) { @@ -1464,10 +1467,12 @@ need_sym_before (struct addsym_node **node, const char *sym) { if (!ptr->othersym) break; + if (ptr->othersym == empty_name) + continue; else if (strcmp (ptr->othersym, sym) == 0) { - free (ptr->othersym); - ptr->othersym = ""; /* Empty name is hopefully never a valid symbol name. */ + free ((char *) ptr->othersym); + ptr->othersym = empty_name; *node = ptr; return TRUE; } @@ -1695,7 +1700,7 @@ filter_symbols (bfd *abfd, bfd *obfd, asymbol **osyms, { if (ptr->othersym) { - if (strcmp (ptr->othersym, "")) + if (ptr->othersym != empty_name) fatal (_("'before=%s' not found"), ptr->othersym); } else |