Fixed command calling crash
authorPekka Riikonen <priikone@silcnet.org>
Sat, 30 Aug 2008 11:14:45 +0000 (14:14 +0300)
committerPekka Riikonen <priikone@silcnet.org>
Sat, 30 Aug 2008 11:14:45 +0000 (14:14 +0300)
If command finishes synchronously the command context is not valid
anymore and cannot be accessed.  Reported by Sami Farin.

lib/silcclient/command.c

index 85e33fe38217f0fe7b17c6c70a97270b1d3e2aca..0e72368ded59126cb750a12bb3413d47c57a6ee3 100644 (file)
@@ -411,6 +411,7 @@ SilcUInt16 silc_client_command_call(SilcClient client,
   SilcUInt32 argc = 0;
   unsigned char **argv = NULL;
   SilcUInt32 *argv_lens = NULL, *argv_types = NULL;
+  SilcUInt16 cmd_ident;
   SilcClientCommand command;
   SilcClientCommandContext cmd;
   char *arg;
@@ -480,7 +481,7 @@ SilcUInt16 silc_client_command_call(SilcClient client,
   cmd->argv = argv;
   cmd->argv_lens = argv_lens;
   cmd->argv_types = argv_types;
-  cmd->cmd_ident = silc_client_cmd_ident(conn);
+  cmd_ident = cmd->cmd_ident = silc_client_cmd_ident(conn);
   cmd->called = TRUE;
   cmd->verbose = TRUE;
   silc_list_init(cmd->reply_callbacks,
@@ -492,7 +493,7 @@ SilcUInt16 silc_client_command_call(SilcClient client,
                       silc_client_command_destructor, NULL, FALSE);
   silc_fsm_start_sync(&cmd->thread, command->command);
 
-  return cmd->cmd_ident;
+  return cmd_ident;
 }
 
 /* Generic function to send any command. The arguments must be sent already