From 9028ed204daa648e2e4b9cbdd1f7bf5f6338696e Mon Sep 17 00:00:00 2001 From: Aaron Muir Hamilton Date: Sun, 22 Oct 2017 17:41:13 +0000 Subject: [PATCH] Check for hexadecimal literals exceeding MaxTokenLength. --- Test/baseResults/overlongLiteral.frag.out | 19 +++++++++++++++++++ Test/overlongLiteral.frag | 1 + .../preprocessor/PpScanner.cpp | 7 +++++-- gtests/AST.FromFile.cpp | 1 + 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 Test/baseResults/overlongLiteral.frag.out create mode 100644 Test/overlongLiteral.frag diff --git a/Test/baseResults/overlongLiteral.frag.out b/Test/baseResults/overlongLiteral.frag.out new file mode 100644 index 000000000..372d77775 --- /dev/null +++ b/Test/baseResults/overlongLiteral.frag.out @@ -0,0 +1,19 @@ +overlongLiteral.frag +ERROR: 0:1: '' : hexadecimal literal too long +ERROR: 0:1: '' : syntax error, unexpected INTCONSTANT +ERROR: 2 compilation errors. No code generated. + + +Shader version: 100 +ERROR: node is still EOpNull! +0:? Linker Objects + + +Linked fragment stage: + +ERROR: Linking fragment stage: Missing entry point: Each stage requires one entry point + +Shader version: 100 +ERROR: node is still EOpNull! +0:? Linker Objects + diff --git a/Test/overlongLiteral.frag b/Test/overlongLiteral.frag new file mode 100644 index 000000000..c351ed6b8 --- /dev/null +++ b/Test/overlongLiteral.frag @@ -0,0 +1 @@ +0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000; diff --git a/glslang/MachineIndependent/preprocessor/PpScanner.cpp b/glslang/MachineIndependent/preprocessor/PpScanner.cpp index fa01549df..d1ddf6851 100644 --- a/glslang/MachineIndependent/preprocessor/PpScanner.cpp +++ b/glslang/MachineIndependent/preprocessor/PpScanner.cpp @@ -420,7 +420,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken) ival = 0; do { - if (ival <= 0x0fffffffu || (enableInt64 && ival <= 0x0fffffffffffffffull)) { + if (len < MaxTokenLength && (ival <= 0x0fffffffu || (enableInt64 && ival <= 0x0fffffffffffffffull))) { ppToken->name[len++] = (char)ch; if (ch >= '0' && ch <= '9') { ii = ch - '0'; @@ -433,7 +433,10 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken) ival = (ival << 4) | ii; } else { if (! AlreadyComplained) { - pp->parseContext.ppError(ppToken->loc, "hexadecimal literal too big", "", ""); + if(len < MaxTokenLength) + pp->parseContext.ppError(ppToken->loc, "hexadecimal literal too big", "", ""); + else + pp->parseContext.ppError(ppToken->loc, "hexadecimal literal too long", "", ""); AlreadyComplained = 1; } ival = 0xffffffffffffffffull; diff --git a/gtests/AST.FromFile.cpp b/gtests/AST.FromFile.cpp index d8510aa52..9ca88ff8d 100644 --- a/gtests/AST.FromFile.cpp +++ b/gtests/AST.FromFile.cpp @@ -183,6 +183,7 @@ INSTANTIATE_TEST_CASE_P( "matrix2.frag", "newTexture.frag", "Operations.frag", + "overlongLiteral.frag", "prepost.frag", "simpleFunctionCall.frag", "structAssignment.frag",