Repository navigation
fix: guard navigation and submit against corrupted state - #196
Merged
Merged
Conversation
Three hardening fixes for hand-edited/corrupted state.json input — a supported, repairable scenario (st validate reports ParentCycle, st repair fixes it), so the CLI must degrade gracefully: - runTop walked single-child links in a bare loop with no visited set; every sibling topology helper already carries a cycle guard. A cyclic state file made `st top` spin at 100% CPU forever. Now errors naming the cycle and pointing at validate/repair. - PushBranches returns (nil, err) on argument-validation failures (invalid remote or branch name); submit dereferenced the nil result before the error path ran, turning a clean usage error into a panic / exit 70. Guard before the first use. - decodeState now enforces map-key == Branch.Name and backfills a missing Name (legacy v0), refusing self-inconsistent records at the single point all serialized state enters through.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three corrupt-
state.jsonhardening fixes (audit round 2, plan 023):st topspun forever on cyclic metadata — the only unguardedchild-walk in the codebase; adds the
seenset every sibling topologyhelper already carries.
st submitdereferencedPushBranches' nil result onargument-validation failure (panic → exit 70); now returns the wrapped
error cleanly.
decodeStateenforces map-key ==Branch.Name(corruption → clearerror) and backfills legacy missing names.
Test plan
TestTopRefusesParentCycle,TestSubmitInvalidBranchNameCleanError,TestDecodeStateBranchNameIntegritymake cigreen locally (Actions retired —make ciis the gate)