libhfnetdriver: rework the timeouts, so more debugging info is printed
@@ -436,9 +436,10 @@ int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
}
#ifdef HFND_RECVTIME
- const struct timeval timeout = {1, 0}; // 1s
+ const struct timeval timeout = {.tv_sec = 1, .tv_usec = 0};
if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) == -1) {
- PLOG_W("Couldn't set setsockopt(sock, SO_RCVTIMEO, 1s) for fd=%d", sock);
+ PLOG_W("Honggfuzz Net Driver (pid=%d): Couldn't set setsockopt(sock=%d, SO_RCVTIMEO, 1s)",
+ (int)getpid(), sock);
}
time_t start = time(NULL);
#endif
@@ -449,13 +450,29 @@ int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
* pressure on the stack size
*/
static char b[1024ULL * 1024ULL * 4ULL];
- while (TEMP_FAILURE_RETRY(recv(sock, b, sizeof(b), MSG_WAITALL)) > 0) {
+ for (;;) {
+ int ret = TEMP_FAILURE_RETRY(recv(sock, b, sizeof(b), MSG_WAITALL));
+ if (ret == 0) {
+ break;
+ }
#ifdef HFND_RECVTIME
+ if (ret == -1 && errno == EWOULDBLOCK) {
time_t end = time(NULL);
if ((end - start) > HFND_RECVTIME) {
+ LOG_W("Honggfuzz Net Driver (pid=%d): Server didn't close the connection(fd=%d) "
+ "within %d seconds. Closing it.",
+ (int)getpid(), sock, HFND_RECVTIME);
break;
}
+ continue;
+ }
#endif
+ if (ret == -1) {
+ PLOG_W("Honggfuzz Net Driver (pid=%d): Connection to the server (sock=%d) closed with "
+ "error",
+ (int)getpid(), sock);
+ break;
+ }
}
close(sock);
