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

cue export nil pointer dereference #2550

Closed
bozaro opened this issue Aug 16, 2023 · 4 comments
Closed

cue export nil pointer dereference #2550

bozaro opened this issue Aug 16, 2023 · 4 comments

Comments

@bozaro
Copy link
Contributor

bozaro commented Aug 16, 2023

What version of CUE are you using (cue version)?

$ cue version

cue version v0.6.0

go version go1.20.7
      -buildmode exe
       -compiler gc
     CGO_ENABLED 1
          GOARCH amd64
            GOOS linux
         GOAMD64 v1

Does this issue reproduce with the latest stable release?

Yes

What did you do?

cue export for file:

package example

#Bar1: {
	bar1: string
}

#Bar2: {
	bar2: string
}

#BarFromName: #Bar1 & {
	#name: string

	let env = #name
	if env != "production" {
		bar2: env
	}
}

#Foo: {
	foo: string
}

#FooConfig: #Foo & {
	#bar: #Bar2

	let env = #bar.cluster.env
	if env == "dev" {
		let _bar = #bar
		foo: _bar
	}
}

#FooConfig: #Foo & {
	#foo: string
	#bar: #BarFromName & {
		#name: #foo
	}
}

foo: #FooConfig & {
	#foo: "dev"
}

What did you expect to see?

Not panic

What did you see instead?

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=0x6ae012]

goroutine 1 [running]:
cuelang.org/go/cmd/cue/cmd.recoverError(0xc0007adeb8)
	/home/bozaro/go/pkg/mod/cuelang.org/[email protected]/cmd/cue/cmd/root.go:318 +0x7b
panic({0xcb7760, 0x13e56b0})
	/usr/lib/go-1.20/src/runtime/panic.go:884 +0x213
cuelang.org/go/internal/core/adt.(*nodeContext).processComprehension(0xc000515800, 0xc0003a33b0, 0x0?)
	/home/bozaro/go/pkg/mod/cuelang.org/[email protected]/internal/core/adt/comprehension.go:400 +0x172
cuelang.org/go/internal/core/adt.(*nodeContext).injectComprehensions(0xc000515800, 0xa0?)
	/home/bozaro/go/pkg/mod/cuelang.org/[email protected]/internal/core/adt/comprehension.go:332 +0x9a
cuelang.org/go/internal/core/adt.(*nodeContext).expandOne(0xc000515800, 0xd8?)
	/home/bozaro/go/pkg/mod/cuelang.org/[email protected]/internal/core/adt/eval.go:2077 +0x89
cuelang.org/go/internal/core/adt.(*OpContext).unify(0xc0000d8900, 0xc0000cb7a0, 0x5)
	/home/bozaro/go/pkg/mod/cuelang.org/[email protected]/internal/core/adt/eval.go:265 +0x685
cuelang.org/go/internal/core/adt.(*nodeContext).completeArcs(0xc000514c00, 0x5)
	/home/bozaro/go/pkg/mod/cuelang.org/[email protected]/internal/core/adt/eval.go:794 +0x1d5
cuelang.org/go/internal/core/adt.(*nodeContext).postDisjunct(0xc000514c00, 0x0?)
	/home/bozaro/go/pkg/mod/cuelang.org/[email protected]/internal/core/adt/eval.go:581 +0x4d2
cuelang.org/go/internal/core/adt.(*nodeContext).expandDisjuncts(0xc000514c00, 0xe8?, 0xc000514c00, 0x0, 0x0, 0x1)
	/home/bozaro/go/pkg/mod/cuelang.org/[email protected]/internal/core/adt/disjunct.go:158 +0x445
cuelang.org/go/internal/core/adt.(*OpContext).unify(0xc0000d8900, 0xc0000cafc0, 0x5)
	/home/bozaro/go/pkg/mod/cuelang.org/[email protected]/internal/core/adt/eval.go:292 +0x7e5
cuelang.org/go/internal/core/adt.(*nodeContext).completeArcs(0xc000514800, 0x5)
	/home/bozaro/go/pkg/mod/cuelang.org/[email protected]/internal/core/adt/eval.go:794 +0x1d5
cuelang.org/go/internal/core/adt.(*nodeContext).postDisjunct(0xc000514800, 0x30?)
	/home/bozaro/go/pkg/mod/cuelang.org/[email protected]/internal/core/adt/eval.go:581 +0x4d2
cuelang.org/go/internal/core/adt.(*nodeContext).expandDisjuncts(0xc000514800, 0xe8?, 0xc000514800, 0x0, 0x0, 0x1)
	/home/bozaro/go/pkg/mod/cuelang.org/[email protected]/internal/core/adt/disjunct.go:158 +0x445
cuelang.org/go/internal/core/adt.(*OpContext).unify(0xc0000d8900, 0xc0000ca5a0, 0x5)
	/home/bozaro/go/pkg/mod/cuelang.org/[email protected]/internal/core/adt/eval.go:292 +0x7e5
