• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Gallopsled / pwntools / 1

18 May 2023 08:32PM UTC coverage: 19.336% (-54.2%) from 73.494%
1

push

github

web-flow
Handle `context.newline` correctly in `tube.interactive()` (#2129)

* Handle `context.newline` correctly in `tube.interactive()`

The `context.newline` or `self.newline` variable isn't obeyed when typing in interactive mode. It is used when sending and receiving lines through `tube.sendline` though, causing a mismatch.

The receiving end of the `tube.interactive()` already has handling of newlines, but the sending side does not.

Example:
```python
from pwn import *
io = process('cat')
io.newline = b'\r\n'
io.sendline(b'auto')
io.interactive()
```

```
$ python testinteractive.py DEBUG
[x] Starting local process '/usr/bin/cat' argv=[b'cat']
[+] Starting local process '/usr/bin/cat' argv=[b'cat'] : pid 19060
[DEBUG] Sent 0x6 bytes:
    b'auto\r\n'
[*] Switching to interactive mode
[DEBUG] Received 0x6 bytes:
    b'auto\r\n'
auto
$ test
[DEBUG] Sent 0x5 bytes:
    b'test\n'
[DEBUG] Received 0x5 bytes:
    b'test\n'
test
```

The expected outcome would be to send `b'test\r\n'.

The same problem arises in non-term mode (`PWNLIB_NOTERM=1`), where stdin is read in binary mode causing the OS line seperators to come through. Correctly replacing them with the `context.newline` setting allows to use the interactive input on windows hosts as well, without constantly sending `\r\n`.

* Update CHANGELOG.md

* Only replace newlines in TTYs

Don't mess with the line endings when piping data through.

* Always send bytes immediately on receive

Only replace newlines in a tty if NOTERM wasn't explicitly set or
the `newline` setting was set.

* Don't return a newline after term.readline lines

The builtin `input()` doesn't include the newline.

* Remove bogous newline from CHANGELOG

189 of 5940 branches covered (3.18%)

1 of 20 new or added lines in 2 files covered. (5.0%)

9283 existing lines in 112 files now uncovered.

3286 of 16994 relevant lines covered (19.34%)

0.39 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.0
/pwnlib/testexample.py
1
"""
2
Module-level documentation would go here, along with a general description
3
of the functionality.  You can also add module-level doctests.
4

5
You can see what the documentation for this module will look like here:
6
https://docs.pwntools.com/en/stable/testexample.html
7

8
The tests for this module are run when the documentation is automatically-generated
9
by Sphinx.  This particular module is invoked by an "automodule" directive, which
10
imports everything in the module, or everything listed in ``__all__`` in the module.
11

12
The doctests are automatically picked up by the ``>>>`` symbol, like from
13
the Python prompt.  For more on doctests, see the `Python documentation
14
<https://docs.python.org/2/library/doctest.html>`_.
15

16
All of the syntax in this file is ReStructuredText.  You can find a
17
`nice cheat sheet here <https://github.com/ralsina/rst-cheatsheet/blob/master/rst-cheatsheet.rst>`_.
18

19
Here's an example of a module-level doctest:
20

21
    >>> add(3, add(2, add(1, 0)))
22
    6
23

24
If doctests are wrong / broken, you can disable them temporarily.
25

26
    >>> add(2, 2) # doctest: +SKIP
27
    5
28

29
Some things in Python are non-deterministic, like ``dict`` or ``set``
30
ordering.  There are a lot of ways to work around this, but the
31
accepted way of doing this is to test for equality.
32

33
    >>> a = {a:a+1 for a in range(3)}
34
    >>> a == {0:1, 1:2, 2:3}
35
    True
36

37
In order to use other modules, they need to be imported from the RST
38
which documents the module.
39

40
    >>> os.path.basename('foo/bar')
41
    'bar'
42

43
"""
44

45
def add(a, b):
2✔
46
    '''add(a, b) -> int
47

48
    Adds the numbers ``a`` and ``b``.
49

50
    Arguments:
51
        a(int): First number to add
52
        b(int): Second number to add
53

54
    Returns:
55
        The sum of ``a`` and ``b``.
56

57
    Examples:
58

59
        >>> add(1,2)
60
        3
61
        >>> add(-1, 33)
62
        32
63
    '''
UNCOV
64
    return a+b
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc