Skip to content

Commit

Permalink
Merge pull request #220 from vsmontalvao/vsmontalvao-stackoverflowfix
Browse files Browse the repository at this point in the history
Fix for stackoverflow crashes on applications with smaller stack size
  • Loading branch information
egli committed Nov 8, 2016
2 parents 98bd609 + 922cd2e commit 67a439a
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions liblouis/compileTranslationTable.c
Expand Up @@ -3778,6 +3778,7 @@ compileRule (FileInfo * nested)
TranslationTableCharacterAttributes after = 0;
TranslationTableCharacterAttributes before = 0;
TranslationTableCharacter *c = NULL;
widechar *patterns = NULL;
int k, i;

noback = nofor = 0;
Expand Down Expand Up @@ -3820,11 +3821,15 @@ compileRule (FileInfo * nested)
case CTO_Match:
{
CharsString ptn_before, ptn_after;
widechar patterns[27720];
TranslationTableOffset offset;
int len, mrk;

memset(patterns, 0xffff, sizeof(patterns));
size_t patternsByteSize = sizeof(*patterns) * 27720;
patterns = (widechar*) malloc(patternsByteSize);
if(!patterns)
outOfMemory();
memset(patterns, 0xffff, patternsByteSize);

noback = 1;
getCharacters(nested, &ptn_before);
getRuleCharsText(nested, &ruleChars);
Expand Down Expand Up @@ -3877,11 +3882,15 @@ compileRule (FileInfo * nested)
case CTO_BackMatch:
{
CharsString ptn_before, ptn_after, ptn_regex;
widechar patterns[27720];
TranslationTableOffset offset;
int len, mrk;

memset(patterns, 0xffff, sizeof(patterns));
size_t patternsByteSize = sizeof(*patterns) * 27720;
patterns = (widechar*) malloc(patternsByteSize);
if(!patterns)
outOfMemory();
memset(patterns, 0xffff, patternsByteSize);

nofor = 1;
getCharacters(nested, &ptn_before);
getRuleCharsText(nested, &ruleChars);
Expand Down Expand Up @@ -4762,6 +4771,10 @@ compileRule (FileInfo * nested)
ok = 0;
break;
}

if (patterns != NULL)
free(patterns);

return ok;
}

Expand Down

0 comments on commit 67a439a

Please sign in to comment.