From c39fc5e742a48a953345980cc1cb8447483e0285 Mon Sep 17 00:00:00 2001 From: vsc Date: Sun, 25 Nov 2001 21:44:42 +0000 Subject: [PATCH] fix heap overflow while indexing (label_array was not being copied properly) git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@197 b08c6af1-5177-4d33-ba66-4b1c6b8b522a --- C/amasm.c | 8 +++++--- C/grow.c | 2 ++ H/compile.h | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/C/amasm.c b/C/amasm.c index 2eaed3da3..1e1017052 100644 --- a/C/amasm.c +++ b/C/amasm.c @@ -117,7 +117,7 @@ static yamop *code_p; static CODEADDR code_addr; static int pass_no; -static int *label_offset; +int *label_offset; static OPREG var_offset; static int is_y_var; @@ -2392,6 +2392,9 @@ do_pass(void) save_machine_regs(); longjmp(CompilerBotch,3); } + + if ( (char *)(label_offset+cpc->rnd1) > freep) + freep = (char *)(label_offset+cpc->rnd1); label_offset[cpc->rnd1] = (CELL) code_p; } /* reset dealloc_found in case there was a branch */ @@ -2569,12 +2572,11 @@ assemble(int mode) * computes labels offsets and total code size 2 - the second pass * produces the final version of the code */ - int *workspace = (int *)freep; CELL size; code_addr = NIL; assembling = mode; - label_offset = workspace; + label_offset = (int *)freep; pass_no = 0; asm_error = FALSE; do_pass(); diff --git a/C/grow.c b/C/grow.c index 83c6beb6a..2915a05c9 100644 --- a/C/grow.c +++ b/C/grow.c @@ -654,6 +654,8 @@ growheap(int fix_code) BlobsStart = cpc = (PInstr *)GlobalAddrAdjust((ADDR)cpc); } fix_compiler_instructions(cpc); + freep = (char *)GlobalAddrAdjust((ADDR)freep); + label_offset = (int *)GlobalAddrAdjust((ADDR)label_offset); } #ifdef TABLING fix_tabling_info(); diff --git a/H/compile.h b/H/compile.h index 46cf59a18..09a5ae9b1 100644 --- a/H/compile.h +++ b/H/compile.h @@ -263,6 +263,8 @@ extern PInstr *icpc, *BlobsStart; extern char *freep, *freep0; +extern int *label_offset; + extern int IPredArity; extern jmp_buf CompilerBotch;