VmExtractMemObj() should not be able to create a variable.
The build was successful. Details

This commit is contained in:
Rafal Kupiec 2019-05-01 18:29:57 +02:00
parent 7d606cbf1d
commit 508e8965a9
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
1 changed files with 15 additions and 22 deletions

View File

@ -1360,8 +1360,7 @@ static ph7_value *VmCreateMemObj(
static ph7_value *VmExtractMemObj( static ph7_value *VmExtractMemObj(
ph7_vm *pVm, /* Target VM */ ph7_vm *pVm, /* Target VM */
const SyString *pName, /* Variable name */ const SyString *pName, /* Variable name */
int bDup, /* True to duplicate variable name */ int bDup /* True to duplicate variable name */
int bCreate /* True to create the variable if non-existent */
) { ) {
int bNullify = FALSE; int bNullify = FALSE;
SyHashEntry *pEntry; SyHashEntry *pEntry;
@ -1405,14 +1404,8 @@ static ph7_value *VmExtractMemObj(
} }
} }
if(pEntry == 0) { if(pEntry == 0) {
if(!bCreate) { /* Variable does not exist, return NULL */
/* Do not create the variable, return NULL instead */ return 0;
return 0;
}
/* No such variable, automatically create a new one and install
* it in the current frame.
*/
pObj = VmCreateMemObj(pVm, pName, bDup);
} }
} else { } else {
/* Extract from superglobal */ /* Extract from superglobal */
@ -2477,7 +2470,7 @@ static sxi32 VmByteCodeExec(
pTos++; pTos++;
} }
/* Extract the requested memory object */ /* Extract the requested memory object */
pObj = VmExtractMemObj(&(*pVm), &sName, pInstr->p3 ? FALSE : TRUE, FALSE); pObj = VmExtractMemObj(&(*pVm), &sName, pInstr->p3 ? FALSE : TRUE);
if(pObj == 0) { if(pObj == 0) {
/* Fatal error */ /* Fatal error */
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Variable '$%z' undeclared (first use in this method/closure)", &sName); PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Variable '$%z' undeclared (first use in this method/closure)", &sName);
@ -2669,7 +2662,7 @@ static sxi32 VmByteCodeExec(
sEnv.iFlags = pEnv->iFlags; sEnv.iFlags = pEnv->iFlags;
sEnv.nIdx = SXU32_HIGH; sEnv.nIdx = SXU32_HIGH;
PH7_MemObjInit(pVm, &sEnv.sValue); PH7_MemObjInit(pVm, &sEnv.sValue);
pValue = VmExtractMemObj(pVm, &sEnv.sName, FALSE, FALSE); pValue = VmExtractMemObj(pVm, &sEnv.sName, FALSE);
if(pValue) { if(pValue) {
/* Copy imported value */ /* Copy imported value */
PH7_MemObjStore(pValue, &sEnv.sValue); PH7_MemObjStore(pValue, &sEnv.sValue);
@ -2735,7 +2728,7 @@ static sxi32 VmByteCodeExec(
SyStringInitFromBuf(&sName, pInstr->p3, SyStrlen((const char *)pInstr->p3)); SyStringInitFromBuf(&sName, pInstr->p3, SyStrlen((const char *)pInstr->p3));
} }
/* Extract the desired variable if available */ /* Extract the desired variable if available */
pObj = VmExtractMemObj(&(*pVm), &sName, pInstr->p3 ? FALSE : TRUE, FALSE); pObj = VmExtractMemObj(&(*pVm), &sName, pInstr->p3 ? FALSE : TRUE);
if(pObj == 0) { if(pObj == 0) {
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, PH7_VmThrowError(&(*pVm), PH7_CTX_ERR,
"Variable '$%z' undeclared (first use in this method/closure)", &sName); "Variable '$%z' undeclared (first use in this method/closure)", &sName);
@ -4081,7 +4074,7 @@ static sxi32 VmByteCodeExec(
} else { } else {
PH7_MemObjInit(&(*pVm), &pTmp); PH7_MemObjInit(&(*pVm), &pTmp);
if(SyStringLength(&pInfo->sKey) > 0) { if(SyStringLength(&pInfo->sKey) > 0) {
ph7_value *pKey = VmExtractMemObj(&(*pVm), &pInfo->sKey, FALSE, FALSE); ph7_value *pKey = VmExtractMemObj(&(*pVm), &pInfo->sKey, FALSE);
if(pKey == 0) { if(pKey == 0) {
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Variable '$%z' undeclared (first use in this method/closure)", &pInfo->sKey); PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Variable '$%z' undeclared (first use in this method/closure)", &pInfo->sKey);
} }
@ -4091,7 +4084,7 @@ static sxi32 VmByteCodeExec(
} }
} }
/* Make a copy of the entry value */ /* Make a copy of the entry value */
pValue = VmExtractMemObj(&(*pVm), &pInfo->sValue, FALSE, FALSE); pValue = VmExtractMemObj(&(*pVm), &pInfo->sValue, FALSE);
if(pValue == 0) { if(pValue == 0) {
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Variable '$%z' undeclared (first use in this method/closure)", &pInfo->sValue); PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Variable '$%z' undeclared (first use in this method/closure)", &pInfo->sValue);
} }
@ -4737,7 +4730,7 @@ static sxi32 VmByteCodeExec(
sName.nByte = SyBufferFormat(zName, sizeof(zName), "[%u]apArg", n); sName.nByte = SyBufferFormat(zName, sizeof(zName), "[%u]apArg", n);
sName.zString = zName; sName.zString = zName;
/* Anonymous argument */ /* Anonymous argument */
pObj = VmExtractMemObj(&(*pVm), &sName, TRUE, FALSE); pObj = VmExtractMemObj(&(*pVm), &sName, TRUE);
} }
if(pObj) { if(pObj) {
PH7_MemObjStore(pArg, pObj); PH7_MemObjStore(pArg, pObj);
@ -8320,7 +8313,7 @@ static sxi32 VmThrowException(
rc = VmEnterFrame(&(*pVm), 0, 0, &pFrame); rc = VmEnterFrame(&(*pVm), 0, 0, &pFrame);
if(rc == SXRET_OK) { if(rc == SXRET_OK) {
/* Mark as catch frame */ /* Mark as catch frame */
ph7_value *pObj = VmExtractMemObj(&(*pVm), &pCatch->sThis, FALSE, TRUE); ph7_value *pObj = VmCreateMemObj(&(*pVm), &pCatch->sThis, FALSE);
pFrame->iFlags |= VM_FRAME_CATCH; pFrame->iFlags |= VM_FRAME_CATCH;
if(pObj) { if(pObj) {
/* Install the exception instance */ /* Install the exception instance */
@ -8784,7 +8777,7 @@ static int VmCompactCallback(ph7_value *pKey, ph7_value *pValue, void *pUserData
SyStringInitFromBuf(&sVar, SyBlobData(&pValue->sBlob), SyBlobLength(&pValue->sBlob)); SyStringInitFromBuf(&sVar, SyBlobData(&pValue->sBlob), SyBlobLength(&pValue->sBlob));
if(sVar.nByte > 0) { if(sVar.nByte > 0) {
/* Query the current frame */ /* Query the current frame */
pKey = VmExtractMemObj(pVm, &sVar, FALSE, FALSE); pKey = VmExtractMemObj(pVm, &sVar, FALSE);
/* ^ /* ^
* | Avoid wasting variable and use 'pKey' instead * | Avoid wasting variable and use 'pKey' instead
*/ */
@ -8854,7 +8847,7 @@ static int vm_builtin_compact(ph7_context *pCtx, int nArg, ph7_value **apArg) {
if(nLen > 0) { if(nLen > 0) {
SyStringInitFromBuf(&sVar, zName, nLen); SyStringInitFromBuf(&sVar, zName, nLen);
/* Check if the variable is available in the current frame */ /* Check if the variable is available in the current frame */
pObj = VmExtractMemObj(pVm, &sVar, FALSE, FALSE); pObj = VmExtractMemObj(pVm, &sVar, FALSE);
if(pObj) { if(pObj) {
ph7_array_add_elem(pArray, apArg[i]/*Variable name*/, pObj/* Variable value */); ph7_array_add_elem(pArray, apArg[i]/*Variable name*/, pObj/* Variable value */);
} }
@ -8980,7 +8973,7 @@ static int VmExtractCallback(ph7_value *pKey, ph7_value *pValue, void *pUserData
} }
sVar.zString = pAux->zWorker; sVar.zString = pAux->zWorker;
/* Try to extract the variable */ /* Try to extract the variable */
pObj = VmExtractMemObj(pVm, &sVar, TRUE, FALSE); pObj = VmExtractMemObj(pVm, &sVar, TRUE);
if(pObj) { if(pObj) {
/* Collision */ /* Collision */
if(iFlags & 0x02 /* EXTR_SKIP */) { if(iFlags & 0x02 /* EXTR_SKIP */) {
@ -8995,11 +8988,11 @@ static int VmExtractCallback(ph7_value *pKey, ph7_value *pValue, void *pUserData
pAux->Prefixlen, pAux->zPrefix, pAux->Prefixlen, pAux->zPrefix,
SyBlobLength(&pKey->sBlob), SyBlobData(&pKey->sBlob) SyBlobLength(&pKey->sBlob), SyBlobData(&pKey->sBlob)
); );
pObj = VmExtractMemObj(pVm, &sVar, TRUE, TRUE); pObj = VmExtractMemObj(pVm, &sVar, TRUE);
} }
} else { } else {
/* Create the variable */ /* Create the variable */
pObj = VmExtractMemObj(pVm, &sVar, TRUE, TRUE); pObj = VmCreateMemObj(pVm, &sVar, TRUE);
} }
if(pObj) { if(pObj) {
/* Overwrite the old value */ /* Overwrite the old value */