Skip to content

Commit c26d71d

Browse files
author
nicm
committed
Add an option to control the input buffer size, from Ken Lau.
1 parent 596ea62 commit c26d71d

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

input.c

+12-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ struct input_ctx {
9393
size_t param_len;
9494

9595
#define INPUT_BUF_START 32
96-
#define INPUT_BUF_LIMIT 1048576
9796
u_char *input_buf;
9897
size_t input_len;
9998
size_t input_space;
@@ -729,6 +728,9 @@ static const struct input_transition input_state_consume_st_table[] = {
729728
{ -1, -1, NULL, NULL }
730729
};
731730

731+
/* Maximum of bytes allowed to read in a single input. */
732+
static size_t input_buffer_size = INPUT_BUF_DEFAULT_SIZE;
733+
732734
/* Input table compare. */
733735
static int
734736
input_table_compare(const void *key, const void *value)
@@ -1193,7 +1195,7 @@ input_input(struct input_ctx *ictx)
11931195
available = ictx->input_space;
11941196
while (ictx->input_len + 1 >= available) {
11951197
available *= 2;
1196-
if (available > INPUT_BUF_LIMIT) {
1198+
if (available > input_buffer_size) {
11971199
ictx->flags |= INPUT_DISCARD;
11981200
return (0);
11991201
}
@@ -3017,3 +3019,11 @@ input_reply_clipboard(struct bufferevent *bev, const char *buf, size_t len,
30173019
bufferevent_write(bev, end, strlen(end));
30183020
free(out);
30193021
}
3022+
3023+
/* Set input buffer size. */
3024+
void
3025+
input_set_buffer_size(size_t buffer_size)
3026+
{
3027+
log_debug("%s: %lu -> %lu", __func__, input_buffer_size, buffer_size);
3028+
input_buffer_size = buffer_size;
3029+
}

options-table.c

+9
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,15 @@ const struct options_table_entry options_table[] = {
348348
"Empty does not write a history file."
349349
},
350350

351+
{ .name = "input-buffer-size",
352+
.type = OPTIONS_TABLE_NUMBER,
353+
.scope = OPTIONS_TABLE_SERVER,
354+
.minimum = INPUT_BUF_DEFAULT_SIZE,
355+
.maximum = UINT_MAX,
356+
.default_num = INPUT_BUF_DEFAULT_SIZE,
357+
.text = "Number of byte accpted in a single input before dropping."
358+
},
359+
351360
{ .name = "menu-style",
352361
.type = OPTIONS_TABLE_STRING,
353362
.scope = OPTIONS_TABLE_WINDOW,

options.c

+2
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,8 @@ options_push_changes(const char *name)
11771177
RB_FOREACH(w, windows, &windows)
11781178
layout_fix_panes(w, NULL);
11791179
}
1180+
if (strcmp(name, "input-buffer-size") == 0)
1181+
input_set_buffer_size(options_get_number(global_options, name));
11801182
RB_FOREACH(s, sessions, &sessions)
11811183
status_update_cache(s);
11821184

tmux.1

+3
Original file line numberDiff line numberDiff line change
@@ -4139,6 +4139,9 @@ option.
41394139
If not empty, a file to which
41404140
.Nm
41414141
will write command prompt history on exit and load it from on start.
4142+
.It Ic input-buffer-size Ar bytes
4143+
Maximum of bytes allowed to read in escape and control sequences.
4144+
Once reached, the sequence will be discarded.
41424145
.It Ic message-limit Ar number
41434146
Set the number of error or information messages to save in the message log for
41444147
each client.

tmux.h

+2
Original file line numberDiff line numberDiff line change
@@ -2840,6 +2840,7 @@ void recalculate_sizes(void);
28402840
void recalculate_sizes_now(int);
28412841

28422842
/* input.c */
2843+
#define INPUT_BUF_DEFAULT_SIZE 1048576
28432844
struct input_ctx *input_init(struct window_pane *, struct bufferevent *,
28442845
struct colour_palette *);
28452846
void input_free(struct input_ctx *);
@@ -2851,6 +2852,7 @@ void input_parse_screen(struct input_ctx *, struct screen *,
28512852
screen_write_init_ctx_cb, void *, u_char *, size_t);
28522853
void input_reply_clipboard(struct bufferevent *, const char *, size_t,
28532854
const char *);
2855+
void input_set_buffer_size(size_t);
28542856

28552857
/* input-key.c */
28562858
void input_key_build(void);

0 commit comments

Comments
 (0)