From: David Woodhouse Date: Tue, 15 Aug 2017 16:35:16 +0000 (+0100) Subject: Fix gpst parse_portal_xmk() some more X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=75827eeedcdf352833979f9e40479f2a3c3ea296;p=users%2Fdwmw2%2Fopenconnect.git Fix gpst parse_portal_xmk() some more If both 'portal-name' and 'gateways' nodes exist, but the 'gateways' node comes first, we'd never handle the 'portal-name'. It might never happen in practice... but that's no excuse :) Signed-off-by: David Woodhouse --- diff --git a/auth-globalprotect.c b/auth-globalprotect.c index 2618f3e1..32410592 100644 --- a/auth-globalprotect.c +++ b/auth-globalprotect.c @@ -170,7 +170,7 @@ err_out: static int parse_portal_xml(struct openconnect_info *vpninfo, xmlNode *xml_node) { struct oc_auth_form form; - xmlNode *x; + xmlNode *x = NULL; struct oc_form_opt_select *opt; struct oc_text_buf *buf = NULL; int max_choices = 0, result; @@ -192,16 +192,22 @@ static int parse_portal_xml(struct openconnect_info *vpninfo, xmlNode *xml_node) * that wishes to give control to the client user, as opposed to the VPN administrator. * The exception is the list of gateways in policy/gateways/external/list */ - if (xmlnode_is_named(xml_node, "policy")) - for (xml_node = xml_node->children; xml_node; xml_node=xml_node->next) - if (xmlnode_is_named(xml_node, "portal-name")) + if (xmlnode_is_named(xml_node, "policy")) { + for (x = xml_node->children, xml_node = NULL; x; x = x->next) { + if (xmlnode_is_named(x, "portal-name")) portal = (char *)xmlNodeGetContent(xml_node); - else if (xmlnode_is_named(xml_node, "gateways")) - for (xml_node = xml_node->children; xml_node; xml_node=xml_node->next) - if (xmlnode_is_named(xml_node, "external")) - for (xml_node = xml_node->children; xml_node; xml_node=xml_node->next) - if (xmlnode_is_named(xml_node, "list")) - goto gateways; + else if (xmlnode_is_named(x, "gateways")) + xml_node = x; + } + } + + if (xml_node) { + for (xml_node = xml_node->children; xml_node; xml_node = xml_node->next) + if (xmlnode_is_named(xml_node, "external")) + for (xml_node = xml_node->children; xml_node; xml_node = xml_node->next) + if (xmlnode_is_named(xml_node, "list")) + goto gateways; + } result = -EINVAL; free_opt(form.opts); free(portal); @@ -288,7 +294,7 @@ static int gpst_login(struct openconnect_info *vpninfo, int portal) struct oc_auth_form *form = NULL; struct oc_text_buf *request_body = buf_alloc(); const char *request_body_type = "application/x-www-form-urlencoded"; - char *xml_buf=NULL, *orig_path; + char *xml_buf = NULL, *orig_path; char *prompt = NULL, *auth_id = NULL; #ifdef HAVE_LIBSTOKEN @@ -398,7 +404,7 @@ int gpst_bye(struct openconnect_info *vpninfo, const char *reason) struct oc_text_buf *request_body = buf_alloc(); const char *request_body_type = "application/x-www-form-urlencoded"; const char *method = "POST"; - char *xml_buf=NULL; + char *xml_buf = NULL; /* In order to logout successfully, the client must send not only * the session's authcookie, but also the portal, user, computer,