]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Ignore preceding and trailing double quotes from log file path.
authorVMware, Inc <>
Wed, 26 Dec 2012 21:22:47 +0000 (13:22 -0800)
committerDmitry Torokhov <dtor@vmware.com>
Thu, 27 Dec 2012 19:46:59 +0000 (11:46 -0800)
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 <dtor@vmware.com>
open-vm-tools/libvmtools/vmtoolsLog.c

index d52700ad19a247fbf706d964e227acb6a40c6684..ca15a1d4b9b499c6fc0a103f4b1deed34e238f0a 100644 (file)
@@ -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);