-
Notifications
You must be signed in to change notification settings - Fork 55
fix: remove bash -c for security hardening #1374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -82,9 +82,26 @@ void ShutdownApplet::x11LockScreen() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| QString originMap; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Step 1: get current keyboard options | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| process.start("bash", {"-c", "/usr/bin/setxkbmap -query | grep option | awk -F ' ' '{print $2}'"}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| process.start("/usr/bin/setxkbmap", QStringList() << "-query"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| process.waitForFinished(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| originMap = QString::fromUtf8(process.readAllStandardOutput()).trimmed(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| QString output = QString::fromUtf8(process.readAllStandardOutput()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| QStringList lines = output.split('\n'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const QString &line : lines) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 查找包含 "option" 的行(原 grep option 命令) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (line.contains("option")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 模拟 awk -F ' ' '{print $2}' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 按空格分割,跳过空字符串 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| QStringList parts = line.split(' ', Qt::SkipEmptyParts); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (parts.size() >= 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| originMap = parts[1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 如果第二个字段以冒号结尾,可能需要进一步处理 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (originMap.endsWith(':')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| originMap = originMap.left(originMap.length() - 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+91
to
+103
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (bug_risk): The trailing-colon handling may be unnecessary and could hide real values. In typical
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+88
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (bug_risk): Consider guarding against malformed output or unexpected field positions. This parsing relies on the options value always being the second non-empty token, as in the old
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Step 2: set keyboard options to un grab | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| process.start("/usr/bin/setxkbmap", {"-option", "grab:break_actions"}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (bug_risk): Tighten the line match to avoid accidental matches on unrelated text.
line.contains("option")matches the oldgrep optionbehavior but is overly broad and could pick up unrelated text (e.g. comments or localized strings). Sincesetxkbmap -queryhas a structured output, prefer a stricter condition likeline.startsWith("options:")(or similar) to ensure you only parse the intended line.