Skip to content

Commit 09c35f8

Browse files
klemensncron2
authored andcommitted
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 = 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 address 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 address 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 #930 Change-Id: I99a6604fdfc682f9609bfe7672aa78285084dcb9 Signed-off-by: Klemens Nanni <[email protected]> Acked-by: Gert Doering <[email protected]> Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1418 Message-Id: <[email protected]> URL: https://www.mail-archive.com/[email protected]/msg34870.html Signed-off-by: Gert Doering <[email protected]> (cherry picked from commit 0ff66c0)
1 parent fa20154 commit 09c35f8

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/openvpn/socket.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,10 @@ get_addr_generic(sa_family_t af, unsigned int flags, const char *hostname,
170170
*sep = '/';
171171
}
172172
out:
173-
freeaddrinfo(ai);
173+
if (ai)
174+
{
175+
freeaddrinfo(ai);
176+
}
174177
free(var_host);
175178

176179
return ret;

0 commit comments

Comments
 (0)