Skip to content

Commit c8bd559

Browse files
fix: add path traversal check in mkTempDir function
- Implemented a validation check in the mkTempDir function to reject infix values containing "..", enhancing security against path traversal vulnerabilities. This change improves the robustness of the temporary directory creation process.
1 parent 6a54479 commit c8bd559

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

basestruct/utils.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,13 @@ bool Utils::kernelSupportFS(const QString &fsType)
817817
QString Utils::mkTempDir(const QString &infix)
818818
{
819819
qDebug() << "Utils::mkTempDir - Creating temp dir with infix:" << infix;
820+
821+
// 路径遍历检查:拒绝包含 ".." 的 infix
822+
if (infix.contains("..")) {
823+
qWarning() << "Utils::mkTempDir - Invalid infix contains path traversal:" << infix;
824+
return QString();
825+
}
826+
820827
// Construct template like "/var/tmp/diskmanager-XXXXXX" or "/var/tmp/diskmanager-INFIX-XXXXXX"
821828
QString dirTemplate = "/var/tmp/";
822829

0 commit comments

Comments
 (0)