[gvfs/gnome-3-22] 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-22] sftp: Prevent potential crash in case of parsing error
- Date: Tue, 28 Mar 2017 13:42:56 +0000 (UTC)
commit 284b997da3cf7b948e870aeb2626597c41152e13
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 378e36b..86e5984 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]