Skip to content

feat(cli): add 'pwn errno --list' + perror-string lookup (#2657)#2727

Open
ChrisJr404 wants to merge 2 commits intoGallopsled:devfrom
ChrisJr404:feature/errno-list
Open

feat(cli): add 'pwn errno --list' + perror-string lookup (#2657)#2727
ChrisJr404 wants to merge 2 commits intoGallopsled:devfrom
ChrisJr404:feature/errno-list

Conversation

@ChrisJr404
Copy link
Copy Markdown
Contributor

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:

  1. `-l / --list` — dump every errno code visible to the standard library, one per line: ` `. The `--list` form was the explicit suggestion in the discussion.
  2. `-s / --search ` — force a case-insensitive substring match against `os.strerror(N)` for all errnos and print every match.
  3. Bare `pwn errno ` — when the argument is neither an integer nor a known errno macro, automatically fall back to the same substring search. So `pwn errno "Cannot allocate memory"` Just Works.

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:

I want stuff like `pwn errno "Cannot allocate memory"` to return EACCES. Can often come in handy when I see the message being printed via errno and want to check the man pages or source to see what condition causes that.

`/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

  • Pure-additive: no existing invocation form changes its output.
  • The positional `error` is now `nargs='?'` so `--list` can run without it; argparse emits the missing-arg error otherwise.
  • The substring fallback is only triggered when the input doesn't parse as an int or errno name — there's no risk of mis-classifying a known macro like `EACCES` as a search term.

ChrisJr404 added 2 commits May 3, 2026 17:53
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

errno: Search by perror string

1 participant