[3/3] openvpn-authenticator: Break read loop when daemon goes away

Message ID 20221206100144.4150532-3-michael.tremer@ipfire.org
State Accepted
Commit 3ee199871b038e0d0232984bc479016d4fc7e6fb
Headers
Series [1/3] openvpn-authenticator: Avoid infinite loop when losing socket connection |

Commit Message

Michael Tremer Dec. 6, 2022, 10:01 a.m. UTC
  Fixes: #12963
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
---
 config/ovpn/openvpn-authenticator | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
  

Comments

Adolf Belka Dec. 7, 2022, 12:22 p.m. UTC | #1
Tested-by: Adolf Belka <adolf.belka@ipfire.org>

On 06/12/2022 11:01, Michael Tremer wrote:
> Fixes: #12963
> Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
> ---
>   config/ovpn/openvpn-authenticator | 8 +++++++-
>   1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/config/ovpn/openvpn-authenticator b/config/ovpn/openvpn-authenticator
> index c22e08f0a..4341993e6 100644
> --- a/config/ovpn/openvpn-authenticator
> +++ b/config/ovpn/openvpn-authenticator
> @@ -68,6 +68,12 @@ class OpenVPNAuthenticator(object):
>   
>   		while True:
>   			char = self.sock.recv(1)
> +
> +			# Break if we could not read from the socket
> +			if not char:
> +				raise EOFError("Could not read from socket")
> +
> +			# Append to buffer
>   			buf.append(char)
>   
>   			# Reached end of line
> @@ -112,7 +118,7 @@ class OpenVPNAuthenticator(object):
>   					self._client_event(line)
>   
>   		# Terminate the daemon when it loses its connection to the OpenVPN daemon
> -		except ConnectionResetError as e:
> +		except (ConnectionResetError, EOFError) as e:
>   			log.error("Connection to OpenVPN has been lost: %s" % e)
>   
>   		log.info("OpenVPN Authenticator terminated")
  

Patch

diff --git a/config/ovpn/openvpn-authenticator b/config/ovpn/openvpn-authenticator
index c22e08f0a..4341993e6 100644
--- a/config/ovpn/openvpn-authenticator
+++ b/config/ovpn/openvpn-authenticator
@@ -68,6 +68,12 @@  class OpenVPNAuthenticator(object):
 
 		while True:
 			char = self.sock.recv(1)
+
+			# Break if we could not read from the socket
+			if not char:
+				raise EOFError("Could not read from socket")
+
+			# Append to buffer
 			buf.append(char)
 
 			# Reached end of line
@@ -112,7 +118,7 @@  class OpenVPNAuthenticator(object):
 					self._client_event(line)
 
 		# Terminate the daemon when it loses its connection to the OpenVPN daemon
-		except ConnectionResetError as e:
+		except (ConnectionResetError, EOFError) as e:
 			log.error("Connection to OpenVPN has been lost: %s" % e)
 
 		log.info("OpenVPN Authenticator terminated")