linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] nfs-server-generator: Fix segfault when /etc/fstab does not exist
@ 2016-08-24 13:21 Steve Dickson
  2016-08-24 13:53 ` Steve Dickson
  0 siblings, 1 reply; 2+ messages in thread
From: Steve Dickson @ 2016-08-24 13:21 UTC (permalink / raw)
  To: Linux NFS Mailing list

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

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>
---
 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] nfs-server-generator: Fix segfault when /etc/fstab does not exist
  2016-08-24 13:21 [PATCH] nfs-server-generator: Fix segfault when /etc/fstab does not exist Steve Dickson
@ 2016-08-24 13:53 ` Steve Dickson
  0 siblings, 0 replies; 2+ messages in thread
From: Steve Dickson @ 2016-08-24 13:53 UTC (permalink / raw)
  To: Linux NFS Mailing list



On 08/24/2016 09:21 AM, Steve Dickson wrote:
> From: Yu Watanabe <watanabe.yu+redhat.bugzilla@gmail.com>
> 
> 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>
Committed... 

steved.
> ---
>  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);
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-08-24 13:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-24 13:21 [PATCH] nfs-server-generator: Fix segfault when /etc/fstab does not exist Steve Dickson
2016-08-24 13:53 ` Steve Dickson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).