fix(middleware): nil-guard param.Schema in UntypedRequestBinder map path#488
Conversation
…er (#487) Add nil check for param.Schema before dereferencing it in the isMap binding path (request.go:76). When binder.Type() returns nil and the parameter has no Schema (common for non-body params with malformed definitions), the code previously panicked with a nil pointer dereference. Add regression unit tests and a fuzz test exercising the map-binding path with varied parameter shapes. Fixes #487 Signed-off-by: Copilot <copilot@github.com>
|
Linter is complaining:
please relax goconst settings in .golangci.yml |
fredbi
left a comment
There was a problem hiding this comment.
Linter is complaining:
Genuine offender
^
Error: /home/runner/work/runtime/runtime/middleware/request_nilschema_test.go:82:14: unused-parameter: parameter 't' seems to be unused, consider removing or renaming it as _ (revive)
linter noise goconst
please relax goconst settings in .golangci.yml
By limiting issues on identifiers of length > 8
Rename unused `t` parameter to `_` in FuzzUntypedRequestBinder. Relax goconst min-len from 2 to 9 to suppress noise on short identifiers. Signed-off-by: Copilot <copilot@github.com>
Fixed in b7db1f4: renamed unused |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #488 +/- ##
=======================================
Coverage 83.36% 83.36%
=======================================
Files 64 64
Lines 4520 4520
=======================================
Hits 3768 3768
- Misses 582 583 +1
+ Partials 170 169 -1 ☔ View full report in Codecov by Harness. |
| tpe := binder.Type() | ||
| if tpe == nil { | ||
| if param.Schema.Type.Contains(typeArray) { | ||
| if param.Schema != nil && param.Schema.Type.Contains(typeArray) { |
| data := make(map[string]any) | ||
| _ = binder.Bind(req, nil, runtime.JSONConsumer(), &data) // must not panic | ||
| }) | ||
| } |
UntypedRequestBinder.Bindpanics with a nil pointer dereference when binding intomap[string]anyand a parameter hasSchema == nil(normal for non-body params like query/path/header with malformed or edge-case type definitions).The panic path:
binder.Type()returns nil → code falls through toparam.Schema.Type.Contains(typeArray)→ nil dereference.Changes
middleware/request.go: Guardparam.Schemabefore dereferencing:When schema is nil, falls through to
map[string]anydefault — correct for non-array params.middleware/request_nilschema_test.go: Regression unit tests for nil-schema and array-schema map-binding paths, plus a fuzz test (FuzzUntypedRequestBinder) exercising varied parameter shapes through theisMapcode path.