From 610ca06883888b3f3b8fe643e0f189dd665f3c56 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Tue, 16 Oct 2012 08:44:26 +0100 Subject: [PATCH] check for overflow in big strings --- C/parser.c | 4 ++++ C/scanner.c | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/C/parser.c b/C/parser.c index ee5101b6d..c0bad6fdb 100644 --- a/C/parser.c +++ b/C/parser.c @@ -560,6 +560,10 @@ ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS) t = MkAtomTerm(Yap_LookupWideAtom(p)); else t = Yap_WideStringToList(p); + if (t == 0L) { + LOCAL_ErrorMessage = "Stack Overflow"; + FAIL; + } NextToken; } break; diff --git a/C/scanner.c b/C/scanner.c index b15f89e1b..fa2e59a05 100644 --- a/C/scanner.c +++ b/C/scanner.c @@ -836,14 +836,14 @@ ch_to_wide(char *base, char *charp) } #define add_ch_to_buff(ch) \ - if (wcharp) { *wcharp++ = (ch); charp = (char *)wcharp; } \ + if (wcharp) { *wcharp++ = (ch); if (wcharp >= (wchar_t *)AuxSp-1024) goto huge_var_error; charp = (char *)wcharp; } \ else { \ if (ch > MAX_ISO_LATIN1 && !wcharp) { \ /* does not fit in ISO-LATIN */ \ wcharp = ch_to_wide(TokImage, charp); \ if (!wcharp) goto huge_var_error; \ *wcharp++ = (ch); charp = (char *)wcharp; \ - } else *charp++ = ch; \ + } else { if (charp >= (char *)AuxSp-1024) goto huge_var_error; *charp++ = ch; } \ } TokEntry *