From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1062) id 8861B3857C51; Thu, 3 Aug 2023 11:51:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8861B3857C51 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] resrc: sprintf sanitizer null destination pointer X-Act-Checkin: binutils-gdb X-Git-Author: Alan Modra X-Git-Refname: refs/heads/master X-Git-Oldrev: e2e7c5261311fd7d557769a73e1fbc496cd56d23 X-Git-Newrev: 137f6bc0dabe209c1617fb396eb590e7b7ee8faa Message-Id: <20230803115123.8861B3857C51@sourceware.org> Date: Thu, 3 Aug 2023 11:51:23 +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: Thu, 03 Aug 2023 11:51:23 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D137f6bc0dabe= 209c1617fb396eb590e7b7ee8faa commit 137f6bc0dabe209c1617fb396eb590e7b7ee8faa Author: Alan Modra Date: Thu Aug 3 08:18:13 2023 +0930 resrc: sprintf sanitizer null destination pointer =20 * 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 *prepr= ocessor, { char *edit, *dir; =20 - if (filename[0] =3D=3D '/' - || filename[0] =3D=3D '\\' - || filename[1] =3D=3D ':') - /* Absolute path. */ - edit =3D dir =3D xstrdup (filename); - else + edit =3D dir =3D xmalloc (strlen (filename) + 3); + if (filename[0] !=3D '/' + && filename[0] !=3D '\\' + && filename[1] !=3D ':') { /* Relative path. */ - edit =3D dir =3D xmalloc (strlen (filename) + 3); - sprintf (dir, "./%s", filename); + *edit++ =3D '.'; + *edit++ =3D '/'; } + edit =3D stpcpy (edit, filename); =20 /* Walk dir backwards stopping at the first directory separator. */ - edit +=3D strlen (dir); while (edit > dir && (edit[-1] !=3D '\\' && edit[-1] !=3D '/')) - { - --edit; - edit[0] =3D 0; - } + --edit; =20 /* Cut off trailing slash. */ - --edit; - edit[0] =3D 0; + *--edit =3D 0; =20 /* Convert all back slashes to forward slashes. */ while ((edit =3D strchr (dir, '\\')) !=3D NULL)