diff --git a/CHANGELOG.md b/CHANGELOG.md index 6288559e6..7abccb64c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ BUG FIXES: * core: plugins listen explicitly on 127.0.0.1, fixing odd hangs. [GH-37] * virtualbox: `boot_wait` defaults to "10s" rather than 0. [GH-44] +* virtualbox: if `http_port_min` and max are the same, it will no longer + panic [GH-53] +* vmware: if `http_port_min` and max are the same, it will no longer + panic [GH-53] ## 0.1.0 (June 28, 2013) diff --git a/builder/virtualbox/step_http_server.go b/builder/virtualbox/step_http_server.go index 40d8b49bc..9a518a972 100644 --- a/builder/virtualbox/step_http_server.go +++ b/builder/virtualbox/step_http_server.go @@ -38,7 +38,14 @@ func (s *stepHTTPServer) Run(state map[string]interface{}) multistep.StepAction portRange := int(config.HTTPPortMax - config.HTTPPortMin) for { var err error - httpPort = uint(rand.Intn(portRange)) + config.HTTPPortMin + var offset uint = 0 + + if portRange > 0 { + // Intn will panic if portRange == 0, so we do a check. + offset = uint(rand.Intn(portRange)) + } + + httpPort = offset + config.HTTPPortMin httpAddr = fmt.Sprintf(":%d", httpPort) log.Printf("Trying port: %d", httpPort) s.l, err = net.Listen("tcp", httpAddr) diff --git a/builder/vmware/step_http_server.go b/builder/vmware/step_http_server.go index 074cd715e..af4a35beb 100644 --- a/builder/vmware/step_http_server.go +++ b/builder/vmware/step_http_server.go @@ -38,7 +38,14 @@ func (s *stepHTTPServer) Run(state map[string]interface{}) multistep.StepAction portRange := int(config.HTTPPortMax - config.HTTPPortMin) for { var err error - httpPort = uint(rand.Intn(portRange)) + config.HTTPPortMin + var offset uint = 0 + + if portRange > 0 { + // Intn will panic if portRange == 0, so we do a check. + offset = uint(rand.Intn(portRange)) + } + + httpPort = offset + config.HTTPPortMin httpAddr = fmt.Sprintf(":%d", httpPort) log.Printf("Trying port: %d", httpPort) s.l, err = net.Listen("tcp", httpAddr)