fix(plugin): normalize panics on invalid origins #7563
Merged
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.
1. Why is this pull request needed and what does it do?
Previously
OriginsFromArgsOrServerBlock()from thepluginpackage accessed the output ofNormalizeExact()by index 0, which could panic when normalization returned an empty slice on error. This happens with malformed input surfaced by fuzzing, for example "unix://<non‑UTF8>".This change hardens normalization in the server block path. If normalization yields no entries, the original value is preserved. The function still returns a newly copied slice.
This preserves legacy semantics for valid inputs while eliminating the crash on malformed ones.
Added tests to validate. The function is now fully covered with the unit tests.
2. Which issues (if any) are related?
Fixes the following OSS-Fuzz finding: https://issues.oss-fuzz.com/issues/42525010
Reproducible by:
Stacktrace:
Details
panic: runtime error: index out of range [0] with length 0goroutine 1 [running]:
github.com/coredns/coredns/plugin.OriginsFromArgsOrServerBlock({0x0?, 0x104777aac?, 0x2000?}, {0x1400068e3a0?, 0x1, 0x100000006?})
/git/coredns/plugin/normalize.go:182 +0x108
github.com/coredns/coredns/plugin/etcd.etcdParse(0x14000182000)
/git/coredns/plugin/etcd/setup.go:56 +0xf4
github.com/coredns/coredns/plugin/etcd.setup(0x14000182000)
/git/coredns/plugin/etcd/setup.go:23 +0x24
github.com/coredns/caddy.executeDirectives(0x1400014a200, {0x16b6a36c0, 0xc}, {0x108aa46a0, 0x36, 0x1?}, {0x140005442a0, 0x1, 0x108aca580?}, 0x0)
/go/pkg/mod/github.com/coredns/[email protected]/caddy.go:663 +0x480
github.com/coredns/caddy.ValidateAndExecuteDirectives({0x10715bf30, 0x14000256ac0}, 0x140005bdd08?, 0x0)
/go/pkg/mod/github.com/coredns/[email protected]/caddy.go:614 +0x2cc
github.com/coredns/caddy.startWithListenerFds({0x10715bf30, 0x14000256ac0}, 0x1400014a200, 0x0)
/go/pkg/mod/github.com/coredns/[email protected]/caddy.go:517 +0x224
github.com/coredns/caddy.Start({0x10715bf30, 0x14000256ac0})
/go/pkg/mod/github.com/coredns/[email protected]/caddy.go:474 +0xbc
github.com/coredns/coredns/coremain.Run()
/git/coredns/coremain/run.go:73 +0x24c
main.main()
/git/coredns/coredns.go:12 +0x1c
Validated locally that the OSS-Fuzz reproducer no longer crashes.
3. Which documentation changes (if any) need to be made?
None.
4. Does this introduce a backward incompatible change or deprecation?
None, preserves existing functionality.