Skip to content

unix: return EINVAL for invalid tty modes#5174

Merged
santigimeno merged 2 commits into
libuv:v1.xfrom
samuel-williams-shopify:unix-tty-invalid-mode-einval
Jun 30, 2026
Merged

unix: return EINVAL for invalid tty modes#5174
santigimeno merged 2 commits into
libuv:v1.xfrom
samuel-williams-shopify:unix-tty-invalid-mode-einval

Conversation

@samuel-williams-shopify

Copy link
Copy Markdown
Contributor

Make the Unix uv_tty_set_mode() implementation return UV_EINVAL for unrecognized uv_tty_mode_t values instead of reaching UNREACHABLE().

The Windows implementation already returns UV_EINVAL for invalid TTY modes, so this makes the behavior consistent across platforms and avoids treating caller-provided enum values as unreachable state.

Validation is performed before raw-mode normalization so invalid modes do not touch terminal state.

Refs: nodejs/node#64140

Local verification:

cmake -S . -B build -DBUILD_TESTING=ON
cmake --build build --target uv_run_tests -j4
./build/uv_run_tests tty_pty

tty_pty passed locally. tty skipped locally because this environment has no controlling /dev/tty.

@samuel-williams-shopify

Copy link
Copy Markdown
Contributor Author

Related Node.js API PR: nodejs/node#64140

That PR exposes Node's existing raw mode and libuv UV_TTY_MODE_IO through tty.ReadStream#setRawMode() while validating public string modes before calling into libuv.

@samuel-williams-shopify
samuel-williams-shopify force-pushed the unix-tty-invalid-mode-einval branch from 8c50f83 to 256d7dd Compare June 29, 2026 23:49
@santigimeno
santigimeno merged commit e949355 into libuv:v1.x Jun 30, 2026
43 of 44 checks passed
@samuel-williams-shopify
samuel-williams-shopify deleted the unix-tty-invalid-mode-einval branch June 30, 2026 23:46
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.

4 participants