-
Notifications
You must be signed in to change notification settings - Fork 158
Open
Description
When using NewFromTemplate(), or other similar functions, a call is made to createEnvCacheMap() to populate a map of the environment variables, used for later lookups:
func createEnvCacheMap(env []string) map[string]int {
envMap := make(map[string]int, len(env))
for i, val := range env {
envMap[val] = i
}
return envMap
}
Unfortunately, this is keying the map on the name/value pair for the environment variable, rather than just the name, so when environment variables are later added with the same name, the updated variables are not added correctly:
// addEnv looks through adds ENV to the Process and checks envMap for
// any duplicates
// This is called by both AddMultipleProcessEnv and AddProcessEnv
func (g *Generator) addEnv(env, key string) {
if idx, ok := g.envMap[key]; ok {
// The ENV exists in the cache, so change its value in g.Config.Process.Env
g.Config.Process.Env[idx] = env
} else {
// else the env doesn't exist, so add it and add it's index to g.envMap
g.Config.Process.Env = append(g.Config.Process.Env, env)
g.envMap[key] = len(g.Config.Process.Env) - 1
}
}
Here, the assumption is made that envMap is keyed by the name only.
Really, createEnvCacheMap() should perform a strings.SplitN(val, "=", 2) and use the name only for its key.
Metadata
Metadata
Assignees
Labels
No labels