[hackers] [sbase] ed: Use snprintf() for constructing the scratch filename || sin

From: <git_AT_suckless.org>
Date: Sat, 2 Jan 2016 11:34:00 +0100 (CET)

commit 16159a61acfad96a8a9905ffd01e3e048a0f1820
Author: sin <sin_AT_2f30.org>
AuthorDate: Sat Jan 2 10:32:44 2016 +0000
Commit: sin <sin_AT_2f30.org>
CommitDate: Sat Jan 2 10:33:56 2016 +0000

    ed: Use snprintf() for constructing the scratch filename

diff --git a/ed.c b/ed.c
index ed55581..686d2aa 100644
--- a/ed.c
+++ b/ed.c
_AT_@ -328,17 +328,17 @@ clearbuf()
 static void
 setscratch()
 {
- int k;
+ int r, k;
         char *dir;
 
         clearbuf();
         clearundo();
         if ((dir = getenv("TMPDIR")) == NULL)
- dir = "/tmp/";
- if (strlcpy(tmpname, dir, sizeof(tmpname)) >= sizeof(tmpname))
- error("scratch file name too long");
- if (strlcat(tmpname, "ed.XXXXXX", sizeof(tmpname)) >= sizeof(tmpname))
- error("scratch file name too long");
+ dir = "/tmp";
+ r = snprintf(tmpname, sizeof(tmpname), "%s/%s",
+ dir, "ed.XXXXXX");
+ if (r < 0 || (size_t)r >= sizeof(tmpname))
+ error("scratch filename too long");
         if ((scratch = mkstemp(tmpname)) < 0)
                 error("failed to create scratch file");
         if ((k = makeline("", NULL)))
Received on Sat Jan 02 2016 - 11:34:00 CET

This archive was generated by hypermail 2.3.0 : Sat Jan 02 2016 - 11:36:12 CET