Skip to contentSkip to conversation

dco_freebsd: replace assert() by if...return

PATCH In review Matthias Andree 2 participants 3 messages Sep 6, 2025 – Sep 8, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dco_freebsd: replace assert() by if...return

The assert() check might be optimized away in Release builds, and killing the process through abort() when input formats are bad when we already have an error message in place does not seem right.

Suggested by: Ralf Lici <[email protected]...>

---
 src/openvpn/dco_freebsd.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
src/openvpn/dco_freebsd.c +8 -2
index 931f9f68..a756dcca 100644
@@ -100,7 +100,10 @@ nvlist_to_sockaddr(const nvlist_t *nvl, struct sockaddr_storage *ss)
 
             in->sin_len = sizeof(*in);
             data = nvlist_get_binary(nvl, "address", &len);
-            assert(len == sizeof(in->sin_addr));
+            if (len != sizeof(in->sin_addr))
+            {
+                return (false);
+            }
             memcpy(&in->sin_addr, data, sizeof(in->sin_addr));
             in->sin_port = nvlist_get_number(nvl, "port");
             break;
@@ -114,7 +117,10 @@ nvlist_to_sockaddr(const nvlist_t *nvl, struct sockaddr_storage *ss)
 
             in6->sin6_len = sizeof(*in6);
             data = nvlist_get_binary(nvl, "address", &len);
-            assert(len == sizeof(in6->sin6_addr));
+            if (len != sizeof(in6->sin6_addr))
+            {
+                return (false);
+            }
             memcpy(&in6->sin6_addr, data, sizeof(in6->sin6_addr));
             in6->sin6_port = nvlist_get_number(nvl, "port");
 
Signature · 1 line
2.51.0
#1 lore raw

Hi,

Quoted 7 lines · Matthias Andree via Openvpn-devel

The assert() check might be optimized away in Release builds, and killing the process through abort() when input formats are bad when we already have an error message in place does not seem right.

Suggested by: Ralf Lici <[email protected]...>

Thanks for the patch. There has been lots of parallel work going on this weekend, and in the end it was decided to go for OpenVPN ASSERT() instead.

(Committed in master and release/2.6 as of "just now")

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#2 lore raw

Am 08.09.25 um 12:39 schrieb Gert Doering:

Quoted 7 lines

Hi,

Quoted 4 lines · Matthias Andree via Openvpn-devel

The assert() check might be optimized away in Release builds, and killing the process through abort() when input formats are bad when we already have an error message in place does not seem right.

Quoted 8 lines
Quoted 3 lines

Suggested by: Ralf Lici <[email protected]...>

Thanks for the patch. There has been lots of parallel work going on this weekend, and in the end it was decided to go for OpenVPN ASSERT() instead.

(Committed in master and release/2.6 as of "just now")

I have updated the FreeBSD port to follow suit but backported the master's patch, didn't take the one from release/2.6. Part of FreeBSD's openvpn-2.6.14_3 port and package, to be consistent with upstream.