Repository navigation
feat(cli): add 'pwn errno --list' + perror-string lookup (#2657) - #2727
ChrisJr404 wants to merge 4 commits into
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
|
I can now see that the original code did not use architecture-specific constants, but it definitely should. $ grep ECONNRESET pwnlib/data/includes/generator/linux/diet/errno.h
#define ECONNRESET 54 /* Connection reset by peer */
#define ECONNRESET 131 /* Connection reset by peer */
#define ECONNRESET 54 /* Connection reset by peer */
#define ECONNRESET 232 /* Connection reset by peer */
#define ECONNRESET 104 /* Connection reset by peer */Also, @ChrisJr404 do you use some kind of a template for your PRs, or generated descriptions? They are a little oddly formatted, and the wording is a bit off. You can use the preview functionality before posting to make sure you get the look you wanted. |
|
@Arusekk your request warrants its own PR as it is a pretty big refactor of this commandline tool. Instead of using the stdlib |


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