Skip to content

fix: move hyphen to end of regex char class - #233

Open
wangrong1069 wants to merge 1 commit into
linuxdeepin:masterfrom
wangrong1069:agent/agent/08cee2157677
Open

wangrong1069 wants to merge 1 commit into
linuxdeepin:masterfrom
wangrong1069:agent/agent/08cee2157677

Conversation

@wangrong1069

@wangrong1069 wangrong1069 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Root Cause Analysis

When creating an SM4 encrypted partition, the password input dialog rejects all keystrokes on Qt6 builds. The root cause is in the Qt6 code path of passwordinputdialog.cpp and decryptdialog.cpp: the regex character class fragment _-+ is interpreted by PCRE2 (QRegularExpression) as a descending range from _ (0x5F) to + (0x2B), which is invalid. An invalid range makes the entire QRegularExpression object invalid, so QRegularExpressionValidator rejects every character, leaving the password field unable to accept any input. The Qt5 QRegExp engine was more lenient and did not exhibit this behavior.

Fix

Move the hyphen (-) from the _-+ position to the very end of the character class (right before ]), where PCRE2 treats it as a literal hyphen instead of a range operator. Applied to both passwordinputdialog.cpp (line 83, Qt6 branch) and decryptdialog.cpp (line 70, Qt6 branch). The Qt5 code paths are left unchanged.

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • The change only repositions a single character within a regex string literal; no function signatures, public APIs, or call contracts are modified.
  • The target regex was introduced in the initial "feat: 新增解密功能" commit and was never separately fixed; this change does not revert any historical fix.

Business Impact Scope

  • SM4 encryption password input (passwordinputdialog.cpp): password fields in the partition creation dialog now accept input on Qt6 builds.
  • LUKS decryption password input (decryptdialog.cpp): password field in the decrypt dialog now accepts input on Qt6 builds.
  • Qt5 builds are unaffected.

Verification Suggestion

Test creating an SM4 encrypted partition and typing a password (including hyphens and special characters). Test the LUKS decrypt dialog password input. Verify Qt5 builds have no behavior change.


根因分析

创建 SM4 加密分区时,密码输入对话框在 Qt6 构建下拒绝所有按键输入。根因在于 passwordinputdialog.cpp 和 decryptdialog.cpp 的 Qt6 代码路径中,正则表达式字符类片段 _-+ 被 PCRE2(QRegularExpression)解释为从 _ (0x5F) 到 + (0x2B) 的降序范围,属于无效范围。无效范围导致整个 QRegularExpression 对象无效,QRegularExpressionValidator 拒绝所有字符,密码输入框无法输入任何内容。Qt5 的 QRegExp 引擎对此更宽松,未出现此问题。

修复方案

将连字符(-)从 _-+ 位置移至字符类末尾(紧邻 ] 之前),此时 PCRE2 将其作为字面量而非范围运算符处理。同时修复 passwordinputdialog.cpp(第 83 行,Qt6 分支)和 decryptdialog.cpp(第 70 行,Qt6 分支)。Qt5 代码路径保持不变。

改动安全评估

代码安全评估

  • 风险等级: 低风险
  • 改动仅将正则表达式字符串字面量中的单个字符重新定位,不涉及函数签名、公开 API 或调用契约的修改。
  • 目标正则自初始"feat: 新增解密功能"提交引入以来未被单独修复过,本次改动不撤销任何历史修复。

业务影响范围

  • SM4 加密密码输入(passwordinputdialog.cpp):分区创建对话框中的密码字段在 Qt6 构建下现在可以正常输入。
  • LUKS 解密密码输入(decryptdialog.cpp):解密对话框中的密码字段在 Qt6 构建下现在可以正常输入。
  • Qt5 构建不受影响。

验证建议

测试创建 SM4 加密分区时输入密码(含连字符和特殊字符)。测试 LUKS 解密对话框的密码输入。验证 Qt5 构建下行为无变化。

Summary by Sourcery

Bug Fixes:

  • Fix Qt6 password validators in the SM4 partition creation and LUKS decryption dialogs so they accept valid password input.

1. Root cause: in the Qt6 code path the password validator regex used
   the character class fragment _-+ which PCRE2 interprets as a
   descending range from _ (0x5F) to + (0x2B); an invalid range makes
   the whole QRegularExpression invalid, so QRegularExpressionValidator
   rejects every keystroke and the password field accepts no input
2. Fix: move the hyphen from the _-+ position to the very end of the
   character class (right before ]), where it is treated as a literal
   hyphen instead of a range operator; applied to both
   passwordinputdialog.cpp and decryptdialog.cpp Qt6 branches
3. Impact: the Qt6 password input fields for SM4 encryption and LUKS
   decryption now accept all intended characters including hyphens;
   Qt5 code path is unchanged

Log: fix password input field rejecting all characters on Qt6 builds

Influence:
1. Test creating an SM4 encrypted partition and typing a password
2. Test the LUKS decrypt dialog password input field
3. Verify passwords containing hyphens are accepted
4. Verify passwords with special characters still work as before

fix: 将连字符移至正则表达式字符类末尾

1. 根因:Qt6 代码路径中密码校验器正则表达式使用字符类片段 _-+,
   PCRE2 将其解释为从 _ (0x5F) 到 + (0x2B) 的降序范围;无效范围
   导致整个 QRegularExpression 无效,QRegularExpressionValidator
   拒绝所有按键,密码输入框无法输入任何内容
