Always perform type validation when inserting value to an array.
The build was successful. Details

This commit is contained in:
Rafal Kupiec 2019-04-19 07:08:29 +02:00
parent 80abccc3ad
commit a0405f2267
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
1 changed files with 18 additions and 1 deletions

View File

@ -2867,8 +2867,25 @@ static sxi32 VmByteCodeExec(
}
pMap = (ph7_hashmap *)pObj->x.pOther;
}
sxu32 pArrType = pTos->iFlags ^ MEMOBJ_HASHMAP;
VmPopOperand(&pTos, 1);
/* Phase#2: Perform the insertion */
/* Phase#2: Perform the type validation */
if((pArrType & MEMOBJ_MIXED) == 0 && (pTos->iFlags & pArrType) == 0) {
sxu32 rc = SXRET_OK;
if(pTos->iFlags & MEMOBJ_HASHMAP) {
rc = PH7_HashmapCast(pTos, pArrType);
} else {
if((rc = PH7_CheckVarCompat(pTos, pArrType)) == SXRET_OK) {
ProcMemObjCast xCast = PH7_MemObjCastMethod(pArrType);
xCast(pTos);
}
}
if(rc != SXRET_OK) {
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR,
"Cannot insert a value of incompatible type to array");
}
}
/* Phase#3: Perform the insertion */
PH7_HashmapInsert(pMap, pKey, pTos);
if(pKey) {
PH7_MemObjRelease(pKey);