From 74357ced0c0ee2e78d6b68af8116c158111c7a27 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Wed, 21 Feb 2018 15:17:02 +0200 Subject: [PATCH] Fixed read of potentially junk values in ZScript parser The following ill-formed ZScript code might crash targets with sizeof(int) != sizeof(void*) like 64-bit Intel class test { void func() { if (true) ( return; ) } } --- src/scripting/zscript/zcc_parser.cpp | 1 + src/scripting/zscript/zcc_parser.h | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/scripting/zscript/zcc_parser.cpp b/src/scripting/zscript/zcc_parser.cpp index cb927bb502..02d78021bd 100644 --- a/src/scripting/zscript/zcc_parser.cpp +++ b/src/scripting/zscript/zcc_parser.cpp @@ -267,6 +267,7 @@ static void ParseSingleFile(FScanner *pSC, const char *filename, int lump, void while (sc.GetToken()) { + value.Largest = 0; value.SourceLoc = sc.GetMessageLine(); switch (sc.TokenType) { diff --git a/src/scripting/zscript/zcc_parser.h b/src/scripting/zscript/zcc_parser.h index 3c1e55805e..5f0889fd2e 100644 --- a/src/scripting/zscript/zcc_parser.h +++ b/src/scripting/zscript/zcc_parser.h @@ -7,11 +7,31 @@ struct ZCCToken { + template + struct TLargest; + + template + struct TLargest + { + using Type = T; + }; + + template + struct TLargest + { + using Type = typename TLargest< + typename std::conditional< + (sizeof(T) > sizeof(U)), T, U + >::type, Ts... + >::Type; + }; + union { int Int; double Float; FString *String; + TLargest::Type Largest; }; int SourceLoc;