Skip to content
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

Panic when sending "null" to the state endpoint #1165

Closed
mjhcorporate opened this issue Jan 8, 2025 · 1 comment
Closed

Panic when sending "null" to the state endpoint #1165

mjhcorporate opened this issue Jan 8, 2025 · 1 comment
Labels

Comments

@mjhcorporate
Copy link
Contributor

Description of the bug

Hoverfly panics when sending null to /api/v2/state.

Steps to reproduce the issue

Start hoverfly, then

curl --request PUT \
  --url http://localhost:8601/api/v2/state \
  --header 'content-type: application/json' \
  --data 'null'

Observed result

Hoverfly error messages seen (If none, say none)

PANIC: runtime error: invalid memory address or nil pointer dereference
goroutine 7 [running]:
github.com/codegangsta/negroni.(*Recovery).ServeHTTP.func1()
        /home/circleci/hoverfly/vendor/github.com/codegangsta/negroni/recovery.go:159 +0xad
panic({0xce9080?, 0x159f390?})
        /usr/local/go/src/runtime/panic.go:770 +0x132
github.com/SpectoLabs/hoverfly/core/handlers/v2.(*StateHandler).Put(0xc000114be0, {0x7f19b860eaf8, 0xc00011c030}, 0xc0003cc6c0, 0x0?)
        /home/circleci/hoverfly/core/handlers/v2/state_handler.go:73 +0xf3
github.com/codegangsta/negroni.HandlerFunc.ServeHTTP(0x10?, {0x7f19b860eaf8?, 0xc00011c030?}, 0x467da5?, 0x10?)
        /home/circleci/hoverfly/vendor/github.com/codegangsta/negroni/negroni.go:29 +0x2d
github.com/codegangsta/negroni.middleware.ServeHTTP({{0xfa9560?, 0xc000115210?}, 0xc0000113c8?}, {0x7f19b860eaf8, 0xc00011c030}, 0xc0003cc6c0)
        /home/circleci/hoverfly/vendor/github.com/codegangsta/negroni/negroni.go:38 +0xa8
github.com/SpectoLabs/hoverfly/core/handlers.(*AuthHandler).RequireTokenAuthentication(0x20?, {0x7f19b860eaf8?, 0xc00011c030?}, 0x0?, 0x0?)
        /home/circleci/hoverfly/core/handlers/auth_handler.go:50 +0x153
github.com/codegangsta/negroni.HandlerFunc.ServeHTTP(0xc00047b800?, {0x7f19b860eaf8?, 0xc00011c030?}, 0xd75660?, 0x412101?)
        /home/circleci/hoverfly/vendor/github.com/codegangsta/negroni/negroni.go:29 +0x2d
github.com/codegangsta/negroni.middleware.ServeHTTP({{0xfa9560?, 0xc000115200?}, 0xc0000113b0?}, {0x7f19b860eaf8, 0xc00011c030}, 0xc0003cc6c0)
        /home/circleci/hoverfly/vendor/github.com/codegangsta/negroni/negroni.go:38 +0xa8
github.com/codegangsta/negroni.(*Negroni).ServeHTTP(0xc0002e30e0, {0x7f19b860eaf8, 0xc00011c028}, 0xc0003cc6c0)
        /home/circleci/hoverfly/vendor/github.com/codegangsta/negroni/negroni.go:96 +0x105
github.com/go-zoo/bone.(*Route).parse(0xc0000c8c60, {0x7f19b860eaf8, 0xc00011c028}, 0xc0003cc6c0)
        /home/circleci/hoverfly/vendor/github.com/go-zoo/bone/route.go:171 +0x1ba
github.com/go-zoo/bone.(*Mux).parse(0xc0002c2000, {0x7f19b860eaf8, 0xc00011c028}, 0xc0003cc6c0)
        /home/circleci/hoverfly/vendor/github.com/go-zoo/bone/helper.go:23 +0x91
github.com/go-zoo/bone.(*Mux).DefaultServe(0xc0002c2000, {0x7f19b860eaf8, 0xc00011c028}, 0xc0003cc6c0)
        /home/circleci/hoverfly/vendor/github.com/go-zoo/bone/bone.go:71 +0x2b
github.com/go-zoo/bone.(*Mux).ServeHTTP(0xc000580008?, {0x7f19b860eaf8?, 0xc00011c028?}, 0x0?)
        /home/circleci/hoverfly/vendor/github.com/go-zoo/bone/bone.go:90 +0x98
github.com/codegangsta/negroni.(*Negroni).UseHandler.Wrap.func1({0x7f19b860eaf8, 0xc00011c028}, 0xc0003cc6c0, 0xc000091380)
        /home/circleci/hoverfly/vendor/github.com/codegangsta/negroni/negroni.go:46 +0x45
github.com/codegangsta/negroni.HandlerFunc.ServeHTTP(0x40ec27?, {0x7f19b860eaf8?, 0xc00011c028?}, 0x8?, 0x3?)
        /home/circleci/hoverfly/vendor/github.com/codegangsta/negroni/negroni.go:29 +0x2d
github.com/codegangsta/negroni.middleware.ServeHTTP({{0xfa9560?, 0xc000010318?}, 0xc000010720?}, {0x7f19b860eaf8, 0xc00011c028}, 0xc0003cc6c0)
        /home/circleci/hoverfly/vendor/github.com/codegangsta/negroni/negroni.go:38 +0xa8
github.com/codegangsta/negroni.(*Recovery).ServeHTTP(0xc00047bb00?, {0x7f19b860eaf8?, 0xc00011c028?}, 0xd75660?, 0x412101?)
        /home/circleci/hoverfly/vendor/github.com/codegangsta/negroni/recovery.go:193 +0x7b
github.com/codegangsta/negroni.middleware.ServeHTTP({{0xfa9460?, 0xc0000a2e10?}, 0xc000010330?}, {0x7f19b860eaf8, 0xc00011c028}, 0xc0003cc6c0)
        /home/circleci/hoverfly/vendor/github.com/codegangsta/negroni/negroni.go:38 +0xa8
github.com/codegangsta/negroni.(*Negroni).ServeHTTP(0xc0002e3710, {0xfae720, 0xc000194380}, 0xc0003cc6c0)
        /home/circleci/hoverfly/vendor/github.com/codegangsta/negroni/negroni.go:96 +0x105
net/http.serverHandler.ServeHTTP({0xfac678?}, {0xfae720?, 0xc000194380?}, 0x6?)
        /usr/local/go/src/net/http/server.go:3142 +0x8e
net/http.(*conn).serve(0xc000314480, {0xfafe10, 0xc000333a10})
        /usr/local/go/src/net/http/server.go:2044 +0x5e8
created by net/http.(*Server).Serve in goroutine 1
        /usr/local/go/src/net/http/server.go:3290 +0x4b4

Expected result

State should set to the "default" state, i.e. all state cleared.

Additional relevant information

  1. Hoverfly version: v1.10.7
@mjhcorporate mjhcorporate changed the title Hoverfly panics when sending "null" to the state endpoint Panic when sending "null" to the state endpoint Jan 8, 2025
@tommysitu tommysitu added the bug label Jan 8, 2025
@tommysitu
Copy link
Member

Thanks for the report @mjhcorporate I've raised a PR to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants