[libvirt] [PATCH 06/10] xen: Use virParseMacAddr instead of sscanf
Eric Blake
eblake at redhat.com
Wed Mar 31 15:58:27 UTC 2010
On 03/30/2010 10:20 AM, Matthias Bolte wrote:
> ---
> src/xen/xend_internal.c | 18 ++----------------
> src/xen/xm_internal.c | 19 +++++--------------
> 2 files changed, 7 insertions(+), 30 deletions(-)
ACK - nice cleanup.
> if (mac[0]) {
> - unsigned int rawmac[6];
> - sscanf(mac, "%02x:%02x:%02x:%02x:%02x:%02x",
> - (unsigned int*)&rawmac[0],
> - (unsigned int*)&rawmac[1],
> - (unsigned int*)&rawmac[2],
> - (unsigned int*)&rawmac[3],
> - (unsigned int*)&rawmac[4],
> - (unsigned int*)&rawmac[5]);
> - net->mac[0] = rawmac[0];
> - net->mac[1] = rawmac[1];
> - net->mac[2] = rawmac[2];
> - net->mac[3] = rawmac[3];
> - net->mac[4] = rawmac[4];
> - net->mac[5] = rawmac[5];
> + if (virParseMacAddr(mac, net->mac) < 0) {
> + xenXMError(conn, VIR_ERR_INTERNAL_ERROR,
> + _("malformed mac address '%s'"), mac);
> + goto cleanup;
> + }
Especially since it fixes a bug where we could have used uninitialized
memory if sscanf had failed.
--
Eric Blake eblake at redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 323 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20100331/54a54338/attachment-0001.sig>
More information about the libvir-list
mailing list