Avoid nil-pointer panic when Rego template source is missing#706
Open
Avoid nil-pointer panic when Rego template source is missing#706
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens the Rego schema driver against malformed ConstraintTemplate inputs by preventing a nil-pointer panic when the Rego template source is missing.
Changes:
- Add a nil guard in
schema.GetSourceto returnErrMissingFieldwhencode.Sourceorcode.Source.Valueisnil. - Add unit tests covering both
Source: nilandSourcewith a nilValue.
Show a summary per file
| File | Description |
|---|---|
constraint/pkg/client/drivers/rego/schema/schema.go |
Adds early validation to avoid dereferencing a nil Source/Value and returns a consistent missing-field error. |
constraint/pkg/client/drivers/rego/schema/schema_test.go |
Adds regression tests to ensure missing/empty source returns ErrMissingField rather than panicking. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 0
Contributor
|
@dependabot rebase |
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.
Motivation
GetSourcein the Rego schema driver dereferencedcode.Sourcewithout checking fornil, allowing a malformed ConstraintTemplate withengine: Regoand missing/nullsourceto cause a nil-pointer panic and crash the process.Description
constraint/pkg/client/drivers/rego/schema.GetSourceto returnErrMissingFieldwhencode.Sourceisnilorcode.Source.Valueisnil, preventing dereference of a nil pointer.constraint/pkg/client/drivers/rego/schema/schema_test.goto cover bothSource: nilandSourcewith an emptyAnythingvalue and assertErrMissingFieldis returned.sourcepayloads and error semantics for bad types or missing requiredregofield.Testing
go test ./pkg/client/drivers/rego/schemafrom theconstraint/module and the package tests passed successfully.go testfrom the repository root path that is not a Go module produced a module initialization error, so tests were executed from theconstraintmodule instead.Codex Task