From 2a8b96105857dee237889f6a9e02d42352874e02 Mon Sep 17 00:00:00 2001 From: dormando Date: Mon, 7 Jun 2021 22:18:05 -0700 Subject: [PATCH] meta: more realistic buffer limit for binary keys. --- proto_text.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/proto_text.c b/proto_text.c index 6e157995d7..67930ccd12 100644 --- a/proto_text.c +++ b/proto_text.c @@ -993,14 +993,17 @@ static int _meta_flag_preparse(token_t *tokens, const size_t ntokens, p += 2; \ } -// TODO: calc bytes remaining in buffer +// NOTE: being a little casual with the write buffer. +// the buffer needs to be sized that the longest possible meta response will +// fit. Here we allow the key to fill up to half the write buffer, in case +// something terrible has gone wrong. #define META_KEY(p, key, nkey, bin) { \ META_CHAR(p, 'k'); \ if (!bin) { \ memcpy(p, key, nkey); \ p += nkey; \ } else { \ - p += base64_encode((unsigned char *) key, nkey, (unsigned char *)p, WRITE_BUFFER_SIZE); \ + p += base64_encode((unsigned char *) key, nkey, (unsigned char *)p, WRITE_BUFFER_SIZE / 2); \ *p = ' '; \ *(p+1) = 'b'; \ p += 2; \