From 6a6a60f5f9ffc1aa953a1c0ca3612ae396c85a15 Mon Sep 17 00:00:00 2001 From: ChinhLee <76194645+chinhkrb113@users.noreply.github.com> Date: Sun, 31 May 2026 16:57:55 +0700 Subject: [PATCH] =?UTF-8?q?fix:=20resolve=20#12475=20=E2=80=94=20p3:=20Inc?= =?UTF-8?q?onsistent=20behavior=20in=20sockets/udp=20send?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #12475 Signed-off-by: ChinhLee <76194645+chinhkrb113@users.noreply.github.com> --- .../src/bin/p3_sockets_udp_states.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/crates/test-programs/src/bin/p3_sockets_udp_states.rs b/crates/test-programs/src/bin/p3_sockets_udp_states.rs index 13afa925cb87..506a66b03f50 100644 --- a/crates/test-programs/src/bin/p3_sockets_udp_states.rs +++ b/crates/test-programs/src/bin/p3_sockets_udp_states.rs @@ -85,16 +85,34 @@ fn test_udp_connected_state_invariants(family: IpAddressFamily) { assert!(matches!(sock.set_send_buffer_size(16000), Ok(_))); } +async fn test_wrong_address_family(family: IpAddressFamily) { + let other_family = match family { + IpAddressFamily::Ipv4 => IpAddressFamily::Ipv6, + IpAddressFamily::Ipv6 => IpAddressFamily::Ipv4, + }; + let bind_address = IpSocketAddress::new(IpAddress::new_loopback(family), 0); + let remote_address = IpSocketAddress::new(IpAddress::new_loopback(other_family), 54321); + let sock = UdpSocket::create(family).unwrap(); + sock.bind(bind_address).unwrap(); + + assert!(matches!( + sock.send(b"test".into(), Some(remote_address)).await, + Err(ErrorCode::InvalidArgument) + )); +} + impl test_programs::p3::exports::wasi::cli::run::Guest for Component { async fn run() -> Result<(), ()> { test_udp_unbound_state_invariants(IpAddressFamily::Ipv4).await; test_udp_bound_state_invariants(IpAddressFamily::Ipv4); test_udp_connected_state_invariants(IpAddressFamily::Ipv4); + test_wrong_address_family(IpAddressFamily::Ipv4).await; if supports_ipv6() { test_udp_unbound_state_invariants(IpAddressFamily::Ipv6).await; test_udp_bound_state_invariants(IpAddressFamily::Ipv6); test_udp_connected_state_invariants(IpAddressFamily::Ipv6); + test_wrong_address_family(IpAddressFamily::Ipv6).await; } Ok(()) }