From 4f637a8be5f51439f9dfecf4513290f2c11ede44 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Fri, 29 Jan 2016 14:36:22 +1100 Subject: [PATCH] Fix off-by-one error in parsing bkeys in parse_client_msg --- src/connector.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/connector.c b/src/connector.c index 4c23708b..0b1f9173 100644 --- a/src/connector.c +++ b/src/connector.c @@ -528,7 +528,7 @@ reparse: blen = bkey_len(bkey); if (len < blen) goto retry; - buflen = slen + blen; + buflen = slen + blen + 1; } else buflen = eol - client->buf + 1; @@ -538,7 +538,6 @@ reparse: invalidate_client(ckp, cdata, client); return; } - if (!(val = json_loads(client->buf, JSON_DISABLE_EOF_CHECK, NULL))) { char *buf = strdup("Invalid JSON, disconnecting\n"); @@ -549,8 +548,10 @@ reparse: } else { char *s; - if (unlikely(blen)) + if (unlikely(blen)) { json_append_bkeys(val, bkey, blen); + blen = 0; + } if (client->passthrough) { int64_t passthrough_id; @@ -580,7 +581,8 @@ reparse: json_decref(val); } client->bufofs -= buflen; - memmove(client->buf, client->buf + buflen, client->bufofs); + if (client->bufofs) + memmove(client->buf, client->buf + buflen, client->bufofs); client->buf[client->bufofs] = '\0'; if (client->bufofs)