summaryrefslogtreecommitdiff
path: root/src/3rdparty
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2014-09-06 19:54:35 +0000
committerrubidium <rubidium@openttd.org>2014-09-06 19:54:35 +0000
commiteb52e65beccd66e8ebdb1d8897b609c331b21bcc (patch)
tree4391ac105c468b52c56a98143c030a26f954658f /src/3rdparty
parent962c1a3242e213a65078ed4217112978ddb0c613 (diff)
downloadopenttd-eb52e65beccd66e8ebdb1d8897b609c331b21bcc.tar.xz
(svn r26777) -Codechange: use safe string functions in squirrel code as well, and prevent using the ones that are deemed unsafe
Diffstat (limited to 'src/3rdparty')
-rw-r--r--src/3rdparty/squirrel/sqstdlib/sqstdaux.cpp5
-rw-r--r--src/3rdparty/squirrel/sqstdlib/sqstdmath.cpp5
-rw-r--r--src/3rdparty/squirrel/squirrel/sqapi.cpp12
-rw-r--r--src/3rdparty/squirrel/squirrel/sqbaselib.cpp5
-rw-r--r--src/3rdparty/squirrel/squirrel/sqclass.cpp5
-rw-r--r--src/3rdparty/squirrel/squirrel/sqcompiler.cpp9
-rw-r--r--src/3rdparty/squirrel/squirrel/sqdebug.cpp26
-rw-r--r--src/3rdparty/squirrel/squirrel/sqfuncstate.cpp5
-rw-r--r--src/3rdparty/squirrel/squirrel/sqlexer.cpp6
-rw-r--r--src/3rdparty/squirrel/squirrel/sqmem.cpp11
-rw-r--r--src/3rdparty/squirrel/squirrel/sqobject.cpp5
-rw-r--r--src/3rdparty/squirrel/squirrel/sqstate.cpp5
-rw-r--r--src/3rdparty/squirrel/squirrel/sqtable.cpp5
-rw-r--r--src/3rdparty/squirrel/squirrel/sqvm.cpp18
14 files changed, 103 insertions, 19 deletions
diff --git a/src/3rdparty/squirrel/sqstdlib/sqstdaux.cpp b/src/3rdparty/squirrel/sqstdlib/sqstdaux.cpp
index c4002bf2c..fcd3c33be 100644
--- a/src/3rdparty/squirrel/sqstdlib/sqstdaux.cpp
+++ b/src/3rdparty/squirrel/sqstdlib/sqstdaux.cpp
@@ -1,9 +1,14 @@
/* see copyright notice in squirrel.h */
+
+#include "../../../stdafx.h"
+
#include <squirrel.h>
#include <sqstdaux.h>
#include <assert.h>
#include <string.h>
+#include "../../../safeguards.h"
+
void sqstd_printcallstack(HSQUIRRELVM v)
{
SQPRINTFUNCTION pf = sq_getprintfunc(v);
diff --git a/src/3rdparty/squirrel/sqstdlib/sqstdmath.cpp b/src/3rdparty/squirrel/sqstdlib/sqstdmath.cpp
index 0f5d65194..e1c9da266 100644
--- a/src/3rdparty/squirrel/sqstdlib/sqstdmath.cpp
+++ b/src/3rdparty/squirrel/sqstdlib/sqstdmath.cpp
@@ -1,9 +1,14 @@
/* see copyright notice in squirrel.h */
+
+#include "../../../stdafx.h"
+
#include <squirrel.h>
#include <math.h>
#include <stdlib.h>
#include <sqstdmath.h>
+#include "../../../safeguards.h"
+
#define SINGLE_ARG_FUNC(_funcname, num_ops) static SQInteger math_##_funcname(HSQUIRRELVM v){ \
SQFloat f; \
sq_decreaseops(v,num_ops); \
diff --git a/src/3rdparty/squirrel/squirrel/sqapi.cpp b/src/3rdparty/squirrel/squirrel/sqapi.cpp
index 1f523e71c..179df117f 100644
--- a/src/3rdparty/squirrel/squirrel/sqapi.cpp
+++ b/src/3rdparty/squirrel/squirrel/sqapi.cpp
@@ -1,6 +1,9 @@
/*
see copyright notice in squirrel.h
*/
+
+#include "../../../stdafx.h"
+
#include <squirrel.h>
#include "sqpcheader.h"
#include "sqvm.h"
@@ -14,6 +17,10 @@
#include "sqfuncstate.h"
#include "sqclass.h"
+#include "../../../string_func.h"
+
+#include "../../../safeguards.h"
+
bool sq_aux_gettypedarg(HSQUIRRELVM v,SQInteger idx,SQObjectType type,SQObjectPtr **o)
{
*o = &stack_get(v,idx);
@@ -40,8 +47,9 @@ SQInteger sq_aux_throwobject(HSQUIRRELVM v,SQObjectPtr &e)
SQInteger sq_aux_invalidtype(HSQUIRRELVM v,SQObjectType type)
{
- sprintf(_ss(v)->GetScratchPad(100), "unexpected type %s", IdType2Name(type));
- return sq_throwerror(v, _ss(v)->GetScratchPad(-1));
+ char buf[100];
+ seprintf(buf, lastof(buf), "unexpected type %s", IdType2Name(type));
+ return sq_throwerror(v, buf);
}
HSQUIRRELVM sq_open(SQInteger initialstacksize)
diff --git a/src/3rdparty/squirrel/squirrel/sqbaselib.cpp b/src/3rdparty/squirrel/squirrel/sqbaselib.cpp
index f29ed60be..28de34194 100644
--- a/src/3rdparty/squirrel/squirrel/sqbaselib.cpp
+++ b/src/3rdparty/squirrel/squirrel/sqbaselib.cpp
@@ -3,6 +3,9 @@
*/
/* Needs to be first due to a squirrel header defining type() and type()
* being used in some versions of the headers included by algorithm. */
+
+#include "../../../stdafx.h"
+
#include <algorithm>
#include "sqpcheader.h"
#include "sqvm.h"
@@ -16,6 +19,8 @@
#include <stdarg.h>
#include <ctype.h>
+#include "../../../safeguards.h"
+
bool str2num(const SQChar *s,SQObjectPtr &res)
{
SQChar *end;
diff --git a/src/3rdparty/squirrel/squirrel/sqclass.cpp b/src/3rdparty/squirrel/squirrel/sqclass.cpp
index 73c8848b5..c62cfaf44 100644
--- a/src/3rdparty/squirrel/squirrel/sqclass.cpp
+++ b/src/3rdparty/squirrel/squirrel/sqclass.cpp
@@ -1,12 +1,17 @@
/*
see copyright notice in squirrel.h
*/
+
+#include "../../../stdafx.h"
+
#include "sqpcheader.h"
#include "sqvm.h"
#include "sqtable.h"
#include "sqclass.h"
#include "sqclosure.h"
+#include "../../../safeguards.h"
+
SQClass::SQClass(SQSharedState *ss,SQClass *base)
{
_base = base;
diff --git a/src/3rdparty/squirrel/squirrel/sqcompiler.cpp b/src/3rdparty/squirrel/squirrel/sqcompiler.cpp
index fc6ede6ac..596bf9622 100644
--- a/src/3rdparty/squirrel/squirrel/sqcompiler.cpp
+++ b/src/3rdparty/squirrel/squirrel/sqcompiler.cpp
@@ -1,6 +1,9 @@
/*
see copyright notice in squirrel.h
*/
+
+#include "../../../stdafx.h"
+
#include <squirrel.h>
#include "sqpcheader.h"
#include <stdarg.h>
@@ -13,6 +16,10 @@
#include "sqvm.h"
#include "sqtable.h"
+#include "../../../string_func.h"
+
+#include "../../../safeguards.h"
+
#define DEREF_NO_DEREF -1
#define DEREF_FIELD -2
@@ -66,7 +73,7 @@ public:
static SQChar temp[256];
va_list vl;
va_start(vl, s);
- vsnprintf(temp, sizeof(temp), s, vl);
+ vseprintf(temp, lastof(temp), s, vl);
va_end(vl);
throw temp;
}
diff --git a/src/3rdparty/squirrel/squirrel/sqdebug.cpp b/src/3rdparty/squirrel/squirrel/sqdebug.cpp
index 54f883f4e..109674f1e 100644
--- a/src/3rdparty/squirrel/squirrel/sqdebug.cpp
+++ b/src/3rdparty/squirrel/squirrel/sqdebug.cpp
@@ -1,6 +1,9 @@
/*
see copyright notice in squirrel.h
*/
+
+#include "../../../stdafx.h"
+
#include <squirrel.h>
#include "sqpcheader.h"
#include <stdarg.h>
@@ -9,6 +12,11 @@
#include "sqclosure.h"
#include "sqstring.h"
+#include "../../../core/alloc_func.hpp"
+#include "../../../string_func.h"
+
+#include "../../../safeguards.h"
+
SQRESULT sq_getfunctioninfo(HSQUIRRELVM v,SQInteger level,SQFunctionInfo *fi)
{
SQInteger cssize = v->_callsstacksize;
@@ -60,9 +68,12 @@ void SQVM::Raise_Error(const SQChar *s, ...)
{
va_list vl;
va_start(vl, s);
- vsprintf(_sp(rsl((SQInteger)strlen(s)+(NUMBER_MAX_CHAR*2))), s, vl);
+ size_t len = strlen(s)+(NUMBER_MAX_CHAR*2);
+ char *buffer = MallocT<char>(len + 1);
+ vseprintf(buffer, buffer + len, s, vl);
va_end(vl);
- _lasterror = SQString::Create(_ss(this),_spval,-1);
+ _lasterror = SQString::Create(_ss(this),buffer,-1);
+ free(buffer);
}
void SQVM::Raise_Error(SQObjectPtr &desc)
@@ -72,16 +83,15 @@ void SQVM::Raise_Error(SQObjectPtr &desc)
SQString *SQVM::PrintObjVal(const SQObject &o)
{
+ char buf[NUMBER_MAX_CHAR+1];
switch(type(o)) {
case OT_STRING: return _string(o);
case OT_INTEGER:
- sprintf(_sp(rsl(NUMBER_MAX_CHAR+1)), SQ_PRINTF64, _integer(o));
- return SQString::Create(_ss(this), _spval);
- break;
+ seprintf(buf, lastof(buf), SQ_PRINTF64, _integer(o));
+ return SQString::Create(_ss(this), buf);
case OT_FLOAT:
- sprintf(_sp(rsl(NUMBER_MAX_CHAR+1)), "%.14g", _float(o));
- return SQString::Create(_ss(this), _spval);
- break;
+ seprintf(buf, lastof(buf), "%.14g", _float(o));
+ return SQString::Create(_ss(this), buf);
default:
return SQString::Create(_ss(this), GetTypeName(o));
}
diff --git a/src/3rdparty/squirrel/squirrel/sqfuncstate.cpp b/src/3rdparty/squirrel/squirrel/sqfuncstate.cpp
index 91219adf8..0259d47d8 100644
--- a/src/3rdparty/squirrel/squirrel/sqfuncstate.cpp
+++ b/src/3rdparty/squirrel/squirrel/sqfuncstate.cpp
@@ -1,6 +1,9 @@
/*
see copyright notice in squirrel.h
*/
+
+#include "../../../stdafx.h"
+
#include "sqpcheader.h"
#include "sqcompiler.h"
#include "sqfuncproto.h"
@@ -9,6 +12,8 @@
#include "sqopcodes.h"
#include "sqfuncstate.h"
+#include "../../../safeguards.h"
+
#ifdef _DEBUG_DUMP
SQInstructionDesc g_InstrDesc[]={
{"_OP_LINE"},
diff --git a/src/3rdparty/squirrel/squirrel/sqlexer.cpp b/src/3rdparty/squirrel/squirrel/sqlexer.cpp
index 4653ab0a8..3d2ab05fa 100644
--- a/src/3rdparty/squirrel/squirrel/sqlexer.cpp
+++ b/src/3rdparty/squirrel/squirrel/sqlexer.cpp
@@ -1,6 +1,9 @@
/*
see copyright notice in squirrel.h
*/
+
+#include "../../../stdafx.h"
+
#include "sqpcheader.h"
#include <ctype.h>
#include <stdlib.h>
@@ -9,9 +12,10 @@
#include "sqcompiler.h"
#include "sqlexer.h"
-#include "../../../stdafx.h"
#include "../../../string_func.h"
+#include "../../../safeguards.h"
+
#define CUR_CHAR (_currdata)
#define RETURN_TOKEN(t) { _prevtoken = _curtoken; _curtoken = t; return t;}
#define IS_EOB() (CUR_CHAR <= SQUIRREL_EOB)
diff --git a/src/3rdparty/squirrel/squirrel/sqmem.cpp b/src/3rdparty/squirrel/squirrel/sqmem.cpp
index 26d07047e..4ab8db44b 100644
--- a/src/3rdparty/squirrel/squirrel/sqmem.cpp
+++ b/src/3rdparty/squirrel/squirrel/sqmem.cpp
@@ -1,9 +1,16 @@
/*
see copyright notice in squirrel.h
*/
+
+#include "../../../stdafx.h"
+
#include "sqpcheader.h"
-void *sq_vm_malloc(SQUnsignedInteger size){ return malloc((size_t)size); }
-void *sq_vm_realloc(void *p, SQUnsignedInteger oldsize, SQUnsignedInteger size){ return realloc(p, (size_t)size); }
+#include "../../../core/alloc_func.hpp"
+#include "../../../safeguards.h"
+
+void *sq_vm_malloc(SQUnsignedInteger size){ return MallocT<char>((size_t)size); }
+
+void *sq_vm_realloc(void *p, SQUnsignedInteger oldsize, SQUnsignedInteger size){ return ReallocT<char>(static_cast<char*>(p), (size_t)size); }
void sq_vm_free(void *p, SQUnsignedInteger size){ free(p); }
diff --git a/src/3rdparty/squirrel/squirrel/sqobject.cpp b/src/3rdparty/squirrel/squirrel/sqobject.cpp
index 1983e937b..da7f60003 100644
--- a/src/3rdparty/squirrel/squirrel/sqobject.cpp
+++ b/src/3rdparty/squirrel/squirrel/sqobject.cpp
@@ -1,6 +1,9 @@
/*
see copyright notice in squirrel.h
*/
+
+#include "../../../stdafx.h"
+
#include "sqpcheader.h"
#include "sqvm.h"
#include "sqstring.h"
@@ -11,6 +14,8 @@
#include "sqclass.h"
#include "sqclosure.h"
+#include "../../../safeguards.h"
+
const SQChar *IdType2Name(SQObjectType type)
{
diff --git a/src/3rdparty/squirrel/squirrel/sqstate.cpp b/src/3rdparty/squirrel/squirrel/sqstate.cpp
index bd270d470..c518f73b9 100644
--- a/src/3rdparty/squirrel/squirrel/sqstate.cpp
+++ b/src/3rdparty/squirrel/squirrel/sqstate.cpp
@@ -1,6 +1,9 @@
/*
see copyright notice in squirrel.h
*/
+
+#include "../../../stdafx.h"
+
#include "sqpcheader.h"
#include "sqopcodes.h"
#include "sqvm.h"
@@ -12,6 +15,8 @@
#include "squserdata.h"
#include "sqclass.h"
+#include "../../../safeguards.h"
+
SQObjectPtr _null_;
SQObjectPtr _true_(true);
SQObjectPtr _false_(false);
diff --git a/src/3rdparty/squirrel/squirrel/sqtable.cpp b/src/3rdparty/squirrel/squirrel/sqtable.cpp
index bb5feba3e..8a54328b3 100644
--- a/src/3rdparty/squirrel/squirrel/sqtable.cpp
+++ b/src/3rdparty/squirrel/squirrel/sqtable.cpp
@@ -1,12 +1,17 @@
/*
see copyright notice in squirrel.h
*/
+
+#include "../../../stdafx.h"
+
#include "sqpcheader.h"
#include "sqvm.h"
#include "sqtable.h"
#include "sqfuncproto.h"
#include "sqclosure.h"
+#include "../../../safeguards.h"
+
SQTable::SQTable(SQSharedState *ss,SQInteger nInitialSize)
{
SQInteger pow2size=MINPOWER2;
diff --git a/src/3rdparty/squirrel/squirrel/sqvm.cpp b/src/3rdparty/squirrel/squirrel/sqvm.cpp
index e94f05118..beba018bf 100644
--- a/src/3rdparty/squirrel/squirrel/sqvm.cpp
+++ b/src/3rdparty/squirrel/squirrel/sqvm.cpp
@@ -1,6 +1,9 @@
/*
see copyright notice in squirrel.h
*/
+
+#include "../../../stdafx.h"
+
#include <squirrel.h>
#include "sqpcheader.h"
#include <math.h>
@@ -15,6 +18,10 @@
#include "sqarray.h"
#include "sqclass.h"
+#include "../../../string_func.h"
+
+#include "../../../safeguards.h"
+
#define TOP() (_stack._vals[_top-1])
#define CLEARSTACK(_last_top) { if((_last_top) >= _top) ClearStack(_last_top); }
@@ -251,18 +258,19 @@ bool SQVM::CMP_OP(CmpOP op, const SQObjectPtr &o1,const SQObjectPtr &o2,SQObject
void SQVM::ToString(const SQObjectPtr &o,SQObjectPtr &res)
{
+ char buf[64];
switch(type(o)) {
case OT_STRING:
res = o;
return;
case OT_FLOAT:
- sprintf(_sp(rsl(NUMBER_MAX_CHAR+1)),"%g",_float(o));
+ seprintf(buf, lastof(buf),"%g",_float(o));
break;
case OT_INTEGER:
- sprintf(_sp(rsl(NUMBER_MAX_CHAR+1)),SQ_PRINTF64,_integer(o));
+ seprintf(buf, lastof(buf),SQ_PRINTF64,_integer(o));
break;
case OT_BOOL:
- sprintf(_sp(rsl(6)),_integer(o)?"true":"false");
+ seprintf(buf, lastof(buf),_integer(o)?"true":"false");
break;
case OT_TABLE:
case OT_USERDATA:
@@ -276,9 +284,9 @@ void SQVM::ToString(const SQObjectPtr &o,SQObjectPtr &res)
}
}
default:
- sprintf(_sp(rsl(sizeof(void*)+20)),"(%s : 0x%p)",GetTypeName(o),(void*)_rawval(o));
+ seprintf(buf, lastof(buf),"(%s : 0x%p)",GetTypeName(o),(void*)_rawval(o));
}
- res = SQString::Create(_ss(this),_spval);
+ res = SQString::Create(_ss(this),buf);
}