[PATCH] Enforce return check on virAsprintf() calls

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 two more instances not found by Coverity
that failed the check.


---
 src/util/virutil.h          | 3 ++-
 src/xen/xend_internal.c     | 6 ++----
 tests/networkxml2conftest.c | 5 +++--
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/util/virutil.h b/src/util/virutil.h
index 5a08c81..c386d24 100644
--- a/src/util/virutil.h
+++ b/src/util/virutil.h
@@ -200,7 +200,8 @@ int virParseNumber(const char **str);
 int virParseVersionString(const char *str, unsigned long *version,
                           bool allowMissing);
 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)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_FMT_PRINTF(2, 0);
 char *virStrncpy(char *dest, const char *src, size_t n, size_t destbytes)
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index b03b7bc..3036cbb 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -2738,10 +2738,8 @@ xenDaemonAttachDeviceFlags(virDomainPtr domain, const char *xml,
             virDevicePCIAddress PCIAddr;
 
             PCIAddr = dev->data.hostdev->source.subsys.u.pci;
-            virAsprintf(&target, "PCI device: %.4x:%.2x:%.2x", PCIAddr.domain,
-                                 PCIAddr.bus, PCIAddr.slot);
-
-            if (target == NULL) {
+            if (virAsprintf(&target, "PCI device: %.4x:%.2x:%.2x",
+                            PCIAddr.domain, PCIAddr.bus, PCIAddr.slot) < 0) {
                 virReportOOMError();
                 goto cleanup;
             }
diff --git a/tests/networkxml2conftest.c b/tests/networkxml2conftest.c
index 3979540..fd24f74 100644
--- a/tests/networkxml2conftest.c
+++ b/tests/networkxml2conftest.c
@@ -102,8 +102,9 @@ testDnsmasqLeaseFileName(const char *netname)
 {
     char *leasefile;
 
-    virAsprintf(&leasefile, "/var/lib/libvirt/dnsmasq/%s.leases",
-                netname);
+    if (virAsprintf(&leasefile, "/var/lib/libvirt/dnsmasq/%s.leases",
+                    netname) < 0)
+        return NULL;
 
     return leasefile;
 }
-- 
1.7.11.7

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]