summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorjmmv <jmmv@FreeBSD.org>2014-03-12 12:27:13 +0000
committerjmmv <jmmv@FreeBSD.org>2014-03-12 12:27:13 +0000
commitfac2f42fa33370c9e7d2636f6b9a2517c8f7a8c6 (patch)
tree699b3dc21b3065fd2a18a9275b6018f84cad92cf /lib
parente3f3db3ff5b093b00e715f517d9c9dc823501000 (diff)
downloadFreeBSD-src-fac2f42fa33370c9e7d2636f6b9a2517c8f7a8c6.zip
FreeBSD-src-fac2f42fa33370c9e7d2636f6b9a2517c8f7a8c6.tar.gz
Make ether_line really report an error when all input is invalid.
The previous code failed to return an error condition when the whole input was invalid due to improper handling of the sscanf return value. Actually, this failure was properly being caught by a test in tools/regression/lib/libc/net/test-ether.t but was not noticed because these tests are never run. (On my way to fixing that ;-) The fix applied here resembles the implementation of ether_line in NetBSD modulo the setting of an errno value (which is not documented as an expectation in the manpage anyway).
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/net/ether_addr.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/libc/net/ether_addr.c b/lib/libc/net/ether_addr.c
index 5d72606..19d10ac 100644
--- a/lib/libc/net/ether_addr.c
+++ b/lib/libc/net/ether_addr.c
@@ -72,11 +72,13 @@ ether_line(const char *l, struct ether_addr *e, char *hostname)
i = sscanf(l, "%x:%x:%x:%x:%x:%x %s", &o[0], &o[1], &o[2], &o[3],
&o[4], &o[5], hostname);
- if (i != 7)
- return (i);
- for (i=0; i<6; i++)
- e->octet[i] = o[i];
- return (0);
+ if (i == 7) {
+ for (i = 0; i < 6; i++)
+ e->octet[i] = o[i];
+ return (0);
+ } else {
+ return (-1);
+ }
}
/*
OpenPOWER on IntegriCloud