Return-Path: Received: from mx1.redhat.com ([209.132.183.28]:44980 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754650AbcHXNxp (ORCPT ); Wed, 24 Aug 2016 09:53:45 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7D08182C for ; Wed, 24 Aug 2016 13:53:37 +0000 (UTC) Received: from steved.boston.devel.redhat.com (vpn-61-155.rdu2.redhat.com [10.10.61.155]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u7ODra19006114 for ; Wed, 24 Aug 2016 09:53:37 -0400 Subject: Re: [PATCH] nfs-server-generator: Fix segfault when /etc/fstab does not exist To: Linux NFS Mailing list References: <1472044876-16332-1-git-send-email-steved@redhat.com> From: Steve Dickson Message-ID: Date: Wed, 24 Aug 2016 09:53:36 -0400 MIME-Version: 1.0 In-Reply-To: <1472044876-16332-1-git-send-email-steved@redhat.com> Content-Type: text/plain; charset=windows-1252 Sender: linux-nfs-owner@vger.kernel.org List-ID: On 08/24/2016 09:21 AM, Steve Dickson wrote: > From: Yu Watanabe > > Added a couple checks to handle failures correctly > > Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1369714 > Signed-off-by: Steve Dickson 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); >