fix Malloc over/underflow

remove trash
This commit is contained in:
Vitor Santos Costa
2018-06-18 10:25:17 +01:00
parent fd4f53a899
commit c092d0f62b
23 changed files with 115 additions and 3756 deletions

View File

@@ -717,12 +717,15 @@ static Int number_chars(USES_REGS1) {
pop_text_stack(l);
return Yap_unify(ARG1, tf);
}
pop_text_stack(l);
LOCAL_ActiveError->errorRawTerm = 0;
Yap_ThrowExistingError();
return false;
}
pop_text_stack(l);
return true;
}

View File

@@ -862,6 +862,7 @@ yamop *Yap_Error__(bool throw, const char *file, const char *function,
// reset_error_description();
if (!throw) {
Yap_JumpToEnv();
pop_text_stack(LOCAL_MallocDepth+1);
}
LOCAL_PrologMode = UserMode;
return P;

View File

@@ -1423,11 +1423,12 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
Int OldBorder = LOCAL_CBorder;
// yap_error_descriptor_t *err_info= LOCAL_ActiveError;
LOCAL_CBorder = LCL0 - ENV;
LOCAL_MallocDepth = AllocLevel();
yhandle_t sls = Yap_CurrentSlot();
sigjmp_buf signew, *sighold = LOCAL_RestartEnv;
LOCAL_RestartEnv = &signew;
int i = AllocLevel();
volatile int i = AllocLevel();
if /* top &&*/ ((lval = sigsetjmp(signew, 1)) != 0) {
switch (lval) {
case 1: { /* restart */
@@ -1458,7 +1459,7 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
*/
/* reset the registers so that we don't have trash in abstract
* machine */
pop_text_stack(i);
pop_text_stack(i+1);
Yap_set_fpu_exceptions(
getAtomicGlobalPrologFlag(ARITHMETIC_EXCEPTIONS_FLAG));
P = (yamop *)FAILCODE;
@@ -1467,7 +1468,7 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
} break;
case 3: { /* saved state */
// LOCAL_ActiveError = err_info;
pop_text_stack(i);
pop_text_stack(i+1);
LOCAL_CBorder = OldBorder;
LOCAL_RestartEnv = sighold;
LOCAL_PrologMode = UserMode;
@@ -1481,7 +1482,7 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
// LOCAL_ActiveError = err_info;
while (B) {
LOCAL_ActiveError->errorNo = ABORT_EVENT;
pop_text_stack(i);
pop_text_stack(i+1);
Yap_CloseSlots(sls);
Yap_JumpToEnv();
}
@@ -1489,7 +1490,7 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
P = (yamop *)FAILCODE;
LOCAL_RestartEnv = sighold;
Yap_CloseSlots(sls);
pop_text_stack(i);
pop_text_stack(i+1);
return false;
break;
case 5:
@@ -1512,13 +1513,15 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
(CELL *)(B->cp_b) > LCL0 - LOCAL_CBorder) {
LOCAL_RestartEnv = sighold;
LOCAL_CBorder = OldBorder;
return false;
pop_text_stack(i+1);
return false;
}
P = FAILCODE;
}
}
YENV = ASP;
YENV[E_CB] = Unsigned(B);
pop_text_stack(i+1);
out = Yap_absmi(0);
/* make sure we don't leave a FAIL signal hanging around */
Yap_get_signal(YAP_FAIL_SIGNAL);
@@ -1526,6 +1529,7 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
CalculateStackGap(PASS_REGS1);
LOCAL_CBorder = OldBorder;
LOCAL_RestartEnv = sighold;
pop_text_stack(i+1);
return out;
}
@@ -2114,6 +2118,7 @@ static Int jump_env(USES_REGS1) {
LCL0 - (CELL *)B > LOCAL_CBorder) {
// we're failing up to the top layer
}
pop_text_stack(LOCAL_MallocDepth+1);
return out;
}

View File

@@ -305,7 +305,7 @@ static void *codes2buf(Term t0, void *b0, bool *get_codes USES_REGS) {
if (!IsVarTerm(t)) {
if (t != TermNil) {
Yap_ThrowError(TYPE_ERROR_LIST, t0, "scanning list of codes");
Yap_ThrowError(TYPE_ERROR_LIST, t, "scanning list of codes");
return NULL;
}
}
@@ -508,6 +508,7 @@ unsigned char *Yap_readText(seq_tv_t *inp USES_REGS) {
s = Malloc(2 * MaxTmp(PASS_REGS1));
if (snprintf(s, MaxTmp(PASS_REGS1) - 1, Int_FORMAT,
IntegerOfTerm(inp->val.t)) < 0) {
pop_text_stack(lvl);
AUX_ERROR(inp->val.t, 2 * MaxTmp(PASS_REGS1), s, char);
}
return pop_output_text_stack(lvl, s);
@@ -527,6 +528,7 @@ unsigned char *Yap_readText(seq_tv_t *inp USES_REGS) {
char *s;
s = Malloc(MaxTmp());
if (!Yap_mpz_to_string(Yap_BigIntOfTerm(inp->val.t), s, MaxTmp() - 1, 10)) {
pop_text_stack(lvl);
AUX_ERROR(inp->val.t, MaxTmp(PASS_REGS1), s, char);
}
return inp->val.uc = pop_output_text_stack(lvl, s);
@@ -766,7 +768,7 @@ void *write_buffer(unsigned char *s0, seq_tv_t *out USES_REGS) {
pop_text_stack(l);
return NULL;
}
out->val.c = pop_output_text_stack__(l, out->val.c);
out->val.c = pop_output_text_stack(l, out->val.c);
return out->val.c;
}