Issue 1360221: telnetlib expect() and read_until() do not time out properly (original) (raw)
In telnetlib, expect() and read_until() take a timeout argument. Unfortunately, the timeout is applied to each individual socket read(), rather than applying a deadline to the entire expect / read_until operation. The result of this is that if a server trickles non-matching data to the client, the expect() or read_until() never times out.
In the case of expect(), it keeps building a larger and larger string of data to match with the regular expressions, leading to the eventual death of the process due to memory exhaustion.
I have attached a patch that means the timeouts occur properly, and also adds a timeout to the initial open()'s connect() call.