Skip to content

Get-LoginPasswordHash - Stop eating the caller loop when the hash query fails - #10704

Open
andreasjordan wants to merge 1 commit into
developmentfrom
fix-get-loginpasswordhash-continue-escape
Open

Get-LoginPasswordHash - Stop eating the caller loop when the hash query fails#10704
andreasjordan wants to merge 1 commit into
developmentfrom
fix-get-loginpasswordhash-continue-escape

Conversation

@andreasjordan

Copy link
Copy Markdown
Collaborator

Part of #10638, the sweep for Stop-Function -Continue outside an enclosing loop. Same shape as #10637.

Problem

Get-LoginPasswordHash reports a failed hash query from its inner catch, followed by a return that never ran with Stop-Function -Continue (private/functions/Get-LoginPasswordHash.ps1:71). No loop encloses that site inside the command, so without -EnableException the continue unwinds out of the command and consumes an iteration of whatever loop the caller runs in. The only caller, Sync-DbaLoginPassword, calls it inside its login loop, so the escape was caught there - but it bypassed the caller's own handling of a missing hash and the return after the call. Latent as far as a user is concerned.

What changed

The -Continue is dropped; the return that follows now runs as written.

Tests

No new test: no red-on-old exists for a latent escape. The caller's test file passes on both editions through the testing-dbatools harness.

created by Claude and reviewed by Andreas Jordan

🤖 Generated with Claude Code

…ry fails

Stop-Function -Continue runs PowerShell's continue. No loop encloses this
call site inside the command, so the continue unwound out of the command
and consumed an iteration of whatever loop the caller runs in: a user's
foreach silently skipped an element, and Pester's runner corrupted. The
escape only bites the non-EnableException path; with EnableException
Stop-Function throws before it gets there.

Latent: the only caller, Sync-DbaLoginPassword, calls it inside its login
loop, so the continue was caught there - but it bypassed the caller's
null-hash handling and the return that follows the call never ran. No
red-on-old test exists for a latent escape; the return after the call now
runs as written.
Part of #10638

(do Get-LoginPasswordHash)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

@potatoqualitee potatoqualitee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The failure path now returns from the helper scope rather than terminating the caller loop, while successful hash retrieval remains unchanged. The control-flow reproduction completes all caller iterations and the current CI checks are green.

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.

2 participants