From 86c29650bae2bf251bb46eeae033c55fe8e9f2a1 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Tue, 17 Feb 2004 22:27:47 +0000 Subject: [PATCH] Fixed error handling in resume data processing. --- CHANGES | 5 +++++ lib/silcclient/client.c | 10 +++++++--- lib/silcclient/client_resume.c | 14 +++++++++++--- lib/silcclient/protocol.h | 10 +++++----- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/CHANGES b/CHANGES index a9451e2b..5a820180 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,8 @@ +Wed Feb 18 02:46:17 EET 2004 Pekka Riikonen + + * Fixed error handling in resuming data processing. Affected + files are lib/silcclient/client_resume.c and client.c. + Tue Feb 17 19:34:30 EET 2004 Pekka Riikonen * Fixed silc_client_send_private_message to return TRUE correctly. diff --git a/lib/silcclient/client.c b/lib/silcclient/client.c index ef15e546..27df4062 100644 --- a/lib/silcclient/client.c +++ b/lib/silcclient/client.c @@ -587,8 +587,7 @@ SILC_TASK_CALLBACK(silc_client_connect_failure_auth) (SilcClientConnAuthInternalContext *)context; SilcClient client = (SilcClient)ctx->client; - client->internal->ops->connected(client, ctx->sock->user_data, - SILC_CLIENT_CONN_ERROR_AUTH); + client->internal->ops->connected(client, ctx->sock->user_data, ctx->status); silc_free(ctx); } @@ -789,6 +788,7 @@ SILC_TASK_CALLBACK(silc_client_connect_to_server_final) protocol->state == SILC_PROTOCOL_STATE_FAILURE) { /* Error occured during protocol */ SILC_LOG_DEBUG(("Error during authentication protocol")); + ctx->status = SILC_CLIENT_CONN_ERROR_AUTH; goto err; } @@ -800,12 +800,15 @@ SILC_TASK_CALLBACK(silc_client_connect_to_server_final) unsigned char *old_id; SilcUInt16 old_id_len; - if (!silc_client_process_detach_data(client, conn, &old_id, &old_id_len)) + if (!silc_client_process_detach_data(client, conn, &old_id, &old_id_len)) { + ctx->status = SILC_CLIENT_CONN_ERROR_RESUME; goto err; + } old_client_id = silc_id_str2id(old_id, old_id_len, SILC_ID_CLIENT); if (!old_client_id) { silc_free(old_id); + ctx->status = SILC_CLIENT_CONN_ERROR_RESUME; goto err; } @@ -818,6 +821,7 @@ SILC_TASK_CALLBACK(silc_client_connect_to_server_final) if (!auth) { silc_free(old_client_id); silc_free(old_id); + ctx->status = SILC_CLIENT_CONN_ERROR_RESUME; goto err; } diff --git a/lib/silcclient/client_resume.c b/lib/silcclient/client_resume.c index 54df971f..928c7df9 100644 --- a/lib/silcclient/client_resume.c +++ b/lib/silcclient/client_resume.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 2002, 2003 Pekka Riikonen + Copyright (C) 2002, 2004 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -110,18 +110,21 @@ bool silc_client_process_detach_data(SilcClient client, SilcBufferStruct detach; SilcUInt32 ch_count; int i, len; + char *newnick; SILC_LOG_DEBUG(("Start")); - silc_free(conn->nickname); silc_buffer_set(&detach, conn->internal->params.detach_data, conn->internal->params.detach_data_len); SILC_LOG_HEXDUMP(("Detach data"), detach.data, detach.len); + *old_id = NULL; + *old_id_len = 0; + /* Take the old client ID from the detachment data */ len = silc_buffer_unformat(&detach, - SILC_STR_UI16_NSTRING_ALLOC(&conn->nickname, + SILC_STR_UI16_NSTRING_ALLOC(&newnick, NULL), SILC_STR_UI16_NSTRING_ALLOC(old_id, old_id_len), SILC_STR_UI_INT(NULL), @@ -129,6 +132,11 @@ bool silc_client_process_detach_data(SilcClient client, SILC_STR_END); if (len == -1) return FALSE; + if (!newnick || !(*old_id) || !(*old_id_len)) + return FALSE; + + silc_free(conn->nickname); + conn->nickname = newnick; silc_buffer_pull(&detach, len); diff --git a/lib/silcclient/protocol.h b/lib/silcclient/protocol.h index 9d937092..019fa37a 100644 --- a/lib/silcclient/protocol.h +++ b/lib/silcclient/protocol.h @@ -2,15 +2,14 @@ protocol.h - Author: Pekka Riikonen + Author: Pekka Riikonen - Copyright (C) 1997 - 2000 Pekka Riikonen + Copyright (C) 1997 - 2004 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - + the Free Software Foundation; version 2 of the License. + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -52,6 +51,7 @@ typedef struct { typedef struct { void *client; SilcSocketConnection sock; + SilcClientConnectionStatus status; /* SKE object from Key Exchange protocol. */ SilcSKE ske; -- 2.43.0