Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
Apr 21, 2024

Conversation

peace-maker
Copy link
Member

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

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 Gallopsled#2366
Copy link

@intrigus-lgtm intrigus-lgtm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me and actually doesn't break my exploit script 👍

@peace-maker
Copy link
Member Author

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_is_newline 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).

Allow to control the behavior of `tube.recvline` and
be able to suppress the new warning.
@peace-maker peace-maker merged commit f2f55f3 into Gallopsled:dev Apr 21, 2024
10 of 11 checks passed
@peace-maker peace-maker deleted the tube_recvline_eof branch April 21, 2024 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tube.readline() skips the last line if it's not terminated with a newline
3 participants