Actions
Bug #4868
closedifconfig(1M)'s "addif" uses an uninitialized mask if not specified
Start date:
2014-05-18
Due date:
% Done:
100%
Estimated time:
Difficulty:
Bite-size
Tags:
needs-triage
Gerrit CR:
Description
If you do something like this (pardon my {v4,v6} regexps):
ifconfig e1000g0 {,inet6} addif {x.y.z.N,xxxx:yyyy::zzzz:NNNN}
you'd expect a sensible default prefix to be set. In either case, if /etc/netmasks exists, it may use that, or for IPv4, the class would be used, or for IPv6, say /64 would be used.
You'd be wrong. Both cases set up /6 of all thing.
Turns out the addif() function of ifconfig forgets to initialize the "mask" sockaddr.
This diff will make addif behave like normal ifconfig (which uses the same-prefixed setifaddr()).
diff --git a/usr/src/cmd/cmd-inet/usr.sbin/ifconfig/ifconfig.c b/usr/src/cmd/cmd index 4fb7837..03d5716 100644 --- a/usr/src/cmd/cmd-inet/usr.sbin/ifconfig/ifconfig.c +++ b/usr/src/cmd/cmd-inet/usr.sbin/ifconfig/ifconfig.c @@ -1836,6 +1836,9 @@ addif(char *str, int64_t param) setaddr = 0; (*afp->af_getaddr)(str, (struct sockaddr *)&laddr, &prefixlen); + (void) memset(&mask, 0, sizeof (mask)); + mask.ss_family = afp->af_af; + switch (prefixlen) { case NO_PREFIX: /* Nothing there - ok */
A follow-on bug might be to factor the common code out of addif() and setifaddr().
Updated by Electric Monk about 8 years ago
- Status changed from New to Closed
- % Done changed from 80 to 100
git commit 60b43c45a204a6c0651e8017e1e505015ba74094
commit 60b43c45a204a6c0651e8017e1e505015ba74094 Author: Dan McDonald <danmcd@omniti.com> Date: 2014-05-19T14:53:50.000Z 4868 ifconfig(1M)'s "addif" uses an uninitialized mask if not specified Reviewed by: Robert Mustacchi <rm@joyent.com> Reviewed by: Andy Stormont <AStormont@racktopsystems.com> Reviewed by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net> Approved by: Garrett D'Amore <garrett@damore.org>
Actions