Subject: connection fails with error binding localhost:XXX when creating new session

From: Jason Alavaliant <[email-masked]>
Date: Sat, 07 Mar 2015 15:28:59 +1300

Package: x2goclient
Version: 4.0.3.2
Severity: important

All clients trying to create a new sessions on my x2go broker setup 
started failing with the error message

Unable to create ssl tunnel:
Error binding localhost:XXX

and in each case the XXX was a port number lower than 1024

Digging through the client code and looking at the shared session 
database on the backend as far as I can tell the issue is;

1) the session database port numbers have reached values of 65000 and 
greater (for example on the last session I created the database gr_port 
was 65087)

2) the client gets given that data and adds 1000 to it 
(onmainwindows.cpp line "int iport=localGraphicPort.toInt() + 1000;")

3) the resulting port number is over the highest valid port number of 
65535 and hence later on when it is used the value overflows around to 
be port 552

4) ports under 1024 are reserved on Unix and can't be used by normal 
user processes and hence the error and the connection failing.

For now I've worked around the issue by patching the client 
onmainwindows.cpp section under the "int iport=localGraphicPort.toInt() 
+ 1000;" line to add to the various checks an extra check that sees in 
the value is over 65535 and if so to subtract 63382 which causes the 
port value to end up above the 1024 range.        I don't think this is 
a complete fix however since it only covers gr_port (which broke first 
since it gets 1000 added to it which doesn't seem to occur for 
sound_port and fs_port?) and I'm not sure if I what direction I should 
be looking at fixing this in order to make a patch that will be accepted 
upstream.

I'm suspecting this might actually be considered an bug with the 
x2goserver database code (it shouldn't set port so high?)   so I'm 
hoping you can advise on where I should be concentrating on fixing the 
code.       I'm not sure if you'll think it should be patched both in 
the client and in the server code   or if it should only be checked for 
in the server code?

Thanks
Jason