summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Kastner <ckk@debian.org>2020-05-12 10:19:35 +0200
committerAndrew G. Morgan <morgan@kernel.org>2020-05-12 10:19:35 +0200
commit370c16a5e0ee04ca255a089aa7aad697984abfc2 (patch)
treef19bc9b2a39950f6f6b80dc586ac97d06c3764a6
parent4a3adbd0924e5c2c16817d00405d048e9fe18651 (diff)
downloadlibcap2-370c16a5e0ee04ca255a089aa7aad697984abfc2.tar.gz
Avoid sys/capability.h on build architecture
libcap/_makenames.c generates a build-time helper, and as such is compiled for the build architecture. The use of sys/capability.h which depends on an arch- specific Linux header eventually leads to a FTCBFS. 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. Signed-off-by: Christian Kastner <ckk@kvr.at> Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
-rw-r--r--libcap/_makenames.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/libcap/_makenames.c b/libcap/_makenames.c
index 185df41..079e78c 100644
--- a/libcap/_makenames.c
+++ b/libcap/_makenames.c
@@ -8,7 +8,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/capability.h>
/*
* #include 'sed' generated array
@@ -22,17 +21,26 @@ 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, maxlength=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;
int n = strlen(list[i].name);
if (n > maxlength) {
@@ -63,5 +71,6 @@ int main(void)
"\n"
"/* END OF FILE */\n");
+ free(pointers);
exit(0);
}