Set umask before running mkstemp because some UNIX flavors don't do this
authorJonathan Dieter <jdieter@gmail.com>
Fri, 14 Sep 2018 12:11:46 +0000 (13:11 +0100)
committerJonathan Dieter <jdieter@gmail.com>
Fri, 14 Sep 2018 12:11:46 +0000 (13:11 +0100)
automatically.
(Coverity ID: 310912)

Signed-off-by: Jonathan Dieter <jdieter@gmail.com>
src/lib/zck.c

index a3359ea7a877494e8e7d8dbc891caa2537285eec..eb58f8aee81b6bb1a9fb673fc755593ab4309280 100644 (file)
@@ -29,6 +29,7 @@
 #include <stdint.h>
 #include <stdbool.h>
 #include <string.h>
+#include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
 #include <errno.h>
@@ -130,7 +131,10 @@ int get_tmp_fd(zckCtx *zck) {
     strncpy(fname+strlen(tmpdir), "/", 2);
     strncpy(fname+strlen(tmpdir)+1, template, strlen(template));
 
+    mode_t old_mode_mask;
+    old_mode_mask = umask (S_IXUSR | S_IRWXG | S_IRWXO);
     temp_fd = mkstemp(fname);
+    umask(old_mode_mask);
     if(temp_fd < 0) {
         free(fname);
         set_error(zck, "Unable to create temporary file");