Skip to content

Commit f025ed5

Browse files
wangrong1069deepin-bot[bot]
authored andcommitted
refactor: improve udevadm command execution in getDiskInfoModel
Resolving security issues and compilation errors.
1 parent 1053d56 commit f025ed5

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

service/diskoperation/DeviceStorage.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -649,14 +649,20 @@ void DeviceStorage::getDiskInfoModel(const QString &devicePath, QString &model)
649649
}
650650
}
651651

652-
cmd = "udevadm info " + devicePath + " | grep ID_MODEL=";
653-
proc.start("bash", QStringList() << "-c" << cmd);
654-
proc.waitForFinished(-1);
655-
outPut = proc.readAllStandardOutput();
656-
if (!outPut.isEmpty()) {
657-
auto idModel = outPut.split("=", QString::SkipEmptyParts);
658-
if (idModel.count() > 1)
659-
model = idModel.at(1).trimmed();
652+
cmd = "udevadm info " + devicePath;
653+
exitcode = Utils::executCmd(cmd, outPut, error);
654+
if (exitcode != 0) {
655+
qDebug() << "Failed to execute udevadm command, error:" << error;
656+
return;
657+
}
658+
QString key = "ID_MODEL=";
659+
int start = outPut.indexOf(key);
660+
if (start != -1) {
661+
start += key.length(); // 移动到等号后面
662+
int end = outPut.indexOf('\n', start); // 找到行尾
663+
if (end == -1) end = outPut.length(); // 如果是最后一行
664+
665+
model = outPut.mid(start, end - start).trimmed();
660666
if (!model.isEmpty())
661667
return;
662668
}

0 commit comments

Comments
 (0)