'+' in strings get translated to ' ' when editing domains. While xenDaemonDomainCreateXML() did URL-escape the sexpr, xenDaemonDomainDefineXML() did not. Remove the explicit urlencode() in xenDaemonDomainCreateXML() and add the direct encoding calls to xend_op_ext() because it calls xend_post() which uses "Content-Type: application/x-www-form-urlencoded". According to <http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1> this requires all parameters to be url-encoded as specified in rfc1738. Notice: virBufferAsprintf(..., "%s=%s", ...) is again replaced by three calls to virBufferURIEncodeString() and virBufferAddChar() because '=' is a "reserved" character, which would get escaped by virBufferURIEncodeString(), which - by the way - escapes anything not c_isalnum(). Signed-off-by: Philipp Hahn <hahn@xxxxxxxxxxxxx> --- src/xen/xend_internal.c | 62 ++++------------------------------------------- 1 files changed, 5 insertions(+), 57 deletions(-)
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c index 8e21701..81ff325 100644 --- a/src/xen/xend_internal.c +++ b/src/xen/xend_internal.c @@ -487,7 +487,9 @@ xend_op_ext(virConnectPtr xend, const char *path, const char *key, va_list ap) while (k) { v = va_arg(ap, const char *); - virBufferAsprintf(&buf, "%s=%s", k, v); + virBufferURIEncodeString(&buf, k); + virBufferAddChar(&buf, '='); + virBufferURIEncodeString(&buf, v); k = va_arg(ap, const char *); if (k) @@ -599,47 +601,6 @@ sexpr_uuid(unsigned char *ptr, const struct sexpr *node, const char *path) return virUUIDParse(r, ptr); } - -/** - * urlencode: - * @string: the input URL - * - * Encode an URL see RFC 2396 and following - * - * Returns the new string or NULL in case of error. - */ -static char * -urlencode(const char *string) -{ - size_t len = strlen(string); - char *buffer; - char *ptr; - size_t i; - - if (VIR_ALLOC_N(buffer, len * 3 + 1) < 0) { - virReportOOMError(); - return (NULL); - } - ptr = buffer; - for (i = 0; i < len; i++) { - switch (string[i]) { - case ' ': - case '\n': - case '&': - snprintf(ptr, 4, "%%%02x", string[i]); - ptr += 3; - break; - default: - *ptr = string[i]; - ptr++; - } - } - - *ptr = 0; - - return buffer; -} - /* PUBLIC FUNCTIONS */ /** @@ -862,22 +823,9 @@ xenDaemonListDomainsOld(virConnectPtr xend) int xenDaemonDomainCreateXML(virConnectPtr xend, const char *sexpr) { - int ret, serrno; - char *ptr; - - ptr = urlencode(sexpr); - if (ptr == NULL) { - /* this should be caught at the interface but ... */ - virXendError(VIR_ERR_INTERNAL_ERROR, - "%s", _("failed to urlencode the create S-Expr")); - return (-1); - } - - ret = xend_op(xend, "", "op", "create", "config", ptr, NULL); + int ret; - serrno = errno; - VIR_FREE(ptr); - errno = serrno; + ret = xend_op(xend, "", "op", "create", "config", sexpr, NULL); return ret; }
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list