[PATCH 3/3] util: Check return value from virStrToLong* functions

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

 



We do so in the vast majority of places, so there's no problem of adding
the attribute to enforce it by the complier and fix a few leftover
places.

This was originally pointed out by Coverity as a recent change triggered
it's warning that our code checked the vast majority of returns from
virStrToLong_ui.
---
 src/util/virsexpr.c   |  6 +++---
 src/util/virstring.h  | 30 ++++++++++++++++++++----------
 src/vbox/vbox_tmpl.c  |  4 ++--
 src/xen/xs_internal.c |  2 +-
 src/xenxs/xen_xm.c    |  9 +++++++--
 5 files changed, 33 insertions(+), 18 deletions(-)

diff --git a/src/util/virsexpr.c b/src/util/virsexpr.c
index f5eb364..f8a0ccd 100644
--- a/src/util/virsexpr.c
+++ b/src/util/virsexpr.c
@@ -567,7 +567,7 @@ sexpr_int(const struct sexpr *sexpr, const char *name)

     if (value) {
         int val = 0;
-        virStrToLong_i(value, NULL, 0, &val);
+        ignore_value(virStrToLong_i(value, NULL, 0, &val));
         return val;
     }
     return 0;
@@ -590,7 +590,7 @@ sexpr_float(const struct sexpr *sexpr, const char *name)

     if (value) {
         double val = 0;
-        virStrToDouble(value, NULL, &val);
+        ignore_value(virStrToDouble(value, NULL, &val));
         return val;
     }
     return 0;
@@ -613,7 +613,7 @@ sexpr_u64(const struct sexpr *sexpr, const char *name)

     if (value) {
         unsigned long long val = 0;
-        virStrToLong_ull(value, NULL, 0, &val);
+        ignore_value(virStrToLong_ull(value, NULL, 0, &val));
         return val;
     }
     return 0;
diff --git a/src/util/virstring.h b/src/util/virstring.h
index df25441..267fbd0 100644
--- a/src/util/virstring.h
+++ b/src/util/virstring.h
@@ -51,43 +51,53 @@ char *virArgvToString(const char *const *argv);
 int virStrToLong_i(char const *s,
                    char **end_ptr,
                    int base,
-                   int *result);
+                   int *result)
+    ATTRIBUTE_RETURN_CHECK;

 int virStrToLong_ui(char const *s,
                     char **end_ptr,
                     int base,
-                    unsigned int *result);
+                    unsigned int *result)
+    ATTRIBUTE_RETURN_CHECK;
 int virStrToLong_uip(char const *s,
                      char **end_ptr,
                      int base,
-                     unsigned int *result);
+                     unsigned int *result)
+    ATTRIBUTE_RETURN_CHECK;
 int virStrToLong_l(char const *s,
                    char **end_ptr,
                    int base,
-                   long *result);
+                   long *result)
+    ATTRIBUTE_RETURN_CHECK;
 int virStrToLong_ul(char const *s,
                     char **end_ptr,
                     int base,
-                    unsigned long *result);
+                    unsigned long *result)
+    ATTRIBUTE_RETURN_CHECK;
 int virStrToLong_ulp(char const *s,
                      char **end_ptr,
                      int base,
-                     unsigned long *result);
+                     unsigned long *result)
+    ATTRIBUTE_RETURN_CHECK;
 int virStrToLong_ll(char const *s,
                     char **end_ptr,
                     int base,
-                    long long *result);
+                    long long *result)
+    ATTRIBUTE_RETURN_CHECK;
 int virStrToLong_ull(char const *s,
                      char **end_ptr,
                      int base,
-                     unsigned long long *result);
+                     unsigned long long *result)
+    ATTRIBUTE_RETURN_CHECK;
 int virStrToLong_ullp(char const *s,
                       char **end_ptr,
                       int base,
-                      unsigned long long *result);
+                      unsigned long long *result)
+    ATTRIBUTE_RETURN_CHECK;
 int virStrToDouble(char const *s,
                    char **end_ptr,
-                   double *result);
+                   double *result)
+    ATTRIBUTE_RETURN_CHECK;

 void virSkipSpaces(const char **str) ATTRIBUTE_NONNULL(1);
 void virSkipSpacesAndBackslash(const char **str) ATTRIBUTE_NONNULL(1);
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index e60a672..a18d7ab 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -2344,8 +2344,8 @@ static void vboxHostDeviceGetXMLDesc(vboxGlobalData *data, virDomainDefPtr def,
         VBOX_UTF16_TO_UTF8(vendorIdUtf16, &vendorIdUtf8);
         VBOX_UTF16_TO_UTF8(productIdUtf16, &productIdUtf8);

-        virStrToLong_ui(vendorIdUtf8, &endptr, 16, &vendorId);
-        virStrToLong_ui(productIdUtf8, &endptr, 16, &productId);
+        ignore_value(virStrToLong_ui(vendorIdUtf8, &endptr, 16, &vendorId));
+        ignore_value(virStrToLong_ui(productIdUtf8, &endptr, 16, &productId));

         def->hostdevs[USBFilterCount]->source.subsys.u.usb.vendor  = vendorId;
         def->hostdevs[USBFilterCount]->source.subsys.u.usb.product = productId;
diff --git a/src/xen/xs_internal.c b/src/xen/xs_internal.c
index 8ddcd7e..7e2d477 100644
--- a/src/xen/xs_internal.c
+++ b/src/xen/xs_internal.c
@@ -335,7 +335,7 @@ xenStoreDomainGetVNCPort(virConnectPtr conn, int domid)

     tmp = virDomainDoStoreQuery(conn, domid, "console/vnc-port");
     if (tmp != NULL) {
-        virStrToLong_i(tmp, NULL, 10, &ret);
+        ignore_value(virStrToLong_i(tmp, NULL, 10, &ret));
         VIR_FREE(tmp);
     }
     return ret;
diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c
index 7eb183e..f6492b5 100644
--- a/src/xenxs/xen_xm.c
+++ b/src/xenxs/xen_xm.c
@@ -1026,8 +1026,13 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
                         if (VIR_STRDUP(graphics->data.vnc.keymap, key + 7) < 0)
                             goto cleanup;
                     } else if (STRPREFIX(key, "vncdisplay=")) {
-                        virStrToLong_i(key + 11, NULL, 10,
-                                       &graphics->data.vnc.port);
+                        if (virStrToLong_i(key + 11, NULL, 10,
+                                           &graphics->data.vnc.port) < 0) {
+                            virReportError(VIR_ERR_INTERNAL_ERROR,
+                                           _("invalid vncdisplay value '%s'"),
+                                           key + 11);
+                            goto cleanup;
+                        }
                         graphics->data.vnc.port += 5900;
                     }
                 } else {
-- 
2.0.0

--
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]