diff options
author | Steve Bennett <steveb@workware.net.au> | 2014-04-28 08:13:18 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2014-04-28 08:20:09 +1000 |
commit | 9dd0d2c1a7ed851474d08714e20511d66ef3122b (patch) | |
tree | 81968c69d5a3c7aabfcddc62e435a4d7c48d95a3 | |
parent | f3bcce096ce1f62d578ca5636a12ce34e08f6a88 (diff) | |
download | jimtcl-9dd0d2c1a7ed851474d08714e20511d66ef3122b.zip jimtcl-9dd0d2c1a7ed851474d08714e20511d66ef3122b.tar.gz jimtcl-9dd0d2c1a7ed851474d08714e20511d66ef3122b.tar.bz2 |
exec, file: set umask before mkstemp
Set umask so that temp files are created with
permissions 0600.
Courtesy of coverity.
Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r-- | jim-exec.c | 4 | ||||
-rw-r--r-- | jim-file.c | 2 |
2 files changed, 5 insertions, 1 deletions
@@ -126,6 +126,7 @@ int Jim_execInit(Jim_Interp *interp) #include <unistd.h> #include <fcntl.h> #include <sys/wait.h> + #include <sys/stat.h> typedef int fdtype; typedef int pidtype; @@ -1576,8 +1577,9 @@ static int JimRewindFd(int fd) static int JimCreateTemp(Jim_Interp *interp, const char *contents, int len) { char inName[] = "/tmp/tcl.tmp.XXXXXX"; - + mode_t mask = umask(S_IXUSR | S_IRWXG | S_IRWXO); int fd = mkstemp(inName); + umask(mask); if (fd == JIM_BAD_FD) { Jim_SetResultErrno(interp, "couldn't create temp file"); return -1; @@ -489,6 +489,7 @@ static int file_cmd_tempfile(Jim_Interp *interp, int argc, Jim_Obj *const *argv) int fd; char *filename; const char *template = "/tmp/tcl.tmp.XXXXXX"; + mode_t mask = umask(S_IXUSR | S_IRWXG | S_IRWXO); if (argc >= 1) { template = Jim_String(argv[0]); @@ -496,6 +497,7 @@ static int file_cmd_tempfile(Jim_Interp *interp, int argc, Jim_Obj *const *argv) filename = Jim_StrDup(template); fd = mkstemp(filename); + umask(mask); if (fd < 0) { Jim_SetResultString(interp, "Failed to create tempfile", -1); Jim_Free(filename); |