check snprintf error aswell, handle as truncation error

Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
This commit is contained in:
Hiltjo Posthuma
2014-06-01 15:01:09 +02:00
committed by sin
parent 953ebf3573
commit eac0f658cf
3 changed files with 13 additions and 10 deletions

View File

@@ -21,7 +21,7 @@ main(int argc, char *argv[])
char *template = "tmp.XXXXXXXXXX";
char *tmpdir = "/tmp", *p;
char tmppath[PATH_MAX];
int fd;
int fd, r;
ARGBEGIN {
case 'd':
@@ -42,8 +42,9 @@ main(int argc, char *argv[])
if ((p = getenv("TMPDIR")))
tmpdir = p;
if (snprintf(tmppath, sizeof(tmppath),
"%s/%s", tmpdir, template) >= sizeof(tmppath))
r = snprintf(tmppath, sizeof(tmppath),
"%s/%s", tmpdir, template);
if (r >= sizeof(tmppath) || r < 0)
eprintf("path too long\n");
if (dflag) {
if (!mkdtemp(tmppath)) {