fix(security): replace shell exec with direct subprocess invocation#208
Conversation
There was a problem hiding this comment.
Sorry @wangrong1069, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
Eliminate /bin/bash -c pipe commands across utils, xfs, luks, partedcore, watcher and DeviceStorage. Use QProcess with explicit argument lists and pipe stdin for passwords (LUKS) and interactive input (fdisk), avoiding shell injection and credential leakage via ps. 移除 utils、xfs、luks、partedcore、watcher 及 DeviceStorage 中通过 /bin/bash -c 执行管道命令的方式,改为使用 QProcess 显式参数列表, 并通过 stdin 传入密码(LUKS)及交互输入(fdisk), 避免 shell 注入及凭据经 ps 泄漏。 Log: 重构命令执行方式,使用直接子进程调用替代 shell 管道 PMS: BUG-368007 Influence: 消除 shell 注入与命令行凭据泄漏风险,提升磁盘管理服务安全性;同时减少对 awk/grep 等外部 shell 工具的依赖。
|
Note
详情{
"service/diskoperation/DeviceStorage.cpp": [
{
"line": " QString key = \"ID_MODEL=\";",
"line_number": 510,
"rule": "S106",
"reason": "Var naming | b7cdc78177"
}
]
} |
deepin pr auto review★ 总体评分:100分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 diff --git a/service/watcher.cpp b/service/watcher.cpp
index 969decb5..e1a4f2a1 100644
--- a/service/watcher.cpp
+++ b/service/watcher.cpp
@@ -14,7 +14,6 @@
#include <QString>
-#include <QRegularExpression>
#include <QCoreApplication>
@@ -24,15 +23,13 @@ namespace DiskManager {
* 等价于管道 `ps -eo cmd | grep -w deepin-diskmanager$`。
*
*/
-bool Watcher::isFrontEndRunning(QString &error)
+bool Watcher::isFrontEndRunning(QString &err)
{
QProcess proc;
proc.start("ps", QStringList() << "-eo" << "cmd");
proc.waitForFinished(-1);
- error = proc.readAllStandardError();
+ err = proc.readAllStandardError();
- static const QRegularExpression rxMatch("(?:^|[^\\w])deepin-diskmanager$");
const QStringList lines = QString::fromLocal8Bit(proc.readAllStandardOutput()).split('\n');
for (const QString &line : lines) {
const QString exe = line.trimmed().section(' ', 0, 0, QString::SectionSkipEmpty);
- if (rxMatch.match(exe).hasMatch()) {
+ if (exe == "deepin-diskmanager" || exe.endsWith("/deepin-diskmanager")) {
return true;
}
} |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: KT-lcz, max-lvs, wangrong1069 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 |
|
/merge |
PMS: BUG-368007