summaryrefslogtreecommitdiff
path: root/src/lib/eina
diff options
context:
space:
mode:
authorSebastian Dransfeld <sebastian.dransfeld@sintef.no>2013-10-16 04:28:53 +0200
committerSebastian Dransfeld <sebastian.dransfeld@sintef.no>2013-10-16 04:28:53 +0200
commit7576ff00f3e014db84ae1a044ae60a78c2222c31 (patch)
tree5bbef91913f86b1ccb2240e4e2e67c43b7bc6da0 /src/lib/eina
parenteea1b83cf6c47b61aea35a70d2e9ff7b2b899780 (diff)
Set secure file permissions for temporary file
From glibc mkstemp man page: In glibc versions 2.06 and earlier, the file is created with permissions 0666, that is, read and write for all users. This old behavior may be a security risk, especially since other UNIX flavors use 0600, and somebody might overlook this detail when porting programs. POSIX.1-2008 adds a requirement that the file be created with mode 0600. More generally, the POSIX specification of mkstemp() does not say anything about file modes, so the application should make sure its file mode creation mask (see umask(2)) is set appropriately before calling mkstemp() (and mkostemp()). And: http://cwe.mitre.org/data/definitions/377.html
Diffstat (limited to 'src/lib/eina')
-rw-r--r--src/lib/eina/eina_file_common.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/lib/eina/eina_file_common.c b/src/lib/eina/eina_file_common.c
index ec9cac8a6e..9a222c2b47 100644
--- a/src/lib/eina/eina_file_common.c
+++ b/src/lib/eina/eina_file_common.c
@@ -869,6 +869,7 @@ eina_file_mkstemp(const char *templatename, Eina_Tmpstr **path)
869 char buffer[PATH_MAX]; 869 char buffer[PATH_MAX];
870 const char *tmpdir; 870 const char *tmpdir;
871 int fd; 871 int fd;
872 mode_t old_umask;
872 873
873#ifndef HAVE_EVIL 874#ifndef HAVE_EVIL
874 tmpdir = getenv("TMPDIR"); 875 tmpdir = getenv("TMPDIR");
@@ -877,7 +878,13 @@ eina_file_mkstemp(const char *templatename, Eina_Tmpstr **path)
877 tmpdir = (char *)evil_tmpdir_get(); 878 tmpdir = (char *)evil_tmpdir_get();
878#endif /* ! HAVE_EVIL */ 879#endif /* ! HAVE_EVIL */
879 880
881 /*
882 * Make sure temp file is created with secure permissions,
883 * http://man7.org/linux/man-pages/man3/mkstemp.3.html#NOTES
884 */
885 old_umask = umask(0077);
880 snprintf(buffer, PATH_MAX, "%s/%s", tmpdir, templatename); 886 snprintf(buffer, PATH_MAX, "%s/%s", tmpdir, templatename);
887 umask(old_umask);
881 888
882 fd = mkstemp(buffer); 889 fd = mkstemp(buffer);
883 if (path) *path = eina_tmpstr_add(buffer); 890 if (path) *path = eina_tmpstr_add(buffer);