Add a little safety around variables that are passed into provisioner.

This commit is contained in:
Taliesin Sisson 2015-07-01 13:46:29 +01:00 committed by Taliesin Sisson
parent bd0b1190f6
commit 6c3030c73a
2 changed files with 6 additions and 5 deletions

View File

@ -347,8 +347,9 @@ func (p *Provisioner) createFlattenedEnvVars(elevated bool) (flattened string, e
// Split vars into key/value components
for _, envVar := range p.config.Vars {
keyValue := strings.Split(envVar, "=")
if len(keyValue) != 2 {
err = errors.New("Shell provisioner environment variables must be in key=value format")
if len(keyValue) != 2 || keyValue[0] == "" {
err = errors.New(fmt.Sprintf("Shell provisioner environment variables must be in key=value format. Currently it is '%s'", envVar))
return
}
envVars[keyValue[0]] = keyValue[1]

View File

@ -305,10 +305,10 @@ func (p *Provisioner) createFlattenedEnvVars() (flattened string, err error) {
// Split vars into key/value components
for _, envVar := range p.config.Vars {
keyValue := strings.Split(envVar, "=")
if len(keyValue) != 2 {
err = errors.New("Shell provisioner environment variables must be in key=value format")
if len(keyValue) != 2 || keyValue[0] == "" {
err = errors.New(fmt.Sprintf("Shell provisioner environment variables must be in key=value format. Currently it is '%s'", envVar))
return
}
}
envVars[keyValue[0]] = keyValue[1]
}
// Create a list of env var keys in sorted order