builder/virtualbox: no panic if ssh host port min/max is same [GH-594]
This commit is contained in:
parent
b330bfd9ee
commit
6c19ba621f
|
@ -21,6 +21,7 @@ BUG FIXES:
|
||||||
* builder/amazon/all: Properly scrub access key and secret key from logs.
|
* builder/amazon/all: Properly scrub access key and secret key from logs.
|
||||||
[GH-554]
|
[GH-554]
|
||||||
* builder/openstack: Properly scrub password from logs [GH-554]
|
* builder/openstack: Properly scrub password from logs [GH-554]
|
||||||
|
* builder/virtualbox: No panic if SSH host port min/max is the same. [GH-594]
|
||||||
* common/uuid: Use cryptographically secure PRNG when generating
|
* common/uuid: Use cryptographically secure PRNG when generating
|
||||||
UUIDs. [GH-552]
|
UUIDs. [GH-552]
|
||||||
* communicator/ssh: File uploads that exceed the size of memory no longer
|
* communicator/ssh: File uploads that exceed the size of memory no longer
|
||||||
|
|
|
@ -25,9 +25,16 @@ func (s *stepForwardSSH) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
|
|
||||||
log.Printf("Looking for available SSH port between %d and %d", config.SSHHostPortMin, config.SSHHostPortMax)
|
log.Printf("Looking for available SSH port between %d and %d", config.SSHHostPortMin, config.SSHHostPortMax)
|
||||||
var sshHostPort uint
|
var sshHostPort uint
|
||||||
|
var offset uint = 0
|
||||||
|
|
||||||
portRange := int(config.SSHHostPortMax - config.SSHHostPortMin)
|
portRange := int(config.SSHHostPortMax - config.SSHHostPortMin)
|
||||||
|
if portRange > 0 {
|
||||||
|
// Have to check if > 0 to avoid a panic
|
||||||
|
offset = uint(rand.Intn(portRange))
|
||||||
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
sshHostPort = uint(rand.Intn(portRange)) + config.SSHHostPortMin
|
sshHostPort = offset + config.SSHHostPortMin
|
||||||
log.Printf("Trying port: %d", sshHostPort)
|
log.Printf("Trying port: %d", sshHostPort)
|
||||||
l, err := net.Listen("tcp", fmt.Sprintf(":%d", sshHostPort))
|
l, err := net.Listen("tcp", fmt.Sprintf(":%d", sshHostPort))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
Loading…
Reference in New Issue