From 69fcfd7577dec1244a7a5888184290bd3696b773 Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Wed, 29 Aug 2012 21:44:00 +0300 Subject: [PATCH] telepathy: improve error handling for _finish() calls In corner cases _finish() uses g_return_val_if_fail() before initializing the GError. So we should always check the return code for failure and then only use the GError contents if it is valid. --- src/telepathy/telepathy-connection.c | 6 +++--- src/telepathy/telepathy-transport.c | 22 +++++++++++++--------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/telepathy/telepathy-connection.c b/src/telepathy/telepathy-connection.c index 97f286c9..0d475d6c 100644 --- a/src/telepathy/telepathy-connection.c +++ b/src/telepathy/telepathy-connection.c @@ -188,13 +188,13 @@ static void password_manager_cb(GObject *source, result, &error); - if (error) { + if (password == NULL) { SIPE_DEBUG_ERROR("password_manager_cb: failed: %s", - error->message); + error ? error->message : "UNKNOWN"); if (base->status != TP_CONNECTION_STATUS_DISCONNECTED) { tp_base_connection_disconnect_with_dbus_error(base, - tp_error_get_dbus_name(error->code), + error ? tp_error_get_dbus_name(error->code) : "", NULL, TP_CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED); } diff --git a/src/telepathy/telepathy-transport.c b/src/telepathy/telepathy-transport.c index 2bc4e9ba..1a91899c 100644 --- a/src/telepathy/telepathy-transport.c +++ b/src/telepathy/telepathy-transport.c @@ -82,9 +82,10 @@ static void read_completed(GObject *stream, &error); if (len < 0) { - SIPE_DEBUG_ERROR("read_completed: error: %s", error->message); + const gchar *msg = error ? error->message : "UNKNOWN"; + SIPE_DEBUG_ERROR("read_completed: error: %s", msg); if (transport->error) - transport->error(conn, error->message); + transport->error(conn, msg); g_error_free(error); return; } else if (len == 0) { @@ -131,9 +132,10 @@ static void socket_connected(GObject *client, &error); if (error) { - SIPE_DEBUG_ERROR("socket_connected: failed: %s", error->message); + const gchar *msg = error ? error->message : "UNKNOWN"; + SIPE_DEBUG_ERROR("socket_connected: failed: %s", msg); if (transport->error) - transport->error(SIPE_TRANSPORT_CONNECTION, error->message); + transport->error(SIPE_TRANSPORT_CONNECTION, msg); g_error_free(error); } else if (g_cancellable_is_cancelled(transport->cancel)) { /* connect already succeeded when transport was disconnected */ @@ -308,13 +310,15 @@ static void write_completed(GObject *stream, { struct sipe_transport_telepathy *transport = data; GError *error = NULL; + gssize written = g_output_stream_write_finish(G_OUTPUT_STREAM(stream), + result, + &error); - g_output_stream_write_finish(G_OUTPUT_STREAM(stream), result, &error); - - if (error) { - SIPE_DEBUG_ERROR("write_completed: error: %s", error->message); + if ((written < 0) || error) { + const gchar *msg = error ? error->message : "UNKNOWN"; + SIPE_DEBUG_ERROR("write_completed: error: %s", msg); if (transport->error) - transport->error(SIPE_TRANSPORT_CONNECTION, error->message); + transport->error(SIPE_TRANSPORT_CONNECTION, msg); g_error_free(error); /* error during flush: give up and close transport */ -- 2.11.4.GIT