[PATCH] nfs-server-generator: Fix segfault when /etc/fstab does not exist

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Yu Watanabe <watanabe.yu+redhat.bugzilla@xxxxxxxxx>

Added a couple checks to handle failures correctly

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1369714
Signed-off-by: Steve Dickson <steved@xxxxxxxxxx>
---
 systemd/nfs-server-generator.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/systemd/nfs-server-generator.c b/systemd/nfs-server-generator.c
index af8bb52..f47718e 100644
--- a/systemd/nfs-server-generator.c
+++ b/systemd/nfs-server-generator.c
@@ -47,6 +47,8 @@ static int is_unique(struct list **lp, char *path)
 		l = l->next;
 	}
 	l = malloc(sizeof(*l));
+	if (l == NULL)
+		return 0;
 	l->name = path;
 	l->next = *lp;
 	*lp = l;
@@ -112,7 +114,7 @@ int main(int argc, char *argv[])
 	strcat(path, filebase);
 	f = fopen(path, "w");
 	if (!f)
-		return 1;
+		exit(1);
 	fprintf(f, "# Automatically generated by nfs-server-generator\n\n[Unit]\n");
 
 	for (i = 0; i < MCL_MAXTYPES; i++) {
@@ -129,6 +131,9 @@ int main(int argc, char *argv[])
 	}
 
 	fstab = setmntent("/etc/fstab", "r");
+	if (!fstab)
+		exit(1);
+
 	while ((mnt = getmntent(fstab)) != NULL) {
 		if (strcmp(mnt->mnt_type, "nfs") != 0 &&
 		    strcmp(mnt->mnt_type, "nfs4") != 0)
@@ -138,6 +143,7 @@ int main(int argc, char *argv[])
 		fprintf(f, ".mount\n");
 	}
 
+	fclose(fstab);
 	fclose(f);
 
 	exit(0);
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Filesystem Development]     [Linux USB Development]     [Linux Media Development]     [Video for Linux]     [Linux NILFS]     [Linux Audio Users]     [Yosemite Info]     [Linux SCSI]

  Powered by Linux