1 From: Helmut Grohne <helmut@subdivi.de>
2 Date: Wed, 30 Dec 2015 22:35:40 +0100
3 Subject: Avoid sys/capability.h on build architecture
5 libcap/_makenames.c generates a build-time helper, and as such is compiled for
6 the build architecture. The use of sys/capability.h which depends on an arch-
7 specific Linux header eventually leads to a FTCBFS.
9 However, the only reason to use the header is to estimate the size of an array
10 "pointers" in _makenames.c. Rather than using this guess, the array can simply
11 be allocated dynamically.
13 Bug-Debian: https://bugs.debian.org/809467
14 Origin: other, https://bugs.debian.org/cgi-bin/bugreport.cgi?msg=5;filename=no_sys_capability_h.patch;att=1;bug=809467
16 Last-Update: 2015-12-30
18 libcap/_makenames.c | 16 ++++++++++++----
19 1 file changed, 12 insertions(+), 4 deletions(-)
21 diff --git a/libcap/_makenames.c b/libcap/_makenames.c
22 index 8cc819b..03dd684 100644
23 --- a/libcap/_makenames.c
24 +++ b/libcap/_makenames.c
29 -#include <sys/capability.h>
32 * #include 'sed' generated array
33 @@ -21,17 +20,25 @@ struct {
37 -/* this should be more than big enough (factor of three at least) */
38 -const char *pointers[8*sizeof(struct __user_cap_data_struct)];
43 + const char **pointers = NULL, **pointers_tmp;
44 + int pointers_avail = 0;
46 for ( i=0; list[i].index >= 0 && list[i].name; ++i ) {
47 if (maxcaps <= list[i].index) {
48 maxcaps = list[i].index + 1;
50 + if (list[i].index >= pointers_avail) {
51 + pointers_avail = 2 * list[i].index + 1;
52 + pointers_tmp = realloc(pointers, pointers_avail * sizeof(char *));
53 + if (!pointers_tmp) {
54 + fputs("out of memory", stderr);
57 + pointers = pointers_tmp;
59 pointers[list[i].index] = list[i].name;
62 @@ -57,5 +64,6 @@ int main(void)
64 "/* END OF FILE */\n");