1 From: roessler <roessler>
2 Date: Mon, 9 Oct 2006 13:39:38 +0000 (+0000)
3 Subject: From: Thomas Roessler <roessler@does-not-exist.org>
4 X-Git-Url: http://dev.mutt.org/cgi-bin/gitweb.cgi?p=mutt/.git;a=commitdiff;h=f6404a53a2b7a9a3b36d89def185e1192abdd108
6 From: Thomas Roessler <roessler@does-not-exist.org>
8 Even more paranoid temporary file creation.
13 @@ -481,14 +481,85 @@ int safe_rename (const char *src, const
17 +/* Create a temporary directory next to a file name */
19 +int mutt_mkwrapdir (const char *path, char *newfile, size_t nflen,
20 + char *newdir, size_t ndlen)
22 + const char *basename;
23 + char parent[_POSIX_PATH_MAX];
27 + strfcpy (parent, NONULL (path), sizeof (parent));
29 + if ((p = strrchr (parent, '/')))
36 + strfcpy (parent, ".", sizeof (parent));
42 + snprintf (newdir, ndlen, "%s/%s", parent, ".muttXXXXXX");
45 + while ((rv = mkdir (newdir, 0700)) == -1 && errno == EEXIST);
50 + snprintf (newfile, nflen, "%s/%s", newdir, NONULL(basename));
54 +int mutt_put_file_in_place (const char *path, const char *safe_file, const char *safe_dir)
58 + rv = safe_rename (safe_file, path);
64 int safe_open (const char *path, int flags)
69 - if ((fd = open (path, flags, 0600)) < 0)
73 + char safe_file[_POSIX_PATH_MAX];
74 + char safe_dir[_POSIX_PATH_MAX];
76 + if (mutt_mkwrapdir (path, safe_file, sizeof (safe_file),
77 + safe_dir, sizeof (safe_dir)) == -1)
80 + if ((fd = open (safe_file, flags, 0600)) < 0)
86 + if (mutt_put_file_in_place (path, safe_file, safe_dir) == -1)
94 + if ((fd = open (path, flags, 0600)) < 0)
98 /* make sure the file is not symlink */
99 if (lstat (path, &osb) < 0 || fstat (fd, &nsb) < 0 ||
100 compare_stat(&osb, &nsb) == -1)