spa: add spa_alloca that does overflow and limit checks

Make a function like alloca but with overflow checks and a max
allocation size.

Use this function where we can and also make sure that all alloca calls
are in some way limited.
This commit is contained in:
Wim Taymans 2026-04-27 10:53:44 +02:00
parent a9f1ad414e
commit ed2c0ad4ee
10 changed files with 84 additions and 51 deletions

View file

@ -457,6 +457,16 @@ struct spa_error_location {
_strp; \
})
#define spa_alloca(n, size, max_size) \
({ \
void *_res = NULL; \
if ((size_t)n > (size_t)max_size / (size_t)size) \
errno = ENOMEM; \
else \
_res = alloca((size_t)n * (size_t)size); \
_res; \
})
/**
* \}
*/