Various fixes to vm_interpreted.c:

- Add opStack protection
- Fix dataMask check for OP_BLOCK_COPY
- Add instruction number check for conditional jumps
- Make errors in VM_PrepareInterpreter nonfatal
This commit is contained in:
Thilo Schulz 2011-06-16 01:11:45 +00:00
parent af5020c57c
commit 83522282f1
5 changed files with 156 additions and 169 deletions

View file

@ -386,28 +386,6 @@ static void ErrJump(void)
exit(1);
}
/*
=================
DoBlockCopy
Executes OP_BLOCK_COPY
=================
*/
void DoBlockCopy(unsigned int dest, unsigned int src, size_t n)
{
unsigned int dataMask = currentVM->dataMask;
if ((dest & dataMask) != dest
|| (src & dataMask) != src
|| ((dest + n) & dataMask) != dest + n
|| ((src + n) & dataMask) != src + n)
{
Com_Error(ERR_DROP, "OP_BLOCK_COPY out of range!");
}
memcpy(currentVM->dataBase + dest, currentVM->dataBase + src, n);
}
/*
=================
DoSyscall
@ -493,7 +471,7 @@ static void DoSyscall(void)
if(opStackOfs < 1)
Com_Error(ERR_DROP, "VM_BLOCK_COPY failed due to corrupted opStack");
DoBlockCopy(opStackBase[opStackOfs - 1], opStackBase[opStackOfs], arg);
VM_BlockCopy(opStackBase[(opStackOfs - 1)], opStackBase[opStackOfs], arg);
break;
default:
Com_Error(ERR_DROP, "Unknown VM operation %d", syscallNum);