From 907a33584eebe8e381eb4376ce63d45ed75c637c Mon Sep 17 00:00:00 2001 From: kanoi Date: Mon, 6 Apr 2015 21:36:23 +1000 Subject: [PATCH] ckpool - sscanf %s stops at a space --- src/stratifier.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/stratifier.c b/src/stratifier.c index 2b23c5e7..67b5c7aa 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -2375,14 +2375,20 @@ static int send_recv_auth(stratum_instance_t *client) worker_instance_t *worker = client->worker_instance; json_error_t err_val; json_t *val = NULL; + int offset = 0; LOGINFO("Got ckdb response: %s", buf); response = alloca(responselen); memset(response, 0, responselen); - if (unlikely(sscanf(buf, "id.%*d.%s", response) < 1 || strlen(response) < 1 || !strchr(response, '='))) { + if (unlikely(sscanf(buf, "id.%*d.%c%n", response, &offset) < 1)) { + LOGWARNING("Got1 unparseable ckdb auth response: %s", buf); + goto out_fail; + } + strcpy(response+1, buf+offset); + if (!strchr(response, '=')) { if (cmdmatch(response, "failed")) goto out; - LOGWARNING("Got unparseable ckdb auth response: %s", buf); + LOGWARNING("Got2 unparseable ckdb auth response: %s", buf); goto out_fail; } cmd = response; @@ -3782,21 +3788,25 @@ static void ckdbq_process(ckpool_t *ckp, char *msg) responselen = strlen(buf); if (likely(responselen > 0)) { char *response = alloca(responselen); + int offset = 0; memset(response, 0, responselen); - sscanf(buf, "id.%*d.%s", response); - if (safecmp(response, "ok")) { - char *cmd; - - cmd = response; - strsep(&cmd, "."); - LOGDEBUG("Got ckdb response: %s cmd %s", response, cmd); - if (cmdmatch(cmd, "heartbeat=")) { - strsep(&cmd, "="); - parse_ckdb_cmd(ckp, cmd); - } + if (sscanf(buf, "id.%*d.%c%n", response, &offset) > 0) { + strcpy(response+1, buf+offset); + if (safecmp(response, "ok")) { + char *cmd; + + cmd = response; + strsep(&cmd, "."); + LOGDEBUG("Got ckdb response: %s cmd %s", response, cmd); + if (cmdmatch(cmd, "heartbeat=")) { + strsep(&cmd, "="); + parse_ckdb_cmd(ckp, cmd); + } + } else + LOGWARNING("Got ckdb failure response: %s", buf); } else - LOGWARNING("Got failed ckdb response: %s", buf); + LOGWARNING("Got bad ckdb response: %s", buf); free(buf); } }