overflow in string

This commit is contained in:
Vitor Santos Costa 2017-08-27 22:17:00 +01:00
parent ccd7916d31
commit ce61f810c2
3 changed files with 41 additions and 7 deletions

View File

@ -1396,12 +1396,14 @@ static DBRef CreateDBStruct(Term Tm, DBProp p, int InFlag, int *pstat,
SMALLUNSGN flag; SMALLUNSGN flag;
int NOfLinks = 0; int NOfLinks = 0;
/* place DBRefs in ConsultStack */ /* place DBRefs in ConsultStack */
DBRef *TmpRefBase = (DBRef *)LOCAL_TrailTop; DBRef *TmpRefBase;
CELL *CodeAbs; /* how much code did we find */ CELL *CodeAbs; /* how much code did we find */
int vars_found = FALSE; int vars_found = FALSE;
yap_error_number oerr = LOCAL_Error_TYPE; yap_error_number oerr = LOCAL_Error_TYPE;
LOCAL_Error_TYPE = YAP_NO_ERROR;
retry_record:
LOCAL_Error_TYPE = YAP_NO_ERROR;
TmpRefBase = (DBRef *)LOCAL_TrailTop;
if (p == NULL) { if (p == NULL) {
if (IsVarTerm(Tm)) { if (IsVarTerm(Tm)) {
#ifdef COROUTINING #ifdef COROUTINING
@ -1500,7 +1502,7 @@ static DBRef CreateDBStruct(Term Tm, DBProp p, int InFlag, int *pstat,
} else { } else {
unsigned int arity; unsigned int arity;
Functor fun; Functor fun;
vars_found = true;
tt = AbsAppl(ppt0->Contents); tt = AbsAppl(ppt0->Contents);
/* we need to store the functor manually */ /* we need to store the functor manually */
fun = FunctorOfTerm(Tm); fun = FunctorOfTerm(Tm);
@ -1510,6 +1512,18 @@ static DBRef CreateDBStruct(Term Tm, DBProp p, int InFlag, int *pstat,
ntp = copy_double(ntp0, RepAppl(Tm)); ntp = copy_double(ntp0, RepAppl(Tm));
break; break;
case (CELL)FunctorString: case (CELL)FunctorString:
{
UInt sz = 1024+sizeof(CELL)*(3 + RepAppl(Tm)[1]);
if (sz >
(char*)AuxSp-(char*)ppt0) {
LOCAL_Error_Size = sz;
if (!Yap_ExpandPreAllocCodeSpace(LOCAL_Error_Size, NULL, TRUE)) {
Yap_Error(RESOURCE_ERROR_AUXILIARY_STACK, TermNil, LOCAL_ErrorMessage);
return NULL;
}
goto retry_record;
}
}
ntp = copy_string(ntp0, RepAppl(Tm)); ntp = copy_string(ntp0, RepAppl(Tm));
break; break;
case (CELL)FunctorDBRef: case (CELL)FunctorDBRef:
@ -1517,6 +1531,18 @@ static DBRef CreateDBStruct(Term Tm, DBProp p, int InFlag, int *pstat,
return CreateDBWithDBRef(Tm, p, dbg); return CreateDBWithDBRef(Tm, p, dbg);
#ifdef USE_GMP #ifdef USE_GMP
case (CELL)FunctorBigInt: case (CELL)FunctorBigInt:
{
UInt sz = 1024+sizeof(CELL)*Yap_SizeOfBigInt(Tm);
if (sz >
(char*)AuxSp-(char*)ppt0) {
LOCAL_Error_Size = sizeof(CELL)*(3 + RepAppl(Tm)[1]);
if (!Yap_ExpandPreAllocCodeSpace(LOCAL_Error_Size, NULL, TRUE)) {
Yap_Error(RESOURCE_ERROR_AUXILIARY_STACK, TermNil, LOCAL_ErrorMessage);
return NULL;
}
goto retry_record;
}
}
ntp = copy_big_int(ntp0, RepAppl(Tm)); ntp = copy_big_int(ntp0, RepAppl(Tm));
break; break;
#endif #endif

View File

@ -1180,13 +1180,15 @@ Term Yap_tokRep(void *tokptre) {
case Name_tok: case Name_tok:
if (!info) { if (!info) {
info = TermNil; info = TermNil;
} else {
info = MkAtomTerm((Atom)info);
} }
return Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, &info); return Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, &info);
case QuasiQuotes_tok: case QuasiQuotes_tok:
info = MkAtomTerm(Yap_LookupAtom("<QQ>")); info = MkAtomTerm(Yap_LookupAtom("<QQ>"));
return Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, &info); return Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, &info);
case Number_tok: case Number_tok:
return Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, &info); return Yap_MkApplTerm(Yap_MkFunctor(AtomNumber, 1), 1, &info);
break; break;
case Var_tok: { case Var_tok: {
Term t[2]; Term t[2];

View File

@ -211,7 +211,13 @@ extern struct various_codes *Yap_heap_regs;
*/ */
static inline yamop *gc_P(yamop *p, yamop *cp) { static inline yamop *gc_P(yamop *p, yamop *cp) {
return (p && p->opc == EXECUTE_CPRED_OPCODE ? cp : p); yamop *n= (p && p->opc == EXECUTE_CPRED_OPCODE ? cp : p);
if (p->opc == Yap_opcode(_try_c) ||
p->opc == Yap_opcode(_try_userc) ||
p->opc == Yap_opcode(_retry_c) ||
p->opc == Yap_opcode(_retry_userc))
return cp;
return n;
} }
/** /**