Skip to content

Commit 99d1872

Browse files
committed
cue: limit validation depth
This is a temporary workaround to not having an occurs check. See Issue #29. Change-Id: I2d6f3bfe3493322cf507e0088d415afaf97bda4f Reviewed-on: https://cue-review.googlesource.com/c/cue/+/2365 Reviewed-by: Marcel van Lohuizen <[email protected]>
1 parent 93e9597 commit 99d1872

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

cue/context.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ type context struct {
4242
// tracing
4343
trace bool
4444
level int
45+
46+
// TODO: replace with proper structural cycle detection/ occurs check.
47+
// See Issue #29.
48+
maxDepth int
4549
}
4650

4751
func (c *context) incEvalDepth() {

cue/validate.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@ func validate(ctx *context, v value) *bottom {
2323
switch x := eval.(type) {
2424
case *structLit:
2525
x = x.expandFields(ctx)
26+
if ctx.maxDepth++; ctx.maxDepth > 20 {
27+
return nil
28+
}
2629
for i := range x.arcs {
2730
if err := validate(ctx, x.at(ctx, i)); err != nil {
31+
ctx.maxDepth--
2832
return err
2933
}
3034
}
35+
ctx.maxDepth--
3136
case *list:
3237
// TODO: also validate types for open lists?
3338
return validate(ctx, x.elem)

0 commit comments

Comments
 (0)