Skip to content

Commit

Permalink
Merge pull request #1507 from vrothberg/fix-1284
Browse files Browse the repository at this point in the history
toml decoding: report unknown keys
  • Loading branch information
mtrmac committed Mar 28, 2022
2 parents 8c27ca2 + 3a98f8f commit 5fc8f69
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion pkg/sysregistriesv2/shortnames.go
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/containers/storage/pkg/homedir"
"github.com/containers/storage/pkg/lockfile"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

// defaultShortNameMode is the default mode of registries.conf files if the
Expand Down Expand Up @@ -315,11 +316,14 @@ func (c *shortNameAliasCache) updateWithConfigurationFrom(updates *shortNameAlia
func loadShortNameAliasConf(confPath string) (*shortNameAliasConf, *shortNameAliasCache, error) {
conf := shortNameAliasConf{}

_, err := toml.DecodeFile(confPath, &conf)
meta, err := toml.DecodeFile(confPath, &conf)
if err != nil && !os.IsNotExist(err) {
// It's okay if the config doesn't exist. Other errors are not.
return nil, nil, errors.Wrapf(err, "loading short-name aliases config file %q", confPath)
}
if keys := meta.Undecoded(); len(keys) > 0 {
logrus.Debugf("Failed to decode keys %q from %q", keys, confPath)
}

// Even if we don’t always need the cache, doing so validates the machine-generated config. The
// file could still be corrupted by another process or user.
Expand Down
5 changes: 4 additions & 1 deletion pkg/sysregistriesv2/system_registries_v2.go
Expand Up @@ -877,10 +877,13 @@ func loadConfigFile(path string, forceV2 bool) (*parsedConfig, error) {

// Load the tomlConfig. Note that `DecodeFile` will overwrite set fields.
var combinedTOML tomlConfig
_, err := toml.DecodeFile(path, &combinedTOML)
meta, err := toml.DecodeFile(path, &combinedTOML)
if err != nil {
return nil, err
}
if keys := meta.Undecoded(); len(keys) > 0 {
logrus.Debugf("Failed to decode keys %q from %q", keys, path)
}

if combinedTOML.V1RegistriesConf.Nonempty() {
// Enforce the v2 format if requested.
Expand Down

0 comments on commit 5fc8f69

Please sign in to comment.