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

Fix readline omitting a trailing \n #2349

Merged
merged 3 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ The table below shows which release corresponds to each branch, and what date th
[2257]: https://github.com/Gallopsled/pwntools/pull/2257
[2225]: https://github.com/Gallopsled/pwntools/pull/2225

## 4.11.2
- [#2349][2349] Fix term.readline omitting a trailing \n

[2349]: https://github.com/Gallopsled/pwntools/pull/2349

## 4.11.1 (`stable`)

- [#2271][2271] FIX: Generated shebang with path to python invalid if path contains spaces
Expand Down
9 changes: 5 additions & 4 deletions pwnlib/term/readline.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import six
import sys
import os

from pwnlib.term import keyconsts as kc
from pwnlib.term import keymap as km
Expand Down Expand Up @@ -404,7 +405,7 @@ def readline(_size=-1, prompt='', float=True, priority=10):
buffer = (buffer_left + buffer_right)
if buffer:
history.insert(0, buffer)
return force_to_bytes(buffer)
return force_to_bytes(buffer) + b'\n'
except KeyboardInterrupt:
control_c()
finally:
Expand Down Expand Up @@ -432,7 +433,7 @@ def raw_input(prompt='', float=True):
float(bool): If set to `True`, prompt and input will float to the
bottom of the screen when `term.term_mode` is enabled.
"""
return readline(-1, prompt, float)
return readline(-1, prompt, float).rstrip(os.linesep.encode())

def str_input(prompt='', float=True):
r"""str_input(prompt='', float=True)
Expand All @@ -445,7 +446,7 @@ def str_input(prompt='', float=True):
float(bool): If set to `True`, prompt and input will float to the
bottom of the screen when `term.term_mode` is enabled.
"""
return readline(-1, prompt, float).decode()
return readline(-1, prompt, float).decode().rstrip(os.linesep)

def eval_input(prompt='', float=True):
"""eval_input(prompt='', float=True)
Expand All @@ -471,7 +472,7 @@ def eval_input(prompt='', float=True):
Favorite object? 20
"""
from pwnlib.util import safeeval
return safeeval.const(readline(-1, prompt, float))
return safeeval.const(readline(-1, prompt, float).rstrip(os.linesep.encode()))

def init():
global safeeval
Expand Down
4 changes: 2 additions & 2 deletions pwnlib/tubes/tube.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,8 +900,8 @@ def recv_thread():
while not go.isSet():
if term.term_mode:
data = term.readline.readline(prompt = prompt, float = True)
if data:
data += self.newline
if data.endswith(b'\n') and self.newline != b'\n':
data = data[:-1] + self.newline
else:
stdin = getattr(sys.stdin, 'buffer', sys.stdin)
data = stdin.read(1)
Expand Down
Loading