Skip to content

generate: key envMap by variable name rather than full env string#810

Open
crawfordxx wants to merge 1 commit into
opencontainers:masterfrom
crawfordxx:fix-createenvcachemap-use-name-as-key
Open

generate: key envMap by variable name rather than full env string#810
crawfordxx wants to merge 1 commit into
opencontainers:masterfrom
crawfordxx:fix-createenvcachemap-use-name-as-key

Conversation

@crawfordxx

Copy link
Copy Markdown

Problem

createEnvCacheMap stores the entire env string (KEY=value) as the map key. The addEnv method looks entries up by just the variable name (KEY), so every lookup misses and AddProcessEnv/RemoveProcessEnv always append a new entry rather than replacing the existing one. Callers that override a pre-existing environment variable silently get duplicate entries.

Fix

Key envMap by the variable name only (the part before the first =), which is what addEnv and all callers expect.

-envMap[val] = i           // key is "KEY=value"
+name, _, _ := strings.Cut(val, "=")
+envMap[name] = i          // key is "KEY"

Impact

Downstream users such as containerd's NRI plugin (which calls AddProcessEnv/RemoveProcessEnv to apply NRI container adjustments) are affected: env-var overrides for pre-existing container env vars are silently dropped.

createEnvCacheMap was storing the full 'KEY=value' string as the map
key. addEnv looks entries up by just the variable name ('KEY'), so every
lookup missed and AddProcessEnv/RemoveProcessEnv always appended a new
entry instead of replacing the existing one.

Fix by extracting the name part (everything before the first '=') and
using that as the map key, consistent with how addEnv performs lookups.

Signed-off-by: crawfordxx <crawfordxx@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant