diff options
author | Björn Gustavsson <[email protected]> | 2011-02-22 10:07:04 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2011-02-23 11:21:23 +0100 |
commit | e1833ee82c7a07e000dbbea3af6c8fefc02582d6 (patch) | |
tree | ee34f1a4ac9da683ef73ef55c102f54b5f3cf540 /erts/emulator/beam | |
parent | 84da094f755c32b507d91ff2269218c43b7e9624 (diff) | |
download | otp-e1833ee82c7a07e000dbbea3af6c8fefc02582d6.tar.gz otp-e1833ee82c7a07e000dbbea3af6c8fefc02582d6.tar.bz2 otp-e1833ee82c7a07e000dbbea3af6c8fefc02582d6.zip |
BEAM loader: Add an assertion to check for overflowed code space
While at it, clean up indentation of CHKBLK() macros.
Diffstat (limited to 'erts/emulator/beam')
-rw-r--r-- | erts/emulator/beam/beam_load.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/erts/emulator/beam/beam_load.c b/erts/emulator/beam/beam_load.c index 4e0d19dafa..788cb4209c 100644 --- a/erts/emulator/beam/beam_load.c +++ b/erts/emulator/beam/beam_load.c @@ -3770,25 +3770,32 @@ freeze_code(LoaderState* stp) CHKBLK(ERTS_ALC_T_CODE,code); if (compile_size) { byte* compile_info = str_table + strtab_size + attr_size; - CHKBLK(ERTS_ALC_T_CODE,code); + CHKBLK(ERTS_ALC_T_CODE,code); sys_memcpy(compile_info, stp->chunks[COMPILE_CHUNK].start, stp->chunks[COMPILE_CHUNK].size); - CHKBLK(ERTS_ALC_T_CODE,code); + + CHKBLK(ERTS_ALC_T_CODE,code); code[MI_COMPILE_PTR] = (BeamInstr) compile_info; - CHKBLK(ERTS_ALC_T_CODE,code); + CHKBLK(ERTS_ALC_T_CODE,code); code[MI_COMPILE_SIZE] = (BeamInstr) stp->chunks[COMPILE_CHUNK].size; - CHKBLK(ERTS_ALC_T_CODE,code); + CHKBLK(ERTS_ALC_T_CODE,code); decoded_size = erts_decode_ext_size(compile_info, compile_size, 0); - CHKBLK(ERTS_ALC_T_CODE,code); + CHKBLK(ERTS_ALC_T_CODE,code); if (decoded_size < 0) { LoadError0(stp, "bad external term representation of compilation information"); } - CHKBLK(ERTS_ALC_T_CODE,code); + CHKBLK(ERTS_ALC_T_CODE,code); code[MI_COMPILE_SIZE_ON_HEAP] = decoded_size; } CHKBLK(ERTS_ALC_T_CODE,code); /* + * Make sure that we have not overflowed the allocated code space. + */ + ASSERT(str_table + strtab_size + attr_size + compile_size == + ((byte *) code) + size); + + /* * Go through all i_new_bs_put_strings instructions, restore the pointer to * the instruction and convert string offsets to pointers (to the * FIRST character). |