Signed-off-by: Daniel Lenski <dlenski at gmail.com> --- auth-globalprotect.c | 8 +++----- http.c | 13 +++++++++++++ openconnect-internal.h | 1 + 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/auth-globalprotect.c b/auth-globalprotect.c index 8e27cfb..2a68386 100644 --- a/auth-globalprotect.c +++ b/auth-globalprotect.c @@ -235,11 +235,9 @@ gateways: buf = buf_alloc(); buf_append(buf, "<GPPortal>\n <ServerList>\n"); if (portal) { - /* XXX: What if the name in 'portal' has characters which need to be - * escaped in XML? Either build up a tree using libxml "properly" - * so it does it for us, or at the very least we need a - * buf_append_xmlescaped(), don't we? */ - buf_append(buf, " <HostEntry><HostName>%s</HostName><HostAddress>%s", portal, vpninfo->hostname); + buf_append(buf, " <HostEntry><HostName>"); + buf_append_xmlescaped(buf, portal); + buf_append(buf, "</HostName><HostAddress>%s", vpninfo->hostname); if (vpninfo->port!=443) buf_append(buf, ":%d", vpninfo->port); buf_append(buf, "/global-protect</HostAddress></HostEntry>\n"); diff --git a/http.c b/http.c index 5307d82..a860ae4 100644 --- a/http.c +++ b/http.c @@ -54,6 +54,19 @@ void buf_append_urlencoded(struct oc_text_buf *buf, const char *str) } } +void buf_append_xmlescaped(struct oc_text_buf *buf, const char *str) +{ + while (str && *str) { + unsigned char c = *str; + if (c=='<' || c=='>' || c=='&' || c=='"' || c=='\'') + buf_append(buf, "&#x%02x;", c); + else + buf_append_bytes(buf, str, 1); + + str++; + } +} + void buf_append_hex(struct oc_text_buf *buf, const void *str, unsigned len) { const unsigned char *data = str; diff --git a/openconnect-internal.h b/openconnect-internal.h index 3bb6a77..8f77f22 100644 --- a/openconnect-internal.h +++ b/openconnect-internal.h @@ -1038,6 +1038,7 @@ int get_utf8char(const char **utf8); void buf_append_from_utf16le(struct oc_text_buf *buf, const void *utf16); void buf_truncate(struct oc_text_buf *buf); void buf_append_urlencoded(struct oc_text_buf *buf, const char *str); +void buf_append_xmlescaped(struct oc_text_buf *buf, const char *str); int buf_error(struct oc_text_buf *buf); int buf_free(struct oc_text_buf *buf); char *openconnect_create_useragent(const char *base); -- 2.7.4