From 2a39201f65c97cf666c562c281defd8b8e2f8937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Tue, 7 Jul 2015 10:08:11 +0200 Subject: text: safer temporary file creation Set umask before calling mkstemp. According to POSIX 2008 this is not necessary since the temporary file is guaranteed to be created with permission restricted to the current user. However this is more secure on non-conforming systems and safe as long as we do not use multiple threads. Fixes Coverity CID 101333. --- text.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/text.c b/text.c index f47ccbc..a77bc07 100644 --- a/text.c +++ b/text.c @@ -919,7 +919,10 @@ bool text_range_save(Text *txt, Filerange *range, const char *filename) { */ size_t size = txt->buf->size; char tmpname[32] = "/tmp/vis-XXXXXX"; - if ((newfd = mkstemp(tmpname)) == -1) + mode_t mask = umask(S_IXUSR | S_IRWXG | S_IRWXO); + newfd = mkstemp(tmpname); + umask(mask); + if (newfd == -1) goto err; if (unlink(tmpname) == -1) goto err; -- cgit v1.2.3