summaryrefslogtreecommitdiffstats
path: root/libmount/src/utils.c
diff options
context:
space:
mode:
authorKarel Zak2012-12-12 13:32:52 +0100
committerKarel Zak2012-12-12 13:32:52 +0100
commit6fc8122490aacbeee8cf6ad7ed37819549e987c4 (patch)
tree09e2dddd2a13ad510e06bea4e15fff54e5285234 /libmount/src/utils.c
parentswapon: fix memmory leak [coverity scan] (diff)
downloadkernel-qcow2-util-linux-6fc8122490aacbeee8cf6ad7ed37819549e987c4.tar.gz
kernel-qcow2-util-linux-6fc8122490aacbeee8cf6ad7ed37819549e987c4.tar.xz
kernel-qcow2-util-linux-6fc8122490aacbeee8cf6ad7ed37819549e987c4.zip
libmount: make mkstemp() more robust [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/utils.c')
-rw-r--r--libmount/src/utils.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/libmount/src/utils.c b/libmount/src/utils.c
index d473bc499..325e1e9db 100644
--- a/libmount/src/utils.c
+++ b/libmount/src/utils.c
@@ -810,6 +810,7 @@ int mnt_open_uniq_filename(const char *filename, char **name)
{
int rc, fd;
char *n;
+ mode_t oldmode;
if (!filename)
return -EINVAL;
@@ -820,7 +821,14 @@ int mnt_open_uniq_filename(const char *filename, char **name)
if (rc <= 0)
return -errno;
+ /* This is for very old glibc and for compatibility with Posix where is
+ * nothing about mkstemp() mode. All sane glibc use secure mode (0600).
+ */
+ oldmode = umask(S_IRGRP|S_IWGRP|S_IXGRP
+ S_IROTH|S_IWOTH|S_IXOTH)
fd = mkstemp(n);
+ umask(oldmask);
+
if (fd >= 0 && name)
*name = n;
else