Skip to content

fix(linux): report a failed display open as Unavailable in raw display handles - #1351

Merged
Legend-Master merged 2 commits into
tauri-apps:devfrom
marrionesa:fix/display-handle-null-checks
Oct 5, 2026
Merged

Legend-Master merged 2 commits into
tauri-apps:devfrom
marrionesa:fix/display-handle-null-checks

Conversation

@marrionesa

Copy link
Copy Markdown
Contributor

Description

Fixes #1347.

Both Linux raw_display_handle_rwh_06 implementations (event_loop.rs and window.rs) passed a failed XOpenDisplay result (null) into XDefaultScreen and then into NonNull::new_unchecked. The first is undefined behavior in Xlib, the second is undefined behavior in Rust (unwrap of a null pointer) — and both happen inside a safe pub fn that already returns Result. The Wayland branch had the same shape: gdk_wayland_display_get_wl_display was unwrapped with NonNull::new_unchecked without a null check.

With this change:

  • X11 (rwh_06, both files): a null return from XOpenDisplay now yields Err(HandleError::Unavailable); XDefaultScreen is only called with a valid display, and the handle is only built from a checked NonNull.
  • Wayland (rwh_06, both files): a null wl_display now yields Err(HandleError::Unavailable) instead of NonNull::new_unchecked UB.
  • X11 (rwh_05, both files): there is no error path in the 0.5 API, so the handle keeps the pre-existing "null display" shape on failure, but XDefaultScreen(NULL) (also UB) is no longer called — the fields are simply left empty.

rwh_06::HandleError::Unavailable is the same error the functions already return when the x11 feature is disabled or Xlib::open() fails, so consumers already have to handle this variant; this change only makes the code stop UB-ing on the way to it.

Testing

  • cargo check -p tao and cargo check -p tao --features rwh_05: clean (the rwh_05 code is not compiled by default features, the fixed X11/XWayland paths are).
  • cargo clippy -p tao --features rwh_05: no warnings on the touched files.
  • cargo test -p tao: all pass.
  • Happy-path check (examples/display_handle_check.rs, kept out of this PR, in #16089-style standalone fashion) on Linux: display_handle() returns Ok with both GDK_BACKEND=x11 (Xlib handle with valid display + screen) and Wayland (default backend on the test machine), so the success path of the reworked branches is exercised end to end.
  • The failure path itself cannot be triggered without either breaking GTK initialization first or exhausting the X server connection limit (the scenario of [bug] App::run_iteration with X11 spams connections #677); the change is a pure null-check on values that were previously new_unchecked'd, so it only converts a UB path into the already-existing Err variant.

…y handles

Both Linux `raw_display_handle_rwh_06` implementations passed a failed
(null) `XOpenDisplay` result into `XDefaultScreen` and
`NonNull::new_unchecked`, which is undefined behavior in Xlib and in
Rust respectively, in a safe `pub fn` returning `Result`. The Wayland
branch did the same with `gdk_wayland_display_get_wl_display` without a
null check. Both now return `Err(HandleError::Unavailable)` on a null
display. The `rwh_05` variants also skip calling `XDefaultScreen` on a
null display (no error path is available there).

Fixes tauri-apps#1347
@marrionesa
marrionesa requested a review from a team as a code owner September 26, 2026 19:57
Copilot AI lite review requested due to automatic review settings September 26, 2026 19:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The reviewed changes safely address the reported Linux display-handle failures.

Review effort: Lite
Findings: None

What changed in this PR

Fixes Linux raw display handle undefined behavior by safely handling unavailable X11 and Wayland displays.

Changes:

  • Checks null X11 and Wayland display pointers.
  • Returns HandleError::Unavailable for rwh_06 failures.
  • Avoids XDefaultScreen(NULL) for rwh_05.
  • Adds a changelog entry.
File Description
src/​platform_impl/​linux/​window.rs Adds X11 and Wayland null checks.
src/​platform_impl/​linux/​event_loop.rs Adds X11 and Wayland null checks.
.changes/​fix-display-handle-null-checks.md Documents the fix.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/platform_impl/linux/event_loop.rs Resolved
Comment thread src/platform_impl/linux/window.rs Resolved
Comment thread src/platform_impl/linux/window.rs Resolved
Comment thread src/platform_impl/linux/window.rs Resolved
@Legend-Master

Copy link
Copy Markdown
Contributor

The idea looks good to me by the way, thanks.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The reviewed changes address the null-pointer safety issues without unresolved blockers.

Review effort: Lite
Findings: None

@marrionesa marrionesa left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed redundant display handle comments

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Package Changes Through 9f977dd

There are 1 changes which include tao with patch

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
tao 0.37.1 0.37.2

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

@Legend-Master
Legend-Master merged commit 3fcda65 into tauri-apps:dev Oct 5, 2026
20 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 5, 2026
@marrionesa
marrionesa deleted the fix/display-handle-null-checks branch October 5, 2026 03:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

raw_display_handle_rwh_06 turns a failed XOpenDisplay into UB

3 participants