From 2a9f49a5c6b58a69373d9af86838498799444810 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Wed, 13 Feb 2019 16:21:55 -0800 Subject: [PATCH] make sure we don't try to load an iso into memory because of a user mistake --- common/iso_config.go | 5 +++++ common/iso_config_test.go | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/common/iso_config.go b/common/iso_config.go index 4f30580bc..75d285e11 100644 --- a/common/iso_config.go +++ b/common/iso_config.go @@ -58,6 +58,11 @@ func (c *ISOConfig) Prepare(ctx *interpolate.Context) (warnings []string, errs [ // If iso_checksum has no value use iso_checksum_url instead. if c.ISOChecksum == "" { + if strings.HasSuffix(strings.ToLower(c.ISOChecksumURL), ".iso") { + errs = append(errs, fmt.Errorf("Error parsing checksum:"+ + " .iso is not a valid checksum extension")) + return warnings, errs + } u, err := url.Parse(c.ISOChecksumURL) if err != nil { errs = append(errs, diff --git a/common/iso_config_test.go b/common/iso_config_test.go index 0a054f700..c38154f42 100644 --- a/common/iso_config_test.go +++ b/common/iso_config_test.go @@ -239,6 +239,16 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) { if i.ISOChecksum != "bar0" { t.Fatalf("should've found \"bar0\" got: %s", i.ISOChecksum) } + + // Test that we won't try to read an iso into memory because of a user + // error + i = testISOConfig() + i.ISOChecksumURL = "file:///not_read.iso" + i.ISOChecksum = "" + warns, err = i.Prepare(nil) + if err == nil { + t.Fatalf("should have error because iso is bad filetype: %s", err) + } } func TestISOConfigPrepare_ISOChecksumType(t *testing.T) {