feat(cli): add 'pwn errno --list' + perror-string lookup (#2657)#2727
Open
ChrisJr404 wants to merge 2 commits intoGallopsled:devfrom
Open
feat(cli): add 'pwn errno --list' + perror-string lookup (#2657)#2727ChrisJr404 wants to merge 2 commits intoGallopsled:devfrom
ChrisJr404 wants to merge 2 commits intoGallopsled:devfrom
Conversation
…opsled#2657) - '--list / -l': dump every known errno (value, name, strerror message). - '--search / -s': force perror-substring match (case-insensitive). - Bare 'pwn errno <text>' falls back to a perror substring search when the argument is neither an integer nor a known errno macro name. So 'pwn errno "Cannot allocate memory"' now prints ENOMEM directly. - Positional 'error' arg is now optional so '--list' can be used alone; argparse explains the requirement when neither is supplied. Closes Gallopsled#2657
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2657.
What
`pwn errno` previously supported looking up a value either by integer or by errno macro name. The issue (filed by @k4lizen) asks for the inverse direction: "I see a perror message in the wild, what errno does it map to?" — e.g. `Cannot allocate memory` → `ENOMEM`.
Three small additions to the existing CLI:
Output for the integer / name path is unchanged.
Demo
```
$ pwn errno 13
#define EACCES 13
Permission denied
$ pwn errno EACCES
#define EACCES 13
Permission denied
$ pwn errno "Cannot allocate memory"
#define ENOMEM 12
Cannot allocate memory
$ pwn errno -s broken
#define EPIPE 32
Broken pipe
$ pwn errno --list | head -3
1 EPERM Operation not permitted
2 ENOENT No such file or directory
3 ESRCH No such process
```
Why
The use case from the issue:
`/usr/bin/errno -l | grep ...` works on Linux but isn't always installed; `pwn errno` ships with pwntools.
Tests
Verified against the local installation:
```
$ pwn errno 13 -> EACCES / Permission denied
$ pwn errno EACCES -> EACCES / Permission denied
$ pwn errno "Cannot allocate memory" -> ENOMEM
$ pwn errno -s broken -> EPIPE
$ pwn errno --list | head -> sorted dump of all errnos
$ pwn errno -> argparse error: 'error required (or pass --list)'
$ pwn errno NotARealError -> No errno for NotARealError
```
Notes