Browse Source

Bugfix: Simplify adding "http://" prefix to avoid strncat overflow (length excludes null byte)

Luke Dashjr 12 years ago
parent
commit
74e4cee477
1 changed files with 3 additions and 3 deletions
  1. 3 3
      miner.c

+ 3 - 3
miner.c

@@ -982,13 +982,13 @@ static char *set_url(char *arg)
 	opt_set_charp(arg, &pool->rpc_url);
 	if (strncmp(arg, "http://", 7) &&
 	    strncmp(arg, "https://", 8)) {
+		const size_t L = strlen(arg);
 		char *httpinput;
 
-		httpinput = malloc(255);
+		httpinput = malloc(8 + L);
 		if (!httpinput)
 			quit(1, "Failed to malloc httpinput");
-		strcpy(httpinput, "http://");
-		strncat(httpinput, arg, 248);
+		sprintf(httpinput, "http://%s", arg);
 		pool->rpc_url = httpinput;
 	}