mirror of
https://github.com/weechat/weechat.git
synced 2026-06-28 13:56:37 +02:00
core: fix crash when buffer is closed during execution of multiple commands (closes #27)
This commit is contained in:
@@ -15,6 +15,8 @@ http://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes]
|
||||
|
||||
== Version 0.4.4 (under dev)
|
||||
|
||||
* core: fix crash when buffer is closed during execution of multiple commands
|
||||
(closes #27)
|
||||
* core: fix compilation on SmartOS (bug #40981, closes #23)
|
||||
* core: add missing \0 at the end of stderr buffer in hook_process
|
||||
* core: fix highlight problem with "(?-i)" and upper case letters in option
|
||||
|
||||
+75
-47
@@ -35,6 +35,7 @@
|
||||
#include "../gui/gui-buffer.h"
|
||||
#include "../gui/gui-chat.h"
|
||||
#include "../gui/gui-filter.h"
|
||||
#include "../gui/gui-window.h"
|
||||
#include "../plugins/plugin.h"
|
||||
|
||||
|
||||
@@ -154,13 +155,17 @@ input_exec_command (struct t_gui_buffer *buffer,
|
||||
void
|
||||
input_data (struct t_gui_buffer *buffer, const char *data)
|
||||
{
|
||||
char *pos, *buf, str_buffer[128], *new_data;
|
||||
char *pos, *buf, str_buffer[128], *new_data, *buffer_full_name;
|
||||
const char *ptr_data, *ptr_data_for_buffer;
|
||||
int length, char_size;
|
||||
int length, char_size, first_command;
|
||||
|
||||
if (!buffer || !data || !data[0] || (data[0] == '\r') || (data[0] == '\n'))
|
||||
return;
|
||||
|
||||
buffer_full_name = strdup (buffer->full_name);
|
||||
if (!buffer_full_name)
|
||||
return;
|
||||
|
||||
/* execute modifier "input_text_for_buffer" */
|
||||
snprintf (str_buffer, sizeof (str_buffer),
|
||||
"0x%lx", (long unsigned int)buffer);
|
||||
@@ -169,56 +174,79 @@ input_data (struct t_gui_buffer *buffer, const char *data)
|
||||
str_buffer,
|
||||
data);
|
||||
|
||||
/* data not dropped? */
|
||||
if (!new_data || new_data[0])
|
||||
/* data was dropped? */
|
||||
if (new_data && !new_data[0])
|
||||
goto end;
|
||||
|
||||
first_command = 1;
|
||||
ptr_data = (new_data) ? new_data : data;
|
||||
while (ptr_data && ptr_data[0])
|
||||
{
|
||||
ptr_data = (new_data) ? new_data : data;
|
||||
while (ptr_data && ptr_data[0])
|
||||
/*
|
||||
* if the buffer pointer is not valid any more (or if it's another
|
||||
* buffer), use the current buffer for the next command
|
||||
*/
|
||||
if (!first_command
|
||||
&& (!gui_buffer_valid (buffer)
|
||||
|| (strcmp (buffer->full_name, buffer_full_name) != 0)))
|
||||
{
|
||||
pos = strchr (ptr_data, '\n');
|
||||
if (pos)
|
||||
pos[0] = '\0';
|
||||
|
||||
ptr_data_for_buffer = string_input_for_buffer (ptr_data);
|
||||
if (ptr_data_for_buffer)
|
||||
{
|
||||
/*
|
||||
* input string is NOT a command, send it to buffer input
|
||||
* callback
|
||||
*/
|
||||
if (string_is_command_char (ptr_data_for_buffer))
|
||||
{
|
||||
char_size = utf8_char_size (ptr_data_for_buffer);
|
||||
length = strlen (ptr_data_for_buffer) + char_size + 1;
|
||||
buf = malloc (length);
|
||||
if (buf)
|
||||
{
|
||||
memcpy (buf, ptr_data_for_buffer, char_size);
|
||||
snprintf (buf + char_size, length - char_size,
|
||||
"%s", ptr_data_for_buffer);
|
||||
input_exec_data (buffer, buf);
|
||||
free (buf);
|
||||
}
|
||||
}
|
||||
else
|
||||
input_exec_data (buffer, ptr_data_for_buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* input string is a command */
|
||||
input_exec_command (buffer, 1, buffer->plugin, ptr_data);
|
||||
}
|
||||
|
||||
if (pos)
|
||||
{
|
||||
pos[0] = '\n';
|
||||
ptr_data = pos + 1;
|
||||
}
|
||||
else
|
||||
ptr_data = NULL;
|
||||
if (!gui_current_window || !gui_current_window->buffer)
|
||||
break;
|
||||
buffer = gui_current_window->buffer;
|
||||
free (buffer_full_name);
|
||||
buffer_full_name = strdup (buffer->full_name);
|
||||
if (!buffer_full_name)
|
||||
break;
|
||||
}
|
||||
|
||||
pos = strchr (ptr_data, '\n');
|
||||
if (pos)
|
||||
pos[0] = '\0';
|
||||
|
||||
ptr_data_for_buffer = string_input_for_buffer (ptr_data);
|
||||
if (ptr_data_for_buffer)
|
||||
{
|
||||
/*
|
||||
* input string is NOT a command, send it to buffer input
|
||||
* callback
|
||||
*/
|
||||
if (string_is_command_char (ptr_data_for_buffer))
|
||||
{
|
||||
char_size = utf8_char_size (ptr_data_for_buffer);
|
||||
length = strlen (ptr_data_for_buffer) + char_size + 1;
|
||||
buf = malloc (length);
|
||||
if (buf)
|
||||
{
|
||||
memcpy (buf, ptr_data_for_buffer, char_size);
|
||||
snprintf (buf + char_size, length - char_size,
|
||||
"%s", ptr_data_for_buffer);
|
||||
input_exec_data (buffer, buf);
|
||||
free (buf);
|
||||
}
|
||||
}
|
||||
else
|
||||
input_exec_data (buffer, ptr_data_for_buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* input string is a command */
|
||||
input_exec_command (buffer, 1, buffer->plugin, ptr_data);
|
||||
}
|
||||
|
||||
if (pos)
|
||||
{
|
||||
pos[0] = '\n';
|
||||
ptr_data = pos + 1;
|
||||
}
|
||||
else
|
||||
ptr_data = NULL;
|
||||
|
||||
first_command = 0;
|
||||
}
|
||||
|
||||
end:
|
||||
if (new_data)
|
||||
free (new_data);
|
||||
if (buffer_full_name)
|
||||
free (buffer_full_name);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user