Merge pull request #411 from ISSOtm/recursion_limit

Add a recursion limit
This commit is contained in:
Eldred Habert
2019-09-02 02:21:16 +02:00
committed by GitHub
17 changed files with 145 additions and 30 deletions

View File

@@ -28,6 +28,8 @@
#include "types.h"
static struct sContext *pFileStack;
static unsigned int nFileStackDepth;
unsigned int nMaxRecursionDepth;
static struct sSymbol *pCurrentMacro;
static YY_BUFFER_STATE CurrentFlexHandle;
static FILE *pCurrentFile;
@@ -51,6 +53,8 @@ uint32_t ulMacroReturnValue;
#define STAT_isMacroArg 2
#define STAT_isREPTBlock 3
/* Max context stack size */
/*
* Context push and pop
*/
@@ -58,6 +62,9 @@ static void pushcontext(void)
{
struct sContext **ppFileStack;
if (++nFileStackDepth > nMaxRecursionDepth)
fatalerror("Recursion limit (%d) exceeded", nMaxRecursionDepth);
ppFileStack = &pFileStack;
while (*ppFileStack)
ppFileStack = &((*ppFileStack)->pNext);
@@ -154,6 +161,8 @@ static int32_t popcontext(void)
fatalerror("%s: Internal error.", __func__);
}
nFileStackDepth--;
free(*ppLastFile);
*ppLastFile = NULL;
yy_switch_to_buffer(CurrentFlexHandle);
@@ -413,6 +422,7 @@ void fstk_Init(char *pFileName)
if (pCurrentFile == NULL)
err(1, "Unable to open file '%s'", pFileName);
}
nFileStackDepth = 0;
nMacroCount = 0;
nCurrentStatus = STAT_isInclude;