[PATCH 1/2] Fix memory leak introduced in 5b96fecb97c752e08fdcebb331b983196f4b8935



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.
---
 src/nm-openvpn-service.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/nm-openvpn-service.c b/src/nm-openvpn-service.c
index 8451067..45e71c0 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.
-- 
2.1.4



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