提交 e7b0e71d 编写于 作者: E Eric Blake

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: NEric Blake <eblake@redhat.com>
上级 0d93526f
...@@ -331,15 +331,15 @@ vmwareDomainConfigDisplay(vmwareDomainPtr pDomain, virDomainDefPtr def) ...@@ -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) ...@@ -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);
......
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* 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); ...@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册