mirror of
				https://github.com/KartKrewDev/RingRacers.git
				synced 2025-10-30 08:01:28 +00:00 
			
		
		
		
	Lua: disallow bitwise not on anything but number values
This fixes a crash.
This commit is contained in:
		
							parent
							
								
									1d107b268c
								
							
						
					
					
						commit
						3b30cc408f
					
				
					 1 changed files with 11 additions and 12 deletions
				
			
		| 
						 | 
					@ -686,6 +686,15 @@ static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void codeunaryarith (FuncState *fs, OpCode op, expdesc *e) {
 | 
				
			||||||
 | 
					  expdesc e2;
 | 
				
			||||||
 | 
					  e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0;
 | 
				
			||||||
 | 
					  if (!isnumeral(e))
 | 
				
			||||||
 | 
					    luaK_exp2anyreg(fs, e);  /* cannot operate on non-numeric constants */
 | 
				
			||||||
 | 
					  codearith(fs, op, e, &e2);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void codecomp (FuncState *fs, OpCode op, int cond, expdesc *e1,
 | 
					static void codecomp (FuncState *fs, OpCode op, int cond, expdesc *e1,
 | 
				
			||||||
                                                          expdesc *e2) {
 | 
					                                                          expdesc *e2) {
 | 
				
			||||||
  int o1 = luaK_exp2RK(fs, e1);
 | 
					  int o1 = luaK_exp2RK(fs, e1);
 | 
				
			||||||
| 
						 | 
					@ -706,18 +715,8 @@ void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) {
 | 
				
			||||||
  expdesc e2;
 | 
					  expdesc e2;
 | 
				
			||||||
  e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0;
 | 
					  e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0;
 | 
				
			||||||
  switch (op) {
 | 
					  switch (op) {
 | 
				
			||||||
    case OPR_MINUS: {
 | 
					    case OPR_MINUS: codeunaryarith(fs, OP_UNM, e); break;
 | 
				
			||||||
      if (!isnumeral(e))
 | 
					    case OPR_BNOT: codeunaryarith(fs, OP_BNOT, e); break;
 | 
				
			||||||
        luaK_exp2anyreg(fs, e);  /* cannot operate on non-numeric constants */
 | 
					 | 
				
			||||||
      codearith(fs, OP_UNM, e, &e2);
 | 
					 | 
				
			||||||
      break;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    case OPR_BNOT: {
 | 
					 | 
				
			||||||
      if (e->k == VK)
 | 
					 | 
				
			||||||
        luaK_exp2anyreg(fs, e);  /* cannot operate on non-numeric constants */
 | 
					 | 
				
			||||||
      codearith(fs, OP_BNOT, e, &e2);
 | 
					 | 
				
			||||||
      break;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    case OPR_NOT: codenot(fs, e); break;
 | 
					    case OPR_NOT: codenot(fs, e); break;
 | 
				
			||||||
    case OPR_LEN: {
 | 
					    case OPR_LEN: {
 | 
				
			||||||
      luaK_exp2anyreg(fs, e);  /* cannot operate on constants */
 | 
					      luaK_exp2anyreg(fs, e);  /* cannot operate on constants */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue