this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cue/parser: use named error return in ParseExpr to fix error loss on bail-out

ParseExpr used unnamed return values, so the deferred recovery from
the "too many errors" panic could not propagate errors back to the
caller. This caused ParseExpr to return nil error for inputs with
enough scanner errors (e.g. invalid UTF-8) to trigger the bail-out,
even though ParseFile correctly rejected the same inputs.

Use a named error return, matching ParseFile's existing pattern.
It looks like ParseExpr has always had this bug,
as it has had this error recovery mechanism since day one
while never using a named return parameter for err.

Found via fuzzing.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: If7ccd6c5e85aa89fa3e8e98dd22c73af7a7b01c2
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1235294
Reviewed-by: Matthew Sackman <matthew@cue.works>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

+8 -1
+1 -1
cue/parser/interface.go
··· 223 223 // The arguments have the same meaning as for Parse, but the source must 224 224 // be a valid CUE (type or value) expression. Specifically, fset must not 225 225 // be nil. 226 - func ParseExpr(filename string, src any, mode ...Option) (ast.Expr, error) { 226 + func ParseExpr(filename string, src any, mode ...Option) (_ ast.Expr, err error) { 227 227 // get source 228 228 text, err := source.ReadAll(filename, src) 229 229 if err != nil {
+7
cue/parser/parser_test.go
··· 1409 1409 } 1410 1410 } 1411 1411 1412 + // invalid UTF-8 must be rejected even when there are many errors, 1413 + // triggering the "too many errors" bail-out in the parser. 1414 + src = "(\xfa\x00\x00\xfa%%\"\n0" 1415 + if _, err := parseExprString(src); err == nil { 1416 + t.Errorf("ParseExpr(%q): got no error for invalid UTF-8", src) 1417 + } 1418 + 1412 1419 // ParseExpr must not crash 1413 1420 for _, src := range valids { 1414 1421 _, _ = parseExprString(src)