[Openvpn-devel,v1] replace assert() calls with ASSERT()

Message ID 20250907211252.23924-1-gert@greenie.muc.de
State New
Headers show
Series [Openvpn-devel,v1] replace assert() calls with ASSERT() | expand

Commit Message

Gert Doering Sept. 7, 2025, 9:12 p.m. UTC
OpenVPN's ASSERT() macro will do a bit more than the standard-libc
assert() call, namely print out which function and what expression
failed, before calling _exit(1).  Also, it can not be accidentially
compiled-away (-DNDEBUG).

Use of ASSERT() generally only advised in cases of "this must not happen,
but if it does, it's a programming or state corruption error that we
must know about".  Use of assert() is lacking the extra debug info, and as
such, not advised at all.

Change-Id: I6480d6f741c2368a0d951004b91167d5943f8f9d
Signed-off-by: Gert Doering <gert@greenie.muc.de>
Acked-by: mandree <matthias.andree@gmx.de>
---

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/+/1171
This mail reflects revision 1 of this Change.

Acked-by according to Gerrit (reflected above):
mandree <matthias.andree@gmx.de>

Comments

Gert Doering Sept. 8, 2025, 10:37 a.m. UTC | #1
As explained in the commit message, and in the discussion around #1169/#1170

Tested locally and via BB.  release/2.6 backport tested locally & via GHA.

Your patch has been applied to the master branch and release/2.6
(sort of a bugfix).  options.c hunk has been skipped (not in 2.6).

commit 88f8edbf7545dc7913d031ea12c4bae5250bb766 (master)
commit 2c57936e8fcfef65e95328b9503eeffde5c6e26a (release/2.6)
Author: Gert Doering
Date:   Sun Sep 7 23:12:46 2025 +0200

     replace assert() calls with ASSERT()

     Signed-off-by: Gert Doering <gert@greenie.muc.de>
     Acked-by: mandree <matthias.andree@gmx.de>
     Message-Id: <20250907211252.23924-1-gert@greenie.muc.de>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg32824.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/src/openvpn/dco_freebsd.c b/src/openvpn/dco_freebsd.c
index 931f9f6..65303cd 100644
--- a/src/openvpn/dco_freebsd.c
+++ b/src/openvpn/dco_freebsd.c
@@ -100,7 +100,7 @@ 
 
             in->sin_len = sizeof(*in);
             data = nvlist_get_binary(nvl, "address", &len);
-            assert(len == sizeof(in->sin_addr));
+            ASSERT(len == sizeof(in->sin_addr));
             memcpy(&in->sin_addr, data, sizeof(in->sin_addr));
             in->sin_port = nvlist_get_number(nvl, "port");
             break;
@@ -114,7 +114,7 @@ 
 
             in6->sin6_len = sizeof(*in6);
             data = nvlist_get_binary(nvl, "address", &len);
-            assert(len == sizeof(in6->sin6_addr));
+            ASSERT(len == sizeof(in6->sin6_addr));
             memcpy(&in6->sin6_addr, data, sizeof(in6->sin6_addr));
             in6->sin6_port = nvlist_get_number(nvl, "port");
 
diff --git a/src/openvpn/init.c b/src/openvpn/init.c
index 39ea8e4..2821cd4 100644
--- a/src/openvpn/init.c
+++ b/src/openvpn/init.c
@@ -319,7 +319,7 @@ 
 static unsigned int
 management_callback_remote_entry_count(void *arg)
 {
-    assert(arg);
+    ASSERT(arg);
     struct context *c = (struct context *)arg;
     struct connection_list *l = c->options.connection_list;
 
@@ -329,8 +329,8 @@ 
 static bool
 management_callback_remote_entry_get(void *arg, unsigned int index, char **remote)
 {
-    assert(arg);
-    assert(remote);
+    ASSERT(arg);
+    ASSERT(remote);
 
     struct context *c = (struct context *)arg;
     struct connection_list *l = c->options.connection_list;
diff --git a/src/openvpn/options.c b/src/openvpn/options.c
index 0616a17..6858a69 100644
--- a/src/openvpn/options.c
+++ b/src/openvpn/options.c
@@ -3486,9 +3486,9 @@ 
     {
         /* Copy --dhcp-options to tuntap_options */
         struct dhcp_options *dhcp = &dns->from_dhcp;
-        assert(sizeof(dhcp->dns) == sizeof(tt->dns));
-        assert(sizeof(dhcp->dns6) == sizeof(tt->dns6));
-        assert(sizeof(dhcp->domain_search_list) == sizeof(tt->domain_search_list));
+        ASSERT(sizeof(dhcp->dns) == sizeof(tt->dns));
+        ASSERT(sizeof(dhcp->dns6) == sizeof(tt->dns6));
+        ASSERT(sizeof(dhcp->domain_search_list) == sizeof(tt->domain_search_list));
 
         tt->domain = dhcp->domain;
         tt->dns_len = dhcp->dns_len;