Skip to content

Reject oversized POSIX descriptors before narrowing them for readiness waits #807

Closed

Description

@LunaStev

Problem

net_wait_readable and net_wait_writable accept an i64 descriptor but narrow it to i32 after checking only for negative values. 4294967295 becomes -1, which POSIX poll ignores, so an invalid descriptor is reported as a timeout. With an infinite timeout this can wait indefinitely; other large values can alias a different descriptor.

Starting points: std/net/poll.wave.

Reproduction

Linux amd64; source-built compiler at ade878134519b0f957ca28a23c6f9cd98e43dff3, LLVM 21, with the matching checkout std. The affected source files are byte-identical to canonical master 286dad9c8fcb0616f7c719c72cbf453a7d9925fd.

Save as /tmp/poll-repro.wave:

import("std::net::poll")::{net_wait_readable, net_wait_writable};
fun main() -> i32 {
    println("{} {}", net_wait_readable(4294967295, 0), net_wait_writable(4294967295, 0));
    return 0;
}
target/debug/wavec --std-root "$PWD/std" build /tmp/poll-repro.wave -O0 -o /tmp/poll-repro
/tmp/poll-repro
# Repeat with -O2.

Both O0 and O2 print 0 0. Expected: both calls reject the out-of-range descriptor, using the existing bad-descriptor error convention.

Scope

Easy: validate the POSIX descriptor range before conversion. Apply the same rule through net_wait_connected. Preserve full-width Windows socket handles and generic poll semantics for deliberately disabled negative entries.

Completion criteria

  • Reject values above the POSIX descriptor range without calling poll.
  • Cover negative values, 2147483648, 4294967295 and 4294967296, with a normal valid descriptor control.
  • Preserve Windows handle behavior; run the regression at O0/O2.

Activity

  1. added
    bug
    good first issue
    needs testing
    on Sep 29, 2026
  2. self-assigned this
    on Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

buggood first issueneeds testing

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions