Skip to content

Commit

Permalink
Exit with error when attempting to forward an unavailable port. (#164)
Browse files Browse the repository at this point in the history
Previous code has an out-of-order error check, starting a thread and *then* returning on error.  This leads to a null-pointer panic if you attempt to forward a port that is already in use.

Please enter the commit message for your changes. Lines starting

Co-authored-by: danielpaulus <[email protected]>
  • Loading branch information
briankrznarich and danielpaulus authored Oct 2, 2022
1 parent e72e44b commit 06383c6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions ios/forward/forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ func Forward(device ios.DeviceEntry, hostPort uint16, phonePort uint16) error {
log.Infof("Start listening on port %d forwarding to port %d on device", hostPort, phonePort)
l, err := net.Listen("tcp", fmt.Sprintf("0.0.0.0:%d", hostPort))

go connectionAccept(l, device.DeviceID, phonePort)

if err != nil {
return err
}

go connectionAccept(l, device.DeviceID, phonePort)

return nil
}

Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,8 @@ func handleProfileList(device ios.DeviceEntry) {
}

func startForwarding(device ios.DeviceEntry, hostPort int, targetPort int) {
forward.Forward(device, uint16(hostPort), uint16(targetPort))
err := forward.Forward(device, uint16(hostPort), uint16(targetPort))
exitIfError("failed to forward port", err)
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
<-c
Expand Down

0 comments on commit 06383c6

Please sign in to comment.