]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
vmware: fix parse of disk source
authorEric Blake <eblake@redhat.com>
Tue, 18 Mar 2014 21:41:28 +0000 (15:41 -0600)
committerEric Blake <eblake@redhat.com>
Mon, 24 Mar 2014 17:55:05 +0000 (11:55 -0600)
While writing disk source refactoring, I discovered that conversion
from XML to vmware modified the disk source in place; if the same
code is reached twice, the second call behaves differently because
the first call didn't clean up its mess.

* src/vmware/vmware_conf.c (vmwareParsePath): Avoid munging input
string.
* src/vmware/vmware_conf.h (vmwareParsePath): Make static.

Signed-off-by: Eric Blake <eblake@redhat.com>
src/vmware/vmware_conf.c
src/vmware/vmware_conf.h

index c96bd624f4083db7ec5e1a2570bc14e097bf9382..c339186ba85d81e2d0aad76f05d59cf7c9549dc0 100644 (file)
@@ -331,15 +331,15 @@ vmwareDomainConfigDisplay(vmwareDomainPtr pDomain, virDomainDefPtr def)
     }
 }
 
-int
-vmwareParsePath(char *path, char **directory, char **filename)
+static int
+vmwareParsePath(const char *path, char **directory, char **filename)
 {
     char *separator;
 
     separator = strrchr(path, '/');
 
     if (separator != NULL) {
-        *separator++ = '\0';
+        separator++;
 
         if (*separator == '\0') {
             virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -347,7 +347,7 @@ vmwareParsePath(char *path, char **directory, char **filename)
             return -1;
         }
 
-        if (VIR_STRDUP(*directory, path) < 0)
+        if (VIR_STRNDUP(*directory, path, separator - path - 1) < 0)
             goto error;
         if (VIR_STRDUP(*filename, separator) < 0) {
             VIR_FREE(*directory);
index b9fca6cc5ead56843c6ac325d9b96e3f66de2627..c99610d4caa4228135ed100ef71bdc0ce79ae783 100644 (file)
@@ -1,5 +1,7 @@
 /*---------------------------------------------------------------------------*/
-/* Copyright 2010, diateam (www.diateam.net)
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ * Copyright 2010, diateam (www.diateam.net)
  * Copyright (c) 2013, Doug Goldstein (cardoe@cardoe.com)
  *
  * This library is free software; you can redistribute it and/or
@@ -71,8 +73,6 @@ int vmwareParseVersionStr(int type, const char *buf, unsigned long *version);
 
 int vmwareDomainConfigDisplay(vmwareDomainPtr domain, virDomainDefPtr vmdef);
 
-int vmwareParsePath(char *path, char **directory, char **filename);
-
 int vmwareConstructVmxPath(char *directoryName, char *name,
                            char **vmxPath);