Skip to content

Commit eb7e2c3

Browse files
committed
Merge branch 'beta' into dev
2 parents 2b7ec5e + 4c0e08c commit eb7e2c3

File tree

5 files changed

+25
-13
lines changed

5 files changed

+25
-13
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ The table below shows which release corresponds to each branch, and what date th
143143
[2257]: https://github.com/Gallopsled/pwntools/pull/2257
144144
[2225]: https://github.com/Gallopsled/pwntools/pull/2225
145145

146+
## 4.11.2
147+
- [#2349][2349] Fix term.readline omitting a trailing \n
148+
- [#2352][2352] add `RETURN_CONST` as an allowed `_const_code` in safeeval
149+
150+
[2349]: https://github.com/Gallopsled/pwntools/pull/2349
151+
[2352]: https://github.com/Gallopsled/pwntools/pull/2352
152+
146153
## 4.11.1 (`stable`)
147154

148155
- [#2271][2271] FIX: Generated shebang with path to python invalid if path contains spaces

pwnlib/term/readline.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import io
77
import six
88
import sys
9+
import os
910

1011
from pwnlib.term import keyconsts as kc
1112
from pwnlib.term import keymap as km
@@ -405,7 +406,7 @@ def readline(_size=-1, prompt='', float=True, priority=10):
405406
buffer = (buffer_left + buffer_right)
406407
if buffer:
407408
history.insert(0, buffer)
408-
return force_to_bytes(buffer)
409+
return force_to_bytes(buffer) + b'\n'
409410
except KeyboardInterrupt:
410411
do_raise = False
411412
try:
@@ -436,7 +437,7 @@ def raw_input(prompt='', float=True):
436437
float(bool): If set to `True`, prompt and input will float to the
437438
bottom of the screen when `term.term_mode` is enabled.
438439
"""
439-
return readline(-1, prompt, float)
440+
return readline(-1, prompt, float).rstrip(os.linesep.encode())
440441

441442
def str_input(prompt='', float=True):
442443
r"""str_input(prompt='', float=True)
@@ -449,7 +450,7 @@ def str_input(prompt='', float=True):
449450
float(bool): If set to `True`, prompt and input will float to the
450451
bottom of the screen when `term.term_mode` is enabled.
451452
"""
452-
return readline(-1, prompt, float).decode()
453+
return readline(-1, prompt, float).decode().rstrip(os.linesep)
453454

454455
def eval_input(prompt='', float=True):
455456
"""eval_input(prompt='', float=True)
@@ -475,7 +476,7 @@ def eval_input(prompt='', float=True):
475476
Favorite object? 20
476477
"""
477478
from pwnlib.util import safeeval
478-
return safeeval.const(readline(-1, prompt, float))
479+
return safeeval.const(readline(-1, prompt, float).rstrip(os.linesep.encode()))
479480

480481
def init():
481482
global safeeval

pwnlib/tubes/ssh.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -951,15 +951,19 @@ def process(self, argv=None, executable=None, tty=True, cwd=None, env=None, igno
951951
python = ssh_process(self, script, tty=True, cwd=cwd, raw=True, level=self.level, timeout=timeout)
952952

953953
try:
954-
python.recvline_contains(b'PWNTOOLS') # Magic flag so that any sh/bash initialization errors are swallowed
955-
python.recvline() # Python interpreter that was selected
954+
python.recvline_contains(b'PWNTOOLS') # Magic flag so that any sh/bash initialization errors are swallowed
955+
try:
956+
if b'python' not in python.recvline(): # Python interpreter that was selected
957+
raise ValueError("Python not found on remote host")
958+
except (EOFError, ValueError):
959+
self.warn_once('Could not find a Python interpreter on %s\n' % self.host
960+
+ "Use ssh.system() instead of ssh.process()\n")
961+
h.failure("Process creation failed")
962+
return None
963+
956964
result = safeeval.const(python.recvline()) # Status flag from the Python script
957965
except (EOFError, ValueError):
958966
h.failure("Process creation failed")
959-
self.warn_once('Could not find a Python interpreter on %s\n' % self.host
960-
+ "Use ssh.run() instead of ssh.process()\n"
961-
"The original error message:\n"
962-
+ python.recvall().decode())
963967
return None
964968

965969
# If an error occurred, try to grab as much output

pwnlib/tubes/tube.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -900,8 +900,8 @@ def recv_thread():
900900
while not go.is_set():
901901
if term.term_mode:
902902
data = term.readline.readline(prompt = prompt, float = True)
903-
if data:
904-
data += self.newline
903+
if data.endswith(b'\n') and self.newline != b'\n':
904+
data = data[:-1] + self.newline
905905
else:
906906
stdin = getattr(sys.stdin, 'buffer', sys.stdin)
907907
data = stdin.read(1)

pwnlib/util/safeeval.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
'BUILD_CONST_KEY_MAP', 'BUILD_STRING',
77
'LOAD_CONST','RETURN_VALUE','STORE_SUBSCR', 'STORE_MAP',
88
'LIST_TO_TUPLE', 'LIST_EXTEND', 'SET_UPDATE', 'DICT_UPDATE', 'DICT_MERGE',
9-
'COPY', 'RESUME',
9+
'COPY', 'RESUME', 'RETURN_CONST'
1010
]
1111

1212
_expr_codes = _const_codes + [

0 commit comments

Comments
 (0)