[network-manager-openvpn] service: fix memory leak introduced in parse_challenge()



commit 90db738220f69fcc01902759e97c9bb4ea8dd20a
Author: Timo Juhani Lindfors <timo lindfors iki fi>
Date:   Wed Apr 5 12:48:27 2017 +0300

    service: fix memory leak introduced in parse_challenge()
    
    Make sure that failure_reason is free'd by refactoring the code so
    that the parent function handles allocation and parse_challenge only
    parses the challenge, not the whole error message.
    
    https://mail.gnome.org/archives/networkmanager-list/2017-April/msg00007.html
    
    [thaller redhat com: fix whitespace and idiomatic commit message subject]
    
    Fixes: 5b96fecb97c752e08fdcebb331b983196f4b8935

 src/nm-openvpn-service.c |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)
---
diff --git a/src/nm-openvpn-service.c b/src/nm-openvpn-service.c
index 8451067..862248f 100644
--- a/src/nm-openvpn-service.c
+++ b/src/nm-openvpn-service.c
@@ -644,15 +644,14 @@ get_detail (const char *input, const char *prefix)
 }
 
 /* Parse challenge response protocol message of the form
- * >PASSWORD:Verification Failed: 'Auth' ['CRV1:flags:state_id:username:text']
+ * CRV1:flags:state_id:username:text
  */
 static gboolean
-parse_challenge (const char *input, char **challenge_state_id, char **challenge_text)
+parse_challenge (const char *failure_reason, char **challenge_state_id, char **challenge_text)
 {
-       char *failure_reason, *colon[4];
+       char *colon[4];
        int challenge_len;
 
-       failure_reason = get_detail (input, ">PASSWORD:Verification Failed: 'Auth' ['");
        if (!(failure_reason && !strncmp (failure_reason, "CRV1:", 4)))
                return FALSE;
 
@@ -875,13 +874,17 @@ handle_management_socket (NMOpenvpnPlugin *plugin,
                gboolean fail = TRUE;
 
                if (!strcmp (auth, "Auth")) {
-                       if (parse_challenge (str, &priv->io_data->challenge_state_id, 
&priv->io_data->challenge_text)) {
+                       char *failure_reason = get_detail (auth, ">PASSWORD:Verification Failed: 'Auth' ['");
+
+                       if (parse_challenge (failure_reason, &priv->io_data->challenge_state_id, 
&priv->io_data->challenge_text)) {
                                _LOGD ("Received challenge '%s' for state '%s'",
                                       priv->io_data->challenge_state_id,
                                       priv->io_data->challenge_text);
                        } else {
                                _LOGW ("Password verification failed");
                        }
+                       g_free(failure_reason);
+
                        if (priv->interactive) {
                                /* Clear existing password in interactive mode, openvpn
                                 * will request a new one after restarting.


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