Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,9 @@ void ModCore::deleteLineOfFileWithItem(const QString &filepath, const QString &i
{
QFile tmpfile(filepath);

if (!tmpfile.open(QIODevice::ReadWrite | QIODevice::Text))
return;

//设置文件游标到起始位置
tmpfile.seek(0);
QTextStream stream(&tmpfile);
Expand All @@ -487,7 +490,9 @@ void ModCore::deleteLineOfFileWithItem(const QString &filepath, const QString &i
#endif
//清除原有内容
tmpfile.resize(0);
tmpfile.seek(0);
stream << newcontent;
stream.flush();
tmpfile.close();
}

Expand Down Expand Up @@ -688,7 +693,7 @@ void ModCore::rmFromBlackList(const QString &modName)
}
//遍历处理/usr/lib/modprobe.d目录下文件
foreach (QString strfile, libfiles) {
rmModFromBlackListFile(etcdir.absoluteFilePath(strfile), modName);
rmModFromBlackListFile(libdir.absoluteFilePath(strfile), modName);
}
}

Expand All @@ -708,7 +713,7 @@ bool ModCore::setModLoadedOnBoot(const QString &modName)

QFileInfo fileinfo(LOADONBOOT_PROBE_DIR);
QString strfilename = QString(LOADONBOOT_FILENAME_TEMPLETE).arg(modName);
QString filepath = fileinfo.dir().absoluteFilePath(strfilename);
QString filepath = QDir(LOADONBOOT_PROBE_DIR).absoluteFilePath(strfilename);

// 路径边界检查:确保最终路径在预期目录内
if (!isPathWithinDirectory(filepath, LOADONBOOT_PROBE_DIR)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ bool isPathWithinDirectory(const QString &filePath, const QString &baseDir)

QFileInfo fileInfo(filePath);
QString canonicalPath = fileInfo.canonicalFilePath();
if (canonicalPath.isEmpty())
canonicalPath = QDir::cleanPath(fileInfo.absoluteFilePath());
if (canonicalPath.isEmpty())
return false;

Expand Down
Loading