KEMBAR78
config: newResource nil pointer dereference · Issue #6603 · open-telemetry/opentelemetry-go-contrib · GitHub
Skip to content

config: newResource nil pointer dereference #6603

@pellared

Description

@pellared

Steps To Reproduce

func TestBug(t *testing.T) {
	data :=
		`resource:
 attributes:
 -
`
	cfg, err := ParseYAML([]byte(data))
	require.NoError(t, err)

	sdk, err := NewSDK(WithOpenTelemetryConfiguration(*cfg))
	require.NoError(t, err)

	assert.NoError(t, sdk.Shutdown(context.Background()))
}

Output:

--- FAIL: TestBug (0.00s)
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=0x8 pc=0xb75609]

goroutine 19 [running]:
testing.tRunner.func1.2({0xc51c40, 0x1437b80})
	/usr/local/go/src/testing/testing.go:1632 +0x230
testing.tRunner.func1()
	/usr/local/go/src/testing/testing.go:1635 +0x35e
panic({0xc51c40?, 0x1437b80?})
	/usr/local/go/src/runtime/panic.go:785 +0x132
go.opentelemetry.io/contrib/config/v0%2e3%2e0.newResource(0xc00011e2d0)
	/home/ropajak/repos/opentelemetry-go-contrib/config/v0.3.0/resource.go:59 +0x249
go.opentelemetry.io/contrib/config/v0%2e3%2e0.NewSDK({0xc00019ff50?, 0xc000116820?, 0x0?})
	/home/ropajak/repos/opentelemetry-go-contrib/config/v0.3.0/config.go:88 +0x1c5
go.opentelemetry.io/contrib/config/v0%2e3%2e0.TestBug(0xc000116820)
	/home/ropajak/repos/opentelemetry-go-contrib/config/v0.3.0/fuzz_test.go:44 +0x128
testing.tRunner(0xc000116820, 0xdbc220)
	/usr/local/go/src/testing/testing.go:1690 +0xf4
created by testing.(*T).Run in goroutine 1
	/usr/local/go/src/testing/testing.go:1743 +0x390
FAIL	go.opentelemetry.io/contrib/config/v0.3.0	0.008s
FAIL

Expected behavior

  1. NewSDK must handle handle nil schema URL.
  2. NICE TO HAVE null attribute should probably be also be considered as an invalid input for ParseYAML (and when parsing JSON as well) as we already have test cases like invalid nil value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: file-configRelated to file-based configurationbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions