Skip to content

Commit 640f9cf

Browse files
committed
wolfio: EmbedRecvFrom: check ipv6 peer on non-ipv6 version
1 parent b4542ed commit 640f9cf

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/wolfio.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,15 @@ static int sockAddrEqual(
385385
return 0;
386386
}
387387

388+
#ifndef WOLFSSL_IPV6
389+
static int PeerIsIpv6(const SOCKADDR_S *peer, XSOCKLENT len)
390+
{
391+
if (len < sizeof(peer->ss_family))
392+
return 0;
393+
return peer->ss_family == WOLFSSL_IP6;
394+
}
395+
#endif /* !WOLFSSL_IPV6 */
396+
388397
static int isDGramSock(int sfd)
389398
{
390399
char type = 0;
@@ -425,6 +434,12 @@ int EmbedReceiveFrom(WOLFSSL *ssl, char *buf, int sz, void *ctx)
425434
peer = NULL;
426435
}
427436
else if (dtlsCtx->userSet) {
437+
#ifndef WOLFSSL_IPV6
438+
if (PeerIsIpv6((SOCKADDR_S*)dtlsCtx->peer.sa, dtlsCtx->peer.sz)) {
439+
WOLFSSL_MSG("ipv6 dtls peer set but no ipv6 support compiled");
440+
return NOT_COMPILED_IN;
441+
}
442+
#endif
428443
peer = &lclPeer;
429444
XMEMSET(&lclPeer, 0, sizeof(lclPeer));
430445
peerSz = sizeof(lclPeer);
@@ -617,6 +632,12 @@ int EmbedSendTo(WOLFSSL* ssl, char *buf, int sz, void *ctx)
617632
else if (!dtlsCtx->connected) {
618633
peer = (const SOCKADDR_S*)dtlsCtx->peer.sa;
619634
peerSz = dtlsCtx->peer.sz;
635+
#ifndef WOLFSSL_IPV6
636+
if (PeerIsIpv6(peer, peerSz)) {
637+
WOLFSSL_MSG("ipv6 dtls peer setted but no ipv6 support compiled");
638+
return NOT_COMPILED_IN;
639+
}
640+
#endif
620641
}
621642

622643
sent = (int)DTLS_SENDTO_FUNCTION(sd, buf, sz, ssl->wflags,

0 commit comments

Comments
 (0)