]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
added prvm_uint_t for bounds check tests in the vm
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 16 Apr 2013 22:17:09 +0000 (22:17 +0000)
committerRudolf Polzer <divverent@xonotic.org>
Fri, 19 Apr 2013 10:58:41 +0000 (12:58 +0200)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11939 d7cf8633-e32d-0410-b094-e92efae38249
::stable-branch::merge=05fa482e8b4b3e344ffd36cbb7e98643c82816ea

prvm_execprogram.h

index 9620daca72176be7c4c45717970c2e2114561a81..5242e68c365280ee8aafab3a21a87e4adeb70efd 100644 (file)
                        case OP_STOREP_FLD:             // integers
                        case OP_STOREP_S:
                        case OP_STOREP_FNC:             // pointers
-                               if ((unsigned int)OPB->_int >= (unsigned int)prog->entityfieldsarea)
+                               if ((prvm_uint_t)OPB->_int - prog->entityfields >= (prvm_uint_t)prog->entityfieldsarea - prog->entityfields)
                                {
-                                       PreError();
-                                       prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
-                                       goto cleanup;
-                               }
-                               if (OPB->_int < prog->entityfields && !prog->allowworldwrites)
-                               {
-                                       prog->xstatement = st - prog->statements;
-                                       VM_Warning(prog, "assignment to world.%s (field %i) in %s\n", PRVM_GetString(prog, PRVM_ED_FieldAtOfs(prog, OPB->_int)->s_name), (int)OPB->_int, prog->name);
+                                       if (OPB->_int < 0 || OPB->_int >= prog->entityfieldsarea)
+                                       {
+                                               PreError();
+                                               prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
+                                               goto cleanup;
+                                       }
+                                       if (OPB->_int < prog->entityfields && !prog->allowworldwrites)
+                                       {
+                                               prog->xstatement = st - prog->statements;
+                                               VM_Warning(prog, "assignment to world.%s (field %i) in %s\n", PRVM_GetString(prog, PRVM_ED_FieldAtOfs(prog, OPB->_int)->s_name), (int)OPB->_int, prog->name);
+                                       }
                                }
                                ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int);
                                ptr->_int = OPA->_int;
                                break;
                        case OP_STOREP_V:
-                               if (OPB->_int < 0 || OPB->_int + 3 > prog->entityfieldsarea)
+                               if ((prvm_uint_t)OPB->_int - prog->entityfields > (prvm_uint_t)prog->entityfieldsarea - prog->entityfields - 3)
                                {
-                                       PreError();
-                                       prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
-                                       goto cleanup;
-                               }
-                               if (OPB->_int < prog->entityfields && !prog->allowworldwrites)
-                               {
-                                       prog->xstatement = st - prog->statements;
-                                       VM_Warning(prog, "assignment to world.%s (field %i) in %s\n", PRVM_GetString(prog, PRVM_ED_FieldAtOfs(prog, OPB->_int)->s_name), (int)OPB->_int, prog->name);
+                                       if (OPB->_int < 0 || OPB->_int > prog->entityfieldsarea - 3)
+                                       {
+                                               PreError();
+                                               prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
+                                               goto cleanup;
+                                       }
+                                       if (OPB->_int < prog->entityfields && !prog->allowworldwrites)
+                                       {
+                                               prog->xstatement = st - prog->statements;
+                                               VM_Warning(prog, "assignment to world.%s (field %i) in %s\n", PRVM_GetString(prog, PRVM_ED_FieldAtOfs(prog, OPB->_int)->s_name), (int)OPB->_int, prog->name);
+                                       }
                                }
                                ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int);
                                ptr->ivector[0] = OPA->ivector[0];
                                break;
 
                        case OP_ADDRESS:
-                               if ((unsigned int)OPA->edict >= (unsigned int)prog->max_edicts)
+                               if ((prvm_uint_t)OPA->edict >= (prvm_uint_t)prog->max_edicts)
                                {
                                        PreError();
                                        prog->error_cmd("%s Progs attempted to address an out of bounds edict number", prog->name);
                                        goto cleanup;
                                }
-                               if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->entityfields))
+                               if ((prvm_uint_t)(OPB->_int) >= (prvm_uint_t)(prog->entityfields))
                                {
                                        PreError();
                                        prog->error_cmd("%s attempted to address an invalid field (%i) in an edict", prog->name, (int)OPB->_int);
                        case OP_LOAD_ENT:
                        case OP_LOAD_S:
                        case OP_LOAD_FNC:
-                               if ((unsigned int)OPA->edict >= (unsigned int)prog->max_edicts)
+                               if ((prvm_uint_t)OPA->edict >= (prvm_uint_t)prog->max_edicts)
                                {
                                        PreError();
                                        prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
                                        goto cleanup;
                                }
-                               if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->entityfields))
+                               if ((prvm_uint_t)(OPB->_int) >= (prvm_uint_t)(prog->entityfields))
                                {
                                        PreError();
                                        prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);
                                break;
 
                        case OP_LOAD_V:
-                               if ((unsigned int)OPA->edict >= (unsigned int)prog->max_edicts)
+                               if ((prvm_uint_t)OPA->edict >= (prvm_uint_t)prog->max_edicts)
                                {
                                        PreError();
                                        prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
                                        goto cleanup;
                                }
-                               if (OPB->_int < 0 || OPB->_int + 2 >= prog->entityfields)
+                               if ((prvm_uint_t)OPB->_int > (prvm_uint_t)prog->entityfields - 3)
                                {
                                        PreError();
                                        prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);