dlltool: sprintf sanitizer null destination pointer

Message ID ZMuTC8WY4lbj688u@squeak.grove.modra.org
State Accepted
Headers
Series dlltool: sprintf sanitizer null destination pointer |

Checks

Context Check Description
snail/binutils-gdb-check success Github commit url

Commit Message

Alan Modra Aug. 3, 2023, 11:44 a.m. UTC
  * dlltool.c (gen_lib_file): Avoid bogus sanitizer error.
  

Patch

diff --git a/binutils/dlltool.c b/binutils/dlltool.c
index 142d43aff81..efa54f1bd72 100644
--- a/binutils/dlltool.c
+++ b/binutils/dlltool.c
@@ -3089,20 +3089,22 @@  gen_lib_file (int delay)
   if (dontdeltemps < 2)
     {
       char *name;
+      size_t stub_len = strlen (TMP_STUB);
 
-      name = xmalloc (strlen (TMP_STUB) + 10);
+      name = xmalloc (stub_len + 10);
+      memcpy (name, TMP_STUB, stub_len);
       for (i = 0; (exp = d_exports_lexically[i]); i++)
 	{
 	  /* Don't delete non-existent stubs for PRIVATE entries.  */
           if (exp->private)
 	    continue;
-	  sprintf (name, "%s%05d.o", TMP_STUB, i);
+	  sprintf (name + stub_len, "%05d.o", i);
 	  if (unlink (name) < 0)
 	    /* xgettext:c-format */
 	    non_fatal (_("cannot delete %s: %s"), name, strerror (errno));
 	  if (ext_prefix_alias)
 	    {
-	      sprintf (name, "%s%05d.o", TMP_STUB, i + PREFIX_ALIAS_BASE);
+	      sprintf (name + stub_len, "%05d.o", i + PREFIX_ALIAS_BASE);
 	      if (unlink (name) < 0)
 		/* xgettext:c-format */
 		non_fatal (_("cannot delete %s: %s"), name, strerror (errno));