gin
gin copied to clipboard
fix context.Value-engine is nil panic
Description
Source code: https://github.com/gin-gonic/gin/blob/b04917c53e310e3746ec90cd93106cda8c956211/context.go#L1208
The attribute engine
is not judged whether it is nil
in the Value
method of gin.Context
,may cause program panic
How to reproduce
- example
package main import ( "fmt" "github.com/gin-gonic/gin" // v1.8.1 ) func main() { ctx := gin.Context{} data := ctx.Value("test") fmt.Println(data) }
- error
panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x2 addr=0x71 pc=0x1027a45c0] goroutine 1 [running]: github.com/gin-gonic/gin.(*Context).Value(0x140000ee000, {0x10283b820?, 0x1028964d8?}) /Users/atopx/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:1198 +0x110 main.main() /Users/atopx/workspace/stu-gin/main.go:10 +0x3c exit status 2