From fac2f42fa33370c9e7d2636f6b9a2517c8f7a8c6 Mon Sep 17 00:00:00 2001 From: jmmv Date: Wed, 12 Mar 2014 12:27:13 +0000 Subject: 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). --- lib/libc/net/ether_addr.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'lib') 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); + } } /* -- cgit v1.1