[network-manager-openvpn/th/chroot-rh1377708: 4/7] service: fix leak in nm_openvpn_start_openvpn_binary() parsing remote



commit f78aabf78331ec75f37655cc6803aa4303910da8
Author: Thomas Haller <thaller redhat com>
Date:   Tue Sep 20 16:21:01 2016 +0200

    service: fix leak in nm_openvpn_start_openvpn_binary() parsing remote
    
    strsep() moves the string forward. The remaining g_free(tmp_dup) at the
    end of the loop was always called with NULL.
    
    Even worse, we might call g_free() with a pointer inside the malloced
    string, which leads to an invalid free.

 src/nm-openvpn-service.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
---
diff --git a/src/nm-openvpn-service.c b/src/nm-openvpn-service.c
index 23fd230..404f1b5 100644
--- a/src/nm-openvpn-service.c
+++ b/src/nm-openvpn-service.c
@@ -1164,9 +1164,12 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
 
        tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_REMOTE);
        if (tmp && *tmp) {
+               gs_free char *tmp_clone = NULL;
+               char *tmp_remaining;
                char *tok, *port, *proto;
-               char *tmp_dup = strdup (tmp);
-               while ((tok = strsep (&tmp_dup, " \t,")) != NULL) {
+
+               tmp_remaining = tmp_clone = g_strdup (tmp);
+               while ((tok = strsep (&tmp_remaining, " \t,")) != NULL) {
                        if (*tok) {
                                port = strchr (tok, ':');
                                proto = port ? strchr (port + 1, ':') : NULL;
@@ -1183,7 +1186,6 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
                                                             NM_VPN_PLUGIN_ERROR,
                                                             NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
                                                             _("Invalid port number '%s'."), port);
-                                               g_free (tmp_dup);
                                                return FALSE;
                                        }
                                } else if (defport) {
@@ -1208,7 +1210,6 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
                                                             NM_VPN_PLUGIN_ERROR,
                                                             NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
                                                             _("Invalid proto '%s'."), proto);
-                                               g_free (tmp_dup);
                                                return FALSE;
                                        }
                                } else if (proto_tcp && !strcmp (proto_tcp, "yes"))
@@ -1217,7 +1218,6 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
                                        add_openvpn_arg (args, "udp");
                        }
                }
-               g_free (tmp_dup);
        }
 
        /* Remote random */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]