mirror of
https://github.com/moby/moby.git
synced 2026-01-11 10:41:43 +00:00
daemon: disallow container port 0
Signed-off-by: Albin Kerouanton <albin.kerouanton@docker.com>
This commit is contained in:
@@ -335,7 +335,7 @@ func validateHealthCheck(healthConfig *containertypes.HealthConfig) error {
|
|||||||
|
|
||||||
func validatePortBindings(ports networktypes.PortMap) error {
|
func validatePortBindings(ports networktypes.PortMap) error {
|
||||||
for port := range ports {
|
for port := range ports {
|
||||||
if !port.IsValid() {
|
if !port.IsValid() || port.Num() == 0 {
|
||||||
return errors.Errorf("invalid port specification: %q", port.String())
|
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))
|
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) {
|
func TestFindNetworkErrorType(t *testing.T) {
|
||||||
d := Daemon{}
|
d := Daemon{}
|
||||||
_, err := d.FindNetwork("fakeNet")
|
_, err := d.FindNetwork("fakeNet")
|
||||||
|
|||||||
Reference in New Issue
Block a user