Skip to content

Commit

Permalink
internal/core/adt: fix nil pointer dereference
Browse files Browse the repository at this point in the history
We had a nil check on envYield.node, but we accessed a node field
right before that nil check for apparently no good reason.

Fixes #2550.

Closes #2551 as merged as of commit f2dc179.

Signed-off-by: Artem V. Navrotskiy <bozaro@yandex.ru>
Change-Id: I0206d02d8c32ee82bc71e0c9b686965ed4f41399
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1167596
Reviewed-by: Paul Jolly <paul@myitcv.io>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
  • Loading branch information
bozaro authored and mvdan committed Aug 18, 2023
1 parent a1038f7 commit 3286ead
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
40 changes: 40 additions & 0 deletions cue/testdata/eval/issue2550.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
-- in.cue --
foo: string
bar: close({})

if bar.missing == "x" {
let _bar = bar
foo: _bar
}
-- out/compile --
--- in.cue
{
foo: string
bar: close({})
if (〈0;bar〉.missing == "x") {
let _bar#1 = 〈1;bar〉
foo: 〈0;let _bar#1〉
}
}
-- out/eval/stats --
Leaks: 1
Freed: 4
Reused: 1
Allocs: 4
Retain: 5

Unifications: 5
Conjuncts: 5
Disjuncts: 9
-- out/eval --
(_|_){
// [incomplete] undefined field: missing:
// ./in.cue:4:8
foo: (_|_){
// [incomplete] undefined field: missing:
// ./in.cue:4:8
}
bar: (#struct){
}
let _bar#1 = (_){ _ }
}
2 changes: 1 addition & 1 deletion internal/core/adt/comprehension.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,10 @@ func (n *nodeContext) processComprehension(d *envYield, state vertexStatus) *Bot
}

// continue to collect other errors.
d.node.state.addBottom(err)
d.done = true
d.inserted = true
if d.node != nil {
d.node.state.addBottom(err)
ctx.PopArc(d.node)
}
return nil
Expand Down

0 comments on commit 3286ead

Please sign in to comment.