]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/yacc: Prevent index out of range. Fixes #9099.
authorJan Mercl <0xjnml@gmail.com>
Thu, 18 Dec 2014 11:24:16 +0000 (12:24 +0100)
committerIan Lance Taylor <iant@golang.org>
Thu, 18 Dec 2014 16:11:50 +0000 (16:11 +0000)
Change-Id: I7ef01a738b6ca49af1c148146d439c81b0a33b16
Reviewed-on: https://go-review.googlesource.com/1785
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/yacc/yacc.go

index 4dba376fc24951f5dacabe26c71331ffba9a630c..0a69c36afc0018858acce7189faed5816bf1512b 100644 (file)
@@ -3400,6 +3400,13 @@ $$default:
        _ = $$pt // guard against "declared and not used"
 
        $$p -= $$R2[$$n]
+       // $$p is now the index of $0. Perform the default action. Iff the
+       // reduced production is ε, $1 is possibly out of range.
+       if $$p+1 >= len($$S) {
+               nyys := make([]$$SymType, len($$S)*2)
+               copy(nyys, $$S)
+               $$S = nyys
+       }
        $$VAL = $$S[$$p+1]
 
        /* consult goto table to find next state */