]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
esx_util: Introduce esxUtil_EscapeInventoryObject()
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 7 Jan 2026 09:34:25 +0000 (10:34 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 8 Jan 2026 14:16:42 +0000 (15:16 +0100)
The aim of this helper function is to URI-encode given string
twice. There's a bug (fixed in next commit) in which we're unable
to fetch .vmx file for a domain if corresponding datastore
contains some special characters (like +). Cole Robinson
discovered that encoding datastore twice enables libvirt to work
around the issue [2]. Well, this function does exactly that.
It was tested with the following inputs and all worked
flawlessly: "datastore", "datastore2", "datastore2+",
"datastore3+-@", "data store2+".

1: https://issues.redhat.com/browse/RHEL-134127
2: https://issues.redhat.com/browse/RHEL-133729#comment-28604072

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
src/esx/esx_util.c
src/esx/esx_util.h

index 7ee0e5f7c0ad44e55c2801707c034aaccebd2d17..9b714d90ba80e9650cc46c666939a1e802269d59 100644 (file)
@@ -448,3 +448,21 @@ esxUtil_EscapeForXml(const char *string)
 
     return virBufferContentAndReset(&buffer);
 }
+
+
+/* esxUtil_EscapeInventoryObject:
+ * @buf: the buffer to append to
+ * @string: the string argument which will be URI-encoded
+ *
+ * URI-encode given @string TWICE and append the result to the @buf. This is
+ * to be used with inventory objects (like 'dcPath' and 'dsName') to work
+ * around a VMware bug in which once round of URI-encoding is not enough.
+ */
+void
+esxUtil_EscapeInventoryObject(virBuffer *buf, const char *string)
+{
+    g_autoptr(GString) escaped = g_string_new(NULL);
+
+    g_string_append_uri_escaped(escaped, string, NULL, false);
+    virBufferURIEncodeString(buf, escaped->str);
+}
index 58bc44e74453582e01ec98449e9bb78cf560edac..29f01e0c1559688c909bc4bd4f3ebe31e4ac5fa0 100644 (file)
@@ -22,6 +22,7 @@
 #pragma once
 
 #include "internal.h"
+#include "virbuffer.h"
 #include "viruri.h"
 
 #define ESX_VI_CHECK_ARG_LIST(val) \
@@ -67,3 +68,5 @@ void esxUtil_ReplaceSpecialWindowsPathChars(char *string);
 char *esxUtil_EscapeDatastoreItem(const char *string);
 
 char *esxUtil_EscapeForXml(const char *string);
+
+void esxUtil_EscapeInventoryObject(virBuffer *buf, const char *string);