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

v3: panic (nil pointer dereference) in parserc.go:789 #665

Closed
bradleyjkemp opened this issue Oct 21, 2020 · 3 comments
Closed

v3: panic (nil pointer dereference) in parserc.go:789 #665

bradleyjkemp opened this issue Oct 21, 2020 · 3 comments

Comments

@bradleyjkemp
Copy link

Hi folks 👋🏻 Found this panic while fuzzing my own project.

Minimal example of the panic (https://play.golang.org/p/GV-Lwua6OMA):

package main

import (
	"gopkg.in/yaml.v3"
)

func main() {
	var t interface{}
	yaml.Unmarshal([]byte("#\n-\n-\n0"), &t)
}

Output:

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

goroutine 1 [running]:
gopkg.in/yaml%2ev3.handleErr(0xc00008df60)
	/tmp/gopath873735581/pkg/mod/gopkg.in/yaml.v3@v3.0.0-20200615113413-eeeca48fe776/yaml.go:294 +0x85
panic(0x5149e0, 0x5f4010)
	/usr/local/go-faketime/src/runtime/panic.go:969 +0x1b9
gopkg.in/yaml%2ev3.yaml_parser_split_stem_comment(0xc00013c000, 0x1)
	/tmp/gopath873735581/pkg/mod/gopkg.in/yaml.v3@v3.0.0-20200615113413-eeeca48fe776/parserc.go:789 +0x42
gopkg.in/yaml%2ev3.yaml_parser_parse_block_sequence_entry(0xc00013c000, 0xc00013c2b0, 0xc00008dd01, 0x4d8b45)
	/tmp/gopath873735581/pkg/mod/gopkg.in/yaml.v3@v3.0.0-20200615113413-eeeca48fe776/parserc.go:703 +0xf9
gopkg.in/yaml%2ev3.yaml_parser_state_machine(0xc00013c000, 0xc00013c2b0, 0x0)
	/tmp/gopath873735581/pkg/mod/gopkg.in/yaml.v3@v3.0.0-20200615113413-eeeca48fe776/parserc.go:179 +0x256
gopkg.in/yaml%2ev3.yaml_parser_parse(0xc00013c000, 0xc00013c2b0, 0xc00011a3c0)
	/tmp/gopath873735581/pkg/mod/gopkg.in/yaml.v3@v3.0.0-20200615113413-eeeca48fe776/parserc.go:129 +0x95
gopkg.in/yaml%2ev3.(*parser).peek(0xc00013c000, 0x7)
	/tmp/gopath873735581/pkg/mod/gopkg.in/yaml.v3@v3.0.0-20200615113413-eeeca48fe776/decode.go:103 +0x45
gopkg.in/yaml%2ev3.(*parser).sequence(0xc00013c000, 0x7)
	/tmp/gopath873735581/pkg/mod/gopkg.in/yaml.v3@v3.0.0-20200615113413-eeeca48fe776/decode.go:258 +0xe5
gopkg.in/yaml%2ev3.(*parser).parse(0xc00013c000, 0xc000000003)
	/tmp/gopath873735581/pkg/mod/gopkg.in/yaml.v3@v3.0.0-20200615113413-eeeca48fe776/decode.go:154 +0xe7
gopkg.in/yaml%2ev3.(*parser).parseChild(...)
	/tmp/gopath873735581/pkg/mod/gopkg.in/yaml.v3@v3.0.0-20200615113413-eeeca48fe776/decode.go:194
gopkg.in/yaml%2ev3.(*parser).document(0xc00013c000, 0x3)
	/tmp/gopath873735581/pkg/mod/gopkg.in/yaml.v3@v3.0.0-20200615113413-eeeca48fe776/decode.go:203 +0x8b
gopkg.in/yaml%2ev3.(*parser).parse(0xc00013c000, 0x0)
	/tmp/gopath873735581/pkg/mod/gopkg.in/yaml.v3@v3.0.0-20200615113413-eeeca48fe776/decode.go:156 +0x87
gopkg.in/yaml%2ev3.unmarshal(0xc000100568, 0x7, 0x7, 0x50a080, 0xc00010a150, 0x0, 0x0, 0x0)
	/tmp/gopath873735581/pkg/mod/gopkg.in/yaml.v3@v3.0.0-20200615113413-eeeca48fe776/yaml.go:161 +0x26a
gopkg.in/yaml%2ev3.Unmarshal(...)
	/tmp/gopath873735581/pkg/mod/gopkg.in/yaml.v3@v3.0.0-20200615113413-eeeca48fe776/yaml.go:89
main.main()
	/tmp/sandbox347243958/prog.go:9 +0x93
@sudermanjr
Copy link

I had the same issue and had to revert to a5ece68 to fix.

@niemeyer
Copy link
Contributor

This is a good example of "The Billion Dollar Mistake". But to be fair, it only happens here because this is a C-style API that was converted to Go but keeping its general shape. The proper fix, to be done eventually, is to replace all these boolean error flags by proper error types.

dgl added a commit to dgl/prometheus that referenced this issue Jun 1, 2022
Picks up the fix for go-yaml/yaml#665 -- we
picked up the important fix for CVE-2022-28948 already.

This only affects go-yaml *v3*; the only user of v3 in Prometheus itself
is rulefmt so the impact seems limited.
dgl added a commit to dgl/prometheus that referenced this issue Jun 1, 2022
Picks up the fix for go-yaml/yaml#665 -- we
picked up the important fix for CVE-2022-28948 already.

This only affects go-yaml *v3*; the only user of v3 in Prometheus itself
is rulefmt so the impact seems limited.

Signed-off-by: David Leadbeater <dgl@dgl.cx>
dgl added a commit to dgl/prometheus that referenced this issue Jun 1, 2022
Picks up the fix for go-yaml/yaml#665 -- we
picked up the important fix for CVE-2022-28948 already.

This only affects go-yaml *v3*; the only user of v3 in Prometheus itself
is rulefmt so the impact seems limited.

Signed-off-by: David Leadbeater <dgl@dgl.cx>
dgl added a commit to prometheus/prometheus that referenced this issue Jun 2, 2022
Picks up the fix for go-yaml/yaml#665 -- we
picked up the important fix for CVE-2022-28948 already.

This only affects go-yaml *v3*; the only user of v3 in Prometheus itself
is rulefmt so the impact seems limited.

Signed-off-by: David Leadbeater <dgl@dgl.cx>
@SuperQ
Copy link

SuperQ commented Jun 3, 2022

Is this valid for the v2 library, if yes, can the fix be back-ported into v2? There are a number of outstanding issues that prevent us from switching from v2 to v3.

Arnoways pushed a commit to Arnoways/prometheus that referenced this issue Jun 8, 2022
Picks up the fix for go-yaml/yaml#665 -- we
picked up the important fix for CVE-2022-28948 already.

This only affects go-yaml *v3*; the only user of v3 in Prometheus itself
is rulefmt so the impact seems limited.

Signed-off-by: David Leadbeater <dgl@dgl.cx>
kaworu added a commit to cilium/cilium-cli that referenced this issue Jun 10, 2022
See go-yaml/yaml#666, and
go-yaml/yaml#665.

Signed-off-by: Alexandre Perrin <alex@isovalent.com>
kaworu added a commit to cilium/certgen that referenced this issue Jun 10, 2022
See go-yaml/yaml#665

Signed-off-by: Alexandre Perrin <alex@isovalent.com>
kaworu added a commit to cilium/fake that referenced this issue Jun 10, 2022
See go-yaml/yaml#666, and
go-yaml/yaml#665.

Signed-off-by: Alexandre Perrin <alex@isovalent.com>
kaworu added a commit to cilium/hubble that referenced this issue Jun 10, 2022
See go-yaml/yaml#665.

Signed-off-by: Alexandre Perrin <alex@isovalent.com>
kaworu added a commit to cilium/hubble-ui that referenced this issue Jun 10, 2022
See go-yaml/yaml#666, and
go-yaml/yaml#665.

Signed-off-by: Alexandre Perrin <alex@isovalent.com>
rolinh pushed a commit to cilium/certgen that referenced this issue Jun 10, 2022
See go-yaml/yaml#665

Signed-off-by: Alexandre Perrin <alex@isovalent.com>
kaworu added a commit to cilium/fake that referenced this issue Jun 10, 2022
See go-yaml/yaml#666, and
go-yaml/yaml#665.

Signed-off-by: Alexandre Perrin <alex@isovalent.com>
kaworu added a commit to cilium/fake that referenced this issue Jun 10, 2022
See go-yaml/yaml#666, and
go-yaml/yaml#665.

Signed-off-by: Alexandre Perrin <alex@isovalent.com>
kaworu added a commit to cilium/hubble that referenced this issue Jun 10, 2022
See go-yaml/yaml#665.

Signed-off-by: Alexandre Perrin <alex@isovalent.com>
tklauser pushed a commit to cilium/cilium-cli that referenced this issue Jun 10, 2022
See go-yaml/yaml#666, and
go-yaml/yaml#665.

Signed-off-by: Alexandre Perrin <alex@isovalent.com>
kaworu added a commit to cilium/hubble-ui that referenced this issue Jun 10, 2022
See go-yaml/yaml#666, and
go-yaml/yaml#665.

Signed-off-by: Alexandre Perrin <alex@isovalent.com>
roidelapluie pushed a commit to roidelapluie/prometheus that referenced this issue Jun 22, 2022
Picks up the fix for go-yaml/yaml#665 -- we
picked up the important fix for CVE-2022-28948 already.

This only affects go-yaml *v3*; the only user of v3 in Prometheus itself
is rulefmt so the impact seems limited.

Signed-off-by: David Leadbeater <dgl@dgl.cx>
aditighag pushed a commit to aditighag/cilium-cli that referenced this issue Apr 21, 2023
See go-yaml/yaml#666, and
go-yaml/yaml#665.

Signed-off-by: Alexandre Perrin <alex@isovalent.com>
michi-covalent pushed a commit to michi-covalent/cilium that referenced this issue May 30, 2023
See go-yaml/yaml#666, and
go-yaml/yaml#665.

Signed-off-by: Alexandre Perrin <alex@isovalent.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants