Skip to contentSkip to conversation

In x_check_status() read errno early

PATCH In review [email protected]... 2 participants 2 messages Jul 22, 2022 – Jul 23, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 In x_check_status() read errno early

From: Selva Nair <[email protected]...>

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 function.

Reported by: Gert Doering <[email protected]...>

---
 src/openvpn/error.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
src/openvpn/error.c +3 -3
index 49ed1dbc..7cd35b17 100644
@@ -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) : "",
         description,
@@ -688,9 +691,6 @@ x_check_status(int status,
         }
 #endif
 
-        bool crt_error = false;
-        int my_errno = openvpn_errno_maybe_crt(&crt_error);
-
         if (!ignore_sys_error(my_errno, crt_error))
         {
             if (extended_msg)
Signature · 1 line
2.30.2
Acked-by on v1 1/1
#1 lore raw

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]193.149.36.253:1196

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 199.102.77.82 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 <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg24728.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering