fix(sandbox-daemon): don't panic on Classify(nil, nil) - #6948
Closed
pedrofrxncx wants to merge 1 commit into
Closed
Conversation
Classify is exported and every other nil-config combination is handled
through a nil-safe accessor method, but nil-before/nil-after reached a
bare after.Env field access and panicked instead of returning no-op the
way nil/&TenantConfig{} already does.
Collaborator
Author
|
Closing as stale: this PR sat past the bot's 48h merge window, main has moved on, and its CI results no longer reflect the current base. This is a housekeeping close, not a rejection of the change — if the underlying problem still exists, the bot will find it again and open a fresh, rebased PR. [studio-bot:stale-close] |
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.
Bug found while auditing
packages/sandbox/daemon-go/internal/configfor malformed-input handling inClassify.Classify(before, after *TenantConfig)handles a nilbeforevia nil-safe accessor methods (HasCloneUrl(),Branch(), etc. all checkc == nilfirst) everywhere except one arm: whenbefore == niland no meaningful field is present, it callsdiffEnv(nil, after.Env)— a bare struct-field access onafter. Ifafteris also nil, that's a nil-pointer dereference panic, not a graceful no-op like the otherwise-symmetricClassify(nil, &TenantConfig{})case (which the existing test suite already covers and returnsKindNoOpfor).Classifyis exported from theconfigpackage and its only current caller (Store.applyinstore.go) always passes a non-nilafter(the result ofDeepMerge, which never returns nil), so this isn't reachable in production today — but it's a real crash-on-misuse footgun in an exported API, and the fix is a one-line normalization plus a regression test.Fix: normalize
afterto&TenantConfig{}at the top ofClassifywhen nil, matching howbeforeis already handled —Classify(nil, nil)now returnsKindNoOp, consistent withClassify(nil, &TenantConfig{}).Reviewer check:
cd packages/sandbox/daemon-go && go test ./internal/config/...Verified locally:
gofmt -l,go vet ./internal/config/...,go test ./internal/config/...(all pass). Full CI covers the rest of the daemon.Summary by cubic
Fixes
Classify(nil, nil)inpackages/sandbox/daemon-go/internal/configfrom panicking on a nil-pointer dereference to returningKindNoOp, matching the existing behavior forClassify(nil, &TenantConfig{}). The bug wasn't reachable from the current caller (Store.applyalways passes a non-nilafter), but it was a crash-on-misuse footgun in an exported API.Written for commit fa2888d. Summary will update on new commits.