Skip to content

Commit 7441d8b

Browse files
committed
fix(grub-theme): replace unsafe shell decode with Go string processing
decodeShellValue used exec.Command("/bin/sh", "-c", "echo -n "+in) to strip shell quoting from grub config values (e.g. GRUB_GFXMODE), creating a command injection surface. Replace with Go-native string processing that strips matching surrounding quotes (single or double) directly, eliminating the shell invocation entirely. Log: 将 decodeShellValue 中的 shell 命令调用替换为 Go 原生字符串处理,消除命令注入风险 pms: BUG-364821
1 parent d9aff3c commit 7441d8b

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

adjust-grub-theme/util.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,16 @@ func eval(vars map[string]float64, expr string) (float64, error) {
141141
}
142142

143143
func decodeShellValue(in string) string {
144-
// #nosec G204
145-
output, err := exec.Command("/bin/sh", "-c", "echo -n "+in).Output()
146-
if err != nil {
147-
// fallback
148-
return strings.Trim(in, "\"")
144+
in = strings.TrimSpace(in)
145+
if len(in) >= 2 {
146+
if in[0] == '"' && in[len(in)-1] == '"' {
147+
return in[1 : len(in)-1]
148+
}
149+
if in[0] == '\'' && in[len(in)-1] == '\'' {
150+
return in[1 : len(in)-1]
151+
}
149152
}
150-
return string(output)
153+
return in
151154
}
152155

153156
const defaultGrubGfxMode = "auto"

0 commit comments

Comments
 (0)