public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
* [binutils-gdb] resrc: sprintf sanitizer null destination pointer
@ 2023-08-03 11:51 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2023-08-03 11:51 UTC (permalink / raw)
  To: bfd-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=137f6bc0dabe209c1617fb396eb590e7b7ee8faa

commit 137f6bc0dabe209c1617fb396eb590e7b7ee8faa
Author: Alan Modra <amodra@gmail.com>
Date:   Thu Aug 3 08:18:13 2023 +0930

    resrc: sprintf sanitizer null destination pointer
    
            * resrc.c (read_rc_file): Use stpcpy rather than sprintf
            followed by strlen.  Tidy.

Diff:
---
 binutils/resrc.c | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)

diff --git a/binutils/resrc.c b/binutils/resrc.c
index 3ea9813d8bd..0d7a6e1cdbc 100644
--- a/binutils/resrc.c
+++ b/binutils/resrc.c
@@ -441,29 +441,23 @@ read_rc_file (const char *filename, const char *preprocessor,
     {
       char *edit, *dir;
 
-      if (filename[0] == '/'
-	  || filename[0] == '\\'
-	  || filename[1] == ':')
-        /* Absolute path.  */
-	edit = dir = xstrdup (filename);
-      else
+      edit = dir = xmalloc (strlen (filename) + 3);
+      if (filename[0] != '/'
+	  && filename[0] != '\\'
+	  && filename[1] != ':')
 	{
 	  /* Relative path.  */
-	  edit = dir = xmalloc (strlen (filename) + 3);
-	  sprintf (dir, "./%s", filename);
+	  *edit++ = '.';
+	  *edit++ = '/';
 	}
+      edit = stpcpy (edit, filename);
 
       /* Walk dir backwards stopping at the first directory separator.  */
-      edit += strlen (dir);
       while (edit > dir && (edit[-1] != '\\' && edit[-1] != '/'))
-	{
-	  --edit;
-	  edit[0] = 0;
-	}
+	--edit;
 
       /* Cut off trailing slash.  */
-      --edit;
-      edit[0] = 0;
+      *--edit = 0;
 
       /* Convert all back slashes to forward slashes.  */
       while ((edit = strchr (dir, '\\')) != NULL)

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-08-03 11:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-03 11:51 [binutils-gdb] resrc: sprintf sanitizer null destination pointer Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).