Skip to content

Commit 0769ab6

Browse files
GongHeng2017deepin-bot[bot]
authored andcommitted
Fix: improve QProcess usage for Qt6 compatibility
- Refactored QProcess::start() calls in parseEDID() to use the modern API by separating program name and arguments instead of shell string concatenation. - Added return value validation for waitForFinished() to handle process execution failures gracefully. - Applied QString::fromLocal8Bit() to standard output reading to ensure proper text encoding handling. - These changes improve code robustness, security (avoiding shell injection risks), and compatibility with Qt6 best practices. Log: fix issue Bug: https://pms.uniontech.com/bug-view-353603.html
1 parent 8509a18 commit 0769ab6

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

deepin-devicemanager/src/Tool/commontools.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,17 @@ void CommonTools::parseEDID(const QStringList &allEDIDS, const QString &input, b
198198
QString edidStr;
199199
if (isHW) {
200200
QProcess process;
201-
process.start(QString("hexdump %1").arg(edid));
202-
process.waitForFinished(-1);
201+
process.start("hexdump", QStringList() << edid);
202+
if (!process.waitForFinished(3000)) {
203+
qCritical() << "Failed to hexdump edid file!";
204+
continue;
205+
}
203206

204-
QString deviceInfo = process.readAllStandardOutput();
205-
if (deviceInfo.isEmpty())
207+
QString deviceInfo = QString::fromLocal8Bit(process.readAllStandardOutput());
208+
if (deviceInfo.isEmpty()) {
209+
qWarning() << "The edid file is empty! " << edid;
206210
continue;
211+
}
207212

208213
QStringList lines = deviceInfo.split("\n");
209214
for (auto line:lines) {
@@ -218,11 +223,16 @@ void CommonTools::parseEDID(const QStringList &allEDIDS, const QString &input, b
218223
}
219224
} else {
220225
QProcess process;
221-
process.start(QString("hexdump -C %1").arg(edid));
222-
process.waitForFinished(-1);
223-
QString deviceInfo = process.readAllStandardOutput();
224-
if (deviceInfo.isEmpty())
226+
process.start("hexdump", QStringList() << "-C" << edid);
227+
if (!process.waitForFinished(3000)) {
228+
qCritical() << "Failed to hexdump edid file!";
225229
continue;
230+
}
231+
QString deviceInfo = QString::fromLocal8Bit(process.readAllStandardOutput());
232+
if (deviceInfo.isEmpty()) {
233+
qWarning() << "The edid file is empty! " << edid;
234+
continue;
235+
}
226236

227237
QStringList lines = deviceInfo.split("\n");
228238
for (auto line: lines) {

0 commit comments

Comments
 (0)