In TServerSocket::listen() a buffer of size 7 is allocated for the string to numeric translation of the port number, defined as int:
An input of 1000000 or more will cause stack corruption. Recommend changing sprintf to something safer, or making a larger buffer. In this case, one can safely allocate a fixed size buffer on the stack to accomodate the largest result possible, avoiding the problem. Alternatively, ensure the input is bound, which is what TSocket::localOpen() does.