diff options
author | Richard van der Hoff <richard@matrix.org> | 2015-10-30 11:41:13 +0000 |
---|---|---|
committer | Richard van der Hoff <richard@matrix.org> | 2015-10-30 11:41:13 +0000 |
commit | 5e45a7d963b848ff9603575948f03927e5ed0b3a (patch) | |
tree | 90799f23c5eca38e05f82c1d981484f935817ac9 | |
parent | ed0c5f6b5ad82df7047296adb081e19102ec4a35 (diff) | |
download | purple-matrix-5e45a7d963b848ff9603575948f03927e5ed0b3a.tar.gz |
Fix segfault on homeserver connection drop
If the connection dropped in the middle of us receiving a sync response, we
tried to set the next_batch setting on the account to an invalid string
(because we failed to initialise the pointer). Fix the segfault that caused,
and clean up some of the other error handling in the area at the same time.
-rw-r--r-- | matrix-connection.c | 12 | ||||
-rw-r--r-- | matrix-sync.c | 5 |
2 files changed, 13 insertions, 4 deletions
diff --git a/matrix-connection.c b/matrix-connection.c index 925fef6..b77942a 100644 --- a/matrix-connection.c +++ b/matrix-connection.c @@ -109,6 +109,14 @@ static void _sync_complete(MatrixConnectionData *ma, gpointer user_data, PurpleConnection *pc = ma->pc; const gchar *next_batch; + ma->active_sync = NULL; + + if(body == NULL) { + purple_connection_error_reason(pc, PURPLE_CONNECTION_ERROR_OTHER_ERROR, + "Couldn't parse sync response"); + return; + } + purple_connection_update_progress(pc, _("Connected"), 2, 3); purple_connection_set_state(pc, PURPLE_CONNECTED); @@ -116,8 +124,8 @@ static void _sync_complete(MatrixConnectionData *ma, gpointer user_data, /* Start the next sync */ if(next_batch == NULL) { - purple_connection_error_reason(pc, - PURPLE_CONNECTION_ERROR_OTHER_ERROR, "No next_batch field"); + purple_connection_error_reason(pc, PURPLE_CONNECTION_ERROR_OTHER_ERROR, + "No next_batch field"); return; } purple_account_set_string(pc->account, PRPL_ACCOUNT_OPT_NEXT_BATCH, diff --git a/matrix-sync.c b/matrix-sync.c index 2f3b887..9190656 100644 --- a/matrix-sync.c +++ b/matrix-sync.c @@ -177,6 +177,8 @@ void matrix_sync_parse(PurpleConnection *pc, JsonNode *body, rooms = matrix_json_object_get_object_member(rootObj, "rooms"); joined_rooms = matrix_json_object_get_object_member(rooms, "joined"); + *next_batch = matrix_json_object_get_string_member(rootObj, "next_batch"); + if(joined_rooms == NULL) { purple_debug_warning("matrixprpl", "didn't find joined rooms list\n"); return; @@ -187,10 +189,9 @@ void matrix_sync_parse(PurpleConnection *pc, JsonNode *body, const gchar *room_id = elem->data; JsonObject *room_data = matrix_json_object_get_object_member( joined_rooms, room_id); + purple_debug_info("matrixprpl", "Syncing room %s", room_id); matrix_sync_room(room_id, room_data, pc); } g_list_free(room_ids); - - *next_batch = matrix_json_object_get_string_member(rootObj, "next_batch"); } |