Skip to content

Commit 6145628

Browse files
committed
configs/validate: audit all returned errors
All the errors returned from Validate should tell about a configuration error. Some were lacking a context, so add it. While at it, fix abusing fmt.Errorf and logrus.Warnf where the argument do not contain %-style formatting. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 34df203 commit 6145628

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

libcontainer/configs/validate/validator.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (v *ConfigValidator) Validate(config *configs.Config) error {
5252
}
5353
for _, c := range warns {
5454
if err := c(config); err != nil {
55-
logrus.WithError(err).Warnf("invalid configuration")
55+
logrus.WithError(err).Warn("invalid configuration")
5656
}
5757
}
5858
return nil
@@ -62,20 +62,17 @@ func (v *ConfigValidator) Validate(config *configs.Config) error {
6262
// to the container's root filesystem.
6363
func (v *ConfigValidator) rootfs(config *configs.Config) error {
6464
if _, err := os.Stat(config.Rootfs); err != nil {
65-
if os.IsNotExist(err) {
66-
return fmt.Errorf("rootfs (%s) does not exist", config.Rootfs)
67-
}
68-
return err
65+
return fmt.Errorf("invalid rootfs: %w", err)
6966
}
7067
cleaned, err := filepath.Abs(config.Rootfs)
7168
if err != nil {
72-
return err
69+
return fmt.Errorf("invalid rootfs: %w", err)
7370
}
7471
if cleaned, err = filepath.EvalSymlinks(cleaned); err != nil {
75-
return err
72+
return fmt.Errorf("invalid rootfs: %w", err)
7673
}
7774
if filepath.Clean(config.Rootfs) != cleaned {
78-
return fmt.Errorf("%s is not an absolute path or is a symlink", config.Rootfs)
75+
return errors.New("invalid rootfs: not an absolute path, or a symlink")
7976
}
8077
return nil
8178
}
@@ -176,7 +173,7 @@ func (v *ConfigValidator) sysctl(config *configs.Config) error {
176173
hostnet, hostnetErr = isHostNetNS(path)
177174
})
178175
if hostnetErr != nil {
179-
return hostnetErr
176+
return fmt.Errorf("invalid netns path: %w", hostnetErr)
180177
}
181178
if hostnet {
182179
return fmt.Errorf("sysctl %q not allowed in host network namespace", s)

0 commit comments

Comments
 (0)