2. 方案:将连字符从 _-+ 位置移至字符类末尾(紧邻 ] 之前),此时
   连字符作为字面量而非范围运算符;同时修复 passwordinputdialog.cpp
   和 decryptdialog.cpp 的 Qt6 分支
3. 影响:Qt6 下 SM4 加密和 LUKS 解密的密码输入框现在可以正常输入
   所有预期字符(含连字符);Qt5 代码路径不受影响

Log: 修复 Qt6 构建下密码输入框无法输入任何字符的问题

Influence:
1. 测试创建 SM4 加密分区时输入密码
2. 测试 LUKS 解密对话框的密码输入框
3. 验证包含连字符的密码可以正常输入
4. 验证包含特殊字符的密码仍可正常使用

PMS: BUG-309977
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: wangrong1069

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

@sourcery-ai

sourcery-ai Bot commented Oct 28, 2026

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

Reviewer's Guide

The PR fixes Qt6 password fields rejecting all input by making the shared validator regex valid under PCRE2 in both SM4 partition creation and LUKS decryption dialogs; the change is limited to regex literals and does not affect Qt5 behavior.

Flow diagram for the Qt6 password validator fix

flowchart LR
    A[Password input dialog] --> B{Qt version}
    B -->|Qt6| C[QRegularExpressionValidator]
    C --> D[Valid character class with hyphen at end]
    D --> E[Password input accepted]
    B -->|Qt5| F[QRegExpValidator unchanged]
Loading

File-Level Changes

Change Details Files
Correct the Qt6 password validators so PCRE2 treats the hyphen as a literal character rather than an invalid range operator.
  • Move the hyphen to the end of the allowed character class.
  • Apply the equivalent regex correction to both password-entry dialogs while leaving Qt5 validators unchanged.
application/widgets/customcontrol/passwordinputdialog.cpp
application/widgets/decryptdialog.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 found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="application/widgets/customcontrol/passwordinputdialog.cpp" line_range="83" />
<code_context>
 #if QT_VERSION_MAJOR > 5
     qDebug() << "QT_VERSION_MAJOR > 5, setting regular expression validator";
-    QRegularExpression regExp("^[A-Za-z0-9`~!@#$%^&*()_-+=<>,.\\/ ]+$");
+    QRegularExpression regExp("^[A-Za-z0-9`~!@#$%^&*()_+=<>,.\\/ -]+$");
     QRegularExpressionValidator *regExpValidator = new QRegularExpressionValidator(regExp, this);
 #else
</code_context>
<issue_to_address>
**Passwords are written to logs**

When a Qt6 user enters a password and submits an encryption or decryption operation, `Utils::executWithInputOutputCmd` logs `*inPut` verbatim at `basestruct/utils.cpp:155`; the enabled dialogs pass the entered password to that helper as cryptsetup input, so plaintext passwords are written to debug logs.

Remove or redact the input logging in `Utils::executWithInputOutputCmd`.

Also at `application/widgets/decryptdialog.cpp:70`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

#if QT_VERSION_MAJOR > 5
qDebug() << "QT_VERSION_MAJOR > 5, setting regular expression validator";
QRegularExpression regExp("^[A-Za-z0-9`~!@#$%^&*()_-+=<>,.\\/ ]+$");
QRegularExpression regExp("^[A-Za-z0-9`~!@#$%^&*()_+=<>,.\\/ -]+$");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Passwords are written to logs

When a Qt6 user enters a password and submits an encryption or decryption operation, Utils::executWithInputOutputCmd logs *inPut verbatim at basestruct/utils.cpp:155; the enabled dialogs pass the entered password to that helper as cryptsetup input, so plaintext passwords are written to debug logs.

Remove or redact the input logging in Utils::executWithInputOutputCmd.

Also at application/widgets/decryptdialog.cpp:70.

Prompt for AI agents
In `application/widgets/customcontrol/passwordinputdialog.cpp` at line 83:

**Passwords are written to logs**

When a Qt6 user enters a password and submits an encryption or decryption operation, `Utils::executWithInputOutputCmd` logs `*inPut` verbatim at `basestruct/utils.cpp:155`; the enabled dialogs pass the entered password to that helper as cryptsetup input, so plaintext passwords are written to debug logs.

Remove or redact the input logging in `Utils::executWithInputOutputCmd`.

Also at `application/widgets/decryptdialog.cpp:70`.

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 100 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交将正则表达式字符类中的连字符从中间位置(_-+)移至末尾(-]), 修复了连字符被误解析为范围运算符的问题。修改涉及2个文件共2处,变更最小化且聚焦, 语法正确、逻辑清晰,无安全漏洞引入,且实际改善了输入校验的准确性。

|


🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['修改已正确,无需额外调整。']


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['正则模式在多个文件中重复,建议后续重构时考虑提取为共享常量,但不在本次提交范围内。']


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['无性能优化建议。']


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: ['无安全加固建议,修复本身提升了输入校验的准确性。']


💡 改进建议代码示例

// passwordinputdialog.cpp & decryptdialog.cpp
// 修复后的正则表达式(连字符移至字符类末尾):
QRegularExpression regExp("^[A-Za-z0-9`~!@#$%^&*()_+=<>,.\\/ -]+$");
// 连字符 `-` 放在字符类末尾,确保被当作字面量匹配,而非范围运算符

本报告由 AI 代码审查工具自动生成

@deepin-bot

deepin-bot Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.0.28
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #251

@deepin-bot

deepin-bot Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.0.29
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #259

@deepin-bot

deepin-bot Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.0.30
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #261

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.

2 participants