res_pjproject: Fix DTLS client check failing on some platforms

Certain platforms (mainly BSD derivatives) have an additional length
field in `sockaddr_in6` and `sockaddr_in`.
`ast_sockaddr_from_pj_sockaddr()` does not take this field into account
when copying over values from the `pj_sockaddr` into the `ast_sockaddr`.
The resulting `ast_sockaddr` will have an uninitialized value for
`sin6_len`/`sin_len` while the other `ast_sockaddr` (not converted from
a `pj_sockaddr`) to check against in `ast_sockaddr_pj_sockaddr_cmp()`
has the correct length value set.

This has the effect that `ast_sockaddr_cmp()` will always indicate
an address mismatch, because it does a bitwise comparison, and all DTLS
packets are dropped even if addresses and ports match.

`ast_sockaddr_from_pj_sockaddr()` now checks whether the length fields
are available on the current platform and sets the values accordingly.

Resolves: #505
(cherry picked from commit 5f9cd260ac)
This commit is contained in:
Albrecht Oster
2025-04-10 23:54:00 +02:00
committed by Asterisk Development Team
parent a6dca5bf3a
commit 7ce8720528
4 changed files with 32 additions and 0 deletions

View File

@@ -560,6 +560,9 @@ int ast_sockaddr_from_pj_sockaddr(struct ast_sockaddr *addr, const pj_sockaddr *
{
if (pjaddr->addr.sa_family == pj_AF_INET()) {
struct sockaddr_in *sin = (struct sockaddr_in *) &addr->ss;
#if defined(HAVE_STRUCT_SOCKADDR_IN_SIN_LEN)
sin->sin_len = sizeof(struct sockaddr_in);
#endif
sin->sin_family = AF_INET;
#if defined(HAVE_PJPROJECT_BUNDLED) && !defined(HAVE_PJPROJECT_BUNDLED_OOT)
sin->sin_addr = pjaddr->ipv4.sin_addr;
@@ -571,6 +574,9 @@ int ast_sockaddr_from_pj_sockaddr(struct ast_sockaddr *addr, const pj_sockaddr *
addr->len = sizeof(struct sockaddr_in);
} else if (pjaddr->addr.sa_family == pj_AF_INET6()) {
struct sockaddr_in6 *sin = (struct sockaddr_in6 *) &addr->ss;
#if defined(HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN)
sin->sin6_len = sizeof(struct sockaddr_in6);
#endif
sin->sin6_family = AF_INET6;
sin->sin6_port = pjaddr->ipv6.sin6_port;
sin->sin6_flowinfo = pjaddr->ipv6.sin6_flowinfo;