]> www.infradead.org Git - users/dwmw2/openconnect.git/commitdiff
esp: Close socket on error
authorDavid Woodhouse <dwmw2@infradead.org>
Wed, 6 Apr 2022 15:43:42 +0000 (16:43 +0100)
committerDavid Woodhouse <dwmw2@infradead.org>
Wed, 6 Apr 2022 15:43:42 +0000 (16:43 +0100)
Previously we would just keep trying to read from it and consume all CPU.

Fixes: 389 (hopefully)
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
esp.c

diff --git a/esp.c b/esp.c
index d607a4e0df8bc4c707baee13dd0cea3c1abc930f..87efa438494b8c90a1a25b0ccd0a00bf6d37ecd4 100644 (file)
--- a/esp.c
+++ b/esp.c
@@ -169,8 +169,15 @@ int esp_mainloop(struct openconnect_info *vpninfo, int *timeout, int readable)
                }
                pkt = vpninfo->dtls_pkt;
                len = recv(vpninfo->dtls_fd, (void *)&pkt->esp, len + sizeof(pkt->esp), 0);
-               if (len <= 0)
-                       break;
+               if (len <= 0) {
+                       if (!len || errno == EAGAIN || errno == EWOULDBLOCK)
+                               break;
+
+                       /* On *real* errors, close the UDP socket and try again later. */
+                       vpn_perror(vpninfo, "ESP recv()");
+                       vpninfo->proto->udp_close(vpninfo);
+                       return 0;
+               }
 
                work_done = 1;