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(a)redhat.com +1-801-349-2682
Libvirt virtualization library
http://libvirt.org