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

daemon/config: Validate() also validate default MTU

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

View file

@ -597,6 +597,9 @@ func Validate(config *Config) error {
} }
// TODO(thaJeztah) Validations below should not accept "0" to be valid; see Validate() for a more in-depth description of this problem // TODO(thaJeztah) Validations below should not accept "0" to be valid; see Validate() for a more in-depth description of this problem
if config.Mtu < 0 {
return fmt.Errorf("invalid default MTU: %d", config.Mtu)
}
if config.MaxConcurrentDownloads < 0 { if config.MaxConcurrentDownloads < 0 {
return fmt.Errorf("invalid max concurrent downloads: %d", config.MaxConcurrentDownloads) return fmt.Errorf("invalid max concurrent downloads: %d", config.MaxConcurrentDownloads)
} }

View file

@ -280,6 +280,15 @@ func TestValidateConfigurationErrors(t *testing.T) {
}, },
expectedErr: "123456 is not a valid domain", expectedErr: "123456 is not a valid domain",
}, },
{
name: "negative MTU",
config: &Config{
CommonConfig: CommonConfig{
Mtu: -10,
},
},
expectedErr: "invalid default MTU: -10",
},
{ {
name: "negative max-concurrent-downloads", name: "negative max-concurrent-downloads",
config: &Config{ config: &Config{
@ -397,6 +406,14 @@ func TestValidateConfiguration(t *testing.T) {
}, },
}, },
}, },
{
name: "with mtu",
config: &Config{
CommonConfig: CommonConfig{
Mtu: 1234,
},
},
},
{ {
name: "with max-concurrent-downloads", name: "with max-concurrent-downloads",
config: &Config{ config: &Config{