Browse Source

Do not allow typecasting to unset a variable.

pull/50/head
Rafal Kupiec 3 years ago
parent
commit
9884f8288b
Signed by: belliash GPG Key ID: 4E829243E0CFE6B4
  1. 8
      engine/compiler.c
  2. 5
      engine/lexer.c
  3. 1
      engine/parser.c
  4. 1
      include/ph7int.h

8
engine/compiler.c

@ -5328,10 +5328,10 @@ static ProcLangConstruct PH7_GenStateGetStatementHandler(
*/
static int PH7_IsLangConstruct(sxu32 nKeywordID) {
if(nKeywordID == PH7_KEYWORD_IMPORT || nKeywordID == PH7_KEYWORD_INCLUDE || nKeywordID == PH7_KEYWORD_REQUIRE
|| nKeywordID == PH7_KEYWORD_ISSET || nKeywordID == PH7_KEYWORD_UNSET || nKeywordID == PH7_KEYWORD_EVAL
|| nKeywordID == PH7_KEYWORD_EMPTY || nKeywordID == PH7_KEYWORD_ARRAY || nKeywordID == PH7_KEYWORD_LIST
|| nKeywordID == PH7_KEYWORD_SELF || nKeywordID == PH7_KEYWORD_PARENT || nKeywordID == PH7_KEYWORD_STATIC
|| /* TICKET 1433-012 */ nKeywordID == PH7_KEYWORD_NEW || nKeywordID == PH7_KEYWORD_CLONE) {
|| nKeywordID == PH7_KEYWORD_ISSET || nKeywordID == PH7_KEYWORD_EVAL || nKeywordID == PH7_KEYWORD_EMPTY
|| nKeywordID == PH7_KEYWORD_ARRAY || nKeywordID == PH7_KEYWORD_LIST || nKeywordID == PH7_KEYWORD_SELF
|| nKeywordID == PH7_KEYWORD_PARENT || nKeywordID == PH7_KEYWORD_STATIC || nKeywordID == PH7_KEYWORD_NEW
|| nKeywordID == PH7_KEYWORD_CLONE) {
return TRUE;
}
/* Not a language construct */

5
engine/lexer.c

@ -225,7 +225,7 @@ static sxi32 TokenizeAerScript(SyStream *pStream, SyToken *pToken, void *pUserDa
pTmp = (SyToken *)SySetPeek(pTokSet);
if(pTmp->nType & PH7_TK_KEYWORD) {
sxi32 nID = SX_PTR_TO_INT(pTmp->pUserData);
if((sxu32)nID & (PH7_KEYWORD_ARRAY | PH7_KEYWORD_INT | PH7_KEYWORD_FLOAT | PH7_KEYWORD_STRING | PH7_KEYWORD_OBJECT | PH7_KEYWORD_BOOL | PH7_KEYWORD_UNSET)) {
if((sxu32)nID & (PH7_KEYWORD_ARRAY | PH7_KEYWORD_INT | PH7_KEYWORD_FLOAT | PH7_KEYWORD_STRING | PH7_KEYWORD_OBJECT | PH7_KEYWORD_BOOL)) {
pTmp = (SyToken *)SySetAt(pTokSet, pTokSet->nUsed - 2);
if(pTmp->nType & PH7_TK_LPAREN) {
/* Merge the three tokens '(' 'TYPE' ')' into a single one */
@ -240,8 +240,6 @@ static sxi32 TokenizeAerScript(SyStream *pStream, SyToken *pToken, void *pUserDa
zTypeCast = "(array)";
} else if(nID & PH7_KEYWORD_OBJECT) {
zTypeCast = "(object)";
} else if(nID & PH7_KEYWORD_UNSET) {
zTypeCast = "(unset)";
}
/* Reflect the change */
pToken->nType = PH7_TK_OP;
@ -632,7 +630,6 @@ static sxu32 KeywordCode(const char *z, int n) {
{"list", PH7_KEYWORD_LIST},
{"require", PH7_KEYWORD_REQUIRE},
{"return", PH7_KEYWORD_RETURN},
{"unset", PH7_KEYWORD_UNSET},
/* Other keywords */
{"array", PH7_KEYWORD_ARRAY},
{"function", PH7_KEYWORD_FUNCTION},

1
engine/parser.c

@ -182,7 +182,6 @@ static const ph7_expr_op aOpTable[] = {
{ {"(float)", sizeof("(float)") - 1 }, EXPR_OP_TYPECAST, 4, EXPR_OP_ASSOC_RIGHT, PH7_OP_CVT_REAL },
{ {"(array)", sizeof("(array)") - 1 }, EXPR_OP_TYPECAST, 4, EXPR_OP_ASSOC_RIGHT, PH7_OP_CVT_ARRAY},
{ {"(object)", sizeof("(object)") - 1}, EXPR_OP_TYPECAST, 4, EXPR_OP_ASSOC_RIGHT, PH7_OP_CVT_OBJ },
{ {"(unset)", sizeof("(unset)") - 1 }, EXPR_OP_TYPECAST, 4, EXPR_OP_ASSOC_RIGHT, PH7_OP_CVT_NULL },
/* Binary operators */
/* Precedence 7,left-associative */
{ {"instanceof", sizeof("instanceof") - 1}, EXPR_OP_INSTOF, 7, EXPR_OP_NON_ASSOC, PH7_OP_IS_A},

1
include/ph7int.h

@ -1608,7 +1608,6 @@ enum ph7_expr_id {
#define PH7_KEYWORD_CATCH 53 /* catch */
#define PH7_KEYWORD_RETURN 54 /* return */
#define PH7_KEYWORD_BREAK 55 /* break */
#define PH7_KEYWORD_UNSET 0x800 /* unset: MUST BE A POWER OF TWO */
#define PH7_KEYWORD_VOID 0x1000 /* void: MUST BE A POWER OF TWO */
#define PH7_KEYWORD_CHAR 0x2000 /* char: MUST BE A POWER OF TWO */
#define PH7_KEYWORD_BOOL 0x4000 /* bool: MUST BE A POWER OF TWO */

Loading…
Cancel
Save