summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Swiecki <robert@swiecki.net>2020-05-28 15:01:07 +0200
committerRobert Swiecki <robert@swiecki.net>2020-05-28 15:01:07 +0200
commit4474f2a01ecfcb07c0b75e33a41817d45fabc92a (patch)
treeea403ceeeb271044099a44e81c0c5b45956d048f
parentb36a3657d3402f60e9218c0599623a44bc928e04 (diff)
downloadhonggfuzz-4474f2a01ecfcb07c0b75e33a41817d45fabc92a.tar.gz
libhfnetdriver: rework the timeouts, so more debugging info is printed
-rw-r--r--libhfnetdriver/netdriver.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/libhfnetdriver/netdriver.c b/libhfnetdriver/netdriver.c
index e0d5d21f..72ac3de8 100644
--- a/libhfnetdriver/netdriver.c
+++ b/libhfnetdriver/netdriver.c
@@ -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) {
-#ifdef HFND_RECVTIME
- time_t end = time(NULL);
- if ((end - start) > HFND_RECVTIME) {
+ 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);