From e7b0e71d92bea36064a927f9c9a3af07fbd26f17 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Tue, 18 Mar 2014 15:41:28 -0600 Subject: [PATCH] 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 --- src/vmware/vmware_conf.c | 8 ++++---- src/vmware/vmware_conf.h | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index c96bd624f4..c339186ba8 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -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); diff --git a/src/vmware/vmware_conf.h b/src/vmware/vmware_conf.h index b9fca6cc5e..c99610d4ca 100644 --- a/src/vmware/vmware_conf.h +++ b/src/vmware/vmware_conf.h @@ -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); -- GitLab