-
Notifications
You must be signed in to change notification settings - Fork 33
fix: prevent activated surface use-after-free on logout #713
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
base: master
Are you sure you want to change the base?
Conversation
Ensure the activated surface is safely cleared when logging out or switching sessions by using QPointer and unifying the reset path through setActivatedSurface(nullptr). Log: prevent activated surface use-after-free on logout PMS: BUG-347763 Influence: logout
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: zorowk 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 |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideRefactors how the active/activated surface is cleared on session removal or switch by centralizing the logic through setActivatedSurface(nullptr) and making the activated-surface pointer a QPointer to avoid use-after-free when the underlying QObjects are destroyed, particularly during logout. Sequence diagram for activated surface reset on logout or session switchsequenceDiagram
actor User
participant SessionManager as Helper
participant Session
participant Surface as SurfaceWrapper
User->>SessionManager: logout()
SessionManager->>SessionManager: removeSession(session)
alt session is active
SessionManager->>SessionManager: m_activeSession.reset()
SessionManager->>SessionManager: setActivatedSurface(null)
SessionManager-->>Surface: QPointer cleared
SessionManager-->>SessionManager: activatedSurfaceChanged signal
else session not active
SessionManager->>SessionManager: no changes to activated surface
end
User->>SessionManager: switchSession(username, id)
SessionManager->>SessionManager: updateActiveUserSession(username, id)
SessionManager->>SessionManager: setActivatedSurface(null)
SessionManager-->>Surface: QPointer cleared
SessionManager-->>SessionManager: activatedSurfaceChanged signal
SessionManager->>SessionManager: update sockets and active session state
Updated class diagram for Helper activated surface handlingclassDiagram
class QObject
class SurfaceWrapper {
}
SurfaceWrapper --|> QObject
class Session {
}
class Helper {
- std_weak_ptr_Session m_activeSession
- QPointer~SurfaceWrapper~ m_activatedSurface
- LockScreen* m_lockScreen
- float m_animationSpeed
- OutputMode m_mode
- QList~qw_idle_inhibitor_v1*~ m_idleInhibitors
+ void removeSession(std_shared_ptr_Session session)
+ void updateActiveUserSession(QString username, int id)
+ void setActivatedSurface(SurfaceWrapper* surface)
+ void activatedSurfaceChanged()
}
Helper o--> Session
Helper o--> SurfaceWrapper
Helper o--> LockScreen
note for Helper "m_activatedSurface is now a QPointer to SurfaceWrapper to prevent use-after-free when the SurfaceWrapper QObject is destroyed"
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 left some high level feedback:
- Now that
m_activatedSurfaceis aQPointer, double-check that all remaining call sites go throughsetActivatedSurface(...)rather than assigning tom_activatedSurfacedirectly, so you don't bypass the unified signaling/cleanup path. - Given the change to
QPointer<SurfaceWrapper>, confirm thatsetActivatedSurface(nullptr)and any comparisons tom_activatedSurfacestill behave as intended when the underlyingSurfaceWrapperis deleted out from under you (e.g., nullification race conditions in logout/session-switch flows).
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Now that `m_activatedSurface` is a `QPointer`, double-check that all remaining call sites go through `setActivatedSurface(...)` rather than assigning to `m_activatedSurface` directly, so you don't bypass the unified signaling/cleanup path.
- Given the change to `QPointer<SurfaceWrapper>`, confirm that `setActivatedSurface(nullptr)` and any comparisons to `m_activatedSurface` still behave as intended when the underlying `SurfaceWrapper` is deleted out from under you (e.g., nullification race conditions in logout/session-switch flows).Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| QPointer<QQuickItem> m_taskSwitch; | ||
| QList<qw_idle_inhibitor_v1 *> m_idleInhibitors; | ||
|
|
||
| SurfaceWrapper *m_activatedSurface = nullptr; |
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.
理论上窗口销毁前, SurfaceWrapper 应该 unmapped 并发送 requestInactive 信号清理焦点
Ensure the activated surface is safely cleared when logging out or switching sessions by using QPointer and unifying the reset path through setActivatedSurface(nullptr).
Log: prevent activated surface use-after-free on logout
PMS: BUG-347763
Influence: logout
Summary by Sourcery
Bug Fixes: