Skip to content

Commit dd0ae80

Browse files
committed
rt: Account for the size of stack_canary in create_stack
1 parent fc028c3 commit dd0ae80

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/rt/rust_stack.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,19 @@ struct stk_seg {
1313
uint8_t data[];
1414
};
1515

16+
// A value that goes at the end of the stack and must not be touched
17+
const uint8_t stack_canary[] = {0xAB, 0xCD, 0xAB, 0xCD,
18+
0xAB, 0xCD, 0xAB, 0xCD,
19+
0xAB, 0xCD, 0xAB, 0xCD,
20+
0xAB, 0xCD, 0xAB, 0xCD};
21+
1622
void
1723
add_stack_canary(stk_seg *stk);
1824

1925
template <class T>
2026
stk_seg *
2127
create_stack(T allocer, size_t sz) {
22-
size_t total_sz = sizeof(stk_seg) + sz;
28+
size_t total_sz = sizeof(stk_seg) + sz + sizeof(stack_canary);
2329
stk_seg *stk = (stk_seg *)allocer->malloc(total_sz, "stack");
2430
memset(stk, 0, sizeof(stk_seg));
2531
add_stack_canary(stk);

0 commit comments

Comments
 (0)