]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- Fix to make sure to not read again after a tcp comm point is closed.
authorW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Tue, 8 Nov 2022 12:23:44 +0000 (13:23 +0100)
committerW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Tue, 8 Nov 2022 12:23:44 +0000 (13:23 +0100)
doc/Changelog
util/netevent.c

index 8b2cfb7625e44f58a35b74093568f2ca7a00535d..23209dabffa75c4aab21e44f5901d68f1e2a8bce 100644 (file)
@@ -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
index 09def2e44b31d476a0f86d2d77e037728d56b545..6ddeb076dd128111265b01e1d6e6216a18d6a287 100644 (file)
@@ -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;
        }