cluster: RHEL510 - libgfs2: Fix up remove_mtab_entry

Andrew Price andyp at fedoraproject.org
Wed Apr 23 13:46:13 UTC 2014


Gitweb:        http://git.fedorahosted.org/git/?p=cluster.git;a=commitdiff;h=2626fb3ca90e285ab703f0da96955e3d0f5190c7
Commit:        2626fb3ca90e285ab703f0da96955e3d0f5190c7
Parent:        6bb05a0862875033268faceddc764c2b2c313510
Author:        Andrew Price <anprice at redhat.com>
AuthorDate:    Tue Feb 4 00:00:05 2014 -0600
Committer:     Andrew Price <anprice at redhat.com>
CommitterDate: Wed Apr 23 14:44:22 2014 +0100

libgfs2: Fix up remove_mtab_entry

mkstemp was creating the temporary mtab file with overly tight
permissions causing /etc/mtab to end up with an 0600 mode instead of the
regular 0644. This patch resets the mode to 0644 by calling fchmod on
the file descriptor returned by mkstemp.

It also removes a superfluous close() call and sets the temp filename
char array on initialisation instead of using strcpy().

Resolves: rhbz#1086861

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

diff --git a/gfs2/libgfs2/misc.c b/gfs2/libgfs2/misc.c
index 6a1f07f..838209e 100644
--- a/gfs2/libgfs2/misc.c
+++ b/gfs2/libgfs2/misc.c
@@ -227,7 +227,7 @@ static void remove_mtab_entry(struct gfs2_sbd *sdp)
 {
 	FILE *mtab, *mtabnew;
 	struct mntent *mountent;
-	char mtab_tmpfn[PATH_MAX];
+	char mtab_tmpfn[] = "/etc/mtab.XXXXXX";
 	int error, fd;
 	mode_t mask;
 
@@ -235,7 +235,7 @@ static void remove_mtab_entry(struct gfs2_sbd *sdp)
 	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);
@@ -243,6 +243,9 @@ static void remove_mtab_entry(struct gfs2_sbd *sdp)
 		die("Couldn't open temporary mtab file for writing: %s\n",
 		    strerror(errno));
 
+	if (fchmod(fd, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH))
+		die("Couldn't change mode of temporary mtab: %s\n", strerror(errno));
+
 	mtabnew = fdopen(fd, "wt");
 	if (mtabnew == NULL)
 		die("Couldn't open %s for writing : %s\n", mtab_tmpfn,
@@ -257,8 +260,7 @@ static void remove_mtab_entry(struct gfs2_sbd *sdp)
 	}
 
 	endmntent(mtab);
-	fclose(mtabnew);
-	close(fd);
+	fclose(mtabnew); /* Closes underlying fd */
 	if (rename(mtab_tmpfn, "/etc/mtab"))
 		fprintf(stderr, "Unable to remove mount entry from mtab.\n");
 }


More information about the cluster-commits mailing list