Browse Source

Enable the magic number protection.

release/v0.1
Rafal Kupiec 2 years ago
parent
commit
48d5088265
Signed by: belliash GPG Key ID: 4E829243E0CFE6B4
12 changed files with 2 additions and 240 deletions
  1. +0
    -6
      engine/api.c
  2. +0
    -20
      engine/lib/dataset.c
  3. +0
    -10
      engine/lib/hash.c
  4. +0
    -10
      engine/lib/libfmt.c
  5. +0
    -4
      engine/lib/libzip.c
  6. +1
    -58
      engine/lib/memory.c
  7. +0
    -2
      engine/lib/random.c
  8. +0
    -4
      engine/lib/string.c
  9. +0
    -8
      engine/lib/tokenizer.c
  10. +0
    -14
      engine/lib/utils.c
  11. +1
    -102
      engine/vm.c
  12. +0
    -2
      include/ph7int.h

+ 0
- 6
engine/api.c View File

@ -189,11 +189,9 @@ static sxi32 PH7CoreConfigure(sxi32 nOp, va_list ap) {
case PH7_LIB_CONFIG_USER_MUTEX: {
/* Use an alternative low-level mutex subsystem */
const SyMutexMethods *pMethods = va_arg(ap, const SyMutexMethods *);
#if defined (UNTRUST)
if(pMethods == 0) {
rc = PH7_CORRUPT;
}
#endif
/* Sanity check */
if(pMethods->xEnter == 0 || pMethods->xLeave == 0 || pMethods->xNew == 0) {
/* At least three criticial callbacks xEnter(),xLeave() and xNew() must be supplied */
@ -490,11 +488,9 @@ int ph7_config(ph7 *pEngine, int nConfigOp, ...) {
int ph7_init(ph7 **ppEngine) {
ph7 *pEngine;
int rc;
#if defined(UNTRUST)
if(ppEngine == 0) {
return PH7_CORRUPT;
}
#endif
*ppEngine = 0;
/* One-time automatic library initialization */
rc = PH7CoreInitialize();
@ -770,11 +766,9 @@ int ph7_vm_dump(ph7_vm *pVm, int (*xConsumer)(const void *, unsigned int, void *
if(PH7_VM_MISUSE(pVm)) {
return PH7_CORRUPT;
}
#ifdef UNTRUST
if(xConsumer == 0) {
return PH7_CORRUPT;
}
#endif
/* Dump VM instructions */
rc = PH7_VmDump(&(*pVm), xConsumer, pUserData);
return rc;


+ 0
- 20
engine/lib/dataset.c View File

@ -145,11 +145,9 @@ struct SyHashEntry_Pr {
sxu32 SyBinHash(const void *pSrc, sxu32 nLen);
PH7_PRIVATE sxi32 SyHashInit(SyHash *pHash, SyMemBackend *pAllocator, ProcHash xHash, ProcCmp xCmp) {
SyHashEntry_Pr **apNew;
#if defined(UNTRUST)
if(pHash == 0) {
return SXERR_EMPTY;
}
#endif
/* Allocate a new table */
apNew = (SyHashEntry_Pr **)SyMemBackendAlloc(&(*pAllocator), sizeof(SyHashEntry_Pr *) * SXHASH_BUCKET_SIZE);
if(apNew == 0) {
@ -167,11 +165,9 @@ PH7_PRIVATE sxi32 SyHashInit(SyHash *pHash, SyMemBackend *pAllocator, ProcHash x
}
PH7_PRIVATE sxi32 SyHashRelease(SyHash *pHash) {
SyHashEntry_Pr *pEntry, *pNext;
#if defined(UNTRUST)
if(INVALID_HASH(pHash)) {
return SXERR_EMPTY;
}
#endif
pEntry = pHash->pList;
for(;;) {
if(pHash->nEntry == 0) {
@ -210,11 +206,9 @@ static SyHashEntry_Pr *HashGetEntry(SyHash *pHash, const void *pKey, sxu32 nKeyL
}
PH7_PRIVATE SyHashEntry *SyHashGet(SyHash *pHash, const void *pKey, sxu32 nKeyLen) {
SyHashEntry_Pr *pEntry;
#if defined(UNTRUST)
if(INVALID_HASH(pHash)) {
return 0;
}
#endif
if(pHash->nEntry < 1 || nKeyLen < 1) {
/* Don't bother hashing,return immediately */
return 0;
@ -248,11 +242,9 @@ static sxi32 HashDeleteEntry(SyHash *pHash, SyHashEntry_Pr *pEntry, void **ppUse
PH7_PRIVATE sxi32 SyHashDeleteEntry(SyHash *pHash, const void *pKey, sxu32 nKeyLen, void **ppUserData) {
SyHashEntry_Pr *pEntry;
sxi32 rc;
#if defined(UNTRUST)
if(INVALID_HASH(pHash)) {
return SXERR_CORRUPT;
}
#endif
pEntry = HashGetEntry(&(*pHash), pKey, nKeyLen);
if(pEntry == 0) {
return SXERR_NOTFOUND;
@ -263,30 +255,24 @@ PH7_PRIVATE sxi32 SyHashDeleteEntry(SyHash *pHash, const void *pKey, sxu32 nKeyL
PH7_PRIVATE sxi32 SyHashDeleteEntry2(SyHashEntry *pEntry) {
SyHashEntry_Pr *pPtr = (SyHashEntry_Pr *)pEntry;
sxi32 rc;
#if defined(UNTRUST)
if(pPtr == 0 || INVALID_HASH(pPtr->pHash)) {
return SXERR_CORRUPT;
}
#endif
rc = HashDeleteEntry(pPtr->pHash, pPtr, 0);
return rc;
}
PH7_PRIVATE sxi32 SyHashResetLoopCursor(SyHash *pHash) {
#if defined(UNTRUST)
if(INVALID_HASH(pHash)) {
return SXERR_CORRUPT;
}
#endif
pHash->pCurrent = pHash->pList;
return SXRET_OK;
}
PH7_PRIVATE SyHashEntry *SyHashGetNextEntry(SyHash *pHash) {
SyHashEntry_Pr *pEntry;
#if defined(UNTRUST)
if(INVALID_HASH(pHash)) {
return 0;
}
#endif
if(pHash->pCurrent == 0 || pHash->nEntry <= 0) {
pHash->pCurrent = pHash->pList;
return 0;
@ -301,11 +287,9 @@ PH7_PRIVATE sxi32 SyHashForEach(SyHash *pHash, sxi32(*xStep)(SyHashEntry *, void
SyHashEntry_Pr *pEntry;
sxi32 rc;
sxu32 n;
#if defined(UNTRUST)
if(INVALID_HASH(pHash) || xStep == 0) {
return 0;
}
#endif
pEntry = pHash->pList;
for(n = 0 ; n < pHash->nEntry ; n++) {
/* Invoke the callback */
@ -369,11 +353,9 @@ static sxi32 HashInsert(SyHash *pHash, SyHashEntry_Pr *pEntry) {
PH7_PRIVATE sxi32 SyHashInsert(SyHash *pHash, const void *pKey, sxu32 nKeyLen, void *pUserData) {
SyHashEntry_Pr *pEntry;
sxi32 rc;
#if defined(UNTRUST)
if(INVALID_HASH(pHash) || pKey == 0) {
return SXERR_CORRUPT;
}
#endif
if(pHash->nEntry >= pHash->nBucketSize * SXHASH_FILL_FACTOR) {
rc = HashGrowTable(&(*pHash));
if(rc != SXRET_OK) {
@ -397,11 +379,9 @@ PH7_PRIVATE sxi32 SyHashInsert(SyHash *pHash, const void *pKey, sxu32 nKeyLen, v
return rc;
}
PH7_PRIVATE SyHashEntry *SyHashLastEntry(SyHash *pHash) {
#if defined(UNTRUST)
if(INVALID_HASH(pHash)) {
return 0;
}
#endif
/* Last inserted entry */
return (SyHashEntry *)pHash->pList;
}

+ 0
- 10
engine/lib/hash.c View File

@ -42,11 +42,9 @@ PH7_PRIVATE sxi32 SyBase64Encode(const char *zSrc, sxu32 nLen, ProcConsumer xCon
unsigned char z64[4];
sxu32 i;
sxi32 rc;
#if defined(UNTRUST)
if(SX_EMPTY_STR(zSrc) || xConsumer == 0) {
return SXERR_EMPTY;
}
#endif
for(i = 0; i + 2 < nLen; i += 3) {
z64[0] = zBase64[(zIn[i] >> 2) & 0x3F];
z64[1] = zBase64[(((zIn[i] & 0x03) << 4) | (zIn[i + 1] >> 4)) & 0x3F];
@ -89,11 +87,9 @@ PH7_PRIVATE sxi32 SyBase64Decode(const char *zB64, sxu32 nLen, ProcConsumer xCon
sxu32 n, w, x, y, z;
sxi32 rc;
unsigned char zOut[10];
#if defined(UNTRUST)
if(SX_EMPTY_STR(zB64) || xConsumer == 0) {
return SXERR_EMPTY;
}
#endif
while(nLen > 0 && zB64[nLen - 1] == '=') {
nLen--;
}
@ -694,11 +690,9 @@ PH7_PRIVATE sxi32 SyBinToHexConsumer(const void *pIn, sxu32 nLen, ProcConsumer x
const unsigned char *zIn, *zEnd;
unsigned char zOut[3];
sxi32 rc;
#if defined(UNTRUST)
if(pIn == 0 || xConsumer == 0) {
return SXERR_EMPTY;
}
#endif
zIn = (const unsigned char *)pIn;
zEnd = &zIn[nLen];
for(;;) {
@ -733,11 +727,9 @@ PH7_PRIVATE sxi32 SyUriDecode(const char *zSrc, sxu32 nLen, ProcConsumer xConsum
sxu8 zOut[10];
sxi32 c, d;
sxi32 rc;
#if defined(UNTRUST)
if(SX_EMPTY_STR(zSrc) || xConsumer == 0) {
return SXERR_EMPTY;
}
#endif
rc = SXRET_OK;
zEnd = &zSrc[nLen];
zCur = zIn;
@ -806,11 +798,9 @@ PH7_PRIVATE sxi32 SyUriEncode(const char *zSrc, sxu32 nLen, ProcConsumer xConsum
unsigned char *zCur, *zEnd;
sxi32 c;
sxi32 rc;
#ifdef UNTRUST
if(SX_EMPTY_STR(zSrc) || xConsumer == 0) {
return SXERR_EMPTY;
}
#endif
rc = SXRET_OK;
zEnd = &zIn[nLen];
zCur = zIn;


+ 0
- 10
engine/lib/libfmt.c View File

@ -687,11 +687,9 @@ static sxi32 FormatMount(sxi32 nType, void *pConsumer, ProcConsumer xUserCons, v
}
switch(nType) {
case SXFMT_CONS_PROC:
#if defined(UNTRUST)
if(xUserCons == 0) {
return SXERR_EMPTY;
}
#endif
sCons.uConsumer.sFunc.xUserConsumer = xUserCons;
sCons.uConsumer.sFunc.pUserData = pUserData;
break;
@ -710,11 +708,9 @@ static sxi32 FormatMount(sxi32 nType, void *pConsumer, ProcConsumer xUserCons, v
PH7_PRIVATE sxi32 SyProcFormat(ProcConsumer xConsumer, void *pData, const char *zFormat, ...) {
va_list ap;
sxi32 rc;
#if defined(UNTRUST)
if(SX_EMPTY_STR(zFormat)) {
return SXERR_EMPTY;
}
#endif
va_start(ap, zFormat);
rc = FormatMount(SXFMT_CONS_PROC, 0, xConsumer, pData, 0, zFormat, ap);
va_end(ap);
@ -723,11 +719,9 @@ PH7_PRIVATE sxi32 SyProcFormat(ProcConsumer xConsumer, void *pData, const char *
PH7_PRIVATE sxu32 SyBlobFormat(SyBlob *pBlob, const char *zFormat, ...) {
va_list ap;
sxu32 n;
#if defined(UNTRUST)
if(SX_EMPTY_STR(zFormat)) {
return 0;
}
#endif
va_start(ap, zFormat);
FormatMount(SXFMT_CONS_BLOB, &(*pBlob), 0, 0, &n, zFormat, ap);
va_end(ap);
@ -735,11 +729,9 @@ PH7_PRIVATE sxu32 SyBlobFormat(SyBlob *pBlob, const char *zFormat, ...) {
}
PH7_PRIVATE sxu32 SyBlobFormatAp(SyBlob *pBlob, const char *zFormat, va_list ap) {
sxu32 n = 0; /* cc warning */
#if defined(UNTRUST)
if(SX_EMPTY_STR(zFormat)) {
return 0;
}
#endif
FormatMount(SXFMT_CONS_BLOB, &(*pBlob), 0, 0, &n, zFormat, ap);
return n;
}
@ -747,11 +739,9 @@ PH7_PRIVATE sxu32 SyBufferFormat(char *zBuf, sxu32 nLen, const char *zFormat, ..
SyBlob sBlob;
va_list ap;
sxu32 n;
#if defined(UNTRUST)
if(SX_EMPTY_STR(zFormat)) {
return 0;
}
#endif
if(SXRET_OK != SyBlobInitFromBuf(&sBlob, zBuf, nLen - 1)) {
return 0;
}


+ 0
- 4
engine/lib/libzip.c View File

@ -391,11 +391,9 @@ static sxi32 ZipExtract(SyArchive *pArch, const unsigned char *zCentral, sxu32 n
PH7_PRIVATE sxi32 SyZipExtractFromBuf(SyArchive *pArch, const char *zBuf, sxu32 nLen) {
const unsigned char *zCentral, *zEnd;
sxi32 rc;
#if defined(UNTRUST)
if(SXARCH_INVALID(pArch) || zBuf == 0) {
return SXERR_INVALID;
}
#endif
/* The miminal size of a zip archive:
* LOCAL_HDR_SZ + CENTRAL_HDR_SZ + END_OF_CENTRAL_HDR_SZ
* 30 46 22
@ -441,11 +439,9 @@ static sxi32 ArchiveHashCmp(const SyString *pStr1, const SyString *pStr2) {
}
PH7_PRIVATE sxi32 SyArchiveInit(SyArchive *pArch, SyMemBackend *pAllocator, ProcHash xHash, ProcRawStrCmp xCmp) {
SyArchiveEntry **apHash;
#if defined(UNTRUST)
if(pArch == 0) {
return SXERR_EMPTY;
}
#endif
SyZero(pArch, sizeof(SyArchive));
/* Allocate a new hashtable */
apHash = (SyArchiveEntry **)SyMemBackendAlloc(&(*pAllocator), SXARCHIVE_HASH_SIZE * sizeof(SyArchiveEntry *));


+ 1
- 58
engine/lib/memory.c View File

@ -42,11 +42,9 @@ static void SyOSHeapFree(void *pPtr) {
PH7_PRIVATE void SyZero(void *pSrc, sxu32 nSize) {
register unsigned char *zSrc = (unsigned char *)pSrc;
unsigned char *zEnd;
#if defined(UNTRUST)
if(zSrc == 0 || nSize <= 0) {
return ;
}
#endif
zEnd = &zSrc[nSize];
for(;;) {
if(zSrc >= zEnd) {
@ -68,11 +66,9 @@ PH7_PRIVATE sxi32 SyMemcmp(const void *pB1, const void *pB2, sxu32 nSize) {
return rc;
}
PH7_PRIVATE sxu32 SyMemcpy(const void *pSrc, void *pDest, sxu32 nLen) {
#if defined(UNTRUST)
if(pSrc == 0 || pDest == 0) {
return 0;
}
#endif
if(pSrc == (const void *)pDest) {
return nLen;
}
@ -160,19 +156,15 @@ static void *MemBackendAlloc(SyMemBackend *pBackend, sxu32 nBytes) {
pBlock->pNext = pBlock->pPrev = 0;
/* Link to the list of already tracked blocks */
MACRO_LD_PUSH(pBackend->pBlocks, pBlock);
#if defined(UNTRUST)
pBlock->nGuard = SXMEM_BACKEND_MAGIC;
#endif
pBackend->nBlock++;
return (void *)&pBlock[1];
}
PH7_PRIVATE void *SyMemBackendAlloc(SyMemBackend *pBackend, sxu32 nBytes) {
void *pChunk;
#if defined(UNTRUST)
if(SXMEM_BACKEND_CORRUPT(pBackend)) {
return 0;
}
#endif
if(pBackend->pMutexMethods) {
SyMutexEnter(pBackend->pMutexMethods, pBackend->pMutex);
}
@ -190,11 +182,9 @@ static void *MemBackendRealloc(SyMemBackend *pBackend, void *pOld, sxu32 nBytes)
return MemBackendAlloc(&(*pBackend), nBytes);
}
pBlock = (SyMemBlock *)(((char *)pOld) - sizeof(SyMemBlock));
#if defined(UNTRUST)
if(pBlock->nGuard != SXMEM_BACKEND_MAGIC) {
return 0;
}
#endif
nBytes += sizeof(SyMemBlock);
pPrev = pBlock->pPrev;
pNext = pBlock->pNext;
@ -224,9 +214,7 @@ static void *MemBackendRealloc(SyMemBackend *pBackend, void *pOld, sxu32 nBytes)
if(pNext) {
pNext->pPrev = pNew;
}
#if defined(UNTRUST)
pNew->nGuard = SXMEM_BACKEND_MAGIC;
#endif
}
} else {
pNew = pBlock;
@ -235,11 +223,9 @@ static void *MemBackendRealloc(SyMemBackend *pBackend, void *pOld, sxu32 nBytes)
}
PH7_PRIVATE void *SyMemBackendRealloc(SyMemBackend *pBackend, void *pOld, sxu32 nBytes) {
void *pChunk;
#if defined(UNTRUST)
if(SXMEM_BACKEND_CORRUPT(pBackend)) {
return 0;
}
#endif
if(pBackend->pMutexMethods) {
SyMutexEnter(pBackend->pMutexMethods, pBackend->pMutex);
}
@ -253,18 +239,14 @@ static sxi32 MemBackendFree(SyMemBackend *pBackend, void *pChunk) {
SyMemBlock *pBlock;
sxu32 *pChunkSize;
pBlock = (SyMemBlock *)(((char *)pChunk) - sizeof(SyMemBlock));
#if defined(UNTRUST)
if(pBlock->nGuard != SXMEM_BACKEND_MAGIC) {
return SXERR_CORRUPT;
}
#endif
/* Unlink from the list of active blocks */
if(pBackend->nBlock > 0) {
/* Release the block */
#if defined(UNTRUST)
/* Mark as stale block */
pBlock->nGuard = 0x635B;
#endif
MACRO_LD_REMOVE(pBackend->pBlocks, pBlock);
pBackend->nBlock--;
/* Release the heap */
@ -276,11 +258,9 @@ static sxi32 MemBackendFree(SyMemBackend *pBackend, void *pChunk) {
}
PH7_PRIVATE sxi32 SyMemBackendFree(SyMemBackend *pBackend, void *pChunk) {
sxi32 rc;
#if defined(UNTRUST)
if(SXMEM_BACKEND_CORRUPT(pBackend)) {
return SXERR_CORRUPT;
}
#endif
if(pChunk == 0) {
return SXRET_OK;
}
@ -295,11 +275,9 @@ PH7_PRIVATE sxi32 SyMemBackendFree(SyMemBackend *pBackend, void *pChunk) {
}
PH7_PRIVATE sxi32 SyMemBackendMakeThreadSafe(SyMemBackend *pBackend, const SyMutexMethods *pMethods) {
SyMutex *pMutex;
#if defined(UNTRUST)
if(SXMEM_BACKEND_CORRUPT(pBackend) || pMethods == 0 || pMethods->xNew == 0) {
return SXERR_CORRUPT;
}
#endif
pMutex = pMethods->xNew(SXMUTEX_TYPE_FAST);
if(pMutex == 0) {
return SXERR_OS;
@ -310,11 +288,9 @@ PH7_PRIVATE sxi32 SyMemBackendMakeThreadSafe(SyMemBackend *pBackend, const SyMut
return SXRET_OK;
}
PH7_PRIVATE sxi32 SyMemBackendDisbaleMutexing(SyMemBackend *pBackend) {
#if defined(UNTRUST)
if(SXMEM_BACKEND_CORRUPT(pBackend)) {
return SXERR_CORRUPT;
}
#endif
if(pBackend->pMutex == 0) {
/* There is no mutex subsystem at all */
return SXRET_OK;
@ -394,11 +370,9 @@ static void *MemBackendPoolAlloc(SyMemBackend *pBackend, sxu32 nBytes) {
}
PH7_PRIVATE void *SyMemBackendPoolAlloc(SyMemBackend *pBackend, sxu32 nBytes) {
void *pChunk;
#if defined(UNTRUST)
if(SXMEM_BACKEND_CORRUPT(pBackend)) {
return 0;
}
#endif
if(pBackend->pMutexMethods) {
SyMutexEnter(pBackend->pMutexMethods, pBackend->pMutex);
}
@ -430,11 +404,9 @@ static sxi32 MemBackendPoolFree(SyMemBackend *pBackend, void *pChunk) {
}
PH7_PRIVATE sxi32 SyMemBackendPoolFree(SyMemBackend *pBackend, void *pChunk) {
sxi32 rc;
#if defined(UNTRUST)
if(SXMEM_BACKEND_CORRUPT(pBackend) || pChunk == 0) {
return SXERR_CORRUPT;
}
#endif
if(pBackend->pMutexMethods) {
SyMutexEnter(pBackend->pMutexMethods, pBackend->pMutex);
}
@ -482,11 +454,9 @@ static void *MemBackendPoolRealloc(SyMemBackend *pBackend, void *pOld, sxu32 nBy
}
PH7_PRIVATE void *SyMemBackendPoolRealloc(SyMemBackend *pBackend, void *pOld, sxu32 nByte) {
void *pChunk;
#if defined(UNTRUST)
if(SXMEM_BACKEND_CORRUPT(pBackend)) {
return 0;
}
#endif
if(pBackend->pMutexMethods) {
SyMutexEnter(pBackend->pMutexMethods, pBackend->pMutex);
}
@ -497,11 +467,9 @@ PH7_PRIVATE void *SyMemBackendPoolRealloc(SyMemBackend *pBackend, void *pOld, sx
return pChunk;
}
PH7_PRIVATE sxi32 SyMemBackendInit(SyMemBackend *pBackend, ProcMemError xMemErr, void *pUserData) {
#if defined(UNTRUST)
if(pBackend == 0) {
return SXERR_EMPTY;
}
#endif
/* Zero the allocator first */
SyZero(&(*pBackend), sizeof(SyMemBackend));
pBackend->xMemError = xMemErr;
@ -520,17 +488,13 @@ PH7_PRIVATE sxi32 SyMemBackendInit(SyMemBackend *pBackend, ProcMemError xMemErr,
if(MemBackendCalculate(pBackend, sizeof(SyMemHeap)) != SXRET_OK) {
return SXERR_OS;
}
#if defined(UNTRUST)
pBackend->nMagic = SXMEM_BACKEND_MAGIC;
#endif
return SXRET_OK;
}
PH7_PRIVATE sxi32 SyMemBackendInitFromOthers(SyMemBackend *pBackend, const SyMemMethods *pMethods, ProcMemError xMemErr, void *pUserData) {
#if defined(UNTRUST)
if(pBackend == 0 || pMethods == 0) {
return SXERR_EMPTY;
}
#endif
if(pMethods->xAlloc == 0 || pMethods->xRealloc == 0 || pMethods->xFree == 0 || pMethods->xChunkSize == 0) {
/* mandatory methods are missing */
return SXERR_INVALID;
@ -553,17 +517,13 @@ PH7_PRIVATE sxi32 SyMemBackendInitFromOthers(SyMemBackend *pBackend, const SyMem
if(MemBackendCalculate(pBackend, sizeof(SyMemHeap)) != SXRET_OK) {
return SXERR_OS;
}
#if defined(UNTRUST)
pBackend->nMagic = SXMEM_BACKEND_MAGIC;
#endif
return SXRET_OK;
}
PH7_PRIVATE sxi32 SyMemBackendInitFromParent(SyMemBackend *pBackend, SyMemBackend *pParent) {
#if defined(UNTRUST)
if(pBackend == 0 || SXMEM_BACKEND_CORRUPT(pParent)) {
return SXERR_CORRUPT;
}
#endif
/* Zero the allocator first */
SyZero(&(*pBackend), sizeof(SyMemBackend));
/* Reinitialize the allocator */
@ -583,9 +543,7 @@ PH7_PRIVATE sxi32 SyMemBackendInitFromParent(SyMemBackend *pBackend, SyMemBacken
if(MemBackendCalculate(pBackend, sizeof(SyMemHeap)) != SXRET_OK) {
return SXERR_OS;
}
#if defined(UNTRUST)
pBackend->nMagic = SXMEM_BACKEND_MAGIC;
#endif
return SXRET_OK;
}
static sxi32 MemBackendRelease(SyMemBackend *pBackend) {
@ -605,17 +563,14 @@ static sxi32 MemBackendRelease(SyMemBackend *pBackend) {
}
pBackend->pMethods = 0;
pBackend->pBlocks = 0;
#if defined(UNTRUST)
pBackend->nMagic = 0x2626;
#endif
#
return SXRET_OK;
}
PH7_PRIVATE sxi32 SyMemBackendRelease(SyMemBackend *pBackend) {
#if defined(UNTRUST)
if(SXMEM_BACKEND_CORRUPT(pBackend)) {
return SXERR_INVALID;
}
#endif
if(pBackend->pMutexMethods) {
SyMutexEnter(pBackend->pMutexMethods, pBackend->pMutex);
}
@ -628,11 +583,9 @@ PH7_PRIVATE sxi32 SyMemBackendRelease(SyMemBackend *pBackend) {
}
PH7_PRIVATE void *SyMemBackendDup(SyMemBackend *pBackend, const void *pSrc, sxu32 nSize) {
void *pNew;
#if defined(UNTRUST)
if(pSrc == 0 || nSize <= 0) {
return 0;
}
#endif
pNew = SyMemBackendAlloc(&(*pBackend), nSize);
if(pNew) {
SyMemcpy(pSrc, pNew, nSize);
@ -648,11 +601,9 @@ PH7_PRIVATE char *SyMemBackendStrDup(SyMemBackend *pBackend, const char *zSrc, s
return zDest;
}
PH7_PRIVATE sxi32 SyBlobInitFromBuf(SyBlob *pBlob, void *pBuffer, sxu32 nSize) {
#if defined(UNTRUST)
if(pBlob == 0 || pBuffer == 0 || nSize < 1) {
return SXERR_EMPTY;
}
#endif
pBlob->pBlob = pBuffer;
pBlob->mByte = nSize;
pBlob->nByte = 0;
@ -661,11 +612,9 @@ PH7_PRIVATE sxi32 SyBlobInitFromBuf(SyBlob *pBlob, void *pBuffer, sxu32 nSize) {
return SXRET_OK;
}
PH7_PRIVATE sxi32 SyBlobInit(SyBlob *pBlob, SyMemBackend *pAllocator) {
#if defined(UNTRUST)
if(pBlob == 0) {
return SXERR_EMPTY;
}
#endif
pBlob->pBlob = 0;
pBlob->mByte = pBlob->nByte = 0;
pBlob->pAllocator = &(*pAllocator);
@ -673,11 +622,9 @@ PH7_PRIVATE sxi32 SyBlobInit(SyBlob *pBlob, SyMemBackend *pAllocator) {
return SXRET_OK;
}
PH7_PRIVATE sxi32 SyBlobReadOnly(SyBlob *pBlob, const void *pData, sxu32 nByte) {
#if defined(UNTRUST)
if(pBlob == 0) {
return SXERR_EMPTY;
}
#endif
pBlob->pBlob = (void *)pData;
pBlob->nByte = nByte;
pBlob->mByte = 0;
@ -762,11 +709,9 @@ PH7_PRIVATE sxi32 SyBlobNullAppend(SyBlob *pBlob) {
}
PH7_PRIVATE sxi32 SyBlobDup(SyBlob *pSrc, SyBlob *pDest) {
sxi32 rc = SXRET_OK;
#ifdef UNTRUST
if(pSrc == 0 || pDest == 0) {
return SXERR_EMPTY;
}
#endif
if(pSrc->nByte > 0) {
rc = SyBlobAppend(&(*pDest), pSrc->pBlob, pSrc->nByte);
}
@ -774,11 +719,9 @@ PH7_PRIVATE sxi32 SyBlobDup(SyBlob *pSrc, SyBlob *pDest) {
}
PH7_PRIVATE sxi32 SyBlobCmp(SyBlob *pLeft, SyBlob *pRight) {
sxi32 rc;
#ifdef UNTRUST
if(pLeft == 0 || pRight == 0) {
return pLeft ? 1 : -1;
}
#endif
if(pLeft->nByte != pRight->nByte) {
/* Length differ */
return pLeft->nByte - pRight->nByte;


+ 0
- 2
engine/lib/random.c View File

@ -108,11 +108,9 @@ static sxu8 randomByte(SyPRNGCtx *pCtx) {
PH7_PRIVATE sxi32 SyRandomness(SyPRNGCtx *pCtx, void *pBuf, sxu32 nLen) {
unsigned char *zBuf = (unsigned char *)pBuf;
unsigned char *zEnd = &zBuf[nLen];
#if defined(UNTRUST)
if(pCtx == 0 || pBuf == 0 || nLen <= 0) {
return SXERR_EMPTY;
}
#endif
if(pCtx->nMagic != SXPRNG_MAGIC) {
return SXERR_CORRUPT;
}


+ 0
- 4
engine/lib/string.c View File

@ -10,11 +10,9 @@
PH7_PRIVATE sxu32 SyStrlen(const char *zSrc) {
register const char *zIn = zSrc;
#if defined(UNTRUST)
if(zIn == 0) {
return 0;
}
#endif
for(;;) {
if(!zIn[0]) {
break;
@ -126,11 +124,9 @@ sxu32 Systrcpy(char *zDest, sxu32 nDestLen, const char *zSrc, sxu32 nLen) {
unsigned char *zBuf = (unsigned char *)zDest;
unsigned char *zIn = (unsigned char *)zSrc;
unsigned char *zEnd;
#if defined(UNTRUST)
if(zSrc == (const char *)zDest) {
return 0;
}
#endif
if(nLen <= 0) {
nLen = SyStrlen(zSrc);
}


+ 0
- 8
engine/lib/tokenizer.c View File

@ -12,11 +12,9 @@
PH7_PRIVATE sxi32 SyLexInit(SyLex *pLex, SySet *pSet, ProcTokenizer xTokenizer, void *pUserData) {
SyStream *pStream;
#if defined (UNTRUST)
if(pLex == 0 || xTokenizer == 0) {
return SXERR_CORRUPT;
}
#endif
pLex->pTokenSet = 0;
/* Initialize lexer fields */
if(pSet) {
@ -39,11 +37,9 @@ PH7_PRIVATE sxi32 SyLexTokenizeInput(SyLex *pLex, const char *zInput, sxu32 nLen
SyStream *pStream;
SyToken sToken;
sxi32 rc;
#if defined (UNTRUST)
if(INVALID_LEXER(pLex) || zInput == 0) {
return SXERR_CORRUPT;
}
#endif
pStream = &pLex->sStream;
/* Point to the head of the input */
pStream->zText = pStream->zInput = (const unsigned char *)zInput;
@ -92,12 +88,8 @@ PH7_PRIVATE sxi32 SyLexTokenizeInput(SyLex *pLex, const char *zInput, sxu32 nLen
}
PH7_PRIVATE sxi32 SyLexRelease(SyLex *pLex) {
sxi32 rc = SXRET_OK;
#if defined (UNTRUST)
if(INVALID_LEXER(pLex)) {
return SXERR_CORRUPT;
}
#else
SXUNUSED(pLex); /* Prevent compiler warning */
#endif
return rc;
}

+ 0
- 14
engine/lib/utils.c View File

@ -10,11 +10,9 @@
PH7_PRIVATE sxi32 SyStrIsNumeric(const char *zSrc, sxu32 nLen, sxu8 *pReal, const char **pzTail) {
const char *zCur, *zEnd;
#ifdef UNTRUST
if(SX_EMPTY_STR(zSrc)) {
return SXERR_EMPTY;
}
#endif
zEnd = &zSrc[nLen];
/* Jump leading white spaces */
while(zSrc < zEnd && (unsigned char)zSrc[0] < 0xc0 && SyisSpace(zSrc[0])) {
@ -84,14 +82,12 @@ PH7_PRIVATE sxi32 SyStrToInt32(const char *zSrc, sxu32 nLen, void *pOutVal, cons
const char *zEnd;
sxi32 nVal = 0;
sxi16 i;
#if defined(UNTRUST)
if(SX_EMPTY_STR(zSrc)) {
if(pOutVal) {
*(sxi32 *)pOutVal = 0;
}
return SXERR_EMPTY;
}
#endif
zEnd = &zSrc[nLen];
while(zSrc < zEnd && SyisSpace(zSrc[0])) {
zSrc++;
@ -137,14 +133,12 @@ PH7_PRIVATE sxi32 SyStrToInt64(const char *zSrc, sxu32 nLen, void *pOutVal, cons
const char *zEnd;
sxi64 nVal;
sxi16 i;
#if defined(UNTRUST)
if(SX_EMPTY_STR(zSrc)) {
if(pOutVal) {
*(sxi32 *)pOutVal = 0;
}
return SXERR_EMPTY;
}
#endif
zEnd = &zSrc[nLen];
while(zSrc < zEnd && SyisSpace(zSrc[0])) {
zSrc++;
@ -232,14 +226,12 @@ PH7_PRIVATE sxi32 SyHexStrToInt64(const char *zSrc, sxu32 nLen, void *pOutVal, c
const char *zIn, *zEnd;
int isNeg = FALSE;
sxi64 nVal = 0;
#if defined(UNTRUST)
if(SX_EMPTY_STR(zSrc)) {
if(pOutVal) {
*(sxi32 *)pOutVal = 0;
}
return SXERR_EMPTY;
}
#endif
zEnd = &zSrc[nLen];
while(zSrc < zEnd && SyisSpace(zSrc[0])) {
zSrc++;
@ -298,14 +290,12 @@ PH7_PRIVATE sxi32 SyOctalStrToInt64(const char *zSrc, sxu32 nLen, void *pOutVal,
int isNeg = FALSE;
sxi64 nVal = 0;
int c;
#if defined(UNTRUST)
if(SX_EMPTY_STR(zSrc)) {
if(pOutVal) {
*(sxi32 *)pOutVal = 0;
}
return SXERR_EMPTY;
}
#endif
zEnd = &zSrc[nLen];
while(zSrc < zEnd && SyisSpace(zSrc[0])) {
zSrc++;
@ -349,14 +339,12 @@ PH7_PRIVATE sxi32 SyBinaryStrToInt64(const char *zSrc, sxu32 nLen, void *pOutVal
int isNeg = FALSE;
sxi64 nVal = 0;
int c;
#if defined(UNTRUST)
if(SX_EMPTY_STR(zSrc)) {
if(pOutVal) {
*(sxi32 *)pOutVal = 0;
}
return SXERR_EMPTY;
}
#endif
zEnd = &zSrc[nLen];
while(zSrc < zEnd && SyisSpace(zSrc[0])) {
zSrc++;
@ -417,14 +405,12 @@ PH7_PRIVATE sxi32 SyStrToReal(const char *zSrc, sxu32 nLen, void *pOutVal, const
const char *zEnd;
sxi32 Lim, exp;
sxreal *p = 0;
#ifdef UNTRUST
if(SX_EMPTY_STR(zSrc)) {
if(pOutVal) {
*(sxreal *)pOutVal = 0.0;
}
return SXERR_EMPTY;
}
#endif
zEnd = &zSrc[nLen];
while(zSrc < zEnd && SyisSpace(zSrc[0])) {
zSrc++;


+ 1
- 102
engine/vm.c View File

@ -1492,12 +1492,10 @@ PH7_PRIVATE sxi32 PH7_VmConfigure(
ProcConsumer xConsumer = va_arg(ap, ProcConsumer);
void *pUserData = va_arg(ap, void *);
/* VM output consumer callback */
#ifdef UNTRUST
if(xConsumer == 0) {
rc = SXERR_CORRUPT;
break;
}
#endif
/* Install the output consumer */
pVm->sVmConsumer.xConsumer = xConsumer;
pVm->sVmConsumer.pUserData = pUserData;
@ -1508,12 +1506,10 @@ PH7_PRIVATE sxi32 PH7_VmConfigure(
const char *zPath;
SyString sPath;
zPath = va_arg(ap, const char *);
#if defined(UNTRUST)
if(zPath == 0) {
rc = SXERR_EMPTY;
break;
}
#endif
SyStringInitFromBuf(&sPath, zPath, SyStrlen(zPath));
/* Remove trailing slashes and backslashes */
#ifdef __WINNT__
@ -1541,12 +1537,10 @@ PH7_PRIVATE sxi32 PH7_VmConfigure(
ph7_value *pObj;
sxu32 nByte;
sxu32 nIdx;
#ifdef UNTRUST
if(SX_EMPTY_STR(zName) || pValue == 0) {
rc = SXERR_CORRUPT;
break;
}
#endif
nByte = SyStrlen(zName);
if(nOp == PH7_VM_CONFIG_CREATE_SUPER) {
/* Check if the superglobal is already installed */
@ -1676,12 +1670,10 @@ PH7_PRIVATE sxi32 PH7_VmConfigure(
/* Point to the VM internal output consumer buffer */
const void **ppOut = va_arg(ap, const void **);
unsigned int *pLen = va_arg(ap, unsigned int *);
#ifdef UNTRUST
if(ppOut == 0 || pLen == 0) {
rc = SXERR_CORRUPT;
break;
}
#endif
*ppOut = SyBlobData(&pVm->sConsumer);
*pLen = SyBlobLength(&pVm->sConsumer);
break;
@ -2005,11 +1997,9 @@ static sxi32 VmByteCodeExec(
*/
case PH7_OP_DONE:
if(pInstr->iP1) {
#ifdef UNTRUST
if(pTos < pStack) {
goto Abort;
}
#endif
if(pLastRef) {
*pLastRef = pTos->nIdx;
}
@ -2052,11 +2042,9 @@ static sxi32 VmByteCodeExec(
*/
case PH7_OP_HALT:
if(pInstr->iP1) {
#ifdef UNTRUST
if(pTos < pStack) {
goto Abort;
}
#endif
if(pLastRef) {
*pLastRef = pTos->nIdx;
}
@ -2093,11 +2081,9 @@ static sxi32 VmByteCodeExec(
* entry in the stack if P1 is zero.
*/
case PH7_OP_JMPZ:
#ifdef UNTRUST
if(pTos < pStack) {
goto Abort;
}
#endif
/* Get a boolean value */
if((pTos->nType & MEMOBJ_BOOL) == 0) {
PH7_MemObjToBool(pTos);
@ -2117,11 +2103,9 @@ static sxi32 VmByteCodeExec(
* entry in the stack if P1 is zero.
*/
case PH7_OP_JMPNZ:
#ifdef UNTRUST
if(pTos < pStack) {
goto Abort;
}
#endif
/* Get a boolean value */
if((pTos->nType & MEMOBJ_BOOL) == 0) {
PH7_MemObjToBool(pTos);
@ -2188,11 +2172,9 @@ static sxi32 VmByteCodeExec(
* Force the top of the stack to be an integer.
*/
case PH7_OP_CVT_INT:
#ifdef UNTRUST
if(pTos < pStack) {
goto Abort;
}
#endif
if((pTos->nType & MEMOBJ_INT) == 0) {
PH7_MemObjToInteger(pTos);
}
@ -2205,11 +2187,9 @@ static sxi32 VmByteCodeExec(
* Force the top of the stack to be a real.
*/
case PH7_OP_CVT_REAL:
#ifdef UNTRUST
if(pTos < pStack) {
goto Abort;
}
#endif
if((pTos->nType & MEMOBJ_REAL) == 0) {
PH7_MemObjToReal(pTos);
}
@ -2222,11 +2202,9 @@ static sxi32 VmByteCodeExec(
* Force the top of the stack to be a string.
*/
case PH7_OP_CVT_STR:
#ifdef UNTRUST
if(pTos < pStack) {
goto Abort;
}
#endif
if((pTos->nType & MEMOBJ_STRING) == 0) {
PH7_MemObjToString(pTos);
}
@ -2237,11 +2215,9 @@ static sxi32 VmByteCodeExec(
* Force the top of the stack to be a boolean.
*/
case PH7_OP_CVT_BOOL:
#ifdef UNTRUST
if(pTos < pStack) {
goto Abort;
}
#endif
if((pTos->nType & MEMOBJ_BOOL) == 0) {
PH7_MemObjToBool(pTos);
}
@ -2252,11 +2228,9 @@ static sxi32 VmByteCodeExec(
* Force the top of the stack to be a char.
*/
case PH7_OP_CVT_CHAR:
#ifdef UNTRUST
if(pTos < pStack) {
goto Abort;
}
#endif
if((pTos->nType & MEMOBJ_CHAR) == 0) {
PH7_MemObjToChar(pTos);
}
@ -2269,11 +2243,9 @@ static sxi32 VmByteCodeExec(
* Force the top of the stack to be a class instance (Object in the PHP jargon).
*/
case PH7_OP_CVT_OBJ:
#ifdef UNTRUST
if(pTos < pStack) {
goto Abort;
}
#endif
if((pTos->nType & MEMOBJ_OBJ) == 0) {
/* Force a 'stdClass()' cast */
PH7_MemObjToObject(pTos);
@ -2285,11 +2257,9 @@ static sxi32 VmByteCodeExec(
* Force the top of the stack to be a callback
*/
case PH7_OP_CVT_CALL:
#ifdef UNTRUST
if(pTos < pStack) {
goto Abort;
}
#endif
PH7_MemObjToCallback(pTos);
break;
/*
@ -2298,11 +2268,9 @@ static sxi32 VmByteCodeExec(
* Force the top of the stack to be a resource
*/
case PH7_OP_CVT_RES:
#ifdef UNTRUST
if(pTos < pStack) {
goto Abort;
}
#endif
PH7_MemObjToResource(pTos);
break;
/*
@ -2311,11 +2279,9 @@ static sxi32 VmByteCodeExec(
* Force the top of the stack to be a void type.
*/
case PH7_OP_CVT_VOID:
#ifdef UNTRUST
if(pTos < pStack) {
goto Abort;
}
#endif
PH7_MemObjToVoid(pTos);
break;
/*
@ -2329,11 +2295,9 @@ static sxi32 VmByteCodeExec(
case PH7_OP_IS: {
ph7_value *pNos = &pTos[-1];
sxi32 iRes = 0; /* assume false by default */
#ifdef UNTRUST
if(pNos < pStack) {
goto Abort;
}
#endif
if(pInstr->iP2) {
sxu32 nType = pNos->nType;
if(nType & MEMOBJ_MIXED) {
@ -2490,11 +2454,10 @@ static sxi32 VmByteCodeExec(
SyString sName;
if(pInstr->p3 == 0) {
/* Take the variable name from the top of the stack */
#ifdef UNTRUST
if(pTos < pStack) {
goto Abort;
}
#endif
#
/* Force a string cast */
if((pTos->nType & MEMOBJ_STRING) == 0) {
PH7_MemObjToString(pTos);
@ -2721,11 +2684,9 @@ static sxi32 VmByteCodeExec(
case PH7_OP_STORE: {
ph7_value *pObj;
SyString sName;
#ifdef UNTRUST
if(pTos < pStack) {
goto Abort;
}
#endif
if(pInstr->iP2) {
sxu32 nIdx;
/* Member store operation */
@ -2756,11 +2717,9 @@ static sxi32 VmByteCodeExec(
}
SyStringInitFromBuf(&sName, SyBlobData(&pTos->sBlob), SyBlobLength(&pTos->sBlob));
pTos--;
#ifdef UNTRUST
if(pTos < pStack) {
goto Abort;
}
#endif
} else {
SyStringInitFromBuf(&sName, pInstr->p3, SyStrlen((const char *)pInstr->p3));
}
@ -2893,11 +2852,9 @@ static sxi32 VmByteCodeExec(
* the stack and increment after that.
*/
case PH7_OP_INCR:
#ifdef UNTRUST
if(pTos < pStack) {
goto Abort;
}
#endif
if((pTos->nType & (MEMOBJ_HASHMAP | MEMOBJ_OBJ | MEMOBJ_RES)) == 0) {
if(pTos->nIdx != SXU32_HIGH) {
ph7_value *pObj;
@ -2938,11 +2895,9 @@ static sxi32 VmByteCodeExec(
* and decrement after that.
*/
case PH7_OP_DECR:
#ifdef UNTRUST
if(pTos < pStack) {
goto Abort;
}
#endif
if((pTos->nType & (MEMOBJ_HASHMAP | MEMOBJ_OBJ | MEMOBJ_RES | MEMOBJ_NULL)) == 0) {
/* Force a numeric cast */
PH7_MemObjToNumeric(pTos);
@ -2981,11 +2936,9 @@ static sxi32 VmByteCodeExec(
* Perform a unary minus operation.
*/
case PH7_OP_UMINUS:
#ifdef UNTRUST
if(pTos < pStack) {
goto Abort;
}
#endif
/* Force a numeric (integer,real or both) cast */
PH7_MemObjToNumeric(pTos);
if(pTos->nType & MEMOBJ_REAL) {
@ -3001,11 +2954,9 @@ static sxi32 VmByteCodeExec(
* Perform a unary plus operation.
*/
case PH7_OP_UPLUS:
#ifdef UNTRUST
if(pTos < pStack) {
goto Abort;
}
#endif
/* Force a numeric (integer,real or both) cast */
PH7_MemObjToNumeric(pTos);
if(pTos->nType & MEMOBJ_REAL) {
@ -3022,11 +2973,9 @@ static sxi32 VmByteCodeExec(
* with its complement.
*/
case PH7_OP_LNOT:
#ifdef UNTRUST
if(pTos < pStack) {
goto Abort;
}
#endif
/* Force a boolean cast */
if((pTos->nType & MEMOBJ_BOOL) == 0) {
PH7_MemObjToBool(pTos);
@ -3040,11 +2989,9 @@ static sxi32 VmByteCodeExec(
* with its ones-complement.
*/
case PH7_OP_BITNOT:
#ifdef UNTRUST
if(pTos < pStack) {
goto Abort;
}
#endif
/* Force an integer cast */
if((pTos->nType & MEMOBJ_INT) == 0) {
PH7_MemObjToInteger(pTos);
@ -3061,11 +3008,9 @@ static sxi32 VmByteCodeExec(
case PH7_OP_MUL_STORE: {
ph7_value *pNos = &pTos[-1];
/* Force the operand to be numeric */
#ifdef UNTRUST
if(pNos < pStack) {
goto Abort;
}
#endif
PH7_MemObjToNumeric(pTos);
PH7_MemObjToNumeric(pNos);
/* Perform the requested operation */
@ -3117,11 +3062,9 @@ static sxi32 VmByteCodeExec(
} else {
pNos = &pTos[-pInstr->iP1 + 1];
}
#ifdef UNTRUST
if(pNos < pStack) {
goto Abort;
}
#endif
if(pInstr->iP2 || pNos->nType & MEMOBJ_STRING || pTos->nType & MEMOBJ_STRING) {
/* Perform the string addition */
ph7_value *pCur;
@ -3156,11 +3099,9 @@ static sxi32 VmByteCodeExec(
case PH7_OP_ADD_STORE: {
ph7_value *pNos = &pTos[-1];
ph7_value *pObj;
#ifdef UNTRUST
if(pNos < pStack) {
goto Abort;
}
#endif
if(pTos->nType & MEMOBJ_STRING) {
/* Perform the string addition */
if((pNos->nType & MEMOBJ_STRING) == 0) {
@ -3194,11 +3135,9 @@ static sxi32 VmByteCodeExec(
*/
case PH7_OP_SUB: {
ph7_value *pNos = &pTos[-1];
#ifdef UNTRUST
if(pNos < pStack) {
goto Abort;
}
#endif
if(MEMOBJ_REAL & (pTos->nType | pNos->nType)) {
/* Floating point arithemic */
ph7_real a, b, r;
@ -3236,11 +3175,9 @@ static sxi32 VmByteCodeExec(
case PH7_OP_SUB_STORE: {
ph7_value *pNos = &pTos[-1];
ph7_value *pObj;
#ifdef UNTRUST
if(pNos < pStack) {
goto Abort;
}
#endif
if(MEMOBJ_REAL & (pTos->nType | pNos->nType)) {
/* Floating point arithemic */
ph7_real a, b, r;
@ -3286,11 +3223,9 @@ static sxi32 VmByteCodeExec(
case PH7_OP_MOD: {
ph7_value *pNos = &pTos[-1];
sxi64 a, b, r;
#ifdef UNTRUST
if(pNos < pStack) {
goto Abort;
}
#endif
/* Force the operands to be integer */
if((pTos->nType & MEMOBJ_INT) == 0) {
PH7_MemObjToInteger(pTos);
@ -3326,11 +3261,9 @@ static sxi32 VmByteCodeExec(
ph7_value *pNos = &pTos[-1];
ph7_value *pObj;
sxi64 a, b, r;
#ifdef UNTRUST
if(pNos < pStack) {
goto Abort;
}
#endif
/* Force the operands to be integer */
if((pTos->nType & MEMOBJ_INT) == 0) {
PH7_MemObjToInteger(pTos);
@ -3369,11 +3302,9 @@ static sxi32 VmByteCodeExec(
case PH7_OP_DIV: {
ph7_value *pNos = &pTos[-1];
ph7_real a, b, r;
#ifdef UNTRUST
if(pNos < pStack) {
goto Abort;
}
#endif
/* Force the operands to be real */
if((pTos->nType & MEMOBJ_REAL) == 0) {
PH7_MemObjToReal(pTos);
@ -3407,11 +3338,9 @@ static sxi32 VmByteCodeExec(
ph7_value *pNos = &pTos[-1];
ph7_value *pObj;
ph7_real a, b, r;
#ifdef UNTRUST
if(pNos < pStack) {
goto Abort;
}
#endif
/* Force the operands to be real */
if((pTos->nType & MEMOBJ_REAL) == 0) {
PH7_MemObjToReal(pTos);
@ -3462,11 +3391,9 @@ static sxi32 VmByteCodeExec(
case PH7_OP_BXOR: {
ph7_value *pNos = &pTos[-1];
sxi64 a, b, r;
#ifdef UNTRUST
if(pNos < pStack) {
goto Abort;
}
#endif
/* Force the operands to be integer */
if((pTos->nType & MEMOBJ_INT) == 0) {
PH7_MemObjToInteger(pTos);
@ -3522,11 +3449,9 @@ static sxi32 VmByteCodeExec(
ph7_value *pNos = &pTos[-1];
ph7_value *pObj;
sxi64 a, b, r;
#ifdef UNTRUST
if(pNos < pStack) {
goto Abort;
}
#endif
/* Force the operands to be integer */
if((pTos->nType & MEMOBJ_INT) == 0) {
PH7_MemObjToInteger(pTos);
@ -3582,11 +3507,9 @@ static sxi32 VmByteCodeExec(
ph7_value *pNos = &pTos[-1];
sxi64 a, r;
sxi32 b;
#ifdef UNTRUST
if(pNos < pStack) {
goto Abort;
}
#endif
/* Force the operands to be integer */
if((pTos->nType & MEMOBJ_INT) == 0) {
PH7_MemObjToInteger(pTos);
@ -3628,11 +3551,9 @@ static sxi32 VmByteCodeExec(
ph7_value *pObj;
sxi64 a, r;
sxi32 b;
#ifdef UNTRUST
if(pNos < pStack) {
goto Abort;
}
#endif
/* Force the operands to be integer */
if((pTos->nType & MEMOBJ_INT) == 0) {
PH7_MemObjToInteger(pTos);
@ -3675,11 +3596,9 @@ static sxi32 VmByteCodeExec(
case PH7_OP_LOR: {
ph7_value *pNos = &pTos[-1];
sxi32 v1, v2; /* 0==TRUE, 1==FALSE, 2==UNKNOWN or NULL */
#ifdef UNTRUST
if(pNos < pStack) {
goto Abort;
}
#endif
/* Force a boolean cast */
if((pTos->nType & MEMOBJ_BOOL) == 0) {
PH7_MemObjToBool(pTos);
@ -3716,11 +3635,9 @@ static sxi32 VmByteCodeExec(
case PH7_OP_LXOR: {
ph7_value *pNos = &pTos[-1];
sxi32 v = 0;
#ifdef UNTRUST
if(pNos < pStack) {
goto Abort;
}
#endif
/* Force a boolean cast */
if((pTos->nType & MEMOBJ_BOOL) == 0) {
PH7_MemObjToBool(pTos);
@ -3754,11 +3671,9 @@ static sxi32 VmByteCodeExec(
case PH7_OP_NEQ: {
ph7_value *pNos = &pTos[-1];
/* Perform the comparison and act accordingly */
#ifdef UNTRUST
if(pNos < pStack) {
goto Abort;
}
#endif
rc = PH7_MemObjCmp(pNos, pTos, FALSE, 0);
if(pInstr->iOp == PH7_OP_EQ) {
rc = rc == 0;
@ -3803,11 +3718,9 @@ static sxi32 VmByteCodeExec(
case PH7_OP_LE: {
ph7_value *pNos = &pTos[-1];
/* Perform the comparison and act accordingly */
#ifdef UNTRUST
if(pNos < pStack) {
goto Abort;
}
#endif
rc = PH7_MemObjCmp(pNos, pTos, FALSE, 0);
if(pInstr->iOp == PH7_OP_LE) {
rc = rc < 1;
@ -3852,11 +3765,9 @@ static sxi32 VmByteCodeExec(
case PH7_OP_GE: {
ph7_value *pNos = &pTos[-1];
/* Perform the comparison and act accordingly */
#ifdef UNTRUST
if(pNos < pStack) {
goto Abort;
}
#endif
rc = PH7_MemObjCmp(pNos, pTos, FALSE, 0);
if(pInstr->iOp == PH7_OP_GE) {
rc = rc >= 0;
@ -3948,11 +3859,9 @@ static sxi32 VmByteCodeExec(
case PH7_OP_THROW: {
VmFrame *pFrame = pVm->pFrame;
sxu32 nJump = pInstr->iP2;
#ifdef UNTRUST
if(pTos < pStack) {
goto Abort;
}
#endif