1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

cmd/dockerd: loadDaemonCliConfig() safeguard for unparsed flags

This function depends on flags having been parsed before it's used;
add a safety-net in case this function would be called before that.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-06-06 12:17:47 +02:00
parent 0281f50efa
commit fce7ebdaa5
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
2 changed files with 5 additions and 0 deletions

View file

@ -384,6 +384,9 @@ func shutdownDaemon(d *daemon.Daemon) {
}
func loadDaemonCliConfig(opts *daemonOptions) (*config.Config, error) {
if !opts.flags.Parsed() {
return nil, errors.New(`cannot load CLI config before flags are parsed`)
}
opts.setDefaultOptions()
conf := opts.daemonConfig

View file

@ -22,6 +22,8 @@ func defaultOptions(t *testing.T, configFile string) *daemonOptions {
assert.NilError(t, err)
opts.flags.StringVar(&opts.configFile, "config-file", defaultDaemonConfigFile, "")
opts.configFile = configFile
err = opts.flags.Parse([]string{})
assert.NilError(t, err)
return opts
}