]> www.infradead.org Git - users/dwmw2/openconnect.git/commitdiff
gpst: Clean up some 'const char *' that shouldn't be const
authorDavid Woodhouse <dwmw2@infradead.org>
Tue, 15 Aug 2017 11:30:40 +0000 (12:30 +0100)
committerDavid Woodhouse <dwmw2@infradead.org>
Tue, 27 Feb 2018 15:27:03 +0000 (16:27 +0100)
... and the associated forced casts to non-const on free()

Although actually... given that we aren't doing the string expansion
thing, perhaps the 'var' returned by xmlnode_get_text() *could* be
const in this case, and just return node->content. Most callers do
seem to have to free it instead of really keeping it, and the few
that want to keep it can use strdup(). Dan?

Signed-off-by: David Woodhouse <dwmw2@infradead.org>
gpst.c

diff --git a/gpst.c b/gpst.c
index eddb6c750f06c74e44ee3f38a343ffa65d0535c0..cd5c74dc74cf9b223bae65210b71e9394a1d963b 100644 (file)
--- a/gpst.c
+++ b/gpst.c
@@ -58,15 +58,17 @@ static const struct pkt dpd_pkt = {
        { .gpst.hdr = { 0x1a, 0x2b, 0x3c, 0x4d } }
 };
 
-/* similar to auth.c's xmlnode_get_text, except that *var should be freed by the caller */
-static int xmlnode_get_text(xmlNode *xml_node, const char *name, const char **var)
+/* similar to auth.c's xmlnode_get_text, including that *var should be freed by the caller,
+   but without the hackish param / %s handling that Cisco needs. And without freeing up
+   the old contents of *var, which is likely to lead to bugs? */
+static int xmlnode_get_text(xmlNode *xml_node, const char *name, char **var)
 {
-       const char *str;
+       char *str;
 
        if (name && !xmlnode_is_named(xml_node, name))
                return -EINVAL;
 
-       str = (const char *)xmlNodeGetContent(xml_node);
+       str = (char *)xmlNodeGetContent(xml_node);
        if (!str)
                return -ENOENT;
 
@@ -164,9 +166,9 @@ static int parse_javascript(char *buf, char **prompt, char **inputStr)
        return status;
 
 err3:
-       if (inputStr) free((void *)*inputStr);
+       if (inputStr) free(*inputStr);
 err2:
-       if (prompt) free((void *)*prompt);
+       if (prompt) free(*prompt);
 err:
        return -EINVAL;
 }
@@ -177,7 +179,7 @@ int gpst_xml_or_error(struct openconnect_info *vpninfo, int result, char *respon
 {
        xmlDocPtr xml_doc;
        xmlNode *xml_node;
-       const char *err = NULL;
+       char *err = NULL;
 
        /* custom error codes returned by /ssl-vpn/login.esp and maybe others */
        if (result == -EACCES)
@@ -257,7 +259,7 @@ out:
                        vpn_progress(vpninfo, PRG_ERR, "%s\n", err);
                        result = -EINVAL;
                }
-               free((void *)err);
+               free(err);
        }
        if (xml_doc)
                xmlFreeDoc(xml_doc);
@@ -348,16 +350,16 @@ static int get_key_bits(xmlNode *xml_node, unsigned char *dest)
 {
        int bits = -1;
        xmlNode *child;
-       const char *s, *p;
+       char *s, *p;
 
        for (child = xml_node->children; child; child=child->next) {
                if (xmlnode_get_text(child, "bits", &s) == 0) {
                        bits = atoi(s);
-                       free((void *)s);
+                       free(s);
                } else if (xmlnode_get_text(child, "val", &s) == 0) {
                        for (p=s; *p && *(p+1) && (bits-=8)>=0; p+=2)
                                *dest++ = unhex(p);
-                       free((void *)s);
+                       free(s);
                }
        }
        return (bits == 0) ? 0 : -EINVAL;
@@ -370,7 +372,7 @@ static int get_key_bits(xmlNode *xml_node, unsigned char *dest)
 static int gpst_parse_config_xml(struct openconnect_info *vpninfo, xmlNode *xml_node)
 {
        xmlNode *member;
-       const char *s;
+       char *s;
        int ii;
 
        if (!xml_node || !xmlnode_is_named(xml_node, "response"))
@@ -396,7 +398,7 @@ static int gpst_parse_config_xml(struct openconnect_info *vpninfo, xmlNode *xml_
                        vpninfo->ip_info.netmask = add_option(vpninfo, "netmask", s);
                else if (!xmlnode_get_text(xml_node, "mtu", &s)) {
                        vpninfo->ip_info.mtu = atoi(s);
-                       free((void *)s);
+                       free(s);
                } else if (!xmlnode_get_text(xml_node, "gw-address", &s)) {
                        /* As remarked in oncp.c, "this is a tunnel; having a
                         * gateway is meaningless." See esp_send_probes_gp for the
@@ -406,7 +408,7 @@ static int gpst_parse_config_xml(struct openconnect_info *vpninfo, xmlNode *xml_
                                vpn_progress(vpninfo, PRG_DEBUG,
                                                         _("Gateway address in config XML (%s) differs from external gateway address (%s).\n"), s, vpninfo->ip_info.gateway_addr);
                        vpninfo->esp_magic = inet_addr(s);
-                       free((void *)s);
+                       free(s);
                } else if (xmlnode_is_named(xml_node, "dns")) {
                        for (ii=0, member = xml_node->children; member && ii<3; member=member->next)
                                if (!xmlnode_get_text(member, "member", &s))
@@ -449,7 +451,7 @@ static int gpst_parse_config_xml(struct openconnect_info *vpninfo, xmlNode *xml_
                                        else if (xmlnode_is_named(member, "akey-s2c"))          get_key_bits(member, vpninfo->esp_in[c].hmac_key);
                                        else if (!xmlnode_get_text(member, "ipsec-mode", &s) && strcmp(s, "esp-tunnel"))
                                                vpn_progress(vpninfo, PRG_ERR, _("GlobalProtect config sent ipsec-mode=%s (expected esp-tunnel)\n"), s);
-                                       free((void *)s);
+                                       free(s);
                                }
                                if (setup_esp_keys(vpninfo, 0))
                                        vpn_progress(vpninfo, PRG_ERR, "Failed to setup ESP keys.\n");