Merge pull request #562 from Salmela/locals-array-overflow-fix

Check that there is space in local variable array
This commit is contained in:
Sven Bergström
2019-09-18 00:20:03 -07:00
committed by GitHub
2 changed files with 188 additions and 0 deletions

View File

@ -2903,6 +2903,16 @@ static void forStatement(Compiler* compiler)
// The space in the variable name ensures it won't collide with a user-defined
// variable.
expression(compiler);
// Verify that there is space to hidden local variables.
// Note that we expect only two addLocal calls next to each other in the
// following code.
if (compiler->numLocals + 2 > MAX_LOCALS)
{
error(compiler, "Cannot declare more than %d variables in one scope. (Not enough space for for-loops internal variables)",
MAX_LOCALS);
return;
}
int seqSlot = addLocal(compiler, "seq ", 4);
// Create another hidden local for the iterator object.

178
test/regression/561.wren Normal file
View File

@ -0,0 +1,178 @@
// This test caused an array oveflow in local variable array due to hidden
// variables of for loop
// expect error line 91
var z = []
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
for (x in z) {
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}