Skip to content

Commit

Permalink
Prevent using port 0 with address_mode=driver
Browse files Browse the repository at this point in the history
  • Loading branch information
schmichael committed Dec 8, 2017
1 parent 9a3ed8b commit 837c7ad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions command/agent/consul/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,9 @@ func getAddress(addrMode, portLabel string, networks structs.Networks, driverNet
if err != nil {
return "", 0, fmt.Errorf("invalid port %q: %v", portLabel, err)
}
if port == 0 {
return "", 0, fmt.Errorf("invalid port: %q: port 0 is invalid", portLabel)
}

return driverNet.IP, port, nil

Expand Down
9 changes: 9 additions & 0 deletions command/agent/consul/unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1541,6 +1541,15 @@ func TestGetAddress(t *testing.T) {
},
ErrContains: "invalid port",
},
{
Name: "DriverZeroPort",
Mode: structs.AddressModeDriver,
PortLabel: "0",
Driver: &cstructs.DriverNetwork{
IP: "10.1.2.3",
},
ErrContains: "invalid port",
},
{
Name: "HostBadPort",
Mode: structs.AddressModeHost,
Expand Down

0 comments on commit 837c7ad

Please sign in to comment.