From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1062) id E08ED3858C53; Wed, 23 Aug 2023 01:46:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E08ED3858C53 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Alan Modra To: bfd-cvs@sourceware.org Subject: [binutils-gdb] bfd_get_symbol_leading_char vs. "" X-Act-Checkin: binutils-gdb X-Git-Author: Alan Modra X-Git-Refname: refs/heads/master X-Git-Oldrev: e2ce77cd639c86ce89b10ee70e73bd09670e0111 X-Git-Newrev: 8c8145a43ee4815b8851f8da7091c04f551dff6e Message-Id: <20230823014624.E08ED3858C53@sourceware.org> Date: Wed, 23 Aug 2023 01:46:24 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Aug 2023 01:46:25 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D8c8145a43ee4= 815b8851f8da7091c04f551dff6e commit 8c8145a43ee4815b8851f8da7091c04f551dff6e Author: Alan Modra Date: Tue Aug 22 21:13:41 2023 +0930 bfd_get_symbol_leading_char vs. "" =20 Some places matching the first char of a string against bfd_get_symbol_leading_char, which may be zero, didn't check for the string being "". This patch adds the check to stop accesses past the end of the string and potential buffer overruns. The dlltool one was found by oss-fuzz quite a while ago. =20 bfd/ * cofflink.c (_bfd_coff_link_input_bfd): Ensure a zero bfd_get_symbol_leading_char doesn't lead to accessing past the zero string terminator. * linker.c (bfd_wrapped_link_hash_lookup): Likewise. (unwrap_hash_lookup): Likewise. binutils/ * dlltool.c (scan_filtered_symbols): Ensure a zero bfd_get_symbol_leading_char doesn't lead to accessing past the zero string terminator. Diff: --- bfd/cofflink.c | 3 ++- bfd/linker.c | 9 ++++++--- binutils/dlltool.c | 3 ++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/bfd/cofflink.c b/bfd/cofflink.c index aea5c4c38a5..221f6e8183a 100644 --- a/bfd/cofflink.c +++ b/bfd/cofflink.c @@ -1618,7 +1618,8 @@ _bfd_coff_link_input_bfd (struct coff_final_link_info= *flaginfo, bfd *input_bfd) /* Ignore fake names invented by compiler; treat them all as the same name. */ if (*name =3D=3D '~' || *name =3D=3D '.' || *name =3D=3D '$' - || (*name =3D=3D bfd_get_symbol_leading_char (input_bfd) + || (*name + && *name =3D=3D bfd_get_symbol_leading_char (input_bfd) && (name[1] =3D=3D '~' || name[1] =3D=3D '.' || name[1] =3D=3D '$'))) name =3D ""; =20 diff --git a/bfd/linker.c b/bfd/linker.c index 0f4f9a1776c..28fffc3ad63 100644 --- a/bfd/linker.c +++ b/bfd/linker.c @@ -544,7 +544,9 @@ bfd_wrapped_link_hash_lookup (bfd *abfd, char prefix =3D '\0'; =20 l =3D string; - if (*l =3D=3D bfd_get_symbol_leading_char (abfd) || *l =3D=3D info->= wrap_char) + if (*l + && (*l =3D=3D bfd_get_symbol_leading_char (abfd) + || *l =3D=3D info->wrap_char)) { prefix =3D *l; ++l; @@ -621,8 +623,9 @@ unwrap_hash_lookup (struct bfd_link_info *info, { const char *l =3D h->root.string; =20 - if (*l =3D=3D bfd_get_symbol_leading_char (input_bfd) - || *l =3D=3D info->wrap_char) + if (*l + && (*l =3D=3D bfd_get_symbol_leading_char (input_bfd) + || *l =3D=3D info->wrap_char)) ++l; =20 if (startswith (l, WRAP)) diff --git a/binutils/dlltool.c b/binutils/dlltool.c index 085d4c2ce41..6d63e11e084 100644 --- a/binutils/dlltool.c +++ b/binutils/dlltool.c @@ -1500,7 +1500,8 @@ scan_filtered_symbols (bfd *abfd, void *minisyms, lon= g symcount, bfd_fatal (bfd_get_filename (abfd)); =20 symbol_name =3D bfd_asymbol_name (sym); - if (bfd_get_symbol_leading_char (abfd) =3D=3D symbol_name[0]) + if (*symbol_name + && *symbol_name =3D=3D bfd_get_symbol_leading_char (abfd)) ++symbol_name; =20 def_exports (xstrdup (symbol_name) , 0, -1, 0, 0,