[Openvpn-devel,v2] openvpnserv: only remove search domains that were added

Message ID 20261112063232.23999-1-gert@greenie.muc.de
State New
Headers
Series [Openvpn-devel,v2] openvpnserv: only remove search domains that were added |

Commit Message

Gert Doering Nov. 12, 2026, 6:32 a.m. UTC
  From: Razvan Cojocaru <razvanc@mailbox.org>

When AddDnsSearchDomains() failed, SetDnsSearchDomains() still called
RemoveDnsSearchDomains() with the new domains, which removes matching
domains already in the search list, e.g. ones configured before the
VPN connected. Record the undo data first, as done for NRPT rules, and
drop it if adding the domains fails.

Broken since ae90cbad ("dns: support multiple domains without DHCP").

Change-Id: I7ffae4da3b29521844a31d234fe6a9dd08954cf4
Signed-off-by: Razvan Cojocaru <razvanc@mailbox.org>
Acked-by: Antonio Quartulli <antonio@mandelbit.com>
Acked-by: Heiko Hund <heiko@ist.eigentlich.net>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2161
---

This change was reviewed on Gerrit and approved by at least one
developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2161
This mail reflects revision 2 of this Change.

Acked-by according to Gerrit (reflected above):
Antonio Quartulli <antonio@mandelbit.com>
Heiko Hund <heiko@ist.eigentlich.net>
  

Patch

diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c
index 81205d6..5d2abeb 100644
--- a/src/openvpnserv/interactive.c
+++ b/src/openvpnserv/interactive.c
@@ -1823,13 +1823,19 @@ 
         strncpy_s(undo_data->itf_name, sizeof(undo_data->itf_name), itf_name, _TRUNCATE);
         undo_data->domains = wide_domains;
 
-        if (AddDnsSearchDomains(list_key, have_list, wide_domains) == FALSE
-            || AddListItem(&(*lists)[undo_domains], undo_data) != NO_ERROR)
+        /* Add undo information first in case there's no heap left */
+        if (AddListItem(&(*lists)[undo_domains], undo_data) != NO_ERROR)
         {
-            RemoveDnsSearchDomains(list_key, wide_domains);
             free(wide_domains);
             free(undo_data);
-            undo_data = NULL;
+            goto out;
+        }
+
+        if (!AddDnsSearchDomains(list_key, have_list, wide_domains))
+        {
+            RemoveListItem(&(*lists)[undo_domains], CmpAny, NULL);
+            free(wide_domains);
+            free(undo_data);
             goto out;
         }
     }