Browse code

Port commit ec905ef825521fc5d5ec69ca8b8b1de22f6606f6 from master to 0.97

Shawn Webb authored on 2013/03/27 05:55:06
Showing 2 changed files
... ...
@@ -662,6 +662,7 @@ int submitstats(const char *clamdcfg, const struct optstruct *opts)
662 662
 		"Host: stats.clamav.net\r\n%s%s%s%s"
663 663
 		"Content-Type: application/x-www-form-urlencoded\r\n"
664 664
 		"User-Agent: %s\r\n"
665
+        "Connection: Close\r\n"
665 666
 		"Content-Length: %u\r\n\r\n"
666 667
 		"%s",
667 668
 		auth ? auth : "", hostid ? "X-HostID: " : "", hostid ? hostid : "", hostid ? "\r\n" : "", uastr, (unsigned int) strlen(query), query) < 0)
... ...
@@ -182,6 +182,9 @@ static ssize_t nonblock_recv(int sock, void *buf, size_t len, int flags, int sec
182 182
 	struct timeval timeout;  /* When we should time out */
183 183
 	int numfd;               /* Highest fdset fd plus 1 */
184 184
 
185
+    /* Zero buffer to maintain sanity in case we're dealing with strings */
186
+    memset(buf, 0x00, len);
187
+
185 188
 	/* Calculate into 'timeout' when we should time out */
186 189
 	gettimeofday(&timeout, 0);
187 190
 	timeout.tv_sec += secs;
... ...
@@ -193,6 +196,7 @@ static ssize_t nonblock_recv(int sock, void *buf, size_t len, int flags, int sec
193 193
 		struct timeval now;
194 194
 		struct timeval wait;
195 195
 		int n;
196
+        ssize_t recvd;
196 197
 
197 198
 		/* Force timeout if we ran out of time */
198 199
 		gettimeofday(&now, 0);
... ...
@@ -217,8 +221,16 @@ static ssize_t nonblock_recv(int sock, void *buf, size_t len, int flags, int sec
217 217
 			break; /* failed */
218 218
 		}
219 219
 
220
-		if (n) {
221
-			return recv(sock, buf, len, flags);
220
+		if (FD_ISSET(sock, &fds)) {
221
+			recvd = recv(sock, buf, len, flags);
222
+            if (recvd < 0) {
223
+                if (errno == EAGAIN)
224
+                    continue;
225
+
226
+                return -1;
227
+            }
228
+
229
+            return recvd;
222 230
 		}
223 231
 
224 232
 		/* Select returned, but there is no work to do... */