mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-25 05:21:16 +00:00
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; ) } }
This commit is contained in:
parent
420602e154
commit
74357ced0c
2 changed files with 21 additions and 0 deletions
|
@ -267,6 +267,7 @@ static void ParseSingleFile(FScanner *pSC, const char *filename, int lump, void
|
||||||
|
|
||||||
while (sc.GetToken())
|
while (sc.GetToken())
|
||||||
{
|
{
|
||||||
|
value.Largest = 0;
|
||||||
value.SourceLoc = sc.GetMessageLine();
|
value.SourceLoc = sc.GetMessageLine();
|
||||||
switch (sc.TokenType)
|
switch (sc.TokenType)
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,11 +7,31 @@
|
||||||
|
|
||||||
struct ZCCToken
|
struct ZCCToken
|
||||||
{
|
{
|
||||||
|
template <typename... Ts>
|
||||||
|
struct TLargest;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct TLargest<T>
|
||||||
|
{
|
||||||
|
using Type = T;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T, typename U, typename... Ts>
|
||||||
|
struct TLargest<T, U, Ts...>
|
||||||
|
{
|
||||||
|
using Type = typename TLargest<
|
||||||
|
typename std::conditional<
|
||||||
|
(sizeof(T) > sizeof(U)), T, U
|
||||||
|
>::type, Ts...
|
||||||
|
>::Type;
|
||||||
|
};
|
||||||
|
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
int Int;
|
int Int;
|
||||||
double Float;
|
double Float;
|
||||||
FString *String;
|
FString *String;
|
||||||
|
TLargest<decltype(Int), decltype(Float), decltype(String)>::Type Largest;
|
||||||
};
|
};
|
||||||
int SourceLoc;
|
int SourceLoc;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue