Fix setting empty ctx sections (#1310)

* Increase CI timeout to 20 minutes

* Fixes: set context-sections '' and add more opts to set empty sections

The `validate_context_sections` function started to receive a string of
`"''"` after the changes in eabab31. Before those changes, it always
received an empty string (`""`).

I am not sure why this behavior changed in that commit, but the current
behavior resembles the native GDB behavior more. We can see this here on
a GDB native parameter:

```
(gdb) set exec-wrapper ''
(gdb) show exec-wrapper
The wrapper for running programs is "''".
```

And so we will keep this native behavior for our config variables for
now. But since this changed, I want to keep the old behavior of: `set
context-sections ''` working, and so this commit brings it.

Additionally, we also now allow setting empty context via multiple
values: empty string, empty quotations or double quotations and with
strings like `-` or `none`.

...and this commit comes with tests for this behavior so it will be
harder to introduce such issues anymore :)
This commit is contained in:
Disconnect3d 2022-10-21 01:03:36 +02:00 committed by GitHub
parent dd26c60e7a
commit 9a580eaa84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View File

@ -80,8 +80,11 @@ def validate_context_sections():
# If someone tries to set an empty string, we let to do that informing about possible values
# (so that it is possible to have no context at all)
if not config_context_sections.value or config_context_sections.value.lower() in (
"''",
'""',
"none",
"empty",
"-",
):
config_context_sections.value = ""
print(

View File

@ -1,6 +1,7 @@
import re
import gdb
import pytest
import pwndbg.commands
import tests
@ -63,3 +64,23 @@ def test_context_disasm_show_fd_filepath(start_binary):
line_nbytes = line_nbytes.strip()
assert re.match(r"nbytes:\s+0x10", line_nbytes)
@pytest.mark.parametrize("sections", ("''", '""', "none", "-", ""))
def test_empty_context_sections(start_binary, sections):
start_binary(USE_FDS_BINARY)
# Sanity check
default_ctx_sects = "regs disasm code ghidra stack backtrace expressions"
assert pwndbg.gdblib.config.context_sections.value == default_ctx_sects
assert gdb.execute("context", to_string=True) != ""
# Actual test check
gdb.execute(f"set context-sections {sections}", to_string=True)
assert pwndbg.gdblib.config.context_sections.value == ""
assert gdb.execute("context", to_string=True) == ""
# Bring back old values && sanity check
gdb.execute(f"set context-sections {default_ctx_sects}")
assert pwndbg.gdblib.config.context_sections.value == default_ctx_sects
assert gdb.execute("context", to_string=True) != ""