vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 8404e0c02489a5c2e37651229937a912b1aa9b00 parent 35b3ab7622ce26a7db58fe2f3a850b0afe763ce1 Author: Marc André Tanner <mat@brain-dump.org> Date: Tue, 7 Jul 2015 10:08:11 +0200 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. Diffstat:
| M | text.c | | | 5 | ++++- |
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git 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;