Source: libcap2
Version: 1:2.24-12
Tags: patch
User: helm...@debian.org
Usertags: rebootstrap

Hi Christian and Steven,

Steven made me aware that libcap2 does not cross from kfreebsd, because
_makenames.c (which is compiled for the build architecture) includes
<sys/capability.h>. Such an assumption generally is an error and can
cause issues with the cross built package.

However, the only reason to use the header is to estimate the size of an
array "pointers" in _makenames.c. Rather than using this guess, the
array can simply be allocated dynamically. So this is what the attached
patch does.

Steven, can you confirm that libcap2 can be crossed after applying this
patch?

Helmut
--- libcap2-2.24.orig/libcap/_makenames.c
+++ libcap2-2.24/libcap/_makenames.c
@@ -7,7 +7,6 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <sys/capability.h>
 
 /*
  * #include 'sed' generated array
@@ -21,17 +20,25 @@ struct {
     {NULL, -1}
 };
 
-/* this should be more than big enough (factor of three at least) */
-const char *pointers[8*sizeof(struct __user_cap_data_struct)];
-
 int main(void)
 {
     int i, maxcaps=0;
+    const char **pointers = NULL, **pointers_tmp;
+    int pointers_avail = 0;
 
     for ( i=0; list[i].index >= 0 && list[i].name; ++i ) {
 	if (maxcaps <= list[i].index) {
 	    maxcaps = list[i].index + 1;
 	}
+	if (list[i].index >= pointers_avail) {
+            pointers_avail = 2 * list[i].index + 1;
+	    pointers_tmp = realloc(pointers, pointers_avail * sizeof(char *));
+	    if (!pointers_tmp) {
+		fputs("out of memory", stderr);
+		exit(1);
+	    }
+	    pointers = pointers_tmp;
+	}
 	pointers[list[i].index] = list[i].name;
     }
 
@@ -57,5 +64,6 @@ int main(void)
 	   "\n"
 	   "/* END OF FILE */\n");
 
+    free(pointers);
     exit(0);
 }

Reply via email to