1
0

vmware: fix parse of disk source

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>
This commit is contained in:
Eric Blake 2014-03-18 15:41:28 -06:00
parent 0d93526fdd
commit e7b0e71d92
2 changed files with 7 additions and 7 deletions

View File

@ -331,15 +331,15 @@ vmwareDomainConfigDisplay(vmwareDomainPtr pDomain, virDomainDefPtr def)
} }
} }
int static int
vmwareParsePath(char *path, char **directory, char **filename) vmwareParsePath(const char *path, char **directory, char **filename)
{ {
char *separator; char *separator;
separator = strrchr(path, '/'); separator = strrchr(path, '/');
if (separator != NULL) { if (separator != NULL) {
*separator++ = '\0'; separator++;
if (*separator == '\0') { if (*separator == '\0') {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
@ -347,7 +347,7 @@ vmwareParsePath(char *path, char **directory, char **filename)
return -1; return -1;
} }
if (VIR_STRDUP(*directory, path) < 0) if (VIR_STRNDUP(*directory, path, separator - path - 1) < 0)
goto error; goto error;
if (VIR_STRDUP(*filename, separator) < 0) { if (VIR_STRDUP(*filename, separator) < 0) {
VIR_FREE(*directory); VIR_FREE(*directory);

View 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) * Copyright (c) 2013, Doug Goldstein (cardoe@cardoe.com)
* *
* This library is free software; you can redistribute it and/or * 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 vmwareDomainConfigDisplay(vmwareDomainPtr domain, virDomainDefPtr vmdef);
int vmwareParsePath(char *path, char **directory, char **filename);
int vmwareConstructVmxPath(char *directoryName, char *name, int vmwareConstructVmxPath(char *directoryName, char *name,
char **vmxPath); char **vmxPath);