From 72e8127293f8fee15e9f68efaaf85bfc10310463 Mon Sep 17 00:00:00 2001 From: is Date: Mon, 4 Mar 2013 04:14:43 +0000 Subject: [PATCH] use mkdtemp() to create temporary directory rather than mktemp() followed by mkdir() closes #3637 --- lib.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lib.c b/lib.c index 9662760d..b80a997b 100644 --- a/lib.c +++ b/lib.c @@ -548,7 +548,6 @@ static int mutt_mkwrapdir (const char *path, char *newfile, size_t nflen, const char *basename; char parent[_POSIX_PATH_MAX]; char *p; - int rv; strfcpy (parent, NONULL (path), sizeof (parent)); @@ -563,17 +562,19 @@ static int mutt_mkwrapdir (const char *path, char *newfile, size_t nflen, basename = path; } - do + snprintf (newdir, ndlen, "%s/%s", parent, ".muttXXXXXX"); + if (mkdtemp(newdir) == NULL) { - snprintf (newdir, ndlen, "%s/%s", parent, ".muttXXXXXX"); - mktemp (newdir); - } - while ((rv = mkdir (newdir, 0700)) == -1 && errno == EEXIST); - - if (rv == -1) - return -1; + dprint(1, (debugfile, "mutt_mkwrapdir: mkdtemp() failed\n")); + return -1; + } - snprintf (newfile, nflen, "%s/%s", newdir, NONULL(basename)); + if (snprintf (newfile, nflen, "%s/%s", newdir, NONULL(basename)) >= nflen) + { + rmdir(newdir); + dprint(1, (debugfile, "mutt_mkwrapdir: string was truncated\n")); + return -1; + } return 0; } -- 2.40.0