ed: Use strlcpy/strlcat to construct the scratch filename

This commit is contained in:
sin 2016-01-02 09:44:06 +00:00
parent 36e2bdf517
commit 3300d5d47a
1 changed files with 5 additions and 5 deletions

10
ed.c
View File

@ -335,12 +335,12 @@ setscratch()
clearundo(); clearundo();
if ((dir = getenv("TMPDIR")) == NULL) if ((dir = getenv("TMPDIR")) == NULL)
dir = "/tmp/"; dir = "/tmp/";
if (strlen(dir) + sizeof("ed.XXXXXX") > FILENAME_MAX) if (strlcpy(tmpname, dir, sizeof(tmpname)) >= sizeof(tmpname))
error("incorrect scratch file name"); error("scratch file name too long");
strcat(strcpy(tmpname, dir), "ed.XXXXX"); if (strlcat(tmpname, "ed.XXXXXX", sizeof(tmpname)) >= sizeof(tmpname))
if ((scratch = mkstemp(tmpname)) < 0) { error("scratch file name too long");
if ((scratch = mkstemp(tmpname)) < 0)
error("failed to create scratch file"); error("failed to create scratch file");
}
if ((k = makeline("", NULL))) if ((k = makeline("", NULL)))
error("input/output error in scratch file"); error("input/output error in scratch file");
relink(k, k, k, k); relink(k, k, k, k);