[gvfs] sftp: Prevent potential crash in case of parsing error



commit 062d4167c856848fc8410be248efa8b5d59910ad
Author: Ondrej Holy <oholy redhat com>
Date:   Fri Mar 17 14:22:07 2017 +0100

    sftp: Prevent potential crash in case of parsing error
    
    Free may be called on statically allocated memory in case of parsing
    error. Let's do not touch the output parameter at all in case of failure.
    
    This issue was revealed by coverity scan.

 daemon/gvfsbackendsftp.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)
---
diff --git a/daemon/gvfsbackendsftp.c b/daemon/gvfsbackendsftp.c
index 7e6bf15..353f092 100644
--- a/daemon/gvfsbackendsftp.c
+++ b/daemon/gvfsbackendsftp.c
@@ -878,7 +878,7 @@ get_hostname_and_ip_address (const gchar *buffer,
                              gchar      **hostname_out,
                              gchar      **ip_address_out)
 {
-  char *startpos, *endpos;
+  char *startpos, *endpos, *hostname;
 
   /* Parse a line that looks like:
    * Warning: the ECDSA/RSA host key for 'hostname' differs from the key for the IP address '...'
@@ -893,13 +893,13 @@ get_hostname_and_ip_address (const gchar *buffer,
   if (!endpos)
     return FALSE;
 
-  *hostname_out = g_strndup (startpos, endpos - startpos);
+  hostname = g_strndup (startpos, endpos - startpos);
 
   /* Then get the ip address. */
   startpos = strchr (endpos + 1, '\'');
   if (!startpos)
     {
-      g_free (hostname_out);
+      g_free (hostname);
       return FALSE;
     }
   startpos++;
@@ -907,10 +907,11 @@ get_hostname_and_ip_address (const gchar *buffer,
   endpos = strchr (startpos, '\'');
   if (!endpos)
     {
-      g_free (hostname_out);
+      g_free (hostname);
       return FALSE;
     }
 
+  *hostname_out = hostname;
   *ip_address_out = g_strndup (startpos, endpos - startpos);
 
   return TRUE;


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