Skip to content

Commit 558419b

Browse files
committed
utils: do not use stack for lens array
The str_join_array function previously declared an array `lens` on the stack with a variable length derived from its `size` parameter. Play safe and do not use the stack for a VLA. Signed-off-by: Giuseppe Scrivano <[email protected]>
1 parent 819c2a7 commit 558419b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/libcrun/utils.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2446,10 +2446,13 @@ has_suffix (const char *str, const char *suffix)
24462446
char *
24472447
str_join_array (int offset, size_t size, char *const array[], const char *joint)
24482448
{
2449-
size_t jlen, lens[size];
2449+
size_t jlen;
2450+
cleanup_free size_t *lens = NULL;
24502451
size_t i, total_size = (size - 1) * (jlen = strlen (joint)) + 1;
24512452
char *result, *p;
24522453

2454+
lens = xmalloc (size * sizeof (*lens));
2455+
24532456
for (i = 0; i < size; ++i)
24542457
{
24552458
total_size += (lens[i] = strlen (array[i]));

0 commit comments

Comments
 (0)