From patchwork Wed Aug 24 13:21:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Dickson X-Patchwork-Id: 9297731 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EE31D60757 for ; Wed, 24 Aug 2016 13:21:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E080A28FE6 for ; Wed, 24 Aug 2016 13:21:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D506D28FE9; Wed, 24 Aug 2016 13:21:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 653FF28FE6 for ; Wed, 24 Aug 2016 13:21:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754309AbcHXNVT (ORCPT ); Wed, 24 Aug 2016 09:21:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52914 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753937AbcHXNVS (ORCPT ); Wed, 24 Aug 2016 09:21:18 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (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 7F20B13CF0 for ; Wed, 24 Aug 2016 13:21:18 +0000 (UTC) Received: from steved.boston.devel.redhat.com (vpn-61-155.rdu2.redhat.com [10.10.61.155]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u7ODLHv4013583 for ; Wed, 24 Aug 2016 09:21:18 -0400 From: Steve Dickson To: Linux NFS Mailing list Subject: [PATCH] nfs-server-generator: Fix segfault when /etc/fstab does not exist Date: Wed, 24 Aug 2016 09:21:16 -0400 Message-Id: <1472044876-16332-1-git-send-email-steved@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 24 Aug 2016 13:21:18 +0000 (UTC) Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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);