Skip to content

pw-inspector: restore "contains at least one" set logic - #1122

Merged
vanhauser-thc merged 1 commit into
vanhauser-thc:masterfrom
joswr1ght:fix/pw-inspector-minsets
Nov 7, 2026
Merged

vanhauser-thc merged 1 commit into
vanhauser-thc:masterfrom
joswr1ght:fix/pw-inspector-minsets

Conversation

@joswr1ght

Copy link
Copy Markdown
Contributor

Problem

Commit 28f073f (the fix for #859, first released in 9.5) changed each character set into an allow-list: every character in a password must belong to one of the given sets. The version string stayed at v0.2, and this contradicts the documented -c MINSETS behavior ("the minimum number of sets required"):

  • With no sets given, nothing is output. pw-inspector -i wordlist.txt -m 10 writes an empty file.
  • -l -u -n rejects any password that contains a symbol (for example, Nell-y1998), so the tool can no longer trim a wordlist to a policy like "at least one lowercase, uppercase, and number".

Fix

Restore the pre-9.5 logic: a set counts when the password contains at least one character from it, and other characters are allowed. Keep the later unsigned char buffer and bounded newline/CR stripping.

Testing

Compared against v9.4 pw-inspector on a 1M-word list. Output and return codes are byte-identical for:

-m 10, -m 10 -l -u -n, -m 8 -l -u -n -p -c 3, -l, -s, -p, -m 6 -M 8 -u -n -c 1, -l -u -n -p -s, -l -u -n -p -s -c 2, -m 10 -c 1 -l -u -n -p -s

Also matches v9.4 on input containing non-ASCII and control bytes. No new compiler warnings under -Wall -Wextra.

Note

This reverts the #859 behavior, where -l alone accepted only all-lowercase passwords. If that behavior is really what is wanted, it would be better to add an opt-in flag without changing the default (documented) behavior of pw-inspector.

Maintainer: If that's what you want, happy to add that flag. I think this PR restores the intention of pw-inspector functionality, matching the documentation.

Commit 28f073f (fix for vanhauser-thc#859) changed each set into an allow-list: every
character in a password must belong to one of the given sets. This breaks
the documented behavior, where -c MINSETS is "the minimum number of sets
required":

- With no sets given, nothing is output, so length-only filtering
  (pw-inspector -m 10) returns an empty list.
- -l -u -n rejects passwords containing any other character, so the tool
  can no longer trim a wordlist to a policy such as "at least one
  lowercase, uppercase, and number".

Restore the pre-9.5 logic: a set counts when the password contains at
least one character from it, and other characters are allowed. Keep the
later unsigned char buffer and bounded newline stripping.

Output is byte-identical to v9.4 pw-inspector across length, single-set,
multi-set, and -c combinations on a 1M-word list.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

There are no active review issues for the change restoring minimum-set character matching.

No open issues 🎉

What changed in this PR

Restores pw-inspector’s pre-9.5 character-set matching behavior to align with the documented minimum-set policy rather than treating selected sets as an allow-list.

Changes:

  • Counts each requested set when at least one matching character is present, while allowing other characters.
  • Restores length-only filtering when no character sets are selected.
  • Preserves the unsigned-character buffer and bounded newline/CR stripping.
File Description
pw-inspector.c Restores presence-based character classification and minimum-set counting.

Review effort: Balanced

@vanhauser-thc

Copy link
Copy Markdown
Owner

thanks

@vanhauser-thc
vanhauser-thc merged commit 0084ce0 into vanhauser-thc:master Nov 7, 2026
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.

3 participants