Skip to content

Map out-of-range raw OS errors to EINVAL on linux_raw - #1712

Open
stepancheg wants to merge 1 commit into
bytecodealliance:mainfrom
stepancheg:st/errno-einval-1781
Open

stepancheg wants to merge 1 commit into
bytecodealliance:mainfrom
stepancheg:st/errno-einval-1781

Conversation

@stepancheg

Copy link
Copy Markdown

Errno::from_raw_os_error asserted on values outside Linux's 1..4096 range. Return Errno::INVAL instead. This also matches the libc backend, whose from_raw_os_error does not panic.

Error handling usually runs when something is already broken, and it is not the default code path, so it tends to be less exercised. A bad errno can come from various places: an incorrectly implemented syscall, or a syscall wrapper that returns a stray value. Mapping those to EINVAL keeps the error observable without taking the process down.

Assisted-by: Cursor:auto

Comment thread src/backend/linux_raw/io/errno.rs Outdated
Comment thread src/backend/linux_raw/io/errno.rs Outdated
@stepancheg
stepancheg force-pushed the st/errno-einval-1781 branch from c2b7eb3 to 67bbf08 Compare October 18, 2026 23:09
`Errno::from_raw_os_error` asserted on values outside Linux's `1..4096`
range. Return `Errno::INVAL` instead. This also matches the libc
backend, whose `from_raw_os_error` does not panic.

Error handling usually runs when something is already broken, and it is
not the default code path, so it tends to be less exercised. A bad
`errno` can come from various places: an incorrectly implemented
syscall, or a syscall wrapper that returns a stray value. Mapping those
to `EINVAL` keeps the error observable without taking the process down.

Assisted-by: Cursor:auto
@stepancheg
stepancheg force-pushed the st/errno-einval-1781 branch from 67bbf08 to 594e8c9 Compare October 18, 2026 23:10
@stepancheg

Copy link
Copy Markdown
Author

Applied suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants