summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKhem Raj <raj.khem@gmail.com>2020-11-08 16:02:15 -0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2020-11-11 10:04:34 +0000
commit4698e7868b34f6d0676842340659fb3a5f58d532 (patch)
treeacd3f8682a762a34f4693a0d5f1e8dffb9703fe8
parent50cd8edc9849d6ab6249d4c49c7e41bb476dcb71 (diff)
downloadopenembedded-core-contrib-4698e7868b34f6d0676842340659fb3a5f58d532.tar.gz
puzzles: Check for excessive constant arguments
Fixes an issue found with LTO builds Signed-off-by: Khem Raj <raj.khem@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/recipes-sato/puzzles/files/0001-malloc-Check-for-excessive-values-to-malloc.patch49
-rw-r--r--meta/recipes-sato/puzzles/puzzles_git.bb1
2 files changed, 50 insertions, 0 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
new file mode 100644
index 0000000000..66af6afa2f
--- /dev/null
+++ b/meta/recipes-sato/puzzles/files/0001-malloc-Check-for-excessive-values-to-malloc.patch
@@ -0,0 +1,49 @@
+From 1c01a5bc9ac7f8aaa484b1a8e0e74aa5f8899d0e Mon Sep 17 00:00:00 2001
+From: Khem Raj <raj.khem@gmail.com>
+Date: Sun, 8 Nov 2020 11:17:59 -0800
+Subject: [PATCH] malloc: Check for excessive values to malloc
+
+with whole program optimizers like lto smalloc()
+is inlined the excessive constant argument is propagated to
+malloc() and ultimately triggers the warning.
+
+malloc.c:15:9: error: argument 1 range [18446744065119617024, 18446744073709551580] exceeds maximum object size 9223372036854775807 [-Werror=alloc-size-larger-than=]
+
+therefore add a check before excessive constant argument before calling
+malloc
+
+Note that this will not happen with normal compile since they happen to
+be in different translation units and compiler can not semantically
+analyze as much
+
+Upstream-Status: Pending
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+---
+ malloc.c | 3 +++
+ 1 file changed, 3 insertions(+)
+
+diff --git a/malloc.c b/malloc.c
+index a7fa7c5..520377c 100644
+--- a/malloc.c
++++ b/malloc.c
+@@ -2,6 +2,7 @@
+ * malloc.c: safe wrappers around malloc, realloc, free, strdup
+ */
+
++#include <stdint.h>
+ #include <stdlib.h>
+ #include <string.h>
+ #include "puzzles.h"
+@@ -12,6 +13,8 @@
+ */
+ void *smalloc(size_t size) {
+ void *p;
++ if (size > PTRDIFF_MAX)
++ fatal("exceeds maximum object size");
+ p = malloc(size);
+ if (!p)
+ fatal("out of memory");
+--
+2.29.2
+
diff --git a/meta/recipes-sato/puzzles/puzzles_git.bb b/meta/recipes-sato/puzzles/puzzles_git.bb
index a0f3b5d9cd..8e4d5b3349 100644
--- a/meta/recipes-sato/puzzles/puzzles_git.bb
+++ b/meta/recipes-sato/puzzles/puzzles_git.bb
@@ -14,6 +14,7 @@ SRC_URI = "git://git.tartarus.org/simon/puzzles.git \
file://0001-Use-Wno-error-format-overflow-if-the-compiler-suppor.patch \
file://0001-pattern.c-Change-string-lenght-parameter-to-be-size_.patch \
file://fix-ki-uninitialized.patch \
+ file://0001-malloc-Check-for-excessive-values-to-malloc.patch \
"
UPSTREAM_CHECK_COMMITS = "1"