logo

bootstrap-initrd

Linux initrd to bootstrap from a small binary seed git clone https://anongit.hacktivis.me/git/bootstrap-initrd.git/

heirloom-no_alloca.patch (2672B)


  1. From c69bc8007b292b9040d398c5507c415427c7dff1 Mon Sep 17 00:00:00 2001
  2. From: "Haelwenn (lanodan) Monnier" <contact@hacktivis.me>
  3. Date: Sun, 2 Feb 2025 15:07:33 +0100
  4. Subject: [PATCH 1/2] tar/tar.c: remove usage of alloca()
  5. ---
  6. tar/tar.c | 11 +++++++----
  7. 1 file changed, 7 insertions(+), 4 deletions(-)
  8. diff --git a/tar/tar.c b/tar/tar.c
  9. index 7985d93..2ad9fb2 100644
  10. --- a/tar/tar.c
  11. +++ b/tar/tar.c
  12. @@ -81,7 +81,6 @@ static const char sccsid[] USED = "@(#)tar.sl 1.177 (gritter) 4/14/07";
  13. #include <inttypes.h>
  14. #include <iblok.h>
  15. #include <locale.h>
  16. -#include <alloca.h>
  17. #include <sys/ioctl.h>
  18. @@ -2027,12 +2026,12 @@ bsrch(const char *s, int n, off_t l, off_t h)
  19. char *b;
  20. off_t m, m1;
  21. - b = alloca(N);
  22. + b = malloc(N);
  23. njab = 0;
  24. loop:
  25. if(l >= h)
  26. - return(-1L);
  27. + goto fail;
  28. m = l + (h-l)/2 - N/2;
  29. if(m < l)
  30. m = l;
  31. @@ -2045,7 +2044,7 @@ bsrch(const char *s, int n, off_t l, off_t h)
  32. m++;
  33. }
  34. if(m >= h)
  35. - return(-1L);
  36. + goto fail;
  37. m1 = m;
  38. j = i;
  39. for(i++; i<N; i++) {
  40. @@ -2063,6 +2062,10 @@ bsrch(const char *s, int n, off_t l, off_t h)
  41. goto loop;
  42. }
  43. return(m);
  44. +
  45. +fail:
  46. + free(b);
  47. + return(-1L);
  48. }
  49. static int
  50. --
  51. 2.45.3
  52. From 8b217e567deae47e92796580dc1684adc6a86efa Mon Sep 17 00:00:00 2001
  53. From: "Haelwenn (lanodan) Monnier" <contact@hacktivis.me>
  54. Date: Sun, 2 Feb 2025 15:09:07 +0100
  55. Subject: [PATCH 2/2] libcommon: get rid of custom getopt (due to alloca)
  56. musl getopt being good anyway
  57. ---
  58. libcommon/Makefile.mk | 6 +-----
  59. 1 file changed, 1 insertion(+), 5 deletions(-)
  60. diff --git a/libcommon/Makefile.mk b/libcommon/Makefile.mk
  61. index 7ef8de1..c9764e6 100644
  62. --- a/libcommon/Makefile.mk
  63. +++ b/libcommon/Makefile.mk
  64. @@ -4,7 +4,7 @@ OBJ = asciitype.o ib_alloc.o ib_close.o ib_free.o ib_getlin.o ib_getw.o \
  65. ib_open.o ib_popen.o ib_read.o ib_seek.o oblok.o sfile.o strtol.o \
  66. getdir.o gmatch.o utmpx.o memalign.o pathconf.o \
  67. sigset.o signal.o sigrelse.o sighold.o sigignore.o sigpause.o \
  68. - getopt.o pfmt.o vpfmt.o setlabel.o setuxlabel.o pfmt_label.o sysv3.o
  69. + pfmt.o vpfmt.o setlabel.o setuxlabel.o pfmt_label.o sysv3.o
  70. libcommon.a: headers $(OBJ)
  71. $(AR) -rv $@ $(OBJ)
  72. $(RANLIB) $@
  73. @@ -101,9 +101,6 @@ pathconf.o: pathconf.c
  74. strtol.o: strtol.c
  75. $(CC) $(CFLAGSS) $(CPPFLAGS) $(LARGEF) $(IWCHAR) -I. -c strtol.c
  76. -getopt.o: getopt.c
  77. - $(CC) $(CFLAGSS) $(CPPFLAGS) $(LARGEF) $(IWCHAR) -I. -c getopt.c
  78. -
  79. sysv3.o: sysv3.c
  80. $(CC) $(CFLAGSS) $(CPPFLAGS) $(LARGEF) $(IWCHAR) -I. -c sysv3.c
  81. @@ -143,7 +140,6 @@ pfmt.o: pfmt.h
  82. vpfmt.o: pfmt.h
  83. setlabel.o: pfmt.h
  84. setuxlabel.o: pfmt.h msgselect.h
  85. -getopt.o: msgselect.h
  86. sighold.o: sigset.h
  87. sigignore.o: sigset.h
  88. sigpause.o: sigset.h
  89. --
  90. 2.45.3