forked from Mirror/wren
Add check for method limit; closes #1193
This commit is contained in:
1
AUTHORS
1
AUTHORS
@ -29,4 +29,5 @@ ruby0x1 <ruby0x1@pm.me>
|
|||||||
Kolja Kube <code@koljaku.be>
|
Kolja Kube <code@koljaku.be>
|
||||||
Alexander Klingenbeck <alexander.klingenbeck@gmx.de>
|
Alexander Klingenbeck <alexander.klingenbeck@gmx.de>
|
||||||
Aviv Beeri <avbeeri@gmail.com>
|
Aviv Beeri <avbeeri@gmail.com>
|
||||||
|
Mai Lapyst <floss@lapyst.dev>
|
||||||
|
|
||||||
|
|||||||
@ -113,6 +113,9 @@
|
|||||||
// field index*.
|
// field index*.
|
||||||
#define MAX_FIELDS 255
|
#define MAX_FIELDS 255
|
||||||
|
|
||||||
|
// The maximum number of methods the vm can handle.
|
||||||
|
#define MAX_METHODS 65535
|
||||||
|
|
||||||
// Use the VM's allocator to allocate an object of [type].
|
// Use the VM's allocator to allocate an object of [type].
|
||||||
#define ALLOCATE(vm, type) \
|
#define ALLOCATE(vm, type) \
|
||||||
((type*)wrenReallocate(vm, NULL, 0, sizeof(type)))
|
((type*)wrenReallocate(vm, NULL, 0, sizeof(type)))
|
||||||
|
|||||||
@ -1852,8 +1852,14 @@ static void finishParameterList(Compiler* compiler, Signature* signature)
|
|||||||
// Gets the symbol for a method [name] with [length].
|
// Gets the symbol for a method [name] with [length].
|
||||||
static int methodSymbol(Compiler* compiler, const char* name, int length)
|
static int methodSymbol(Compiler* compiler, const char* name, int length)
|
||||||
{
|
{
|
||||||
return wrenSymbolTableEnsure(compiler->parser->vm,
|
int symbol = wrenSymbolTableEnsure(compiler->parser->vm,
|
||||||
&compiler->parser->vm->methodNames, name, length);
|
&compiler->parser->vm->methodNames, name, length);
|
||||||
|
|
||||||
|
if (symbol > MAX_METHODS) {
|
||||||
|
error(compiler, "Method limit of %d reached.", MAX_METHODS);
|
||||||
|
}
|
||||||
|
|
||||||
|
return symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Appends characters to [name] (and updates [length]) for [numParams] "_"
|
// Appends characters to [name] (and updates [length]) for [numParams] "_"
|
||||||
|
|||||||
@ -1418,6 +1418,7 @@ WrenHandle* wrenMakeCallHandle(WrenVM* vm, const char* signature)
|
|||||||
// Add the signatue to the method table.
|
// Add the signatue to the method table.
|
||||||
int method = wrenSymbolTableEnsure(vm, &vm->methodNames,
|
int method = wrenSymbolTableEnsure(vm, &vm->methodNames,
|
||||||
signature, signatureLength);
|
signature, signatureLength);
|
||||||
|
ASSERT(method <= MAX_METHODS, "Method limit reached.");
|
||||||
|
|
||||||
// Create a little stub function that assumes the arguments are on the stack
|
// Create a little stub function that assumes the arguments are on the stack
|
||||||
// and calls the method.
|
// and calls the method.
|
||||||
|
|||||||
Reference in New Issue
Block a user