aboutsummaryrefslogtreecommitdiffstats
path: root/testing/apparmor/0001-libapparmor-fix-reallocarray-FTBFS-w-older-glibc.patch
blob: 590ccd489ed0add40315476cfa8ebaf94ed71954 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
From e9b875a4b48d5a41d6c398a44ac6bec216fded5f Mon Sep 17 00:00:00 2001
From: Steve Beattie <steve.beattie@canonical.com>
Date: Wed, 18 Apr 2018 12:37:09 -0700
Subject: [PATCH 01/11] libapparmor: fix reallocarray FTBFS w/older glibc

The recently added overlay cache directory support added to libapparmor
makes use of reallocarray(3) to resize memory allocations; however,
reallocarray() was only included in glibc 2.26. This commit adds a
configure check for reallocarray() and if it's not available, provides
it as a wrapper around realloc(3).

PR: https://gitlab.com/apparmor/apparmor/merge_requests/100
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>

(cherry picked from commit 8e6313761246099429e9bd12ea6db02d7052188b)
---
 libraries/libapparmor/configure.ac  |  2 +-
 libraries/libapparmor/src/private.c | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/libraries/libapparmor/configure.ac b/libraries/libapparmor/configure.ac
index 479ba6dd..73d99398 100644
--- a/libraries/libapparmor/configure.ac
+++ b/libraries/libapparmor/configure.ac
@@ -81,7 +81,7 @@ AM_CONDITIONAL(HAVE_RUBY, test x$with_ruby = xyes)
 AC_HEADER_STDC
 AC_CHECK_HEADERS(unistd.h stdint.h syslog.h)
 
-AC_CHECK_FUNCS([asprintf __secure_getenv secure_getenv])
+AC_CHECK_FUNCS([asprintf __secure_getenv secure_getenv reallocarray])
 
 AM_PROG_CC_C_O
 AC_C_CONST
diff --git a/libraries/libapparmor/src/private.c b/libraries/libapparmor/src/private.c
index bece09d1..218f6628 100644
--- a/libraries/libapparmor/src/private.c
+++ b/libraries/libapparmor/src/private.c
@@ -43,6 +43,17 @@
  #endif
 #endif
 
+/**
+ * Allow libapparmor to build on older glibcs and other libcs that do
+ * not support reallocarray.
+ */
+#ifndef HAVE_REALLOCARRY
+void *reallocarray(void *ptr, size_t nmemb, size_t size)
+{
+	return realloc(ptr, nmemb * size);
+}
+#endif
+
 struct ignored_suffix_t {
 	const char * text;
 	int len;
-- 
2.17.1