cluster: RHEL6 - libgfs2: Set umask before calling mkstemp

Andrew Price andyp at fedoraproject.org
Fri Aug 16 14:47:23 UTC 2013


Gitweb:        http://git.fedorahosted.org/git/?p=cluster.git;a=commitdiff;h=136be5fd39fc6a2f1a277e5f8c9be542e514a538
Commit:        136be5fd39fc6a2f1a277e5f8c9be542e514a538
Parent:        6ab6b7c93a8868f5f95eea67fc3588af9e8c2a52
Author:        Andrew Price <anprice at redhat.com>
AuthorDate:    Fri Aug 16 10:37:40 2013 +0100
Committer:     Andrew Price <anprice at redhat.com>
CommitterDate: Fri Aug 16 10:40:01 2013 +0100

libgfs2: Set umask before calling mkstemp

Coverity highlighted a case where mkstemp() was being called without the
umask being set. This sets the umask to create the file with 0600
permissions and then restores it after mkstemp() is called.

rhbz#996233

Signed-off-by: Andrew Price <anprice at redhat.com>
---
 gfs2/libgfs2/misc.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/gfs2/libgfs2/misc.c b/gfs2/libgfs2/misc.c
index 6807f60..3989bf1 100644
--- a/gfs2/libgfs2/misc.c
+++ b/gfs2/libgfs2/misc.c
@@ -219,13 +219,16 @@ static void remove_mtab_entry(struct gfs2_sbd *sdp)
 	struct mntent *mountent;
 	char mtab_tmpfn[PATH_MAX];
 	int error, fd;
+	mode_t mask;
 
 	mtab = setmntent("/etc/mtab", "rt");
 	if (mtab == NULL)
 		die("Couldn't open /etc/mtab for writing: %s\n",
 		    strerror(errno));
 	strcpy(mtab_tmpfn, "/etc/mtab.XXXXXX");
+	mask = umask(S_IXUSR | S_IRWXG | S_IRWXO);
 	fd = mkstemp(mtab_tmpfn);
+	umask(mask);
 	if (fd < 0)
 		die("Couldn't open temporary mtab file for writing: %s\n",
 		    strerror(errno));


More information about the cluster-commits mailing list