From bf1c2ef09bb39f377011db00a4d0d8d449b4cc53 Mon Sep 17 00:00:00 2001 From: ckolivas Date: Wed, 18 Mar 2015 16:00:18 +1100 Subject: [PATCH] Cope with variable length ckdb responses on the heartbeat as well --- src/stratifier.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/stratifier.c b/src/stratifier.c index 0c732c72..32123a6d 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -2350,6 +2350,7 @@ static int send_recv_auth(stratum_instance_t *client) sdata_t *sdata = ckp->data; char *buf = NULL, *json_msg; bool contended = false; + size_t responselen = 0; char cdfield[64]; int ret = 1; json_t *val; @@ -2389,15 +2390,16 @@ static int send_recv_auth(stratum_instance_t *client) contended = true; free(json_msg); - if (likely(buf)) { + /* Leave ample room for response based on buf length */ + if (likely(buf)) + responselen = strlen(buf); + if (likely(responselen > 0)) { char *cmd = NULL, *secondaryuserid = NULL, *response; worker_instance_t *worker = client->worker_instance; json_error_t err_val; - size_t responselen; json_t *val = NULL; LOGINFO("Got ckdb response: %s", buf); - responselen = strlen(buf); /* Leave ample room for response based on buf length */ response = alloca(responselen); memset(response, 0, responselen); if (unlikely(sscanf(buf, "id.%*d.%s", response) < 1 || strlen(response) < 1 || !strchr(response, '='))) { @@ -3782,6 +3784,7 @@ static bool test_and_clear(bool *val, mutex_t *lock) static void ckdbq_process(ckpool_t *ckp, char *msg) { sdata_t *sdata = ckp->data; + size_t responselen = 0; char *buf = NULL; while (!buf) { @@ -3801,9 +3804,12 @@ static void ckdbq_process(ckpool_t *ckp, char *msg) /* Process any requests from ckdb that are heartbeat responses with * specific requests. */ - if (likely(buf)) { - char response[PAGESIZE] = {}; + if (likely(buf)) + responselen = strlen(buf); + if (likely(responselen > 0)) { + char *response = alloca(responselen); + memset(response, 0, responselen); sscanf(buf, "id.%*d.%s", response); if (safecmp(response, "ok")) { char *cmd;