From 7661fdfcf96720560766df4dd2a04182d47bdfed Mon Sep 17 00:00:00 2001 From: Martin Pywell Date: Mon, 28 Oct 2024 10:44:50 +1100 Subject: [PATCH] common: validate iso_file input --- builder/proxmox/common/config.go | 5 +++++ builder/proxmox/common/config_test.go | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/builder/proxmox/common/config.go b/builder/proxmox/common/config.go index 4c1eb141..6ceee0de 100644 --- a/builder/proxmox/common/config.go +++ b/builder/proxmox/common/config.go @@ -678,6 +678,11 @@ func (c *Config) Prepare(upper interface{}, raws ...interface{}) ([]string, []st // (possibly to a local file) to an ISO file that will be downloaded and // then uploaded to Proxmox. if c.ISOs[idx].ISOFile != "" { + // ISOFile should match :iso/ format + res := regexp.MustCompile(`^.+:iso\/.+$`) + if !res.MatchString(c.ISOs[idx].ISOFile) { + errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("iso_path should match pattern \":iso/\". Provided value was \"%s\"", c.ISOs[idx].ISOFile)) + } c.ISOs[idx].ShouldUploadISO = false } else { c.ISOs[idx].DownloadPathKey = "downloaded_additional_iso_path_" + strconv.Itoa(idx) diff --git a/builder/proxmox/common/config_test.go b/builder/proxmox/common/config_test.go index 50cbc39d..eeec71ba 100644 --- a/builder/proxmox/common/config_test.go +++ b/builder/proxmox/common/config_test.go @@ -151,6 +151,17 @@ func TestISOs(t *testing.T) { "type": "ide", }, }, + { + name: "iso_file should fail if not correct format", + expectedToFail: true, + ISOs: map[string]interface{}{ + "type": "ide", + "cd_files": []string{ + "config_test.go", + }, + "iso_file": "local:/test.iso", + }, + }, { name: "cd_files and iso_file specified should fail", expectedToFail: true,