@@ -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++) {
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 <neilb@suse.com> --- 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