Browse Source

Merge commit '25c39c9' into stratum

Luke Dashjr 13 years ago
parent
commit
749ef4739a
3 changed files with 14 additions and 4 deletions
  1. 2 2
      miner.c
  2. 6 1
      ocl.c
  3. 6 1
      util.c

+ 2 - 2
miner.c

@@ -2502,7 +2502,7 @@ static bool submit_upstream_work(const struct work *work, CURL *curl, bool resub
 		if (opt_scrypt)
 			sprintf(hashshow, "%08lx.%08lx", (unsigned long)(hash32[7]), (unsigned long)(hash32[6]));
 		else {
-			int intdiff = round(work->work_difficulty);
+			int intdiff = floor(work->work_difficulty);
 			uint64_t sharediff = share_diff(work);
 			char diffdisp[16];
 
@@ -4992,7 +4992,7 @@ static void stratum_share_result(json_t *val, json_t *res_val, json_t *err_val,
 	int intdiff;
 
 	hash32 = (uint32_t *)(work->hash);
-	intdiff = round(work->work_difficulty);
+	intdiff = floor(work->work_difficulty);
 	suffix_string(sharediff, diffdisp, 0);
 	sprintf(hashshow, "%08lx Diff %s/%d%s", (unsigned long)(hash32[6]), diffdisp, intdiff,
 		work->block? " BLOCK!" : "");

+ 6 - 1
ocl.c

@@ -993,8 +993,13 @@ built:
 			bufsize = cgpu->max_alloc;
 		applog(LOG_DEBUG, "Creating scrypt buffer sized %d", bufsize);
 		clState->padbufsize = bufsize;
+
+		/* This buffer is weird and might work to some degree even if
+		 * the create buffer call has apparently failed, so check if we
+		 * get anything back before we call it a failure. */
+		clState->padbuffer8 = NULL;
 		clState->padbuffer8 = clCreateBuffer(clState->context, CL_MEM_READ_WRITE, bufsize, NULL, &status);
-		if (status != CL_SUCCESS) {
+		if (status != CL_SUCCESS && !clState->padbuffer8) {
 			applog(LOG_ERR, "Error %d: clCreateBuffer (padbuffer8), decrease CT or increase LG", status);
 			return NULL;
 		}

+ 6 - 1
util.c

@@ -923,6 +923,7 @@ char *recv_line(struct pool *pool)
 
 	if (!strstr(pool->sockbuf, "\n")) {
 		char s[RBUFSIZE];
+		size_t sspace;
 		CURLcode rc;
 
 		if (!sock_full(pool, true)) {
@@ -939,7 +940,11 @@ char *recv_line(struct pool *pool)
 			applog(LOG_DEBUG, "Failed to recv sock in recv_line");
 			goto out;
 		}
-		strcat(pool->sockbuf, s);
+		/* Prevent buffer overflows, but if 8k is still not enough,
+		 * likely we have had some comms issues and the data is all
+		 * useless anyway */
+		sspace = RECVSIZE - strlen(pool->sockbuf);
+		strncat(pool->sockbuf, s, sspace);
 	}
 
 	buflen = strlen(pool->sockbuf);