Skip to content

glob: anchor the "**/" tail to a path-segment boundary - #42

Merged
nmatt0 merged 1 commit into
masterfrom
fix/glob-segment-anchor
Oct 29, 2026
Merged

nmatt0 merged 1 commit into
masterfrom
fix/glob-segment-anchor

Conversation

@nmatt0

@nmatt0 nmatt0 commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Problem

glob_match("**/shadow", "bin/login.shadow") returns true. The **/ branch in gm() collapses the **, consumes the /, then retries the remaining pattern at every character offset, so the tail can match in the middle of a segment.

Every builtin path rule with a literal final segment inherits this. An ELF binary named login.shadow is reported as a shadow-file ("Password hash database"), dbus-wpa_supplicant.conf as a wifi-config, and so on, so a directory holding several such files yields a cluster of bogus credential findings alongside the one genuine shadow.

Fix

The documented contract is that ** crosses segments and the literal tail is a whole final segment. Restart the tail match only at the root or immediately after a /. **/shadow still matches shadow, a/shadow and a/b/shadow, but no longer the shadow tail of a/login.shadow.

Tests

New negative unit cases in tests/unit/unit_tests.cpp (bin/login.shadow, login.shadow, notid_rsa, myhtpasswd all rejected) plus a **/shadow -> var/config/shadow positive. Full suite green: mithril_unit (1451 checks) and tests/run.sh all passed.

glob_match("**/shadow", "bin/login.shadow") returned true. The "**/" branch
collapsed the "**", consumed the "/", then retried the tail at every character
offset, so the tail matched mid-segment. Every builtin path rule with a literal
final segment inherited this: an ELF binary named login.shadow was reported as a
shadow-file (credential store), dbus-wpa_supplicant.conf as a wifi-config, and
so on.

Match the documented contract ("**" crosses segments; the literal tail is a
whole segment) by restarting the tail only at the root or just after a "/".
"**/shadow" still matches shadow, a/shadow and a/b/shadow, but no longer the
shadow tail of a/login.shadow. Add negative unit cases.
@nmatt0
nmatt0 merged commit 2347876 into master Oct 29, 2026
4 checks passed
@nmatt0
nmatt0 deleted the fix/glob-segment-anchor branch October 29, 2026 23:05
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.

1 participant