cuelang.org/go/internal/core/adt.(*Vertex).Finalize(...)
	/home/bozaro/go/pkg/mod/cuelang.org/[email protected]/internal/core/adt/composite.go:638
cuelang.org/go/cue.newVertexRoot(0x7f07d87d7848?, 0xc0000d8900?, 0x100?)
	/home/bozaro/go/pkg/mod/cuelang.org/[email protected]/cue/types.go:614 +0x72
cuelang.org/go/cue.newValueRoot(0xedb3f8?, 0xc000392e28?, {0xed9e80?, 0xc0000ca5a0?})
	/home/bozaro/go/pkg/mod/cuelang.org/[email protected]/cue/types.go:623 +0x4d
cuelang.org/go/cue.(*Context).make(0xc000392e28, 0x0?)
	/home/bozaro/go/pkg/mod/cuelang.org/[email protected]/cue/context.go:253 +0x6c
cuelang.org/go/cue.(*Context).BuildInstances(0xc000392e28, {0xc00044cb10, 0x1, 0x0?})
	/home/bozaro/go/pkg/mod/cuelang.org/[email protected]/cue/context.go:152 +0x1f9
cuelang.org/go/cmd/cue/cmd.buildInstances(0xc0003b1230, {0xc00044cb10, 0x1, 0x140e5a0?}, 0x0)
	/home/bozaro/go/pkg/mod/cuelang.org/[email protected]/cmd/cue/cmd/common.go:729 +0x52
cuelang.org/go/cmd/cue/cmd.(*buildPlan).instances(0xc0003fe9c0)
	/home/bozaro/go/pkg/mod/cuelang.org/[email protected]/cmd/cue/cmd/common.go:171 +0x4a
cuelang.org/go/cmd/cue/cmd.runExport(0xc0003b1230?, {0xc0003ea4c0, 0x1, 0x1})
	/home/bozaro/go/pkg/mod/cuelang.org/[email protected]/cmd/cue/cmd/export.go:113 +0x19a
cuelang.org/go/cmd/cue/cmd.mkRunE.func1(0xc0003f0300?, {0xc0003ea4c0, 0x1, 0x1})
	/home/bozaro/go/pkg/mod/cuelang.org/[email protected]/cmd/cue/cmd/root.go:87 +0xb3
github.com/spf13/cobra.(*Command).execute(0xc0003f0300, {0xc0003ea480, 0x1, 0x1})
	/home/bozaro/go/pkg/mod/github.com/spf13/[email protected]/command.go:940 +0x862
github.com/spf13/cobra.(*Command).ExecuteC(0xc000005200)
	/home/bozaro/go/pkg/mod/github.com/spf13/[email protected]/command.go:1068 +0x3bd
github.com/spf13/cobra.(*Command).Execute(...)
	/home/bozaro/go/pkg/mod/github.com/spf13/[email protected]/command.go:992
cuelang.org/go/cmd/cue/cmd.(*Command).Run(0xc0003b1230, {0x2?, 0x2?})
	/home/bozaro/go/pkg/mod/cuelang.org/[email protected]/cmd/cue/cmd/root.go:303 +0x6b
cuelang.org/go/cmd/cue/cmd.Main()
	/home/bozaro/go/pkg/mod/cuelang.org/[email protected]/cmd/cue/cmd/root.go:231 +0x79
main.main()
	/home/bozaro/go/pkg/mod/cuelang.org/[email protected]/cmd/cue/main.go:24 +0x19
@mvdan
Copy link
Member

mvdan commented Aug 16, 2023

Out of curiosity, did you git bisect to see if this is a relatively recent regression?

@bozaro
Copy link
Contributor Author

bozaro commented Aug 16, 2023

Out of curiosity, did you git bisect to see if this is a relatively recent regression?

I didn't do bisect. This bug has been around since at least April 26th 2023.

My colleague made this correction a long time ago, but without creating a PR: https://github.com/joomcode/cue/pull/11/commits/1b57363c14956cea8b6999e0777a5c840b5f1077

@mvdan
Copy link
Member

mvdan commented Aug 16, 2023

Ah, thanks. So at least it wasn't a very recent regression.

Here is a significantly smaller reproducer, which you should use as a regression test in your PR for the sake of avoiding verbosity:

exec cue export in.cue

-- in.cue --
foo: string
bar: close({})

if bar.missing == "x" {
	let _bar = bar
	foo: _bar
}

@mvdan mvdan added NeedsFix panic and removed NeedsInvestigation Triage Requires triage/attention labels Aug 16, 2023
@mvdan mvdan self-assigned this Aug 16, 2023
@bozaro
Copy link
Contributor Author

bozaro commented Aug 16, 2023

Yes. This example also reproduces the problem.
I will now replace testcase in PR.

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

Successfully merging a pull request may close this issue.

2 participants