Enforce return check on virAsprintf() calls
Way back when I started making changes for Coverity messages my first set were to a bunch of CHECKED_RETURN errors. In particular virAsprintf() had a few callers that Coverity noted didn't check their return (although some did check if the buffer being printed to was NULL or not). It was suggested at the time as a further patch an ATTRIBUTE_RETURN_CHECK should be added to virAsprintf(), see: https://www.redhat.com/archives/libvir-list/2013-January/msg00120.html This patch does that and fixes a few more instances not found by Coverity that failed the check.
This commit is contained in:
parent
6405713f2a
commit
46b1d8cf7a
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* virerror.c: error handling and reporting code for libvirt
|
* virerror.c: error handling and reporting code for libvirt
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006, 2008-2012 Red Hat, Inc.
|
* Copyright (C) 2006, 2008-2013 Red Hat, Inc.
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
@ -647,7 +647,7 @@ virRaiseErrorFull(const char *filename ATTRIBUTE_UNUSED,
|
|||||||
} else {
|
} else {
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
virVasprintf(&str, fmt, ap);
|
ignore_value(virVasprintf(&str, fmt, ap));
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* virutil.h: common, generic utility functions
|
* virutil.h: common, generic utility functions
|
||||||
*
|
*
|
||||||
* Copyright (C) 2010-2012 Red Hat, Inc.
|
* Copyright (C) 2010-2013 Red Hat, Inc.
|
||||||
* Copyright (C) 2006, 2007 Binary Karma
|
* Copyright (C) 2006, 2007 Binary Karma
|
||||||
* Copyright (C) 2006 Shuveb Hussain
|
* Copyright (C) 2006 Shuveb Hussain
|
||||||
*
|
*
|
||||||
@ -200,9 +200,11 @@ int virParseNumber(const char **str);
|
|||||||
int virParseVersionString(const char *str, unsigned long *version,
|
int virParseVersionString(const char *str, unsigned long *version,
|
||||||
bool allowMissing);
|
bool allowMissing);
|
||||||
int virAsprintf(char **strp, const char *fmt, ...)
|
int virAsprintf(char **strp, const char *fmt, ...)
|
||||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_FMT_PRINTF(2, 3);
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_FMT_PRINTF(2, 3)
|
||||||
|
ATTRIBUTE_RETURN_CHECK;
|
||||||
int virVasprintf(char **strp, const char *fmt, va_list list)
|
int virVasprintf(char **strp, const char *fmt, va_list list)
|
||||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_FMT_PRINTF(2, 0);
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_FMT_PRINTF(2, 0)
|
||||||
|
ATTRIBUTE_RETURN_CHECK;
|
||||||
char *virStrncpy(char *dest, const char *src, size_t n, size_t destbytes)
|
char *virStrncpy(char *dest, const char *src, size_t n, size_t destbytes)
|
||||||
ATTRIBUTE_RETURN_CHECK;
|
ATTRIBUTE_RETURN_CHECK;
|
||||||
char *virStrcpy(char *dest, const char *src, size_t destbytes)
|
char *virStrcpy(char *dest, const char *src, size_t destbytes)
|
||||||
|
@ -2738,10 +2738,8 @@ xenDaemonAttachDeviceFlags(virDomainPtr domain, const char *xml,
|
|||||||
virDevicePCIAddress PCIAddr;
|
virDevicePCIAddress PCIAddr;
|
||||||
|
|
||||||
PCIAddr = dev->data.hostdev->source.subsys.u.pci;
|
PCIAddr = dev->data.hostdev->source.subsys.u.pci;
|
||||||
virAsprintf(&target, "PCI device: %.4x:%.2x:%.2x", PCIAddr.domain,
|
if (virAsprintf(&target, "PCI device: %.4x:%.2x:%.2x",
|
||||||
PCIAddr.bus, PCIAddr.slot);
|
PCIAddr.domain, PCIAddr.bus, PCIAddr.slot) < 0) {
|
||||||
|
|
||||||
if (target == NULL) {
|
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -102,9 +102,8 @@ testDnsmasqLeaseFileName(const char *netname)
|
|||||||
{
|
{
|
||||||
char *leasefile;
|
char *leasefile;
|
||||||
|
|
||||||
virAsprintf(&leasefile, "/var/lib/libvirt/dnsmasq/%s.leases",
|
ignore_value(virAsprintf(&leasefile, "/var/lib/libvirt/dnsmasq/%s.leases",
|
||||||
netname);
|
netname));
|
||||||
|
|
||||||
return leasefile;
|
return leasefile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* virsh-domain.c: Commands to manage domain
|
* virsh-domain.c: Commands to manage domain
|
||||||
*
|
*
|
||||||
* Copyright (C) 2005, 2007-2012 Red Hat, Inc.
|
* Copyright (C) 2005, 2007-2013 Red Hat, Inc.
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
@ -9011,8 +9011,7 @@ vshCompleteXMLFromDomain(vshControl *ctl, virDomainPtr dom, char *oldXML,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Get all possible devices */
|
/* Get all possible devices */
|
||||||
virAsprintf(&xpath, "/domain/devices/%s", node->name);
|
if (virAsprintf(&xpath, "/domain/devices/%s", node->name) < 0) {
|
||||||
if (!xpath) {
|
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user