]> xenbits.xensource.com Git - libvirt.git/commitdiff
Remove use of strncpy in qemudExtractMonitorPath.
authorChris Lalancette <clalance@redhat.com>
Mon, 3 Aug 2009 15:07:19 +0000 (17:07 +0200)
committerChris Lalancette <clalance@redhat.com>
Mon, 31 Aug 2009 19:01:36 +0000 (21:01 +0200)
qemudExtractMonitorPath() was doing a VIR_ALLOC_N followed by a
strncpy.  However, this isn't necessary; we can do the same thing
using strndup, which is much safer.

Signed-off-by: Chris Lalancette <clalance@redhat.com>
src/qemu_driver.c

index eb22940ad9973cd3e73fcf42c31714589bcc4a6e..f51430761aaa272ff7406b4cec8deb5a0581fd15 100644 (file)
@@ -1029,12 +1029,12 @@ qemudExtractMonitorPath(virConnectPtr conn,
      */
     while (*tmp) {
         if (c_isspace(*tmp)) {
-            if (VIR_ALLOC_N(*path, (tmp-dev)+1) < 0) {
+            *path = strndup(dev, tmp-dev);
+            if (*path == NULL) {
                 virReportOOMError(conn);
                 return -1;
             }
-            strncpy(*path, dev, (tmp-dev));
-            (*path)[(tmp-dev)] = '\0';
+
             /* ... now further update offset till we get EOL */
             *offset = tmp - haystack;
             return 0;