From patchwork Thu Dec 8 04:27:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 9465757 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 93A7360459 for ; Thu, 8 Dec 2016 04:27:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A291283FF for ; Thu, 8 Dec 2016 04:27:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6EBAD28415; Thu, 8 Dec 2016 04:27:54 +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 D5C57283FF for ; Thu, 8 Dec 2016 04:27:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752704AbcLHE1x (ORCPT ); Wed, 7 Dec 2016 23:27:53 -0500 Received: from mx2.suse.de ([195.135.220.15]:43930 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751091AbcLHE1w (ORCPT ); Wed, 7 Dec 2016 23:27:52 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 68140AAC8; Thu, 8 Dec 2016 04:27:51 +0000 (UTC) From: NeilBrown To: "J. Bruce Fields" , Steve Dickson Date: Thu, 08 Dec 2016 15:27:24 +1100 Subject: [PATCH 01/10] nfsd: move and improve test on valid port Cc: linux-nfs@vger.kernel.org Message-ID: <148117124448.31271.15941445957552185502.stgit@noble> In-Reply-To: <148117122602.31271.13586847542442809540.stgit@noble> References: <148117122602.31271.13586847542442809540.stgit@noble> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 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 nfssvc_set_sockets() access textual port numbers (by lookup in /etc/services). This uses getaddrinfo which reports errors, except for out-of-range numbers. So change the test on a valid port to only complain if the port given is purely numeric, but is out-of-range. Also move it so that any default value gets tested the same as any argument value. Signed-off-by: NeilBrown --- utils/nfsd/nfsd.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/utils/nfsd/nfsd.c b/utils/nfsd/nfsd.c index 62b2876948c3..89179be76113 100644 --- a/utils/nfsd/nfsd.c +++ b/utils/nfsd/nfsd.c @@ -59,7 +59,7 @@ static struct option longopts[] = int main(int argc, char **argv) { - int count = NFSD_NPROC, c, i, error = 0, portnum = 0, fd, found_one; + int count = NFSD_NPROC, c, i, error = 0, portnum, fd, found_one; char *p, *progname, *port, *rdma_port = NULL; char **haddr = NULL; int hcounter = 0; @@ -132,12 +132,6 @@ main(int argc, char **argv) case 'P': /* XXX for nfs-server compatibility */ case 'p': /* only the last -p option has any effect */ - portnum = atoi(optarg); - if (portnum <= 0 || portnum > 65535) { - fprintf(stderr, "%s: bad port number: %s\n", - progname, optarg); - usage(progname); - } free(port); port = xstrdup(optarg); break; @@ -245,6 +239,15 @@ main(int argc, char **argv) xlog_open(progname); + portnum = strtol(port, &p, 0); + if (!*p && (portnum <= 0 || portnum > 65535)) { + /* getaddrinfo will catch other errors, but not + * out-of-range numbers. + */ + xlog(L_ERROR, "invalid port number: %s", port); + exit(1); + } + /* make sure that at least one version is enabled */ found_one = 0; for (c = NFSD_MINVERS; c <= NFSD_MAXVERS; c++) {