From: W.C.A. Wijngaards Date: Tue, 8 Nov 2022 12:23:44 +0000 (+0100) Subject: - Fix to make sure to not read again after a tcp comm point is closed. X-Git-Tag: release-1.17.1rc1~22 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=52a9e6268ec0580700a1db1146c02e771ed0448a;p=thirdparty%2Funbound.git - Fix to make sure to not read again after a tcp comm point is closed. --- diff --git a/doc/Changelog b/doc/Changelog index 8b2cfb762..23209dabf 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,5 +1,6 @@ 8 November 2022: Wouter - Fix to ignore tcp events for closed comm points. + - Fix to make sure to not read again after a tcp comm point is closed. 21 October 2022: George - Merge #767 from jonathangray: consistently use IPv4/IPv6 in diff --git a/util/netevent.c b/util/netevent.c index 09def2e44..6ddeb076d 100644 --- a/util/netevent.c +++ b/util/netevent.c @@ -2545,8 +2545,9 @@ comm_point_tcp_handle_write(int fd, struct comm_point* c) return 1; } -/** read again to drain buffers when there could be more to read */ -static void +/** read again to drain buffers when there could be more to read, returns 0 + * on failure which means the comm point is closed. */ +static int tcp_req_info_read_again(int fd, struct comm_point* c) { while(c->tcp_req_info->read_again) { @@ -2563,9 +2564,10 @@ tcp_req_info_read_again(int fd, struct comm_point* c) (void)(*c->callback)(c, c->cb_arg, NETEVENT_CLOSED, NULL); } - return; + return 0; } } + return 1; } /** read again to drain buffers when there could be more to read */ @@ -2663,7 +2665,6 @@ comm_point_tcp_handle_callback(int fd, short event, void* arg) #endif ) { int has_tcpq = (c->tcp_req_info != NULL); - int* moreread = c->tcp_more_read_again; if(!comm_point_tcp_handle_read(fd, c, 0)) { reclaim_tcp_handler(c); if(!c->tcp_do_close) { @@ -2674,15 +2675,16 @@ comm_point_tcp_handle_callback(int fd, short event, void* arg) } return; } - if(has_tcpq && c->tcp_req_info && c->tcp_req_info->read_again) - tcp_req_info_read_again(fd, c); - if(moreread && *moreread) + if(has_tcpq && c->tcp_req_info && c->tcp_req_info->read_again) { + if(!tcp_req_info_read_again(fd, c)) + return; + } + if(c->tcp_more_read_again && *c->tcp_more_read_again) tcp_more_read_again(fd, c); return; } if(event&UB_EV_WRITE) { int has_tcpq = (c->tcp_req_info != NULL); - int* morewrite = c->tcp_more_write_again; if(!comm_point_tcp_handle_write(fd, c)) { reclaim_tcp_handler(c); if(!c->tcp_do_close) { @@ -2693,9 +2695,11 @@ comm_point_tcp_handle_callback(int fd, short event, void* arg) } return; } - if(has_tcpq && c->tcp_req_info && c->tcp_req_info->read_again) - tcp_req_info_read_again(fd, c); - if(morewrite && *morewrite) + if(has_tcpq && c->tcp_req_info && c->tcp_req_info->read_again) { + if(!tcp_req_info_read_again(fd, c)) + return; + } + if(c->tcp_more_write_again && *c->tcp_more_write_again) tcp_more_write_again(fd, c); return; }