Skip to content
Merged
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
8 changes: 8 additions & 0 deletions basestruct/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,14 @@ bool Utils::kernelSupportFS(const QString &fsType)

QString Utils::mkTempDir(const QString &infix)
{
qDebug() << "Utils::mkTempDir - Creating temp dir with infix:" << infix;

// 路径遍历检查:拒绝包含 ".." 的 infix
Comment on lines 662 to +666
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (performance): Consider avoiding unconditional qDebug noise in a frequently used utility

Since this helper is used in many places, an unconditional qDebug here could generate excessive logs in normal runs. If this is for troubleshooting, consider guarding it behind a debug/verbose flag or moving the logging to a higher-level caller that invokes mkTempDir.

Suggested change
QString Utils::mkTempDir(const QString &infix)
{
qDebug() << "Utils::mkTempDir - Creating temp dir with infix:" << infix;
// 路径遍历检查:拒绝包含 ".." 的 infix
QString Utils::mkTempDir(const QString &infix)
{
#ifdef QT_DEBUG
qDebug() << "Utils::mkTempDir - Creating temp dir with infix:" << infix;
#endif
// 路径遍历检查:拒绝包含 ".." 的 infix

if (infix.contains("..")) {
qWarning() << "Utils::mkTempDir - Invalid infix contains path traversal:" << infix;
return QString();
Comment on lines +667 to +669
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 suggestion (security): Path traversal mitigation likely also needs to handle slashes and absolute paths

Rejecting ".." is helpful, but infix values that include path separators ("/" or "\") or start with a slash could still affect the final path, depending on how dirTemplate and infix are combined. To avoid mkTempDir escaping the intended base directory, also reject any path separators and leading slashes, or restrict infix to a filename-like pattern (e.g., alphanumerics, dash, underscore).

}

// Construct template like "/var/tmp/diskmanager-XXXXXX" or "/var/tmp/diskmanager-INFIX-XXXXXX"
QString dirTemplate = "/var/tmp/";

Expand Down