check program counter on OP_CALL and OP_LEAVE

This commit is contained in:
Ludwig Nussel 2007-06-25 09:45:18 +00:00
parent ecbb43c9b0
commit 6a5908d444

View file

@ -394,9 +394,8 @@ nextInstruction:
r0 = ((int *)opStack)[0]; r0 = ((int *)opStack)[0];
r1 = ((int *)opStack)[-1]; r1 = ((int *)opStack)[-1];
nextInstruction2: nextInstruction2:
opcode = codeImage[ programCounter++ ];
#ifdef DEBUG_VM #ifdef DEBUG_VM
if ( (unsigned)programCounter > vm->codeLength ) { if ( (unsigned)programCounter >= vm->codeLength ) {
Com_Error( ERR_DROP, "VM pc out of range" ); Com_Error( ERR_DROP, "VM pc out of range" );
} }
@ -420,6 +419,7 @@ nextInstruction2:
} }
profileSymbol->profileCount++; profileSymbol->profileCount++;
#endif #endif
opcode = codeImage[ programCounter++ ];
switch ( opcode ) { switch ( opcode ) {
#ifdef DEBUG_VM #ifdef DEBUG_VM
@ -564,6 +564,8 @@ nextInstruction2:
Com_Printf( "%s<--- %s\n", DEBUGSTR, VM_ValueToSymbol( vm, programCounter ) ); Com_Printf( "%s<--- %s\n", DEBUGSTR, VM_ValueToSymbol( vm, programCounter ) );
} }
#endif #endif
} else if ( (unsigned)programCounter >= vm->codeLength ) {
Com_Error( ERR_DROP, "VM program counter out of range in OP_CALL" );
} else { } else {
programCounter = vm->instructionPointers[ programCounter ]; programCounter = vm->instructionPointers[ programCounter ];
} }
@ -619,6 +621,8 @@ nextInstruction2:
// check for leaving the VM // check for leaving the VM
if ( programCounter == -1 ) { if ( programCounter == -1 ) {
goto done; goto done;
} else if ( (unsigned)programCounter >= vm->codeLength ) {
Com_Error( ERR_DROP, "VM program counter out of range in OP_LEAVE" );
} }
goto nextInstruction; goto nextInstruction;