gfs2-utils: master - gfs2_edit: Set umask before calling mkstemp in savemetaopen()

Andrew Price andyp at fedoraproject.org
Fri Sep 19 13:44:52 UTC 2014


Gitweb:        http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=2b4fcf7ac3589fa8cef3b9985fdca3562b0fbb07
Commit:        2b4fcf7ac3589fa8cef3b9985fdca3562b0fbb07
Parent:        5ad00f239c7ccfa89e279a4996a29a12783bef6e
Author:        Andrew Price <anprice at redhat.com>
AuthorDate:    Thu Sep 18 14:51:41 2014 +0100
Committer:     Andrew Price <anprice at redhat.com>
CommitterDate: Thu Sep 18 14:51:41 2014 +0100

gfs2_edit: Set umask before calling mkstemp in savemetaopen()

Spotted by coverity: Calling "mkstemp(char *)" without securely setting
umask first.

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

diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index 360b144..5147ee5 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -259,6 +259,7 @@ static struct metafd savemetaopen(char *out_fn, int gziplevel)
 	struct metafd mfd = {-1, NULL, NULL, gziplevel};
 	char gzmode[3] = "w9";
 	char dft_fn[] = DFT_SAVE_FILE;
+	mode_t mask = umask(S_IXUSR | S_IRWXG | S_IRWXO);
 
 	if (!out_fn) {
 		out_fn = dft_fn;
@@ -266,6 +267,7 @@ static struct metafd savemetaopen(char *out_fn, int gziplevel)
 	} else {
 		mfd.fd = open(out_fn, O_RDWR | O_CREAT, 0644);
 	}
+	umask(mask);
 	mfd.filename = out_fn;
 
 	if (mfd.fd < 0) {


More information about the cluster-commits mailing list