lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Sat, 25 Oct 2008 10:00:45 +0200
From:	Johannes Berg <johannes@...solutions.net>
To:	Joe Perches <joe@...ches.com>
Cc:	"David S. Miller" <davem@...emloft.net>,
	netdev <netdev@...r.kernel.org>
Subject: Re: [PATCH] add %pM printf format specifier

On Fri, 2008-10-24 at 18:41 -0700, Joe Perches wrote:


> > +static char *mac_address(char *buf, char *end, u8 *addr, int field_width, int precision, int flags)
> > +{
> > +	/* room for 6 * two hex digits, 5 colons and trailing zero */
> > +	char mac[18];
> > +	char *p = mac, *pend = mac + sizeof(mac);
> > +	int i;
> > +
> > +	for (i=0; i < 6; i++) {
> > +		p = number(p, pend, addr[i], 16, 2, -1, SMALL | ZEROPAD);
> > +		*p++ = ':';
> > +	}
> 
> For consistency, shouldn't the function name be mac_address_string?
> 
> I (and perhaps Harvey H) would be happier with:
> 
> 	char mac[18];
> 	char *p = mac;
> 	int i;
> 
> 	for (i = 0; i < 5; i++) {
> 		p = pack_hex_byte(p, addr[i]);
> 		*p++ = ':';
> 	}
> 	p = pack_hex_byte(p, addr[5]);
> 	*p = '\0';
> 
> Smaller, faster, etc...

Heh. I wasn't aware of pack_hex_byte. Not sure it really is smaller
though with the inlining, and kernel messages ought not to be
performance sensitive. OTOH, this is _way_ simpler in terms of code,
I'll send v2.

> Also, as the number of %p(foo) types increases, perhaps
> something like sparse could validate the printf argument
> types?

Hard to do really, what guarantees that a MAC address is 6 bytes, which
is the relevant thing? :)

johannes

Download attachment "signature.asc" of type "application/pgp-signature" (837 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