Skip to content

fix: use stat not lstat for -u, -g, -k in mock_all_from_stat#80

Draft
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot:koan.atoomic/fix-stat-dispatch-ugk
Draft

fix: use stat not lstat for -u, -g, -k in mock_all_from_stat#80
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot:koan.atoomic/fix-stat-dispatch-ugk

Conversation

@Koan-Bot
Copy link
Copy Markdown
Contributor

@Koan-Bot Koan-Bot commented Apr 6, 2026

What

Fix stat/lstat dispatch for -u, -g, -k checks in _check_from_stat.

Why

The regex controlling whether stat or lstat is called was missing u, g, k. This caused these operators to use lstat (which doesn't follow symlinks), diverging from real Perl where -u, -g, -k follow symlinks. A mock_all_from_stat on a symlink to a setuid binary would silently return the wrong result.

How

Added ugk to the character class at line 291: qr{^[sfdMXxzACORWeorwugk]$}.

Testing

  • New t/stat-dispatch-ugk.t verifying:
    • -u/-g/-k dispatch stat (not lstat) to the mock callback
    • Setuid, setgid, and sticky bits are correctly detected through stat
  • Full test suite passes

Closes #61

🤖 Generated with Claude Code

The stat/lstat dispatch regex in _check_from_stat was missing u, g, k
characters. This caused setuid/setgid/sticky checks to use lstat
instead of stat, which doesn't follow symlinks — diverging from real
Perl semantics where -u, -g, -k operate on the symlink target.

Add ugk to the character class so these checks correctly use stat.

Closes cpan-authors#61

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

correctness: _check_from_stat uses lstat instead of stat for -u, -g, -k

1 participant