[Openvpn-devel] In x_check_status() read errno early

Message ID 20220722204007.7537-1-selva.nair@gmail.com
State Accepted
Headers show
Series [Openvpn-devel] In x_check_status() read errno early | expand

Commit Message

Selva Nair July 22, 2022, 10:40 a.m. UTC
From: Selva Nair <selva.nair@gmail.com>

The correct errno can get overwritten by the call to
format_extended_socket_error() which may set errno to EAGAIN
losing the original error and cause to bypass the error reporting
below. Fix by reading the errno of interest at the top of the

Reported by: Gert Doering <gert@greenie.muc.de>
Signed-off-by: Selva Nair <selva.nair@gmail.com>
 src/openvpn/error.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)


Gert Doering July 23, 2022, 2:17 a.m. UTC | #1
Acked-by: Gert Doering <gert@greenie.muc.de>

Thanks for investigating and locating the issue so quickly - I think
it would have taken me much longer to understand what really happens
(if I read it right, the code would *query* for the extended status 
just fine, gobble errno in the process, and then ignore the 
"extended_msg" later, due to ignore_sys_error() being triggered)

But anyway - we're back to "it works!"

2022-07-23 14:08:24 us=700677 UDPv6 link remote: [AF_INET6]2001:608:2:a::253:1196
W2022-07-23 14:08:24 us=727325 read UDPv6 [ECONNREFUSED]: Connection refused (fd=3,code=111)

2022-07-23 14:09:30 us=94516 UDPv4 link remote: [AF_INET]
W2022-07-23 14:09:30 us=117381 read UDPv4 [ECONNREFUSED]: Connection refused (fd=3,code=111)

and indeed, --mtu-disc yes also works again...

2022-07-23 14:15:15 write UDPv4 [EMSGSIZE Path-MTU=1300]: Message too long (fd=3,code=90)

2022-07-23 14:12:15 write UDPv6 [EMSGSIZE Path-MTU=1280]: Message too long (fd=3,code=90)

(this is triggered by adding a reduced-mtu route on a linux router in
between - "ip route add dev ppp0 mtu 1300" - so easy to
test manually, not sure yet how to do that programmatically in a 
reasonably sane way)

Your patch has been applied to the master branch.

commit 95afd63ac74197980ecff2b3ecb2116d62035f7f
Author: Selva Nair
Date:   Fri Jul 22 16:40:07 2022 -0400

     In x_check_status() read errno early

     Signed-off-by: Selva Nair <selva.nair@gmail.com>
     Acked-by: Gert Doering <gert@greenie.muc.de>
     Message-Id: <20220722204007.7537-1-selva.nair@gmail.com>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg24728.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>

kind regards,

Gert Doering


diff --git a/src/openvpn/error.c b/src/openvpn/error.c
index 49ed1dbc..7cd35b17 100644
--- a/src/openvpn/error.c
+++ b/src/openvpn/error.c
@@ -658,6 +658,9 @@  x_check_status(int status,
     const char *extended_msg = NULL;
+    bool crt_error = false;
+    int my_errno = openvpn_errno_maybe_crt(&crt_error);
     msg(x_cs_verbose_level, "%s %s returned %d",
         sock ? proto2ascii(sock->info.proto, sock->info.af, true) : "",
@@ -688,9 +691,6 @@  x_check_status(int status,
-        bool crt_error = false;
-        int my_errno = openvpn_errno_maybe_crt(&crt_error);
         if (!ignore_sys_error(my_errno, crt_error))
             if (extended_msg)