mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
Merge pull request #51695 from vvoland/51684-docker-29.x
[docker-29.x backport] daemon: disallow container port 0
This commit is contained in:
@@ -335,7 +335,7 @@ func validateHealthCheck(healthConfig *containertypes.HealthConfig) error {
|
||||
|
||||
func validatePortBindings(ports networktypes.PortMap) error {
|
||||
for port := range ports {
|
||||
if !port.IsValid() {
|
||||
if !port.IsValid() || port.Num() == 0 {
|
||||
return errors.Errorf("invalid port specification: %q", port.String())
|
||||
}
|
||||
|
||||
|
||||
@@ -300,6 +300,18 @@ func TestValidateContainerIsolation(t *testing.T) {
|
||||
assert.Check(t, is.Error(err, "invalid isolation 'invalid' on "+runtime.GOOS))
|
||||
}
|
||||
|
||||
func TestInvalidContainerPort0(t *testing.T) {
|
||||
d := Daemon{}
|
||||
|
||||
hc := containertypes.HostConfig{
|
||||
PortBindings: map[network.Port][]network.PortBinding{
|
||||
network.MustParsePort("0/tcp"): {},
|
||||
},
|
||||
}
|
||||
_, err := d.verifyContainerSettings(&configStore{}, &hc, nil, false)
|
||||
assert.Error(t, err, `invalid port specification: "0/tcp"`)
|
||||
}
|
||||
|
||||
func TestFindNetworkErrorType(t *testing.T) {
|
||||
d := Daemon{}
|
||||
_, err := d.FindNetwork("fakeNet")
|
||||
|
||||
Reference in New Issue
Block a user