Skip to content

Commit 2bc47d3

Browse files
committed
Add bounds checking to solve_phi_insertion
Prevent buffer overflow in phi node insertion algorithm by adding bounds checks to the fixed-size work_list array (64 elements).
1 parent 6e819ea commit 2bc47d3

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/ssa.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,11 @@ void solve_phi_insertion(void)
607607
int work_list_idx = 0;
608608

609609
for (ref_block_t *ref = var->ref_block_list.head; ref;
610-
ref = ref->next)
610+
ref = ref->next) {
611+
if (work_list_idx >= 64) /* Prevent buffer overflow */
612+
break;
611613
work_list[work_list_idx++] = ref->bb;
614+
}
612615

613616
for (int i = 0; i < work_list_idx; i++) {
614617
basic_block_t *bb = work_list[i];
@@ -653,7 +656,7 @@ void solve_phi_insertion(void)
653656
break;
654657
}
655658
}
656-
if (!found)
659+
if (!found && work_list_idx < 64) /* Bounds check */
657660
work_list[work_list_idx++] = df;
658661
}
659662
}

0 commit comments

Comments
 (0)