[libvirt] [PATCHv2 3/8] Remove VIR_STRNDUP usage with checked pointers

Ján Tomko jtomko at redhat.com
Wed Dec 11 13:23:19 UTC 2019


Remove the usage where sanity of the length argument is verified
by other conditions not matching the previous patches.

Signed-off-by: Ján Tomko <jtomko at redhat.com>
---
 src/libxl/xen_common.c | 18 ++++++++----------
 tools/vsh.c            |  5 ++---
 2 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c
index 8c07df80b6..912dd8834a 100644
--- a/src/libxl/xen_common.c
+++ b/src/libxl/xen_common.c
@@ -815,9 +815,8 @@ xenParseSxprChar(const char *value,
             goto error;
         }
 
-        if (offset != value &&
-            VIR_STRNDUP(def->source->data.tcp.host, value, offset - value) < 0)
-            goto error;
+        if (offset != value)
+            def->source->data.tcp.host = g_strndup(value, offset - value);
 
         offset2 = strchr(offset, ',');
         offset++;
@@ -843,9 +842,9 @@ xenParseSxprChar(const char *value,
             goto error;
         }
 
-        if (offset != value &&
-            VIR_STRNDUP(def->source->data.udp.connectHost, value, offset - value) < 0)
-            goto error;
+        if (offset != value)
+            def->source->data.udp.connectHost = g_strndup(value,
+                                                          offset - value);
 
         offset2 = strchr(offset, '@');
         if (offset2 != NULL) {
@@ -860,10 +859,9 @@ xenParseSxprChar(const char *value,
                 goto error;
             }
 
-            if (offset3 > (offset2 + 1) &&
-                VIR_STRNDUP(def->source->data.udp.bindHost,
-                            offset2 + 1, offset3 - offset2 - 1) < 0)
-                goto error;
+            if (offset3 > (offset2 + 1))
+                def->source->data.udp.bindHost = g_strndup(offset2 + 1,
+                                                           offset3 - offset2 - 1);
 
             def->source->data.udp.bindService = g_strdup(offset3 + 1);
         } else {
diff --git a/tools/vsh.c b/tools/vsh.c
index dd2c039b47..5ccda5ab44 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -348,9 +348,8 @@ vshCmddefCheckInternals(vshControl *ctl,
                          cmd->name);
                 return -1; /* alias options are tracked by the original name */
             }
-            if ((p = strchr(name, '=')) &&
-                VIR_STRNDUP(name, name, p - name) < 0)
-                return -1;
+            if ((p = strchr(name, '=')))
+                name = g_strndup(name, p - name);
             for (j = i + 1; cmd->opts[j].name; j++) {
                 if (STREQ(name, cmd->opts[j].name) &&
                     cmd->opts[j].type != VSH_OT_ALIAS)
-- 
2.21.0




More information about the libvir-list mailing list