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 dereferencing non-object variables #377

Closed
afflerbach opened this issue Nov 15, 2021 · 0 comments · Fixed by #376
Closed

Panic when dereferencing non-object variables #377

afflerbach opened this issue Nov 15, 2021 · 0 comments · Fixed by #376
Assignees
Labels
bug Something isn't working

Comments

@afflerbach
Copy link
Contributor

afflerbach commented Nov 15, 2021

Describe the bug

Panic when dereferencing non-object (string, array, possibly number as well) variables (as discussed in chat the other day):

ERRO[0032] not a string                                  build=dev handler=endpoint panic="
goroutine 53 [running]:
runtime/debug.Stack()
	/usr/lib64/go/1.17/src/runtime/debug/stack.go:24 +0x72
github.com/avenga/couper/handler.(*Endpoint).ServeHTTP.func1()
	handler/endpoint.go:85 +0x8e
panic({0x103cac0, 0x1317090})
	/usr/lib64/go/1.17/src/runtime/panic.go:1047 +0x266
github.com/zclconf/go-cty/cty.Value.AsString({{{0x13378d8, 0xc0001a645f}}, {0x1171720, 0xc0002836b0}})
	vendor/github.com/zclconf/go-cty/cty/value_ops.go:1256 +0x19e
github.com/zclconf/go-cty/cty.Value.AsValueMap({{{0x1337a28, 0xc00011e990}}, {0x102c9a0, 0xc00011e9a8}})
	vendor/github.com/zclconf/go-cty/cty/value_ops.go:1326 +0x13b
github.com/avenga/couper/eval.walk.func1({0xc0002b954b, 0x5})
	eval/value.go:267 +0x94
github.com/avenga/couper/eval.walk({{{0x1337a28, 0xc00011e990}}, {0x102c9a0, 0xc00011e9a8}}, {{{0x0, 0x0}}, {0x0, 0x0}}, {0xc00028d370, 0x1, ...})
	eval/value.go:274 +0x215
github.com/avenga/couper/eval.walk({{{0x13379b8, 0xc00021cb50}}, {0x107be00, 0xc0002bf530}}, {{{0x0, 0x0}}, {0x0, 0x0}}, {0xc00028d360, 0x2, ...})
	eval/value.go:278 +0x285
github.com/avenga/couper/eval.walk({{{0x13379b8, 0xc00021cbd0}}, {0x107be00, 0xc0002bf680}}, {{{0x0, 0x0}}, {0x0, 0x0}}, {0xc00028d350, 0x3, ...})
	eval/value.go:278 +0x285
github.com/avenga/couper/eval.traversalValue(0xc0002d6818, {0xc00028d340, 0x4, 0x4})
	eval/value.go:254 +0x3a5
github.com/avenga/couper/eval.newLiteralValueExpr(0xc00011eb58, {0x1336fe0, 0xc000114d80})
	eval/value.go:127 +0x73d
github.com/avenga/couper/eval.newLiteralValueExpr(0xc00011eb58, {0x1336f00, 0xc00059a500})
	eval/value.go:106 +0x1385
github.com/avenga/couper/eval.Value(0x108f920, {0x1336f00, 0xc00052c140})
	eval/value.go:54 +0xc5
github.com/avenga/couper/handler/producer.NewResponse(0xc000099000, {0x1336db0, 0xc0002364d0}, 0xc000596b00, 0xc8)
	handler/producer/response.go:58 +0x898
github.com/avenga/couper/handler.(*Endpoint).ServeHTTP(0xc0003a78c0, {0x1330c78, 0xc0005a9200}, 0xc000099000)
	handler/endpoint.go:148 +0x319e
github.com/avenga/couper/handler.(*AccessControl).ServeHTTP(0xc0003a7950, {0x1330c78, 0xc0005a9200}, 0xc000099000)
	handler/access_control.go:36 +0x69c
github.com/avenga/couper/server.(*HTTPServer).ServeHTTP(0xc0003d2780, {0x1330c78, 0xc0005a9200}, 0xc000099000)
	server/http.go:242 +0x12ff
github.com/avenga/couper/handler/middleware.(*TraceHandler).ServeHTTP(0xc00007e430, {0x1330c78, 0xc0005a9200}, 0xc000099000)
	handler/middleware/trace.go:48 +0xb55
github.com/avenga/couper/handler/middleware.(*UID).ServeHTTP(0xc000420090, {0x1330c78, 0xc0005a9200}, 0xc000099000)
	handler/middleware/uid.go:56 +0xa07
github.com/avenga/couper/logging.(*AccessLog).ServeHTTP(0xc0003f7350, {0x1330c78,0xc0005a9200}, 0xc000099000, {0x131f120, 0xc000420090})
	logging/access_log.go:42 +0x97
github.com/avenga/couper/server.New.func1({0x1330c78, 0xc0005a9200}, 0xc0002e7688)
	server/http.go:100 +0x6b
net/http.HandlerFunc.ServeHTTP(0xc0003ee3a0, {0x1330c78, 0xc0005a9200}, 0x18de540)
	/usr/lib64/go/1.17/src/net/http/server.go:2046 +0x4e
github.com/avenga/couper/handler/middleware.NewRecordHandler.func1.1({0x1331758, 0xc0005ae1c0}, 0xc000099000)
	handler/middleware/status.go:30 +0x65e
net/http.HandlerFunc.ServeHTTP(0xc0004200c0, {0x1331758, 0xc0005ae1c0}, 0x18de568)
	/usr/lib64/go/1.17/src/net/http/server.go:2046 +0x4e
github.com/avenga/couper/server.New.func2({0x1331758, 0xc0005ae1c0},0xc000098f00)
	server/http.go:104 +0x45f
net/http.HandlerFunc.ServeHTTP(0xc0003f7380, {0x1331758, 0xc0005ae1c0}, 0x1)
	/usr/lib64/go/1.17/src/net/http/server.go:2046 +0x4e
net/http.serverHandler.ServeHTTP({0xc0002beae0}, {0x1331758, 0xc0005ae1c0}, 0xc000098f00)
	/usr/lib64/go/1.17/src/net/http/server.go:2878 +0x89b
net/http.(*conn).serve(0xc00059a3c0, {0x1336bb8, 0xc0004202d0})
	/usr/lib64/go/1.17/src/net/http/server.go:1929 +0x12e5
created by net/http.(*Server).Serve
	/usr/lib64/go/1.17/src/net/http/server.go:3033 +0x848

To Reproduce
Steps to reproduce the behavior:

  1. Which Couper version?
    master

  2. Provide your configuration file *.hcl. Remove sensitive data.
    see Failing test (crashes) when dereferencing primitive or array-type val… #376

value1 = request.query.foo[0].ooops
value2 = request.query.foo.ooops
  1. Provide a curl call for reproduction
    $ curl -i 'localhost:8080/bad/dereference/array?foo=bar'

  2. See an error response or error log.
    HTTP/1.1 500 Internal Server Error, see trace above or
    https://github.com/avenga/couper/pull/376/checks#step:7:1937

Expected behavior
No panic, succeeding test case in #376
$ go test -v -race ./server/http_integration_test.go -run TestEndpoint_ResponseNilEvaluation

Screenshots

Additional context
#376

@afflerbach afflerbach added the bug Something isn't working label Nov 15, 2021
@malud malud self-assigned this Dec 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants