fix overflow bugs in parser and scanner: check if we have space
before we start writing! git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@658 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
8d9d9cb4d5
commit
36a9f180c3
16
C/grow.c
16
C/grow.c
@ -716,7 +716,7 @@ growstack(long size)
|
||||
gc_verbose = is_gc_verbose();
|
||||
stack_overflows++;
|
||||
if (gc_verbose) {
|
||||
YP_fprintf(YP_stderr, "[SO] Stack overflow %d\n", stack_overflows);
|
||||
YP_fprintf(YP_stderr, "[SO] Stack Overflow %d\n", stack_overflows);
|
||||
YP_fprintf(YP_stderr, "[SO] Heap: %8ld cells (%p-%p)\n", (unsigned long int)(H-(CELL *)GlobalBase),GlobalBase,H);
|
||||
YP_fprintf(YP_stderr, "[SO] Local:%8ld cells (%p-%p)\n", (unsigned long int)(LCL0-ASP),LCL0,ASP);
|
||||
YP_fprintf(YP_stderr, "[SO] Trail:%8ld cells (%p-%p)\n",
|
||||
@ -771,7 +771,7 @@ AdjustScannerStacks(TokEntry **tksp, VarEntry **vep)
|
||||
VarEntry *ves = *vep;
|
||||
|
||||
if (tks != NULL) {
|
||||
tks = *tksp = (TokEntry *)TrailAddrAdjust((ADDR)tks);
|
||||
tks = *tksp = TokEntryAdjust(tks);
|
||||
}
|
||||
while (tks != NULL) {
|
||||
TokEntry *tktmp;
|
||||
@ -789,7 +789,7 @@ AdjustScannerStacks(TokEntry **tksp, VarEntry **vep)
|
||||
}
|
||||
tktmp = tks->TokNext;
|
||||
if (tktmp != NULL) {
|
||||
tktmp = (TokEntry *)TrailAddrAdjust((ADDR)tktmp);
|
||||
tktmp = TokEntryAdjust(tktmp);
|
||||
tks->TokNext = tktmp;
|
||||
}
|
||||
tks = tktmp;
|
||||
@ -800,12 +800,12 @@ AdjustScannerStacks(TokEntry **tksp, VarEntry **vep)
|
||||
}
|
||||
ves = AnonVarTable;
|
||||
if (ves != NULL) {
|
||||
ves = AnonVarTable = (VarEntry *)TrailAddrAdjust((ADDR)ves);
|
||||
ves = AnonVarTable = VarEntryAdjust(ves);
|
||||
}
|
||||
while (ves != NULL) {
|
||||
VarEntry *vetmp = ves->VarLeft;
|
||||
if (vetmp != NULL) {
|
||||
vetmp = (VarEntry *)TrailAddrAdjust((ADDR)vetmp);
|
||||
vetmp = VarEntryAdjust(vetmp);
|
||||
ves->VarLeft = vetmp;
|
||||
}
|
||||
ves->VarAdr = TermNil;
|
||||
@ -853,8 +853,10 @@ growstack_in_parser(tr_fr_ptr *old_trp, TokEntry **tksp, VarEntry **vep)
|
||||
MoveLocalAndTrail();
|
||||
AdjustScannerStacks(tksp, vep);
|
||||
{
|
||||
tr_fr_ptr nTR = TR;
|
||||
*old_trp = TR = PtoTRAdjust(*old_trp);
|
||||
tr_fr_ptr nTR;
|
||||
nTR = TR = PtoTRAdjust(TR);
|
||||
*old_trp = PtoTRAdjust(*old_trp);
|
||||
TR = *old_trp;
|
||||
AdjustGrowStack();
|
||||
TR = nTR;
|
||||
}
|
||||
|
@ -2841,7 +2841,7 @@ p_read (void)
|
||||
#if EMACS
|
||||
int emacs_cares = FALSE;
|
||||
#endif
|
||||
tr_fr_ptr old_TR;
|
||||
tr_fr_ptr old_TR, TR_before_parse;
|
||||
|
||||
if (Stream[c_input_stream].status & Binary_Stream_f) {
|
||||
Error(PERMISSION_ERROR_INPUT_BINARY_STREAM, MkAtomTerm(Stream[c_input_stream].u.file.name), "read_term/2");
|
||||
@ -2883,9 +2883,11 @@ p_read (void)
|
||||
}
|
||||
}
|
||||
repeat_cycle:
|
||||
TR_before_parse = TR;
|
||||
if (ErrorMessage || (t = Parse ()) == 0) {
|
||||
if (ErrorMessage && (strcmp(ErrorMessage,"Stack Overflow") == 0)) {
|
||||
/* ignore term we just built */
|
||||
TR = TR_before_parse;
|
||||
H = old_H;
|
||||
if (growstack_in_parser(&old_TR, &tokstart, &VarTable)) {
|
||||
old_H = H;
|
||||
@ -2900,6 +2902,7 @@ p_read (void)
|
||||
return(FALSE);
|
||||
} else if (ParserErrorStyle == CONTINUE_ON_PARSER_ERROR) {
|
||||
ErrorMessage = NULL;
|
||||
TR = TR_before_parse;
|
||||
/* try again */
|
||||
goto repeat_cycle;
|
||||
} else {
|
||||
|
@ -295,6 +295,10 @@ ParseArgs(Atom a)
|
||||
* Needed because the arguments for the functor are placed in reverse
|
||||
* order
|
||||
*/
|
||||
if (H > ASP-(nargs+1)) {
|
||||
ErrorMessage = "Stack Overflow";
|
||||
FAIL;
|
||||
}
|
||||
#ifdef SFUNC
|
||||
if (pe)
|
||||
t = MkSFTerm(MkFunctor(a, SFArity), nargs, p, pe->NilValue);
|
||||
@ -304,10 +308,6 @@ ParseArgs(Atom a)
|
||||
t = MkApplTerm(MkFunctor(a, nargs), nargs, p);
|
||||
#endif
|
||||
/* check for possible overflow against local stack */
|
||||
if (H > ASP-4096) {
|
||||
ErrorMessage = "Stack Overflow";
|
||||
FAIL;
|
||||
}
|
||||
checkfor((Term) ')');
|
||||
return (t);
|
||||
}
|
||||
|
@ -55,6 +55,8 @@ Inline(LocalAdjust, CELL, CELL, val, (val+LDiff) )
|
||||
Inline(LocalAddrAdjust, ADDR, ADDR, ptr, (ptr+LDiff) )
|
||||
Inline(TrailAdjust, CELL, CELL, val, (val+TrDiff) )
|
||||
Inline(TrailAddrAdjust, ADDR, ADDR, ptr, (ptr+TrDiff) )
|
||||
Inline(TokEntryAdjust, TokEntry *, TokEntry*, ptr, ((CELL)ptr+TrDiff) )
|
||||
Inline(VarEntryAdjust, VarEntry *, VarEntry*, ptr, ((CELL)ptr+TrDiff) )
|
||||
/* heap data structures */
|
||||
Inline(FuncAdjust, Functor, Functor, f, (Functor)(CharP(f)+HDiff) )
|
||||
Inline(CellPtoHeapAdjust, CELL *, CELL *, ptr, ((CELL *)(CharP(ptr) + HDiff)) )
|
||||
|
Reference in New Issue
Block a user