Commit 87a7fe83 authored by Szymon Janc's avatar Szymon Janc Committed by Benjamin Walsh
Browse files

kernel: legacy: Fix int overflow in nano_stack_init



Last argument for k_stack_init is of time int resulting in UINT_MAX
being converted to negative value. Instead of UINT_MAX use maximum
possible number of entires that won't result in stack->base and
stack->top overflow.

Change-Id: I8470f6dd18abcccc72590e07e0d0efd4ce2208cc
Signed-off-by: default avatarSzymon Janc <ext.szymon.janc@tieto.com>
parent 0859df1e
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#include <stdint.h>
#include <errno.h>
#include <limits.h>
#include <misc/util.h>
#include <misc/__assert.h>

/* nanokernel/microkernel execution context types */
@@ -2757,7 +2758,12 @@ static inline __deprecated void *nano_lifo_get(struct nano_lifo *lifo,
static inline __deprecated void nano_stack_init(struct nano_stack *stack,
						uint32_t *data)
{
	k_stack_init(stack, data, UINT_MAX);
	int entries;

	/* use max possible number of entries */
	entries = min(INT_MAX, UINTPTR_MAX - (uint32_t)data) / sizeof(*data);

	k_stack_init(stack, data, entries);
}

/**