mirror of
https://github.com/janet-lang/janet
synced 2026-09-08 02:19:12 +00:00
Add fix for #1744
Usually, we try to pre-allocate a few extra stack values for convenience, but we don't actually need to. Avoid a buffer overflow in the case where this "extra" was causing us to go over INT32_MAX.
This commit is contained in:
+6
-1
@@ -1111,7 +1111,12 @@ static const uint8_t *unmarshal_one_fiber(
|
||||
}
|
||||
|
||||
/* Allocate stack memory */
|
||||
fiber->capacity = fiber_stacktop + 10;
|
||||
if (fiber_stacktop < INT32_MAX - 10) {
|
||||
fiber->capacity = fiber_stacktop + 10;
|
||||
} else {
|
||||
/* Extra capacity is usually nice to avoid immediately reallocing on pushed arguments, but not needed */
|
||||
fiber->capacity = INT32_MAX;
|
||||
}
|
||||
fiber->data = janet_malloc(sizeof(Janet) * fiber->capacity);
|
||||
if (!fiber->data) {
|
||||
JANET_OUT_OF_MEMORY;
|
||||
|
||||
Reference in New Issue
Block a user