浏览代码

add some stack-condition error checking to sqstdlib registration routines and to sqstd_dofile

zeromus 9 年之前
父节点
当前提交
b9fc931752
共有 4 个文件被更改,包括 12 次插入0 次删除
  1. 6 0
      sqstdlib/sqstdio.cpp
  2. 2 0
      sqstdlib/sqstdmath.cpp
  3. 2 0
      sqstdlib/sqstdstring.cpp
  4. 2 0
      sqstdlib/sqstdsystem.cpp

+ 6 - 0
sqstdlib/sqstdio.cpp

@@ -399,6 +399,10 @@ SQRESULT sqstd_loadfile(HSQUIRRELVM v,const SQChar *filename,SQBool printerror)
 
 SQRESULT sqstd_dofile(HSQUIRRELVM v,const SQChar *filename,SQBool retval,SQBool printerror)
 {
+    //at least one entry must exist in order for us to push it as the environment
+    if(sq_gettop(v) == 0)
+        return sq_throwerror(v,_SC("environment table expected"));	
+
     if(SQ_SUCCEEDED(sqstd_loadfile(v,filename,printerror))) {
         sq_push(v,-2);
         if(SQ_SUCCEEDED(sq_call(v,1,retval,SQTrue))) {
@@ -468,6 +472,8 @@ static const SQRegFunction iolib_funcs[]={
 
 SQRESULT sqstd_register_iolib(HSQUIRRELVM v)
 {
+    if(sq_gettype(v,-1) != OT_TABLE)
+        return sq_throwerror(v,_SC("table expected"));	
     SQInteger top = sq_gettop(v);
     //create delegate
     declare_stream(v,_SC("file"),(SQUserPointer)SQSTD_FILE_TYPE_TAG,_SC("std_file"),_file_methods,iolib_funcs);

+ 2 - 0
sqstdlib/sqstdmath.cpp

@@ -88,6 +88,8 @@ static const SQRegFunction mathlib_funcs[] = {
 
 SQRESULT sqstd_register_mathlib(HSQUIRRELVM v)
 {
+    if(sq_gettype(v,-1) != OT_TABLE)
+        return sq_throwerror(v,_SC("table expected"));	
     SQInteger i=0;
     while(mathlib_funcs[i].name!=0) {
         sq_pushstring(v,mathlib_funcs[i].name,-1);

+ 2 - 0
sqstdlib/sqstdstring.cpp

@@ -473,6 +473,8 @@ static const SQRegFunction stringlib_funcs[]={
 
 SQInteger sqstd_register_stringlib(HSQUIRRELVM v)
 {
+    if(sq_gettype(v,-1) != OT_TABLE)
+        return sq_throwerror(v,_SC("table expected"));
     sq_pushstring(v,_SC("regexp"),-1);
     sq_newclass(v,SQFalse);
     SQInteger i = 0;

+ 2 - 0
sqstdlib/sqstdsystem.cpp

@@ -132,6 +132,8 @@ static const SQRegFunction systemlib_funcs[]={
 
 SQInteger sqstd_register_systemlib(HSQUIRRELVM v)
 {
+    if(sq_gettype(v,-1) != OT_TABLE)
+        return sq_throwerror(v,_SC("table expected"));
     SQInteger i=0;
     while(systemlib_funcs[i].name!=0)
     {