修复剩余 CodeQL 高危告警

This commit is contained in:
MengMengCode
2026-07-18 21:31:31 +08:00
parent 04cefe0cf1
commit 6bdeafccf2
3 changed files with 14 additions and 18 deletions
+5 -11
View File
@@ -4,7 +4,6 @@ import (
"os"
"path/filepath"
"runtime"
"strings"
"clicd/internal/config"
)
@@ -193,10 +192,14 @@ func CacheDir() string {
func ImagePath(id string) string {
img := FindImage(id)
ext := ".qcow2"
safeID := "__invalid_image_id__"
if img != nil {
safeID = img.ID
}
if img != nil && img.Distro == "windows" {
ext = ".iso"
}
fileName := localImageID(id) + ext
fileName := safeID + ext
for _, pool := range config.StoragePoolsForContent(config.StorageContentImages) {
candidate := filepath.Join(pool.Path, "images", "kvm", fileName)
if info, err := os.Stat(candidate); err == nil && !info.IsDir() {
@@ -210,15 +213,6 @@ func ImagePath(id string) string {
return filepath.Join(CacheDir(), fileName)
}
func localImageID(id string) string {
trimmed := strings.TrimSpace(id)
local := filepath.Base(trimmed)
if trimmed == "" || local == "." || local == ".." || local != trimmed || strings.ContainsAny(trimmed, `/\\`) {
return "__invalid_image_id__"
}
return local
}
// IsWindowsImage returns true if the image distro is "windows".
func IsWindowsImage(id string) bool {
img := FindImage(id)