From: "cron2 (Code Review)" Date: Mon, 8 Dec 2025 11:34:07 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, kn@...2273... Message-ID: <0d66ca0ffe78009eb41fa3fb9b83c26ab9f3c18d-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="Vi25bxC7ZGo="; charset=UTF-8 Subject: [Openvpn-devel] [XS] Change in openvpn[master]: Prevent crash on invalid server-ipv6 argument List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: plaisthos , openvpn-devel --Vi25bxC7ZGo= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/14= 18?usp=3Demail ) Change subject: Prevent crash on invalid server-ipv6 argument ...................................................................... Prevent crash on invalid server-ipv6 argument `get_addr_generic()` expects `openvpn_getaddrinfo()` to return a newly allocated struct, but getaddrinfo(3) failure leaves `*ai =3D NULL` as-is. On OpenBSD, unlike free(3), freegetaddrinfo(3) requires a valid struct, thus callers must check the argument to avoid NULL-deref or double-free: ``` $ openvpn --server-ipv6 '' 2025-12-06 11:59:18 RESOLVE: Cannot resolve host address: :[AF_INET6] (no a= ddress associated with name) Segmentation fault (core dumped) ``` Guard against empty `ai`, i.e. failure, like similar code already does: ``` $ ./openvpn --server-ipv6 '' 2025-12-06 12:05:11 RESOLVE: Cannot resolve host address: :[AF_INET6] (no a= ddress associated with name) Options error: error parsing --server-ipv6 parameter Use --help for more information. ``` Spotted through a configuration typo "server-ipv6 fd00:/64" with 2.6.17, reproduced with and tested against 2.7rc3 on OpenBSD/amd64 7.8-current. NB: Standards are unclear wrt. freeaddrinfo(3)'s NULL handling; Linux, FreeBSD and illumos do check it and thus not crash. Github: fixes OpenVPN/openvpn#930 Change-Id: I99a6604fdfc682f9609bfe7672aa78285084dcb9 Signed-off-by: Klemens Nanni Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1418 Message-Id: <20251207210529.9949-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg34= 870.html Signed-off-by: Gert Doering --- M src/openvpn/socket.c 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c index 46bedf4..80c2895 100644 --- a/src/openvpn/socket.c +++ b/src/openvpn/socket.c @@ -189,7 +189,10 @@ *sep =3D '/'; } out: - freeaddrinfo(ai); + if (ai) + { + freeaddrinfo(ai); + } free(var_host); return ret; -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1418?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: merged Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I99a6604fdfc682f9609bfe7672aa78285084dcb9 Gerrit-Change-Number: 1418 Gerrit-PatchSet: 3 Gerrit-Owner: klemens Gerrit-Reviewer: cron2 Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel --Vi25bxC7ZGo= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 sub= mitted this change.

View Change

Prevent crash on invalid server-ipv6 argument
`get_addr_generic()` expects `openvpn_getaddrinfo()` to return a newly=
allocated struct, but getaddrinfo(3) failure leaves `*ai =3D NULL` as-i= s.

On OpenBSD, unlike free(3), freegetaddrinfo(3) requires a valid s= truct,
thus callers must check the argument to avoid NULL-deref or doubl= e-free:

```
$ openvpn --server-ipv6 ''
2025-12-06 11:5= 9:18 RESOLVE: Cannot resolve host address: :[AF_INET6] (no address associat= ed with name)
Segmentation fault (core dumped)
```

Guard again= st empty `ai`, i.e. failure, like similar code already does:

```
= $ ./openvpn --server-ipv6 ''
2025-12-06 12:05:11 RESOLVE: Cannot= resolve host address: :[AF_INET6] (no address associated with name)
Opt= ions error: error parsing --server-ipv6 parameter
Use --help for more in= formation.
```

Spotted through a configuration typo "server-= ipv6 fd00:/64" with 2.6.17,
reproduced with and tested against 2.7r= c3 on OpenBSD/amd64 7.8-current.

NB: Standards are unclear wrt. free= addrinfo(3)'s NULL handling;
Linux, FreeBSD and illumos do check= it and thus not crash.

Github: fixes OpenVPN/openvpn#930

Cha= nge-Id: I99a6604fdfc682f9609bfe7672aa78285084dcb9
Signed-off-by: Klemens= Nanni <kn@...2273...>
Acked-by: Gert Doering <gert@...1296...&= gt;
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1418
Message-I= d: <20251207210529.9949-1-gert@...1296...>
URL: https://www.mail-a= rchive.com/openvpn-devel@lists.sourceforge.net/msg34870.html
Signed-off-= by: Gert Doering <gert@...1296...>
---
M src/openvpn/socket.c1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c
index 46bedf4..80c2895 100644
--- a/src/openvpn/socket.c
+++ b/src/openvpn/socket.c
@@ -189,7 +189,10= @@
*sep =3D '/';
}
out:
- = freeaddrinfo(ai);
= + if (ai)
+ {
+ freeaddrinfo(= ai);
+ } free(var_host);

return r= et;

To view, visit change 1418. To unsubscr= ibe, or for help writing mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I99a6604fdfc682f9609bfe7672a= a78285084dcb9
Gerrit-Change-Number: 1418
Gerrit-PatchSet: 3
Gerrit-Owner: klemens <kn@...2273...>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --Vi25bxC7ZGo=--