Browse Source

Bugfix: Safely handle all-space cURL debug messages, should they ever happen

Luke Dashjr 12 years ago
parent
commit
03cb5a7059
1 changed files with 3 additions and 1 deletions
  1. 3 1
      util.c

+ 3 - 1
util.c

@@ -273,8 +273,10 @@ static int my_curl_debug(__maybe_unused CURL *curl, curl_infotype infotype, char
 			// data is not null-terminated, so we need to copy and terminate it for applog
 			char datacp[datasz + 1];
 			memcpy(datacp, data, datasz);
-			while (isspace(datacp[datasz-1]))
+			while (likely(datasz) && unlikely(isspace(datacp[datasz-1])))
 				--datasz;
+			if (unlikely(!datasz))
+				break;
 			datacp[datasz] = '\0';
 			applog(LOG_DEBUG, "Pool %u: %s", pool->pool_no, datacp);
 			break;