-
Notifications
You must be signed in to change notification settings - Fork 34
fix: fix crash on logout #675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The reason of crash is that the treeland cannot find fullServerName for default WSocket. We should provide an always-available WSocket in defaultWaylandSocket() method, instead of the socket of current session.
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts Helper’s Wayland/XWayland accessors to be const-correct and changes the "default" Wayland socket to a reserved, always-available socket for the fixed user instead of the active session’s socket, preventing crashes when logging out. Sequence diagram for resolving the default Wayland socket on logoutsequenceDiagram
actor Compositor
participant Helper
participant C_Library as C_Library_getpwnam
participant SessionManager as Session_manager
participant Session
participant WSocket
Compositor->>Helper: defaultWaylandSocket()
activate Helper
Helper->>C_Library: getpwnam(dde)
C_Library-->>Helper: passwd_struct_with_uid
Helper->>Helper: waylandSocketForUid(uid)
Helper->>SessionManager: sessionForUid(uid)
SessionManager-->>Helper: Session
Helper->>Session: access socket
Session-->>Helper: WSocket
Helper-->>Compositor: WSocket
deactivate Helper
Class diagram for Helper and session socket accessorsclassDiagram
class Helper {
+addSocket(socket WSocket*) void
+removeXWayland(xwayland WXWayland*) void
+removeSession(session std_shared_ptr_Session) void
+xwaylandForUid(uid uid_t) WXWayland* const
+waylandSocketForUid(uid uid_t) WSocket* const
+sessionForUid(uid uid_t) std_shared_ptr_Session const
+sessionForXWayland(xwayland WXWayland*) std_shared_ptr_Session const
+sessionForSocket(socket WSocket*) std_shared_ptr_Session const
+defaultWaylandSocket() WSocket* const
-m_activeSession std_weak_ptr_Session
}
class Session {
+xwayland WXWayland*
+socket WSocket*
}
class WSocket
class WXWayland
Helper "1" --> "*" Session : manages
Session "1" --> "1" WSocket : socket
Session "1" --> "1" WXWayland : xwayland
Helper ..> WSocket : returns
Helper ..> WXWayland : returns
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - I've found 1 issue, and left some high level feedback:
- In
defaultWaylandSocket(), callinggetpwnam("dde")->pw_uidwithout checking for a null return fromgetpwnamcan itself cause a crash; add a null check and a safe fallback path if the user does not exist. - Relying on a hard‑coded username "dde" in
defaultWaylandSocket()may be brittle in customized deployments; consider making this user configurable or deriving it from existing configuration/state instead of hard‑coding. - If
Helperis used from multiple threads, the use ofgetpwnam(which is not thread‑safe) indefaultWaylandSocket()could introduce data races; consider usinggetpwnam_ror resolving and caching the UID at startup.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `defaultWaylandSocket()`, calling `getpwnam("dde")->pw_uid` without checking for a null return from `getpwnam` can itself cause a crash; add a null check and a safe fallback path if the user does not exist.
- Relying on a hard‑coded username "dde" in `defaultWaylandSocket()` may be brittle in customized deployments; consider making this user configurable or deriving it from existing configuration/state instead of hard‑coding.
- If `Helper` is used from multiple threads, the use of `getpwnam` (which is not thread‑safe) in `defaultWaylandSocket()` could introduce data races; consider using `getpwnam_r` or resolving and caching the UID at startup.
## Individual Comments
### Comment 1
<location> `src/seat/helper.cpp:2382` </location>
<code_context>
- if (ptr && ptr->socket)
- return ptr->socket;
- return nullptr;
+ return waylandSocketForUid(getpwnam("dde")->pw_uid);
}
</code_context>
<issue_to_address>
**issue (bug_risk):** Guard against `getpwnam("dde")` returning `nullptr` before dereferencing.
If `getpwnam("dde")` returns `nullptr` (e.g. user missing or misconfigured), this will dereference a null pointer and crash. Store the result in a local variable, check for `nullptr`, and return `nullptr` or another fallback if the lookup fails.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: calsys456, zccrs The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
The reason of crash is that the treeland cannot find fullServerName for default WSocket. We should provide an always-available WSocket in defaultWaylandSocket() method, instead of the socket of current session.
Summary by Sourcery
Ensure the default Wayland socket lookup uses a reserved, always-available socket instead of the active session socket to prevent crashes on logout.
Bug Fixes:
Enhancements: