[gvfs/gnome-3-20] sftp: Prevent potential crash in case of parsing error
- From: Ondrej Holy <oholy src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gvfs/gnome-3-20] sftp: Prevent potential crash in case of parsing error
- Date: Tue, 28 Mar 2017 13:48:28 +0000 (UTC)
commit 0cab53c82dca94e39e2ef565f67681231ad6af78
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 78dce92..1be12e1 100644
--- a/daemon/gvfsbackendsftp.c
+++ b/daemon/gvfsbackendsftp.c
@@ -856,7 +856,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 '...'
@@ -871,13 +871,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++;
@@ -885,10 +885,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]