Bug Description
Next() and OverrideParam() access c.route.Handlers and c.route.Params without checking if c.route is nil. Other methods like Route() and IsMiddleware() properly guard against nil c.route.
How to Reproduce
Steps to reproduce the behavior:
- Call
Next() from a custom error handler or middleware that runs before routing
c.route is nil (router hasn't set it yet)
c.route.Handlers panics with nil pointer dereference
Affected Code
ctx.go:249-259 — Next():
func (c *DefaultCtx) Next() error {
c.indexHandler++
if c.indexHandler < len(c.route.Handlers) { // PANIC if c.route is nil
ctx.go:419-442 — OverrideParam():
func (c *DefaultCtx) OverrideParam(name, value string) {
if !c.Matched() { // checks c.isMatched, NOT c.route != nil
return
}
for i, param := range c.route.Params { // PANIC if c.route is nil
Contrast with correct patterns
Route() at line 365 and IsMiddleware() at line 387 properly check:
if c.route == nil { // correct nil guard
return &Route{...}
}
Expected Behavior
func (c *DefaultCtx) Next() error {
c.indexHandler++
if c.route != nil && c.indexHandler < len(c.route.Handlers) {
// ...
}
}
func (c *DefaultCtx) OverrideParam(name, value string) {
if c.route == nil {
return
}
// ...
}
Fiber Version
v3 (latest main branch)
Bug Description
Next()andOverrideParam()accessc.route.Handlersandc.route.Paramswithout checking ifc.routeis nil. Other methods likeRoute()andIsMiddleware()properly guard against nilc.route.How to Reproduce
Steps to reproduce the behavior:
Next()from a custom error handler or middleware that runs before routingc.routeis nil (router hasn't set it yet)c.route.Handlerspanics with nil pointer dereferenceAffected Code
ctx.go:249-259—Next():ctx.go:419-442—OverrideParam():Contrast with correct patterns
Route()at line 365 andIsMiddleware()at line 387 properly check:Expected Behavior
Fiber Version
v3 (latest main branch)