Gallopsled / pwntools

CTF framework and exploit development library
http://pwntools.com
Other
11.69k stars 1.67k forks source link

Return buffered data on first EOF in tube.readline() #2376

Closed peace-maker closed 2 months ago

peace-maker commented 3 months ago

When there is still data available in the tube buffer when an EOFError occurs in tube.recvline(), return that data even though it doesn't contain a newline. The next time tube.recvline() is called afterwards will raise EOFError normally.

This behavior is in line with the GNU readline implementation and avoids loss of data. It allows tube.stream() to print everything that's received before the receiving end terminates.

A new warning is logged when data is returned due to an EOF informing about the lack of the trailing newline character.

Fixes #2366

peace-maker commented 3 months ago

While discussing this on the CTF discord the wish for a configuration option to control the recvline behavior as well as printing of the new warning came up. Keeping it here for reference.

[PB] theKidOfArcrania: it might make sense to have some sort of configuration option for the user to explicitly state what behavior they want. that way there's a way to squelch the warning or this: https://xkcd.com/1172/ [RedRocket] Peace-Maker: Hm, some context.eof_isnewline defaulting to True? [PB] theKidOfArcrania_: so the idea im thinking is you have a tristate value either of a argument to recvline, or a context.throw_eof_on_incomplete_line where you have three settings (None where you implement default sane behavior but emit warning, False, if you want to explicitly state that you want new behavior, or True if you want old behavior and suppress the warning).