From 3dae1a7015374101edaf5f465410428e71d0d0ee Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Fri, 4 Mar 2016 18:59:38 -0800 Subject: [PATCH] First fuzz-detected error! --- stutterfuzz.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/stutterfuzz.c b/stutterfuzz.c index 9f312c8..634def7 100644 --- a/stutterfuzz.c +++ b/stutterfuzz.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -172,7 +173,7 @@ static struct file *file_next() { iter = iter->next->next; rounds++; if (!(++rounds % 100)) { - fprintf(stderr, "\rRounds: %ju", (uintmax_t) rounds); + fprintf(stderr, "\rRounds: %ju\r", (uintmax_t) rounds); } } else { iter = iter->next; @@ -239,10 +240,33 @@ static void conn_send_message(struct conn *conn) { conn->offset += to_send; } -static void conn_send_messages() { +static void conn_check(struct conn *conn) { + int error; + socklen_t len = sizeof(error); + assert(getsockopt(conn->fd, SOL_SOCKET, SO_ERROR, &error, &len) == 0); + if (!error) { + conn->state = CONN_SENDING; + return; + } + if (error == EINPROGRESS) { + return; + } + fprintf(stderr, "\nConnection failed: %s\n", strerror(error)); + exit(EXIT_FAILURE); +} + +static void conn_cycle() { struct conn *iter, *next; list_for_each_entry_safe(iter, next, &conn_head, conn_list) { - conn_send_message(iter); + switch (iter->state) { + case CONN_CONNECTING: + conn_check(iter); + break; + + case CONN_SENDING: + conn_send_message(iter); + break; + } } } @@ -251,7 +275,7 @@ int main(int argc, char *argv[]) { if (!parse_opts(argc, argv)) { fprintf(stderr, "Usage: TODO\n"); - return 1; + exit(EXIT_FAILURE); } file_open(); @@ -265,8 +289,8 @@ int main(int argc, char *argv[]) { }; while (true) { + conn_cycle(); conn_fill(); - conn_send_messages(); assert(!nanosleep(&ts, NULL)); }