summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOndrej Holy <oholy@redhat.com>2017-03-17 14:22:07 +0100
committerOndrej Holy <oholy@redhat.com>2017-03-23 11:24:17 +0100
commit062d4167c856848fc8410be248efa8b5d59910ad (patch)
treea63fafce29dac82d4bcefbc3c5f929c0b6426f50
parent67faa3b09f7768e271a3037268e3f8cb1137f447 (diff)
downloadgvfs-062d4167c856848fc8410be248efa8b5d59910ad.tar.gz
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.
-rw-r--r--daemon/gvfsbackendsftp.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/daemon/gvfsbackendsftp.c b/daemon/gvfsbackendsftp.c
index 7e6bf155..353f092e 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;