Skip to content

Commit 90a5920

Browse files
committed
Merge pull request #1791 from pguyot/w32/fix-bs_start_match_4-corruption
Fix possible memory corruption with OP_BS_START_MATCH{2,4} These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license). SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
2 parents 38d2fca + 5c40224 commit 90a5920

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ integer (this never happens with integers < 28 bits)
9292
- Correctly set Pico-W unique dhcp hostname when using the default, previously all rp2040 devices
9393
used the same "PicoW" dhcp hostname, causing collisions when multiple rp2040 are on the same
9494
network. (See issue #1094)
95+
- Fixed possible memory corruption when doing binary matching.
9596

9697
### Changed
9798

src/libAtomVM/opcodesswitch.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4670,17 +4670,17 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
46704670
DECODE_LITERAL(live, pc);
46714671
term slots_term;
46724672
DECODE_COMPACT_TERM(slots_term, pc);
4673-
DEST_REGISTER(dreg);
4674-
DECODE_DEST_REGISTER(dreg, pc);
4673+
GC_SAFE_DEST_REGISTER(dreg);
4674+
DECODE_DEST_REGISTER_GC_SAFE(dreg, pc);
46754675

46764676
#ifdef IMPL_CODE_LOADER
46774677
TRACE("bs_start_match2/5\n");
46784678
#endif
46794679

46804680
#ifdef IMPL_EXECUTE_LOOP
4681-
TRACE("bs_start_match2/5, fail=%i src=0x%lx live=%u arg3=0x%lx dreg=%c%i\n", fail, src, (unsigned) live, slots_term, T_DEST_REG(dreg));
4681+
TRACE("bs_start_match2/5, fail=%i src=0x%lx live=%u arg3=0x%lx dreg=%c%i\n", fail, src, (unsigned) live, slots_term, T_DEST_REG_GC_SAFE(dreg));
46824682
if (!(term_is_binary(src) || term_is_match_state(src))) {
4683-
WRITE_REGISTER(dreg, src);
4683+
WRITE_REGISTER_GC_SAFE(dreg, src);
46844684
pc = mod->labels[fail];
46854685
} else {
46864686
int slots = term_to_int(slots_term);
@@ -4695,7 +4695,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
46954695

46964696
term match_state = term_alloc_bin_match_state(src, slots, &ctx->heap);
46974697

4698-
WRITE_REGISTER(dreg, match_state);
4698+
WRITE_REGISTER_GC_SAFE(dreg, match_state);
46994699
}
47004700
#endif
47014701
break;
@@ -6459,15 +6459,15 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
64596459
DECODE_LITERAL(live, pc);
64606460
term src;
64616461
DECODE_COMPACT_TERM(src, pc);
6462-
DEST_REGISTER(dreg);
6463-
DECODE_DEST_REGISTER(dreg, pc);
6462+
GC_SAFE_DEST_REGISTER(dreg);
6463+
DECODE_DEST_REGISTER_GC_SAFE(dreg, pc);
64646464

64656465
#ifdef IMPL_CODE_LOADER
64666466
TRACE("bs_start_match4/4\n");
64676467
#endif
64686468

64696469
#ifdef IMPL_EXECUTE_LOOP
6470-
TRACE("bs_start_match4/4, fail_atom=%u fail_label=%u live=%u src=%p dreg=%c%i\n", (unsigned) fail_atom, (unsigned) fail_label, (unsigned) live, (void *) src, T_DEST_REG(dreg));
6470+
TRACE("bs_start_match4/4, fail_atom=%u fail_label=%u live=%u src=%p dreg=%c%i\n", (unsigned) fail_atom, (unsigned) fail_label, (unsigned) live, (void *) src, T_DEST_REG_GC_SAFE(dreg));
64716471

64726472
// no_fail: we know it's a binary or a match_state
64736473
// resume: we know it's a match_state
@@ -6485,7 +6485,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
64856485
src = x_regs[live];
64866486
term match_state = term_alloc_bin_match_state(src, 0, &ctx->heap);
64876487

6488-
WRITE_REGISTER(dreg, match_state);
6488+
WRITE_REGISTER_GC_SAFE(dreg, match_state);
64896489
}
64906490
#endif
64916491
break;

0 commit comments

Comments
 (0)