Tue Apr 14 05:14:18 2015 UTC ()
Pull up following revision(s) (requested by christos in ticket #687):
	usr.sbin/nfsd/nfsd.c: revision 1.63
Memset the whole cfg array, not piecemeal because otherwise you'll end
up with random data depending on the options set.


(snj)
diff -r1.62 -r1.62.4.1 src/usr.sbin/nfsd/nfsd.c

cvs diff -r1.62 -r1.62.4.1 src/usr.sbin/nfsd/nfsd.c (expand / switch to unified diff)

--- src/usr.sbin/nfsd/nfsd.c 2014/03/29 13:50:53 1.62
+++ src/usr.sbin/nfsd/nfsd.c 2015/04/14 05:14:17 1.62.4.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: nfsd.c,v 1.62 2014/03/29 13:50:53 gson Exp $ */ 1/* $NetBSD: nfsd.c,v 1.62.4.1 2015/04/14 05:14:17 snj Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1989, 1993, 1994 4 * Copyright (c) 1989, 1993, 1994
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Rick Macklem at The University of Guelph. 8 * Rick Macklem at The University of Guelph.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -32,27 +32,27 @@ @@ -32,27 +32,27 @@
32 * SUCH DAMAGE. 32 * SUCH DAMAGE.
33 */ 33 */
34 34
35#include <sys/cdefs.h> 35#include <sys/cdefs.h>
36#ifndef lint 36#ifndef lint
37__COPYRIGHT("@(#) Copyright (c) 1989, 1993, 1994\ 37__COPYRIGHT("@(#) Copyright (c) 1989, 1993, 1994\
38 The Regents of the University of California. All rights reserved."); 38 The Regents of the University of California. All rights reserved.");
39#endif /* not lint */ 39#endif /* not lint */
40 40
41#ifndef lint 41#ifndef lint
42#if 0 42#if 0
43static char sccsid[] = "@(#)nfsd.c 8.9 (Berkeley) 3/29/95"; 43static char sccsid[] = "@(#)nfsd.c 8.9 (Berkeley) 3/29/95";
44#else 44#else
45__RCSID("$NetBSD: nfsd.c,v 1.62 2014/03/29 13:50:53 gson Exp $"); 45__RCSID("$NetBSD: nfsd.c,v 1.62.4.1 2015/04/14 05:14:17 snj Exp $");
46#endif 46#endif
47#endif /* not lint */ 47#endif /* not lint */
48 48
49#include <sys/param.h> 49#include <sys/param.h>
50#include <sys/ioctl.h> 50#include <sys/ioctl.h>
51#include <sys/stat.h> 51#include <sys/stat.h>
52#include <sys/wait.h> 52#include <sys/wait.h>
53#include <sys/uio.h> 53#include <sys/uio.h>
54#include <sys/ucred.h> 54#include <sys/ucred.h>
55#include <sys/mount.h> 55#include <sys/mount.h>
56#include <sys/socket.h> 56#include <sys/socket.h>
57#include <sys/socketvar.h> 57#include <sys/socketvar.h>
58#include <poll.h> 58#include <poll.h>
@@ -130,27 +130,26 @@ struct conf { @@ -130,27 +130,26 @@ struct conf {
130static int cfg_family[] = { PF_INET, PF_INET, PF_INET6, PF_INET6 }; 130static int cfg_family[] = { PF_INET, PF_INET, PF_INET6, PF_INET6 };
131static const char *cfg_netconf[] = { "udp", "tcp", "udp6", "tcp6" }; 131static const char *cfg_netconf[] = { "udp", "tcp", "udp6", "tcp6" };
132static int cfg_socktype[] = { 132static int cfg_socktype[] = {
133 SOCK_DGRAM, SOCK_STREAM, SOCK_DGRAM, SOCK_STREAM }; 133 SOCK_DGRAM, SOCK_STREAM, SOCK_DGRAM, SOCK_STREAM };
134static int cfg_protocol[] = { 134static int cfg_protocol[] = {
135 IPPROTO_UDP, IPPROTO_TCP, IPPROTO_UDP, IPPROTO_TCP }; 135 IPPROTO_UDP, IPPROTO_TCP, IPPROTO_UDP, IPPROTO_TCP };
136 136
137static int 137static int
138tryconf(struct conf *cfg, int t, int reregister) 138tryconf(struct conf *cfg, int t, int reregister)
139{ 139{
140 struct addrinfo hints; 140 struct addrinfo hints;
141 int ecode; 141 int ecode;
142 142
143 memset(cfg, 0, sizeof(*cfg)); 
144 memset(&hints, 0, sizeof hints); 143 memset(&hints, 0, sizeof hints);
145 hints.ai_flags = AI_PASSIVE; 144 hints.ai_flags = AI_PASSIVE;
146 hints.ai_family = cfg_family[t]; 145 hints.ai_family = cfg_family[t];
147 hints.ai_socktype = cfg_socktype[t]; 146 hints.ai_socktype = cfg_socktype[t];
148 hints.ai_protocol = cfg_protocol[t]; 147 hints.ai_protocol = cfg_protocol[t];
149 148
150 ecode = getaddrinfo(NULL, "nfs", &hints, &cfg->ai); 149 ecode = getaddrinfo(NULL, "nfs", &hints, &cfg->ai);
151 if (ecode != 0) { 150 if (ecode != 0) {
152 syslog(LOG_ERR, "getaddrinfo %s: %s", cfg_netconf[t], 151 syslog(LOG_ERR, "getaddrinfo %s: %s", cfg_netconf[t],
153 gai_strerror(ecode)); 152 gai_strerror(ecode));
154 return -1; 153 return -1;
155 } 154 }
156 155
@@ -463,26 +462,27 @@ main(int argc, char *argv[]) @@ -463,26 +462,27 @@ main(int argc, char *argv[])
463 warnx("This is the default behavior now and you can remove"); 462 warnx("This is the default behavior now and you can remove");
464 warnx("all options."); 463 warnx("all options.");
465 tcpflag = udpflag = 1; 464 tcpflag = udpflag = 1;
466 if (ip6flag == 1 && ip4flag == 0) 465 if (ip6flag == 1 && ip4flag == 0)
467 ip4flag = 1; 466 ip4flag = 1;
468 } 467 }
469 468
470 if (debug == 0) { 469 if (debug == 0) {
471 parent_fd = daemon2_fork(); 470 parent_fd = daemon2_fork();
472 } 471 }
473 472
474 openlog("nfsd", LOG_PID, LOG_DAEMON); 473 openlog("nfsd", LOG_PID, LOG_DAEMON);
475 474
 475 memset(cfg, 0, sizeof(cfg));
476 for (i = 0; i < __arraycount(cfg); i++) { 476 for (i = 0; i < __arraycount(cfg); i++) {
477 if (ip4flag == 0 && cfg_family[i] == PF_INET) 477 if (ip4flag == 0 && cfg_family[i] == PF_INET)
478 continue; 478 continue;
479 if (ip6flag == 0 && cfg_family[i] == PF_INET6) 479 if (ip6flag == 0 && cfg_family[i] == PF_INET6)
480 continue; 480 continue;
481 if (tcpflag == 0 && cfg_protocol[i] == IPPROTO_TCP) 481 if (tcpflag == 0 && cfg_protocol[i] == IPPROTO_TCP)
482 continue; 482 continue;
483 if (udpflag == 0 && cfg_protocol[i] == IPPROTO_UDP) 483 if (udpflag == 0 && cfg_protocol[i] == IPPROTO_UDP)
484 continue; 484 continue;
485 tryconf(&cfg[i], i, reregister); 485 tryconf(&cfg[i], i, reregister);
486 } 486 }
487 487
488 for (i = 0; i < nfsdcnt; i++) { 488 for (i = 0; i < nfsdcnt; i++) {