summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2015-04-11 19:33:36 +0000
committerrubidium <rubidium@openttd.org>2015-04-11 19:33:36 +0000
commit5ed8ac8a816feaa3df4b6938dff2ff9f3ccd76e6 (patch)
tree32d7fc8376680e67e9e957cd705d18c3393afef7
parent262c3c93c8fff3cce40fade9b1c2775cebbe41ab (diff)
downloadopenttd-5ed8ac8a816feaa3df4b6938dff2ff9f3ccd76e6.tar.xz
(svn r27233) -Fix [FS#6272]: crash when no AIs were installed due to improper handling of non-ASCII characters by the string pointer lexer
-rw-r--r--src/3rdparty/squirrel/squirrel/sqapi.cpp26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/3rdparty/squirrel/squirrel/sqapi.cpp b/src/3rdparty/squirrel/squirrel/sqapi.cpp
index 8374f7f31..f02fee29f 100644
--- a/src/3rdparty/squirrel/squirrel/sqapi.cpp
+++ b/src/3rdparty/squirrel/squirrel/sqapi.cpp
@@ -1261,10 +1261,28 @@ struct BufState{
WChar buf_lexfeed(SQUserPointer file)
{
- BufState *buf=(BufState*)file;
- if(buf->size<(buf->ptr+1))
- return 0;
- return buf->buf[buf->ptr++];
+ /* Convert an UTF-8 character into a WChar */
+ BufState *buf = (BufState *)file;
+ const char *p = &buf->buf[buf->ptr];
+
+ if (buf->size < buf->ptr + 1) return 0;
+
+ /* Read the first character, and get the length based on UTF-8 specs. If invalid, bail out. */
+ uint len = Utf8EncodedCharLen(*p);
+ if (len == 0) {
+ buf->ptr++;
+ return -1;
+ }
+
+ /* Read the remaining bits. */
+ if (buf->size < buf->ptr + len) return 0;
+ buf->ptr += len;
+
+ /* Convert the character, and when definitely invalid, bail out as well. */
+ WChar c;
+ if (Utf8Decode(&c, p) != len) return -1;
+
+ return c;
}
SQRESULT sq_compilebuffer(HSQUIRRELVM v,const SQChar *s,SQInteger size,const SQChar *sourcename,SQBool raiseerror) {