Skip to content

Commit

Permalink
relay: fix crash on /upgrade received from a client (weechat protocol)
Browse files Browse the repository at this point in the history
Some commands like /upgrade sent by relay client can cause problems, because
they were executed immediately (while relay code is running). The /upgrade
command unloads all plugins, so the result is unpredictable (it can cause a
crash).

This commit adds a timer (1 millisecond) to delay the execution of command
after we go back in the WeeChat main loop.
  • Loading branch information
flashcode committed Mar 7, 2014
1 parent c87cd88 commit 7a191c2
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
1 change: 1 addition & 0 deletions ChangeLog.asciidoc
Expand Up @@ -62,6 +62,7 @@ http://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes]
* lua: fix interpreter used after unload of a script
* perl: fix context used after unload of a script
* python: fix interpreter used after unload of a script
* relay: fix crash on /upgrade received from a client (weechat protocol)
* relay: add info "relay_client_count" with optional status name as argument
* relay: add signals "relay_client_xxx" for client status changes (closes #2)
* relay: add option relay.network.clients_purge_delay
Expand Down
59 changes: 57 additions & 2 deletions src/plugins/relay/weechat/relay-weechat-protocol.c
Expand Up @@ -332,6 +332,43 @@ RELAY_WEECHAT_PROTOCOL_CALLBACK(nicklist)
return WEECHAT_RC_OK;
}

/*
* Timer callback for input command.
*/

int
relay_weechat_protocol_input_timer_cb (void *data,
int remaining_calls)
{
char **timer_args;
int i;
struct t_gui_buffer *ptr_buffer;

/* make C compiler happy */
(void) remaining_calls;

timer_args = (char **)data;

if (!timer_args)
return WEECHAT_RC_ERROR;

if (timer_args[0] && timer_args[1] && timer_args[2])
{
ptr_buffer = weechat_buffer_search (timer_args[0], timer_args[1]);
if (ptr_buffer)
weechat_command (ptr_buffer, timer_args[2]);
}

for (i = 0; i < 3; i++)
{
if (timer_args[i])
free (timer_args[i]);
}
free (timer_args);

return WEECHAT_RC_OK;
}

/*
* Callback for command "input" (from client).
*
Expand All @@ -344,7 +381,7 @@ RELAY_WEECHAT_PROTOCOL_CALLBACK(nicklist)
RELAY_WEECHAT_PROTOCOL_CALLBACK(input)
{
struct t_gui_buffer *ptr_buffer;
char *pos;
char *pos, **timer_args;

RELAY_WEECHAT_PROTOCOL_MIN_ARGS(2);

Expand All @@ -353,7 +390,25 @@ RELAY_WEECHAT_PROTOCOL_CALLBACK(input)
{
pos = strchr (argv_eol[0], ' ');
if (pos)
weechat_command (ptr_buffer, pos + 1);
{
/*
* use a timer to execute the command after we go back in the
* WeeChat main loop (some commands like /upgrade executed now can
* cause a crash)
*/
timer_args = malloc (3 * sizeof (*timer_args));
if (timer_args)
{
timer_args[0] = strdup (weechat_buffer_get_string (ptr_buffer,
"plugin"));
timer_args[1] = strdup (weechat_buffer_get_string (ptr_buffer,
"name"));
timer_args[2] = strdup (pos + 1);
weechat_hook_timer (1, 0, 1,
&relay_weechat_protocol_input_timer_cb,
timer_args);
}
}
}

return WEECHAT_RC_OK;
Expand Down

0 comments on commit 7a191c2

Please sign in to comment.