[Openvpn-devel] Fix fatal error at switching remotes (#629)

Message ID 20200916131349.27668-1-themiron@yandex-team.ru
State Superseded
Headers show
Series [Openvpn-devel] Fix fatal error at switching remotes (#629) | expand

Commit Message

Vladislav Grishenko Sept. 16, 2020, 3:13 a.m. UTC
If remote server has been resolved to multiple addresses, at
least one connection attemt has been made and connection to
the last address was skipped by management - resolved earlier
link socket addrinfo objects will not be cleared neither on
instance close nor in the next connection entry loop.
This causes fatal error assert:

    >REMOTE:openvpn.net,1194,udp
    remote ACCEPT
    SUCCESS: remote command succeeded
    >REMOTE:openvpn.net,1194,udp
    remote SKIP
    SUCCESS: remote command succeeded
    >FATAL:Assertion failed at init.c:504 (c->c1.link_socket_addr.current_remote == NULL)

Fix this behaviour by cleaning stale addinfo objects.

Signed-off-by: Vladislav Grishenko <themiron@yandex-team.ru>
---
 src/openvpn/init.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

Patch

diff --git a/src/openvpn/init.c b/src/openvpn/init.c
index a785934a..508270a7 100644
--- a/src/openvpn/init.c
+++ b/src/openvpn/init.c
@@ -500,6 +500,16 @@  next_connection_entry(struct context *c)
                  */
                 if (!c->options.persist_remote_ip)
                 {
+                    if (c->c1.link_socket_addr.remote_list)
+                    {
+                        /* Connection entry addinfo objects might have been resolved
+                         * earlier but the entry itself might have been skipped by
+                         * management on the previous loop. if so, need to clear the
+                         * addrinfo objects as close_instance does */
+                        clear_remote_addrlist(&c->c1.link_socket_addr,
+                                              !c->options.resolve_in_advance);
+                    }
+
                     /* close_instance should have cleared the addrinfo objects */
                     ASSERT(c->c1.link_socket_addr.current_remote == NULL);
                     ASSERT(c->c1.link_socket_addr.remote_list == NULL);