sbase

suckless unix tools
git clone git://git.2f30.org/sbase.git
Log | Files | Refs | README | LICENSE

commit 6a088a92521d4c1e01384c1183b0de27d887e9cd
parent cf60336e09a7cf73f4750c4f5ec0fffdb9dca2dc
Author: sin <sin@2f30.org>
Date:   Sat Jan  2 09:44:06 +0000

ed: Use strlcpy/strlcat to construct the scratch filename

Diffstat:
ed.c | 10+++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/ed.c b/ed.c @@ -335,12 +335,12 @@ setscratch() clearundo(); if ((dir = getenv("TMPDIR")) == NULL) dir = "/tmp/"; - if (strlen(dir) + sizeof("ed.XXXXXX") > FILENAME_MAX) - error("incorrect scratch file name"); - strcat(strcpy(tmpname, dir), "ed.XXXXX"); - if ((scratch = mkstemp(tmpname)) < 0) { + 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"); + if ((scratch = mkstemp(tmpname)) < 0) error("failed to create scratch file"); - } if ((k = makeline("", NULL))) error("input/output error in scratch file"); relink(k, k, k, k);