From 17bb17f2339b44761325f92e30b186d26273c9eb Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 21 Oct 2014 15:30:53 +1100 Subject: [PATCH] Try sanitising too short nonce2 submissions as well as too long by appending 0s --- src/stratifier.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/stratifier.c b/src/stratifier.c index 8928764b..e5832d65 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -2155,12 +2155,12 @@ static json_t *parse_submit(stratum_instance_t *client, json_t *json_msg, char idstring[20]; uint32_t ntime32; uchar hash[32]; + int nlen, len; time_t now_t; json_t *val; int64_t id; ts_t now; FILE *fp; - int len; ts_realtime(&now); now_t = now.tv_sec; @@ -2232,9 +2232,16 @@ static json_t *parse_submit(stratum_instance_t *client, json_t *json_msg, /* Fix broken clients sending too many chars. Nonce2 is part of the * read only json so use a temporary variable and modify it. */ len = wb->enonce2varlen * 2; - if ((int)strlen(nonce2) > len) { + nlen = strlen(nonce2); + if (nlen > len) { nonce2 = strdupa(nonce2); nonce2[len] = '\0'; + } else if (nlen < len) { + char *tmp = nonce2; + + nonce2 = strdupa("0000000000000000"); + memcpy(nonce2, tmp, nlen); + nonce2[len] = '\0'; } sdiff = submission_diff(client, wb, nonce2, ntime32, nonce, hash); bswap_256(sharehash, hash); @@ -2245,11 +2252,6 @@ static json_t *parse_submit(stratum_instance_t *client, json_t *json_msg, json_set_string(json_msg, "reject-reason", SHARE_ERR(err)); goto out_submit; } - if ((int)strlen(nonce2) < len) { - err = SE_INVALID_NONCE2; - *err_val = JSON_ERR(err); - goto out_unlock; - } /* Ntime cannot be less, but allow forward ntime rolling up to max */ if (ntime32 < wb->ntime32 || ntime32 > wb->ntime32 + 7000) { err = SE_NTIME_INVALID;