Fix URL-escaping for domainDefine
'+' 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@univention.de>
This commit is contained in:
parent
498d783387
commit
b14e7d2a16
@ -487,7 +487,9 @@ xend_op_ext(virConnectPtr xend, const char *path, const char *key, va_list ap)
|
|||||||
while (k) {
|
while (k) {
|
||||||
v = va_arg(ap, const char *);
|
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 *);
|
k = va_arg(ap, const char *);
|
||||||
|
|
||||||
if (k)
|
if (k)
|
||||||
@ -599,47 +601,6 @@ sexpr_uuid(unsigned char *ptr, const struct sexpr *node, const char *path)
|
|||||||
return virUUIDParse(r, ptr);
|
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 */
|
/* PUBLIC FUNCTIONS */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -862,22 +823,9 @@ xenDaemonListDomainsOld(virConnectPtr xend)
|
|||||||
int
|
int
|
||||||
xenDaemonDomainCreateXML(virConnectPtr xend, const char *sexpr)
|
xenDaemonDomainCreateXML(virConnectPtr xend, const char *sexpr)
|
||||||
{
|
{
|
||||||
int ret, serrno;
|
int ret;
|
||||||
char *ptr;
|
|
||||||
|
|
||||||
ptr = urlencode(sexpr);
|
ret = xend_op(xend, "", "op", "create", "config", sexpr, NULL);
|
||||||
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);
|
|
||||||
|
|
||||||
serrno = errno;
|
|
||||||
VIR_FREE(ptr);
|
|
||||||
errno = serrno;
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user