Browse Source

Nonce2 stratum submission is not working with nonce2 lengths >4, revert the buggy __bin2hex function and use bin2hex.

Con Kolivas 12 years ago
parent
commit
e95ad0479f
3 changed files with 10 additions and 19 deletions
  1. 7 9
      cgminer.c
  2. 3 9
      util.c
  3. 0 1
      util.h

+ 7 - 9
cgminer.c

@@ -5149,9 +5149,9 @@ static void *stratum_sthread(void *userdata)
 		quit(1, "Failed to create stratum_q in stratum_sthread");
 
 	while (42) {
+		char *noncehex, *nonce2, *nonce2hex;
 		struct stratum_share *sshare;
 		uint32_t *hash32, nonce;
-		char *noncehex, *nonce2;
 		struct work *work;
 		bool submitted;
 		char s[1024];
@@ -5179,20 +5179,18 @@ static void *stratum_sthread(void *userdata)
 		sshare->id = swork_id++;
 		mutex_unlock(&sshare_lock);
 
-		/* nonce2 length can be bigger than uint32_t but we only use
-		 * the 4 bytes so avoid potential overflow if a pool has set a
-		 * large length by allocating the ram ourselves and using the
-		 * low level __bin2hex function. */
-		work->nonce2_len += 1; /* Null byte */
-		align_len(&work->nonce2_len);
 		nonce2 = alloca(work->nonce2_len);
 		memset(nonce2, 0, work->nonce2_len);
-		__bin2hex(nonce2, (const unsigned char *)&work->nonce2, sizeof(uint32_t));
+		memcpy(nonce2, &work->nonce2, sizeof(uint32_t));
+		nonce2hex = bin2hex((const unsigned char *)nonce2, work->nonce2_len);
+		if (unlikely(!nonce2hex))
+			quit(1, "Failed to bin2hex nonce2 in stratum_thread");
 
 		snprintf(s, sizeof(s),
 			"{\"params\": [\"%s\", \"%s\", \"%s\", \"%s\", \"%s\"], \"id\": %d, \"method\": \"mining.submit\"}",
-			pool->rpc_user, work->job_id, nonce2, work->ntime, noncehex, sshare->id);
+			pool->rpc_user, work->job_id, nonce2hex, work->ntime, noncehex, sshare->id);
 		free(noncehex);
+		free(nonce2hex);
 
 		applog(LOG_INFO, "Submitting share %08lx to pool %d",
 					(long unsigned int)htole32(hash32[6]), pool->pool_no);

+ 3 - 9
util.c

@@ -576,14 +576,6 @@ char *get_proxy(char *url, struct pool *pool)
 	return url;
 }
 
-void __bin2hex(char *s, const unsigned char *p, size_t len)
-{
-	int i;
-
-	for (i = 0; i < (int)len; i++)
-		sprintf(s + (i * 2), "%02x", (unsigned int)p[i]);
-}
-
 /* Returns a malloced array string of a binary value of arbitrary length. The
  * array is rounded up to a 4 byte size to appease architectures that need
  * aligned array  sizes */
@@ -591,6 +583,7 @@ char *bin2hex(const unsigned char *p, size_t len)
 {
 	ssize_t slen;
 	char *s;
+	int i;
 
 	slen = len * 2 + 1;
 	if (slen % 4)
@@ -599,7 +592,8 @@ char *bin2hex(const unsigned char *p, size_t len)
 	if (unlikely(!s))
 		quithere(1, "Failed to calloc");
 
-	__bin2hex(s, p, len);
+	for (i = 0; i < (int)len; i++)
+		sprintf(s + (i * 2), "%02x", (unsigned int)p[i]);
 
 	return s;
 }

+ 0 - 1
util.h

@@ -70,7 +70,6 @@ enum dev_reason;
 struct cgpu_info;
 int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) (void *), void *arg);
 void thr_info_cancel(struct thr_info *thr);
-void __bin2hex(char *s, const unsigned char *p, size_t len);
 void nmsleep(unsigned int msecs);
 void nusleep(unsigned int usecs);
 void cgtime(struct timeval *tv);