From e2232647172f0b8ed89927a96931e6166a87b9ed Mon Sep 17 00:00:00 2001 From: ckolivas Date: Thu, 28 Jan 2016 14:38:05 +1100 Subject: [PATCH] Include bkey header length in forward_passthrough_msg --- src/generator.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/generator.c b/src/generator.c index bfe15abb..95112d14 100644 --- a/src/generator.c +++ b/src/generator.c @@ -1924,25 +1924,29 @@ static void reconnect_proxy(proxy_instance_t *proxi) static void forward_passthrough_msg(ckpool_t *ckp, char *buf, int len) { - int slen = strlen(buf), blen = len - slen; + int slen = strlen(buf); char *bkey = NULL; - if (unlikely(blen > 0)) + if (unlikely(len > slen)) { bkey = strstr(buf + slen - 5, "bkey"); - if (bkey) { - json_t *val = json_loads(buf, JSON_DISABLE_EOF_CHECK, NULL); - - if (unlikely(!val)) { - LOGWARNING("No json in bkey appended message %s", buf); - goto out; + if (bkey) { + json_t *val = json_loads(buf, JSON_DISABLE_EOF_CHECK, NULL); + int blen; + + LOGDEBUG("Bkey found in forward_passthrough_msg"); + blen = len - (bkey - buf); + if (unlikely(!val)) { + LOGWARNING("No json in bkey appended message %s", buf); + goto out; + } + json_append_bkeys(val, bkey, blen); + buf = json_dumps(val, JSON_COMPACT); + json_decref(val); + LOGDEBUG("Passthrough recv received upstream bkey msg: %s", buf); + send_proc(ckp->connector, buf); + free(buf); + return; } - json_append_bkeys(val, bkey, blen); - buf = json_dumps(val, JSON_COMPACT); - json_decref(val); - LOGDEBUG("Passthrough recv received upstream bkey msg: %s", buf); - send_proc(ckp->connector, buf); - free(buf); - return; } out: LOGDEBUG("Passthrough recv received upstream msg: %s", buf);