From 081be455f63a89cdabb6e865bc9b5b14f961da4d Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Thu, 16 Jun 2022 16:45:42 +0800 Subject: [PATCH] Fix register allocator distance integer overflow issue --- core/iwasm/fast-jit/jit_regalloc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/iwasm/fast-jit/jit_regalloc.c b/core/iwasm/fast-jit/jit_regalloc.c index ba0d09452..4b4b8fed3 100644 --- a/core/iwasm/fast-jit/jit_regalloc.c +++ b/core/iwasm/fast-jit/jit_regalloc.c @@ -22,7 +22,7 @@ typedef struct UintStack { uint32 top; /* Elements of the vector. */ - uint16 elem[1]; + uint32 elem[1]; } UintStack; static bool @@ -424,6 +424,11 @@ collect_distances(RegallocContext *rc, JitBasicBlock *basic_block) if (!uint_stack_push(&(rc_get_vr(rc, *regp))->distances, distance)) return -1; + /* Integer overflow check, normally it won't happen, but + we had better add the check here */ + if (distance >= INT32_MAX) + return -1; + distance++; }