[PATCH] Makefile.in: Make for loop failures fatal
Without set -e, these for loops will exit with code 0 and so make will regard the recipes as being successful. --- Makefile.in | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile.in b/Makefile.in index ee471583..a12ed426 100644 --- a/Makefile.in +++ b/Makefile.in @@ -752,7 +752,7 @@ Makefile makefile: config.status $(srcdir)/Makefile.in CONFIG_FILES=Makefile CONFIG_HEADERS= $(SHELL) ./config.status Makefiles makefiles: config.status $(srcdir)/Makefile.in - @for mf in $(CREATED_MAKEFILES); do \ + @set -e; for mf in $(CREATED_MAKEFILES); do \ CONFIG_FILES=$$mf CONFIG_HEADERS= $(SHELL) ./config.status ; \ done @@ -838,16 +838,16 @@ install-headers-dirs: @${SHELL} $(SUPPORT_SRC)mkinstalldirs $(DESTDIR)$(pkgconfigdir) install-headers: install-headers-dirs - @for hf in $(INSTALLED_HEADERS) ; do \ + @set -e; for hf in $(INSTALLED_HEADERS) ; do \ ${INSTALL_DATA} $(srcdir)/"$$hf" $(DESTDIR)$(headersdir)/$$hf; \ done - @for hf in $(INSTALLED_INCFILES) ; do \ + @set -e; for hf in $(INSTALLED_INCFILES) ; do \ ${INSTALL_DATA} $(BASHINCDIR)/"$$hf" $(DESTDIR)$(headersdir)/include/$$hf; \ done - @for hf in $(INSTALLED_BUILTINS_HEADERS) ; do \ + @set -e; for hf in $(INSTALLED_BUILTINS_HEADERS) ; do \ ${INSTALL_DATA} $(BUILTIN_SRCDIR)/"$$hf" $(DESTDIR)$(headersdir)/builtins/$$hf; \ done - @for hf in $(CREATED_HEADERS) ; do \ + @set -e; for hf in $(CREATED_HEADERS) ; do \ ${INSTALL_DATA} $(BUILD_DIR)/"$$hf" $(DESTDIR)$(headersdir)/$$hf; \ done -$(INSTALL_DATA) $(SDIR)/bash.pc $(DESTDIR)$(pkgconfigdir)/bash.pc -- 2.20.1
[PATCH 1/3] aclocal.m4: Fix BASH_FUNC_STRSIGNAL when compiling for FreeBSD/RISC-V
POSIX defines strsignal(3) as being in string.h, not signal.h. We leave the test as also checking signal.h for compatibility with any legacy non-conforming systems. --- aclocal.m4 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aclocal.m4 b/aclocal.m4 index 1413267f..c4a54f27 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -300,7 +300,8 @@ AC_DEFUN(BASH_FUNC_STRSIGNAL, [AC_MSG_CHECKING([for the existence of strsignal]) AC_CACHE_VAL(bash_cv_have_strsignal, [AC_TRY_LINK([#include -#include ], +#include +#include ], [char *s = (char *)strsignal(2);], bash_cv_have_strsignal=yes, bash_cv_have_strsignal=no)]) AC_MSG_RESULT($bash_cv_have_strsignal) -- 2.20.1
[PATCH 2/3] aclocal.m4: Fix BASH_FUNC_SBRK when cross-compiling for FreeBSD/RISC-V
FreeBSD unconditionally provides a prototype for sbrk(2), but on recent ports (AArch64 and RISC-V) it does not provide the deprecated symbol. This means that, when cross-compiling, we currently only get to use AC_CHECK_FUNCS_ONCE, and so believe sbrk(2) to be available. Instead, use AC_TRY_LINK so we can detect this case when cross-compiling. Also, only define HAVE_SBRK when our tests pass, since xmalloc.c checks whether it's defined, not its value. This likely meant the case where sbrk(2) was available but broken did not in fact do the right thing. --- aclocal.m4 | 11 --- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/aclocal.m4 b/aclocal.m4 index c4a54f27..c785e197 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -4196,7 +4196,12 @@ AC_DEFINE_UNQUOTED([WEXITSTATUS_OFFSET], [$bash_cv_wexitstatus_offset], [Offset AC_DEFUN([BASH_FUNC_SBRK], [ - AC_CHECK_FUNCS_ONCE([sbrk]) + AC_MSG_CHECKING([for sbrk]) + AC_CACHE_VAL(ac_cv_func_sbrk, + [AC_TRY_LINK([#include ], + [ void *x = sbrk (4096); ], + ac_cv_func_sbrk=yes, ac_cv_func_sbrk=no)]) + AC_MSG_RESULT($ac_cv_func_sbrk) if test X$ac_cv_func_sbrk = Xyes; then AC_CACHE_CHECK([for working sbrk], [bash_cv_func_sbrk], [AC_TRY_RUN([ @@ -4219,8 +4224,8 @@ main(int c, char **v) ac_cv_func_sbrk=no fi fi - if test $ac_cv_func_sbrk = no; then -AC_DEFINE(HAVE_SBRK, 0, + if test $ac_cv_func_sbrk = yes; then +AC_DEFINE(HAVE_SBRK, 1, [Define if you have a working sbrk function.]) fi ]) -- 2.20.1
[PATCH 3/3] configure.ac: Disable Bash malloc on FreeBSD/arm64 and FreeBSD/RISC-V
These recent ports do not provide sbrk(2) and so the Bash version of malloc cannot be used. --- configure.ac | 3 +++ 1 file changed, 3 insertions(+) diff --git a/configure.ac b/configure.ac index 52b4cdbd..dd8d9003 100644 --- a/configure.ac +++ b/configure.ac @@ -88,6 +88,9 @@ sparc-linux*) opt_bash_malloc=no ;; # sparc running linux; requires ELF *-qnx*)opt_bash_malloc=no ;; # QNX 4.2, QNX [67].x *-nsk*)opt_bash_malloc=no ;; # HP NonStop *-haiku*) opt_bash_malloc=no ;; # Haiku OS +# Recent FreeBSD architectures lack the deprecated sbrk(2) +aarch64-freebsd*) opt_bash_malloc=no ;; +riscv*-freebsd*) opt_bash_malloc=no ;; # Deprecated -- bash malloc is suitable #sparc-netbsd*)opt_bash_malloc=no ;; # needs 8-byte alignment #mips-irix6*) opt_bash_malloc=no ;; # needs 8-byte alignment -- 2.20.1
[PATCH] unwind_prot.c: Avoid buffer overflow
In unwind_protect_mem_internal, we must make sure to allocate at least a full UNWIND_ELT, even if the required size for desired_setting is less than the remaining padding in UNWIND_ELT. Otherwise when we come to memset it with 0xdf in unwind_frame_discard_internal we will overflow the allocation. On existing 32-bit and 64-bit architectures, this padding happens to be only 4 bytes, and no users of this function call it with a size smaller than 4 (unwind_protect_short and unwind_protect_string are both currently unused). However, we should not rely on this as this could change in future. Moreover on CHERI-RISC-V, pointers are replaced with capabilities, 16-byte fat pointers, and the padding now ends up being 12 bytes, violating this assumption, but also trapping on this detected buffer overflow by virtue of its fine-grained bounds. --- unwind_prot.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/unwind_prot.c b/unwind_prot.c index c9196dc1..37429924 100644 --- a/unwind_prot.c +++ b/unwind_prot.c @@ -349,6 +349,8 @@ unwind_protect_mem_internal (var, psize) size = *(int *) psize; allocated = size + offsetof (UNWIND_ELT, sv.v.desired_setting[0]); + if (allocated < sizeof (UNWIND_ELT)) +allocated = sizeof (UNWIND_ELT); elt = (UNWIND_ELT *)xmalloc (allocated); elt->head.next = unwind_protect_list; elt->head.cleanup = (Function *) restore_variable; -- 2.20.1
[PATCH 0/3] Fix cross-compiling for FreeBSD/RISC-V
This patch series includes the necessary changes for bash to cross-compile for FreeBSD/RISC-V, and likely also FreeBSD/arm64, though I have not tested that. Jessica Clarke (3): aclocal.m4: Fix BASH_FUNC_STRSIGNAL when compiling for FreeBSD/RISC-V aclocal.m4: Fix BASH_FUNC_SBRK when cross-compiling for FreeBSD/RISC-V configure.ac: Disable Bash malloc on FreeBSD/arm64 and FreeBSD/RISC-V aclocal.m4 | 14 ++ configure.ac | 3 +++ 2 files changed, 13 insertions(+), 4 deletions(-) -- 2.20.1
[PATCH] Makefile.in: Fix out-of-tree build
y.tab.h is present in the source directory, not generated in the build directory. --- Makefile.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile.in b/Makefile.in index 5fcb44b0..ee471583 100644 --- a/Makefile.in +++ b/Makefile.in @@ -459,7 +459,7 @@ INSTALLED_HEADERS = shell.h bashjmp.h command.h syntax.h general.h error.h \ make_cmd.h subst.h sig.h externs.h builtins.h \ bashtypes.h xmalloc.h config-top.h config-bot.h \ bashintl.h bashansi.h bashjmp.h alias.h hashlib.h \ - conftypes.h unwind_prot.h jobs.h siglist.h + conftypes.h unwind_prot.h jobs.h siglist.h y.tab.h INSTALLED_BUILTINS_HEADERS = bashgetopt.h common.h getopt.h INSTALLED_INCFILES =posixstat.h ansi_stdlib.h filecntl.h posixdir.h \ memalloc.h stdc.h posixjmp.h posixwait.h posixtime.h systimes.h \ @@ -562,7 +562,7 @@ CREATED_MAKEFILES = Makefile builtins/Makefile doc/Makefile \ examples/loadables/Makefile.inc \ examples/loadables/perl/Makefile support/Makefile \ lib/intl/Makefile po/Makefile po/Makefile.in -CREATED_HEADERS = signames.h config.h pathnames.h version.h y.tab.h \ +CREATED_HEADERS = signames.h config.h pathnames.h version.h \ ${DEFDIR}/builtext.h OTHER_DOCS = $(srcdir)/CHANGES $(srcdir)/COMPAT $(srcdir)/NEWS $(srcdir)/POSIX \ -- 2.20.1
[PATCH] finfo.c: Fix -Wformat warnings
We must cast these to unsigned long like the surrounding code. --- examples/loadables/finfo.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/loadables/finfo.c b/examples/loadables/finfo.c index 4273aa59..92e98008 100644 --- a/examples/loadables/finfo.c +++ b/examples/loadables/finfo.c @@ -334,13 +334,13 @@ int flags; else printf("%ld\n", st->st_ctime); } else if (flags & OPT_DEV) - printf("%d\n", st->st_dev); + printf("%lu\n", (unsigned long)st->st_dev); else if (flags & OPT_INO) printf("%lu\n", (unsigned long)st->st_ino); else if (flags & OPT_FID) - printf("%d:%lu\n", st->st_dev, (unsigned long)st->st_ino); + printf("%lu:%lu\n", (unsigned long)st->st_dev, (unsigned long)st->st_ino); else if (flags & OPT_NLINK) - printf("%d\n", st->st_nlink); + printf("%lu\n", (unsigned long)st->st_nlink); else if (flags & OPT_LNKNAM) { #ifdef S_ISLNK b = xmalloc(4096); -- 2.20.1