Avoid-sys-capability.h-on-build-architecture.patch 1.9 KB

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