Skip to content

Validate native address families and lengths before decoding socket results #989

Closed

Description

@LunaStev

Problem

The typed address-query helpers decode successful native calls without checking the returned sockaddr family or length. Passing an IPv4 socket to net_local_addr_v6 returns success and fabricates an IPv6 address from IPv4 bytes and uninitialized trailing storage. The inverse direction can silently interpret IPv6 data as IPv4. Typed accept/receive result paths use the same unchecked approach.

Starting point: native address conversion and result helpers.

Reproduction

Audited canonical master 540728c2eb6cc12f5c69c3fb3fdb96e07ba059a4 on Linux amd64 with a checkout-built Wave 0.0.1-alpha-dev, matching checkout std, Rust 1.89.0 and LLVM 21.1.8. Executed at O0/O2 with no external network endpoint:

import("std::net::socket_base")::{net_socket_udp_v4,net_local_addr_v6,net_close};
import("std::net::address")::{SocketAddrV6,socket_addr_v6_any};
fun main() -> i32 {
    var fd: i64 = net_socket_udp_v4();
    if (fd < 0) { return 1; }
    var address: SocketAddrV6 = socket_addr_v6_any(0);
    println("status {}", net_local_addr_v6(fd, &address));
    net_close(fd);
    return 0;
}

Build/run with target/debug/wavec --std-root "$PWD/std" build repro.wave -O0 --run, then O2. Both print status 0. Expected: a reported family mismatch and unchanged output storage. This is an executed Linux result; other native platforms still need validation.

Scope

Check native family and returned length before typed result conversion for local/peer queries, accept and receive-from. Keep valid v4/v6 behavior, native errors and accepted-socket ownership correct on conversion failures. Generic accept without a requested peer address must continue accepting either supported family. Resolver-owned addresses already have their own family/length selection and should retain it.

Completion criteria

  • Opposite-family local/peer queries fail without exposing partially initialized output.
  • Typed accept/receive paths cannot decode truncated or wrong-family native storage as a valid address; no accepted socket leaks.
  • Valid v4/v6 loopback controls pass on supported native targets with their platform-specific sockaddr layouts.

Activity

  1. added
    bug
    help wanted
    on Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bughelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions