Be less strict over msgpack message size

This commit is contained in:
Nicolas Viennot 2016-03-28 16:27:09 -04:00
parent 02694d2a96
commit 71d31e60e6
3 changed files with 8 additions and 9 deletions

View File

@ -108,13 +108,14 @@ void tmate_sync_layout(void)
/* TODO add a buffer for pty_data ? */
#define TMATE_MAX_PTY_SIZE (16*1024)
void tmate_pty_data(struct window_pane *wp, const char *buf, size_t len)
{
size_t max_write, to_write;
size_t to_write;
max_write = TMATE_MAX_MESSAGE_SIZE - 16;
while (len > 0) {
to_write = len < max_write ? len : max_write;
to_write = len < TMATE_MAX_PTY_SIZE ? len : TMATE_MAX_PTY_SIZE;
pack(array, 3);
pack(int, TMATE_OUT_PTY_DATA);

View File

@ -178,10 +178,12 @@ void unpack_array(struct tmate_unpacker *uk, struct tmate_unpacker *nested)
uk->argc--;
}
#define UNPACKER_RESERVE_SIZE 1024
void tmate_decoder_init(struct tmate_decoder *decoder, tmate_decoder_reader *reader,
void *userdata)
{
if (!msgpack_unpacker_init(&decoder->unpacker, TMATE_MAX_MESSAGE_SIZE))
if (!msgpack_unpacker_init(&decoder->unpacker, UNPACKER_RESERVE_SIZE))
tmate_fatal("Cannot initialize the unpacker");
decoder->reader = reader;
decoder->userdata = userdata;
@ -196,9 +198,7 @@ void tmate_decoder_destroy(struct tmate_decoder *decoder)
void tmate_decoder_get_buffer(struct tmate_decoder *decoder,
char **buf, size_t *len)
{
ssize_t current_size = msgpack_unpacker_message_size(&decoder->unpacker);
if (!msgpack_unpacker_reserve_buffer(&decoder->unpacker,
TMATE_MAX_MESSAGE_SIZE - current_size))
if (!msgpack_unpacker_reserve_buffer(&decoder->unpacker, UNPACKER_RESERVE_SIZE))
tmate_fatal("cannot expand decoder buffer");
*buf = msgpack_unpacker_buffer(&decoder->unpacker);

View File

@ -1,8 +1,6 @@
#ifndef TMATE_PROTOCOL_H
#define TMATE_PROTOCOL_H
#define TMATE_MAX_MESSAGE_SIZE (16*1024)
enum tmate_control_out_msg_types {
TMATE_CTL_AUTH,
TMATE_CTL_DEAMON_OUT_MSG,