summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2013-11-30 18:45:19 +0100
committerSebastien Helleu <flashcode@flashtux.org>2013-11-30 18:45:19 +0100
commit92d6074931a36e12a41ef75a028c60a160e2d528 (patch)
treeec507bd6e16d0654581d212bf89890ac31a6428d /src/gui
parent3e90657ab077a3f2e186e2c5849e0a503e551bb4 (diff)
downloadweechat-92d6074931a36e12a41ef75a028c60a160e2d528.zip
core: add limits for buffers (max 10000 buffers opened, number of a buffer: between 1 and INT_MAX - 10000)
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/gui-buffer.c18
-rw-r--r--src/gui/gui-buffer.h5
2 files changed, 23 insertions, 0 deletions
diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c
index ad4645f49..daae4f8d6 100644
--- a/src/gui/gui-buffer.c
+++ b/src/gui/gui-buffer.c
@@ -492,6 +492,16 @@ gui_buffer_new (struct t_weechat_plugin *plugin,
return NULL;
}
+ if (gui_buffers_count >= GUI_BUFFERS_MAX)
+ {
+ gui_chat_printf (NULL,
+ _("%sError: maximum number of buffers is reached "
+ "(%d)"),
+ gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
+ GUI_BUFFERS_MAX);
+ return NULL;
+ }
+
/* create new buffer */
new_buffer = malloc (sizeof (*new_buffer));
if (!new_buffer)
@@ -2611,6 +2621,8 @@ gui_buffer_renumber (int number1, int number2, int start_number)
if (start_number < 1)
start_number = ptr_first_buffer->number;
+ else if (start_number > GUI_BUFFER_NUMBER_MAX)
+ start_number = GUI_BUFFER_NUMBER_MAX;
/* the start number must be greater than buffer before first buffer */
if (ptr_first_buffer->prev_buffer
@@ -2676,6 +2688,9 @@ gui_buffer_move_to_number (struct t_gui_buffer *buffer, int number)
if (number < 1)
number = 1;
+ if (number > GUI_BUFFER_NUMBER_MAX)
+ number = GUI_BUFFER_NUMBER_MAX;
+
/* buffer number is already OK ? */
if (number == buffer->number)
return;
@@ -2998,6 +3013,9 @@ gui_buffer_unmerge (struct t_gui_buffer *buffer, int number)
ptr_new_active_buffer = NULL;
+ if (number > GUI_BUFFER_NUMBER_MAX)
+ number = GUI_BUFFER_NUMBER_MAX;
+
/* by default, we move buffer to buffer->number + 1 */
if ((number < 1) || (number == buffer->number))
{
diff --git a/src/gui/gui-buffer.h b/src/gui/gui-buffer.h
index ae36d14d3..5057eb68c 100644
--- a/src/gui/gui-buffer.h
+++ b/src/gui/gui-buffer.h
@@ -20,6 +20,7 @@
#ifndef __WEECHAT_GUI_BUFFER_H
#define __WEECHAT_GUI_BUFFER_H 1
+#include <limits.h>
#include <regex.h>
struct t_hashtable;
@@ -46,6 +47,10 @@ enum t_gui_buffer_notify
#define GUI_BUFFER_MAIN "weechat"
+#define GUI_BUFFERS_MAX 10000
+
+#define GUI_BUFFER_NUMBER_MAX (INT_MAX - 10000)
+
#define GUI_TEXT_SEARCH_DISABLED 0
#define GUI_TEXT_SEARCH_BACKWARD 1
#define GUI_TEXT_SEARCH_FORWARD 2