-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Missing required fields cause panic #162
Merged
Merged
Conversation
This file contains 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
hbagdi
approved these changes
Jun 1, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, thanks for the clean patch.
rainest
pushed a commit
that referenced
this pull request
Apr 21, 2021
The validation logic sometimes does not catch missing required fields, resulting in a panic. This updates the schema generation to fix it. Example: ```yaml services: - host: httpbin.org #name: service routes: - headers: my-header: - httpbin.org #name: route plugins: - name: key-auth consumers: - keyauth_credentials: - key: foo #username: consumer upstreams: - hash_on: none #name: upstream ``` will cause segfaults like the following for any of the commented out lines above: ```ShellSession $ deck diff -s kong.yaml panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x141b947] goroutine 7 [running]: github.com/hbagdi/deck/file.(*stateBuilder).services(0xc0003cfb28) /home/hbagdi/deck/file/builder.go:392 +0x5d7 github.com/hbagdi/deck/file.(*stateBuilder).build(0xc0003cfb28, 0x0, 0x0, 0x0) /home/hbagdi/deck/file/builder.go:53 +0xfa github.com/hbagdi/deck/file.Get(0xc000388000, 0xc00006d200, 0x1, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...) /home/hbagdi/deck/file/reader.go:51 +0x130 github.com/hbagdi/deck/cmd.syncMain(0xc00005c060, 0x1, 0x1, 0xc0000f9d01, 0xa, 0x0, 0x0) /home/hbagdi/deck/cmd/common.go:102 +0x325 github.com/hbagdi/deck/cmd.glob..func1(0x1ad8440, 0xc00000c0e0, 0x0, 0x2, 0x0, 0x0) /home/hbagdi/deck/cmd/diff.go:25 +0x56 github.com/spf13/cobra.(*Command).execute(0x1ad8440, 0xc00000c0a0, 0x2, 0x2, 0x1ad8440, 0xc00000c0a0) /home/hbagdi/go/pkg/mod/github.com/spf13/cobra@v0.0.7/command.go:838 +0x453 github.com/spf13/cobra.(*Command).ExecuteC(0x1ad79c0, 0x0, 0x0, 0x0) /home/hbagdi/go/pkg/mod/github.com/spf13/cobra@v0.0.7/command.go:943 +0x317 github.com/spf13/cobra.(*Command).Execute(...) /home/hbagdi/go/pkg/mod/github.com/spf13/cobra@v0.0.7/command.go:883 github.com/hbagdi/deck/cmd.Execute.func2(0xc00005c010, 0xc000028110) /home/hbagdi/deck/cmd/root.go:59 +0x2d created by github.com/hbagdi/deck/cmd.Execute /home/hbagdi/deck/cmd/root.go:58 +0xba ``` Also switches the order in which one of two fields are required to have `id` last so it gives a more meaningful error message - only the first is displayed, e.g.: ```ShellSession $ ./deck diff -s kong.yaml Error: reading file: validating file content: 7 errors occurred: upstreams.0: name is required services.0: Must validate at least one schema (anyOf) services.0: name is required services.0.routes.0: Must validate at least one schema (anyOf) services.0.routes.0: name is required consumers.0: Must validate at least one schema (anyOf) consumers.0: username is required ``` From #162
AntoineJac
pushed a commit
that referenced
this pull request
Jan 23, 2024
The validation logic sometimes does not catch missing required fields, resulting in a panic. This updates the schema generation to fix it. Example: ```yaml services: - host: httpbin.org #name: service routes: - headers: my-header: - httpbin.org #name: route plugins: - name: key-auth consumers: - keyauth_credentials: - key: foo #username: consumer upstreams: - hash_on: none #name: upstream ``` will cause segfaults like the following for any of the commented out lines above: ```ShellSession $ deck diff -s kong.yaml panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x141b947] goroutine 7 [running]: github.com/hbagdi/deck/file.(*stateBuilder).services(0xc0003cfb28) /home/hbagdi/deck/file/builder.go:392 +0x5d7 github.com/hbagdi/deck/file.(*stateBuilder).build(0xc0003cfb28, 0x0, 0x0, 0x0) /home/hbagdi/deck/file/builder.go:53 +0xfa github.com/hbagdi/deck/file.Get(0xc000388000, 0xc00006d200, 0x1, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...) /home/hbagdi/deck/file/reader.go:51 +0x130 github.com/hbagdi/deck/cmd.syncMain(0xc00005c060, 0x1, 0x1, 0xc0000f9d01, 0xa, 0x0, 0x0) /home/hbagdi/deck/cmd/common.go:102 +0x325 github.com/hbagdi/deck/cmd.glob..func1(0x1ad8440, 0xc00000c0e0, 0x0, 0x2, 0x0, 0x0) /home/hbagdi/deck/cmd/diff.go:25 +0x56 github.com/spf13/cobra.(*Command).execute(0x1ad8440, 0xc00000c0a0, 0x2, 0x2, 0x1ad8440, 0xc00000c0a0) /home/hbagdi/go/pkg/mod/github.com/spf13/cobra@v0.0.7/command.go:838 +0x453 github.com/spf13/cobra.(*Command).ExecuteC(0x1ad79c0, 0x0, 0x0, 0x0) /home/hbagdi/go/pkg/mod/github.com/spf13/cobra@v0.0.7/command.go:943 +0x317 github.com/spf13/cobra.(*Command).Execute(...) /home/hbagdi/go/pkg/mod/github.com/spf13/cobra@v0.0.7/command.go:883 github.com/hbagdi/deck/cmd.Execute.func2(0xc00005c010, 0xc000028110) /home/hbagdi/deck/cmd/root.go:59 +0x2d created by github.com/hbagdi/deck/cmd.Execute /home/hbagdi/deck/cmd/root.go:58 +0xba ``` Also switches the order in which one of two fields are required to have `id` last so it gives a more meaningful error message - only the first is displayed, e.g.: ```ShellSession $ ./deck diff -s kong.yaml Error: reading file: validating file content: 7 errors occurred: upstreams.0: name is required services.0: Must validate at least one schema (anyOf) services.0: name is required services.0.routes.0: Must validate at least one schema (anyOf) services.0.routes.0: name is required consumers.0: Must validate at least one schema (anyOf) consumers.0: username is required ``` From #162
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.
The validation logic sometimes does not catch missing required fields, resulting in a panic. This updates the schema generation to fix it.
E.g. the following config:
will cause segfaults like the following for any of the commented out lines above:
Also switches the order in which one of two fields are required to have
id
last so it gives a more meaningful error message - only the first is displayed, e.g.: