diff options
Diffstat (limited to 'meta/recipes-sato/puzzles/files/0001-malloc-Check-for-excessive-values-to-malloc.patch')
-rw-r--r-- | meta/recipes-sato/puzzles/files/0001-malloc-Check-for-excessive-values-to-malloc.patch | 92 |
1 files changed, 44 insertions, 48 deletions
diff --git a/meta/recipes-sato/puzzles/files/0001-malloc-Check-for-excessive-values-to-malloc.patch b/meta/recipes-sato/puzzles/files/0001-malloc-Check-for-excessive-values-to-malloc.patch index 66af6afa2f..b572b55d1c 100644 --- a/meta/recipes-sato/puzzles/files/0001-malloc-Check-for-excessive-values-to-malloc.patch +++ b/meta/recipes-sato/puzzles/files/0001-malloc-Check-for-excessive-values-to-malloc.patch | |||
@@ -1,49 +1,45 @@ | |||
1 | From 1c01a5bc9ac7f8aaa484b1a8e0e74aa5f8899d0e Mon Sep 17 00:00:00 2001 | 1 | tree234: Avoid excessive values to malloc |
2 | From: Khem Raj <raj.khem@gmail.com> | 2 | |
3 | Date: Sun, 8 Nov 2020 11:17:59 -0800 | 3 | with whole program optimizers like lto, smalloc() is inlined the excessive |
4 | Subject: [PATCH] malloc: Check for excessive values to malloc | 4 | constant argument is propagated to malloc() and ultimately triggers the warning. |
5 | 5 | ||
6 | with whole program optimizers like lto smalloc() | 6 | | tmp/work/core2-64-poky-linux/puzzles/2_0.0+gitAUTOINC+640f9235c7-r0/git/tree234.c: In function 'disptree': |
7 | is inlined the excessive constant argument is propagated to | 7 | | tmp/work/core2-64-poky-linux/puzzles/2_0.0+gitAUTOINC+640f9235c7-r0/git/tree234.c:46:17: error: argument 1 value '18446744073709551612' exceeds maximum object size 9223372036854775807 [-Werror=alloc-size-larger-than=] |
8 | malloc() and ultimately triggers the warning. | 8 | | 46 | #define smalloc malloc |
9 | 9 | | | ^ | |
10 | malloc.c:15:9: error: argument 1 range [18446744065119617024, 18446744073709551580] exceeds maximum object size 9223372036854775807 [-Werror=alloc-size-larger-than=] | 10 | | tmp/work/core2-64-poky-linux/puzzles/2_0.0+gitAUTOINC+640f9235c7-r0/git/tree234.c:1631:17: note: in expansion of macro 'smalloc' |
11 | 11 | | 1631 | leveldata = smalloc(ht * (width+2)); | |
12 | therefore add a check before excessive constant argument before calling | 12 | | | ^~~~~~~ |
13 | malloc | 13 | | In file included from tmp/work/core2-64-poky-linux/puzzles/2_0.0+gitAUTOINC+640f9235c7-r0/git/tree234.c:29: |
14 | 14 | | tmp/work/core2-64-poky-linux/puzzles/2_0.0+gitAUTOINC+640f9235c7-r0/recipe-sysroot/usr/include/stdlib.h:539:14: note: in a call to allocation function 'malloc' declared here | |
15 | Note that this will not happen with normal compile since they happen to | 15 | | 539 | extern void *malloc (size_t __size) __THROW __attribute_malloc__ |
16 | be in different translation units and compiler can not semantically | 16 | | | ^~~~~~ |
17 | analyze as much | 17 | | tmp/work/core2-64-poky-linux/puzzles/2_0.0+gitAUTOINC+640f9235c7-r0/git/tree234.c:46:17: error: argument 1 value '18446744073709551600' exceeds maximum object size 9223372036854775807 [-Werror=alloc-size-larger-than=] |
18 | 18 | | 46 | #define smalloc malloc | |
19 | Upstream-Status: Pending | 19 | | | ^ |
20 | 20 | | tmp/work/core2-64-poky-linux/puzzles/2_0.0+gitAUTOINC+640f9235c7-r0/git/tree234.c:1632:18: note: in expansion of macro 'smalloc' | |
21 | Signed-off-by: Khem Raj <raj.khem@gmail.com> | 21 | | 1632 | ctx.levels = smalloc(ht * sizeof(char *)); |
22 | --- | 22 | | | ^~~~~~~ |
23 | malloc.c | 3 +++ | 23 | | In file included from tmp/work/core2-64-poky-linux/puzzles/2_0.0+gitAUTOINC+640f9235c7-r0/git/tree234.c:29: |
24 | 1 file changed, 3 insertions(+) | 24 | | tmp/work/core2-64-poky-linux/puzzles/2_0.0+gitAUTOINC+640f9235c7-r0/recipe-sysroot/usr/include/stdlib.h:539:14: note: in a call to allocation function 'malloc' declared here |
25 | 25 | | 539 | extern void *malloc (size_t __size) __THROW __attribute_malloc__ | |
26 | diff --git a/malloc.c b/malloc.c | 26 | | | ^~~~~~ |
27 | index a7fa7c5..520377c 100644 | 27 | | cc1: some warnings being treated as errors |
28 | --- a/malloc.c | 28 | |
29 | +++ b/malloc.c | 29 | Upstream-Status: Submitted [email discussion with upstream] |
30 | @@ -2,6 +2,7 @@ | 30 | |
31 | * malloc.c: safe wrappers around malloc, realloc, free, strdup | 31 | Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> |
32 | */ | 32 | |
33 | Index: git/tree234.c | ||
34 | =================================================================== | ||
35 | --- git.orig/tree234.c | ||
36 | +++ git/tree234.c | ||
37 | @@ -1621,7 +1621,7 @@ void disptree(tree234 *t) { | ||
38 | dispctx ctx; | ||
39 | char *leveldata; | ||
40 | int width = count234(t); | ||
41 | - int ht = height234(t) * 3 - 2; | ||
42 | + unsigned int ht = height234(t) * 3 - 2; | ||
43 | int i; | ||
33 | 44 | ||
34 | +#include <stdint.h> | 45 | if (!t->root) { |
35 | #include <stdlib.h> | ||
36 | #include <string.h> | ||
37 | #include "puzzles.h" | ||
38 | @@ -12,6 +13,8 @@ | ||
39 | */ | ||
40 | void *smalloc(size_t size) { | ||
41 | void *p; | ||
42 | + if (size > PTRDIFF_MAX) | ||
43 | + fatal("exceeds maximum object size"); | ||
44 | p = malloc(size); | ||
45 | if (!p) | ||
46 | fatal("out of memory"); | ||
47 | -- | ||
48 | 2.29.2 | ||
49 | |||