summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+redhat.bugzilla@gmail.com>2016-08-24 09:15:34 -0400
committerSteve Dickson <steved@redhat.com>2016-08-24 09:15:34 -0400
commit21c3ca72fb1b3b4aea30b7cc4989b23daf6bd2dd (patch)
tree77d9f552492af74d16e62e7779537cd378e41b99
parentdf0b99980d74505299e9289c2ccddd03a48b664f (diff)
downloadnfs-utils-21c3ca72fb1b3b4aea30b7cc4989b23daf6bd2dd.tar.gz
nfs-server-generator: Fix segfault when /etc/fstab does not exist
Added a couple checks to handle failures correctly Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1369714 Signed-off-by: Steve Dickson <steved@redhat.com>
-rw-r--r--systemd/nfs-server-generator.c8
1 files changed, 7 insertions, 1 deletions
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);