Skip to content

fix: add null check for QDrag after exec in DTabBarPrivate::startDrag#760

Open
18202781743 wants to merge 1 commit into
linuxdeepin:masterfrom
18202781743:master
Open

fix: add null check for QDrag after exec in DTabBarPrivate::startDrag#760
18202781743 wants to merge 1 commit into
linuxdeepin:masterfrom
18202781743:master

Conversation

@18202781743

@18202781743 18202781743 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

QDrag may be deleted by Qt's DnD framework during exec(), causing
the QPointer to become null. Check drag before accessing it after
exec() returns to prevent SIGSEGV.

Summary by Sourcery

Bug Fixes:

  • Add a null check for QDrag after exec() in DTabBarPrivate::startDrag to avoid dereferencing a deleted drag object.

@18202781743
18202781743 requested review from BLumia and mhduiy July 21, 2026 07:30
@sourcery-ai

sourcery-ai Bot commented Jul 21, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds a null check on the QPointer after exec() in DTabBarPrivate::startDrag() to prevent dereferencing a deleted drag object and causing a SIGSEGV.

Sequence diagram for updated DTabBarPrivate::startDrag drag handling

sequenceDiagram
    participant DTabBarPrivate
    participant QDrag
    participant QtDnDFramework

    DTabBarPrivate->>QDrag: exec()
    QDrag->>QtDnDFramework: startDrag
    alt drag object is deleted during exec
        QtDnDFramework-->>QDrag: delete
        QDrag-->>DTabBarPrivate: exec() returns
        DTabBarPrivate->>DTabBarPrivate: [if !drag] return
    else drag object survives
        QDrag-->>DTabBarPrivate: exec() returns
        DTabBarPrivate->>DTabBarPrivate: [if drag]
        DTabBarPrivate->>QDrag: target()
        DTabBarPrivate->>DTabBarPrivate: tabReleaseRequested / other post-drag logic
    end
Loading

File-Level Changes

Change Details Files
Guard post-exec drag handling with a null check on the QPointer to avoid dereferencing a deleted drag object.
  • Insert explanatory comment describing that Qt’s DnD framework may delete QDrag during exec(), invalidating the QPointer.
  • Add an early return if the drag pointer is null immediately after dragEnd(action) is emitted, before any further access to drag.
  • Preserve existing logic for handling IgnoreAction and non-local drag targets, now executed only when drag is still valid.
src/widgets/dtabbar.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot 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.

Hey - I've left some high level feedback:

  • Consider moving the null-check/early return closer to the exec() call so it’s immediately clear that all subsequent uses of drag in the method depend on it surviving the DnD framework.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider moving the null-check/early return closer to the exec() call so it’s immediately clear that all subsequent uses of `drag` in the method depend on it surviving the DnD framework.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码修复了拖拽操作中可能出现的空指针解引用崩溃问题,提升了应用稳定性。
逻辑正确且注释清晰,无安全漏洞,因仅涉及局部修复给予95分。

■ 【详细分析】

  • 1.语法逻辑(基本正确)✓

DTabBarPrivate::startDrag() 函数中,Q_EMIT q_func()->dragEnd(action); 执行后,添加了对 drag 指针的空检查。由于 Qt 的 DnD 框架可能在 exec() 期间删除 QDrag 对象,导致 QPointer 失效,此处的提前返回逻辑完全正确,避免了后续访问 drag->target() 时的 SIGSEGV。
潜在问题:无
建议:无需修改

  • 2.代码质量(良好)✓

新增的注释清晰地解释了为什么需要在这里进行空指针检查,说明了 QDrag 被 DnD 框架删除的背景以及避免 SIGSEGV 的目的,代码可读性高。
潜在问题:无
建议:无需修改

  • 3.代码性能(无性能问题)✓

仅增加了一次指针判空操作,开销极小,对性能没有任何负面影响。
潜在问题:无
建议:无需修改

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次修改修复了潜在的空指针解引用崩溃风险,未引入新的安全漏洞。该崩溃问题属于本地应用稳定性范畴,不构成安全漏洞。

  • 建议:无需修改

■ 【改进建议代码示例】

void DTabBarPrivate::startDrag()
{
    // ... existing code ...

    Q_EMIT q_func()->dragEnd(action);

    // QDrag may be deleted by Qt's DnD framework during exec(),
    // causing the QPointer to become null. Early-return to avoid SIGSEGV.
    if (!drag)
        return;

    if (action == Qt::IgnoreAction) {
        Q_EMIT q_func()->tabReleaseRequested(d->pressedIndex);
    } else if (drag->target() != this) {
        // ... existing code ...
    }
}

@18202781743

18202781743 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

根据堆栈查询到drag为空,目前没复现手段,在此做了规避。

            Stack trace of thread 74126:
            #0  0x00007279312592cb _ZN7QObject13doSetPropertyEPKcPK8QVariantPS2_ (libQt6Core.so.6 + 0x1a52cb)
            #1  0x0000727932a7e983 _ZN3Dtk6Widget14DTabBarPrivate9startDragEv (libdtk6widget.so.6 + 0x29b983)
            #2  0x000072793125091f _ZN7QObject5eventEP6QEvent (libQt6Core.so.6 + 0x19c91f)
            #3  0x000072793220c025 _ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent (libQt6Widgets.so.6 + 0x18b025)
            #4  0x000072793120deb8 _ZN16QCoreApplication15notifyInternal2EP7QObjectP6QEvent (libQt6Core.so.6 + 0x159eb8)
            #5  0x0000727931215d77 _ZN23QCoreApplicationPrivate16sendPostedEventsEP7QObjectiP11QThreadData (libQt6Core.so.6 + 0x161d77)
            #6  0x0000727931405507 n/a (libQt6Core.so.6 + 0x351507)
            #7  0x00007279301718e9 n/a (libglib-2.0.so.0 + 0x5a8e9)
            #8  0x00007279301739e7 n/a (libglib-2.0.so.0 + 0x5c9e7)
            #9  0x0000727930173ff0 g_main_context_iteration (libglib-2.0.so.0 + 0x5cff0)
            #10 0x0000727931402d50 _ZN20QEventDispatcherGlib13processEventsE6QFlagsIN10QEventLoop17ProcessEventsFlagEE (libQt6Core.so.6 + 0x34ed50)
            #11 0x0000727931216c2a _ZN10QEventLoop4execE6QFlagsINS_17ProcessEventsFlagEE (libQt6Core.so.6 + 0x162c2a)
            #12 0x0000727931210ce8 _ZN16QCoreApplication4execEv (libQt6Core.so.6 + 0x15cce8)
            #13 0x00005bec406d910e main (dde-file-manager + 0x1610e)
            #14 0x0000727930c7cb8a n/a (libc.so.6 + 0x27b8a)
            #15 0x0000727930c7cc45 __libc_start_main (libc.so.6 + 0x27c45)
            #16 0x00005bec406dbfd1 n/a (dde-file-manager + 0x18fd1)

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, BLumia

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

QDrag may be deleted by Qt's DnD framework during exec(), causing
the QPointer to become null. Check drag before accessing it after
exec() returns to prevent SIGSEGV.
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.

3 participants