From: VMware, Inc <> Date: Wed, 26 Dec 2012 21:22:47 +0000 (-0800) Subject: Ignore preceding and trailing double quotes from log file path. X-Git-Tag: 2012.12.26-958366~17 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=31fa1a3fc1db7d6db2373da3dc84e516a873f26d;p=thirdparty%2Fopen-vm-tools.git Ignore preceding and trailing double quotes from log file path. A log file path could be specified within double quotes. As double quotes are handled in different ways by different file systems, we ignore all the preceding and trailing double quotes to simplify the specification for the log file path value. Signed-off-by: Dmitry Torokhov --- diff --git a/open-vm-tools/libvmtools/vmtoolsLog.c b/open-vm-tools/libvmtools/vmtoolsLog.c index d52700ad1..ca15a1d4b 100644 --- a/open-vm-tools/libvmtools/vmtoolsLog.c +++ b/open-vm-tools/libvmtools/vmtoolsLog.c @@ -321,6 +321,78 @@ VMToolsLog(const gchar *domain, } +/* + ******************************************************************************* + * VMToolsGetLogFilePath -- */ /** + * + * @brief Fetches sanitized path for the log file. + * + * @param[in] key The key for log file path. + * @param[in] domain Domain name. + * @param[in] cfg Config dictionary. + * + * @return Sanitized path for the log file. + * + ******************************************************************************* + */ + +static gchar * +VMToolsGetLogFilePath(const gchar *key, + const gchar *domain, + GKeyFile *cfg) +{ + gsize len = 0; + gchar *path = NULL; + gchar *origPath = NULL; + + path = g_key_file_get_string(cfg, LOGGING_GROUP, key, NULL); + if (path == NULL) { + return NULL; + } + + len = strlen(path); + origPath = path; + + /* + * Drop all the preceding '"' chars + */ + while (*path == '"') { + path++; + len--; + } + + /* + * Ensure that path contains something more + * meaningful than just '"' chars + */ + if (len == 0) { + g_warning("Invalid path for domain '%s'.", domain); + g_free(origPath); + path = NULL; + } else { + /* Drop the trailing '"' chars */ + gchar *sanePath = g_strdup(path); + g_free(origPath); + path = sanePath; + + if (path != NULL) { + while (*(path + len - 1) == '"') { + *(path + len - 1) = '\0'; + len--; + } + + if (len == 0) { + g_warning("Invalid path for domain '%s'.", domain); + g_free(origPath); + path = NULL; + } + } + } + + return path; +} + + /* ******************************************************************************* * VMToolsGetLogHandler -- */ /** @@ -358,7 +430,7 @@ VMToolsGetLogHandler(const gchar *handler, handler = "file"; g_snprintf(key, sizeof key, "%s.data", domain); - path = g_key_file_get_string(cfg, LOGGING_GROUP, key, NULL); + path = VMToolsGetLogFilePath(key, domain, cfg); if (path != NULL) { g_snprintf(key, sizeof key, "%s.maxLogSize", domain); maxSize = (guint) g_key_file_get_integer(cfg, LOGGING_GROUP, key, &err);