]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: Fix regression of wwn reading
authorOsier Yang <jyang@redhat.com>
Mon, 6 May 2013 12:45:11 +0000 (20:45 +0800)
committerOsier Yang <jyang@redhat.com>
Mon, 13 May 2013 09:10:59 +0000 (17:10 +0800)
Introduced by commit 244ce462e29, which refactored the helper for wwn
reading, however, it forgot to change the old "strndup" and "sizeof(buf)",
"sizeof(buf)" operates on the fixed length array ("buf") in the old code,
but now "buf" is a pointer.

Before the fix:

% virsh nodedev-dumpxml scsi_host5
<device>
  <name>scsi_host5</name>
  <parent>pci_0000_04_00_1</parent>
  <capability type='scsi_host'>
    <host>5</host>
    <capability type='fc_host'>
      <wwnn>2001001b</wwnn>
      <wwpn>2101001b</wwpn>
      <fabric_wwn>2001000d</fabric_wwn>
    </capability>
  </capability>
</device>

With the fix:

% virsh nodedev-dumpxml scsi_host5
<device>
  <name>scsi_host5</name>
  <parent>pci_0000_04_00_1</parent>
  <capability type='scsi_host'>
    <host>5</host>
    <capability type='fc_host'>
      <wwnn>0x2001001b32a9da4e</wwnn>
      <wwpn>0x2101001b32a9da4e</wwpn>
      <fabric_wwn>0x2001000dec9877c1</fabric_wwn>
    </capability>
  </capability>
</device>

src/util/virutil.c

index 3c0a48131d89c0ef3593df12a766eddafdfd2e59..39eeefb99ef65dba59276bd892ef2c1913653188 100644 (file)
@@ -1694,10 +1694,8 @@ virReadFCHost(const char *sysfs_prefix,
     else
         p = buf;
 
-    if (!(*result = strndup(p, sizeof(buf)))) {
-        virReportOOMError();
+    if (VIR_STRDUP(*result, p) < 0)
         goto cleanup;
-    }
 
     ret = 0;
 cleanup: