runtime-tools icon indicating copy to clipboard operation
runtime-tools copied to clipboard

NewFromSpec is deprecated, but required to avoid addEnv panic from nil envMap

Open dtrudg opened this issue 3 years ago • 0 comments

The addition of Generator.envMap and its use for caching env vars requires it to be non-nil, or a call to AddProcessEnv() will panic within addEnv() at:

https://github.com/opencontainers/runtime-tools/blob/59cdde06764be8d761db120664020f0415f36045/generate/generate.go#L532

envMap is initialized in New() or NewFromSpec(). However, NewFromSpec() is marked deprecated:

// NewFromSpec creates a configuration Generator from a given
// configuration.
//
// Deprecated: Replace with:
//
//   generator := Generator{Config: config}

The replacement of creating the Generator struct directly will not initialize envMap, so a panic is possible.

Possibly use of envMap should be protected in case it is nil, and/or the non-deprecated method of creating with a config should permit initializing it?

dtrudg avatar May 11 '21 23:05 dtrudg