config-parser icon indicating copy to clipboard operation
config-parser copied to clipboard

nil pointer dereference in endline comment with spaces

Open dosmanak opened this issue 3 years ago • 1 comments

First of all thank you for your great work folks. :hugs:

So I've created haproxy.org/backend-config-snippet and I added a acl line with comment like

acl is_whitelisted src 1.2.3.4  # don't use on production

and I got SIGSEV!

I rolled back config and then tried to reproduce it and the is causing the panic in configParser.

Here's the stacktrace:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x58 pc=0xdbcaa4]

goroutine 32 [running]:
github.com/haproxytech/config-parser/v4.(*configParser).ProcessLine(_, {_, _}, {_, _, _}, {_, _}, {{}, {0x1b48ae1, ...}, ...})
	/go/pkg/mod/github.com/haproxytech/config-parser/[email protected]/reader.go:155 +0xa24
github.com/haproxytech/config-parser/v4.(*configParser).Process(0xc0000f2840, {0x1d7ee80, 0xc000948990})
	/go/pkg/mod/github.com/haproxytech/config-parser/[email protected]/reader.go:90 +0x61a
github.com/haproxytech/config-parser/v4.New({0xc000776040, 0x1, 0xc000d06420})
	/go/pkg/mod/github.com/haproxytech/config-parser/[email protected]/parser.go:112 +0x1bd
github.com/haproxytech/client-native/v3/configuration.(*client).AddParser(0xc00049bd40, {0xc000d06420, 0x24})
	/go/pkg/mod/github.com/haproxytech/client-native/[email protected]/configuration/configuration.go:131 +0x25f
github.com/haproxytech/client-native/v3/configuration.(*Transaction).startTransaction(0xc00049bd40, 0x3, 0x0)
	/go/pkg/mod/github.com/haproxytech/client-native/[email protected]/configuration/transaction.go:128 +0x2d5
github.com/haproxytech/client-native/v3/configuration.(*Transaction).StartTransaction(0x0, 0xc0017cd330)
	/go/pkg/mod/github.com/haproxytech/client-native/[email protected]/configuration/transaction.go:99 +0x1b
github.com/haproxytech/kubernetes-ingress/pkg/haproxy/api.(*clientNative).APIStartTransaction(0xc000450ba0)
	/src/pkg/haproxy/api/api.go:128 +0x76
github.com/haproxytech/kubernetes-ingress/pkg/controller.(*HAProxyController).clientAPIClosure(0xc000172f00, 0xc0017cd440)
	/src/pkg/controller/controller.go:58 +0x49
github.com/haproxytech/kubernetes-ingress/pkg/controller.(*HAProxyController).setToReady(0xc000172f00)
	/src/pkg/controller/controller.go:177 +0x4f
github.com/haproxytech/kubernetes-ingress/pkg/controller.(*HAProxyController).updateHAProxy(0xc000172f00)
	/src/pkg/controller/controller.go:152 +0x505
github.com/haproxytech/kubernetes-ingress/pkg/controller.(*HAProxyController).SyncData(0xc000172f00)
	/src/pkg/controller/monitor.go:36 +0x457
github.com/haproxytech/kubernetes-ingress/pkg/controller.(*HAProxyController).Start(0xc000172f00)
	/src/pkg/controller/controller.go:81 +0x125
created by main.main
	/src/main.go:118 +0xac5

that led me to https://github.com/haproxytech/config-parser/blob/7d0ec01198d41d7f767d57c608056ceb9401099d/reader.go#L155

I know it was rude of me to use such char in a comment especialy in the endline comment, but nevertheless I created this issue.

dosmanak avatar Dec 01 '22 10:12 dosmanak

@dosmanak sorry for not responding earlier, this has slipped over my radar

I can reproduce it and will create a fix for it

I know it was rude of me to use such char in a comment especially in the end-line comment, but nevertheless I created this issue.

:D, space or not, one space on end of the comment should not cause a panic for whole application.

oktalz avatar Jan 19 '23 09:01 oktalz