diff options
author | Gustavo A. R. Silva <gustavoars@kernel.org> | 2020-12-16 05:43:07 +0100 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2020-12-16 07:46:16 +0100 |
commit | 47e684aaa2661b2af39474a12d05447865ce9184 (patch) | |
tree | 6bfcd0f9ad5e26bd8428027416a7742d41263947 | |
parent | lib/stackdepot.c: replace one-element array with flexible-array member (diff) | |
download | linux-47e684aaa2661b2af39474a12d05447865ce9184.tar.xz linux-47e684aaa2661b2af39474a12d05447865ce9184.zip |
lib/stackdepot.c: use flex_array_size() helper in memcpy()
Make use of the flex_array_size() helper to calculate the size of a
flexible array member within an enclosing structure.
This helper offers defense-in-depth against potential integer overflows,
while at the same time makes it explicitly clear that we are dealing with
a flexible array member.
Link: https://lkml.kernel.org/r/186e37fe07196ee41a0e562fa8a8cb7a01112ec5.1601565471.git.gustavoars@kernel.org
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | lib/stackdepot.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/stackdepot.c b/lib/stackdepot.c index c6106cfb7950..683b6a8ddade 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -135,7 +135,7 @@ static struct stack_record *depot_alloc_stack(unsigned long *entries, int size, stack->handle.slabindex = depot_index; stack->handle.offset = depot_offset >> STACK_ALLOC_ALIGN; stack->handle.valid = 1; - memcpy(stack->entries, entries, size * sizeof(unsigned long)); + memcpy(stack->entries, entries, flex_array_size(stack, entries, size)); depot_offset += required_size; return stack; |