mirror of
https://github.com/GOSTSec/sgminer
synced 2025-01-23 04:54:26 +00:00
Avoid dynamically adding stack memory for nonce2 in the stratum send thread and check the pool's nonce2_len will not cause an overflow.
This commit is contained in:
parent
f0328f8cd0
commit
d4ac1915fa
16
cgminer.c
16
cgminer.c
@ -5213,12 +5213,12 @@ static void *stratum_sthread(void *userdata)
|
|||||||
quit(1, "Failed to create stratum_q in stratum_sthread");
|
quit(1, "Failed to create stratum_q in stratum_sthread");
|
||||||
|
|
||||||
while (42) {
|
while (42) {
|
||||||
char *noncehex, *nonce2, *nonce2hex;
|
|
||||||
struct stratum_share *sshare;
|
struct stratum_share *sshare;
|
||||||
|
char *noncehex, *nonce2hex;
|
||||||
uint32_t *hash32, nonce;
|
uint32_t *hash32, nonce;
|
||||||
|
char s[1024], nonce2[8];
|
||||||
struct work *work;
|
struct work *work;
|
||||||
bool submitted;
|
bool submitted;
|
||||||
char s[1024];
|
|
||||||
|
|
||||||
if (unlikely(pool->removed))
|
if (unlikely(pool->removed))
|
||||||
break;
|
break;
|
||||||
@ -5227,6 +5227,14 @@ static void *stratum_sthread(void *userdata)
|
|||||||
if (unlikely(!work))
|
if (unlikely(!work))
|
||||||
quit(1, "Stratum q returned empty work");
|
quit(1, "Stratum q returned empty work");
|
||||||
|
|
||||||
|
if (unlikely(work->nonce2_len > 8)) {
|
||||||
|
applog(LOG_ERR, "Pool %d asking for inappropriately long nonce2 length %d",
|
||||||
|
pool->pool_no, (int)work->nonce2_len);
|
||||||
|
applog(LOG_ERR, "Not attempting to submit shares");
|
||||||
|
free_work(work);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
sshare = calloc(sizeof(struct stratum_share), 1);
|
sshare = calloc(sizeof(struct stratum_share), 1);
|
||||||
hash32 = (uint32_t *)work->hash;
|
hash32 = (uint32_t *)work->hash;
|
||||||
submitted = false;
|
submitted = false;
|
||||||
@ -5243,8 +5251,8 @@ static void *stratum_sthread(void *userdata)
|
|||||||
sshare->id = swork_id++;
|
sshare->id = swork_id++;
|
||||||
mutex_unlock(&sshare_lock);
|
mutex_unlock(&sshare_lock);
|
||||||
|
|
||||||
nonce2 = alloca(work->nonce2_len);
|
memset(nonce2, 0, 8);
|
||||||
memset(nonce2, 0, work->nonce2_len);
|
/* We only use uint32_t sized nonce2 increments internally */
|
||||||
memcpy(nonce2, &work->nonce2, sizeof(uint32_t));
|
memcpy(nonce2, &work->nonce2, sizeof(uint32_t));
|
||||||
nonce2hex = bin2hex((const unsigned char *)nonce2, work->nonce2_len);
|
nonce2hex = bin2hex((const unsigned char *)nonce2, work->nonce2_len);
|
||||||
if (unlikely(!nonce2hex))
|
if (unlikely(!nonce2hex))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user