From e9a942a19485b83690596cc8ae375b86777eaf9e Mon Sep 17 00:00:00 2001 From: Ralf Wildenhues Date: Thu, 27 Nov 2008 21:46:36 +0100 Subject: [PATCH] Cope with whitespace in $MISSING and $install_sh. * configure.ac (am_AUTOHEADER): New substitution, save the value of $AUTOHEADER before AM_INIT_AUTOMAKE may add $MISSING. * tests/defs.in: Use am_AUTOHEADER. * lib/am/install.am: Fix typo. * m4/install-sh.m4 (AM_PROG_INSTALL_SH): Add suitable single-quote quoting to install_sh, but only if needed. * m4/missing.m4 (AM_MISSING_HAS_RUN): Add suitable double-quote quoting to MISSING, but only if needed. * m4/sanity.m4 (AM_SANITY_CHECK): Abort configure if `pwd` or $srcdir contain shell meta-characters that cannot be handled; space and tab are allowed in the former only. * tests/sanity.test: New test. * tests/Makefile.am: Adjust. * NEWS: Update. Reports by Jim Meyering and others. Signed-off-by: Ralf Wildenhues --- ChangeLog | 20 ++++++++++++++ Makefile.in | 1 + NEWS | 11 ++++++++ configure | 44 ++++++++++++++++++++++++++---- configure.ac | 3 ++- doc/Makefile.in | 1 + lib/Automake/Makefile.in | 1 + lib/Automake/tests/Makefile.in | 1 + lib/Makefile.in | 1 + lib/am/Makefile.in | 1 + lib/am/install.am | 4 +-- m4/Makefile.in | 1 + m4/install-sh.m4 | 11 ++++++-- m4/missing.m4 | 13 ++++++--- m4/sanity.m4 | 21 ++++++++++++--- tests/Makefile.am | 1 + tests/Makefile.in | 2 ++ tests/defs.in | 2 +- tests/sanity.test | 49 ++++++++++++++++++++++++++++++++++ 19 files changed, 170 insertions(+), 18 deletions(-) create mode 100755 tests/sanity.test diff --git a/ChangeLog b/ChangeLog index ef7f710a5..c31e083c2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2008-11-27 Ralf Wildenhues + Jim Meyering + + Cope with whitespace in $MISSING and $install_sh. + * configure.ac (am_AUTOHEADER): New substitution, save the value + of $AUTOHEADER before AM_INIT_AUTOMAKE may add $MISSING. + * tests/defs.in: Use am_AUTOHEADER. + * lib/am/install.am: Fix typo. + * m4/install-sh.m4 (AM_PROG_INSTALL_SH): Add suitable + single-quote quoting to install_sh, but only if needed. + * m4/missing.m4 (AM_MISSING_HAS_RUN): Add suitable double-quote + quoting to MISSING, but only if needed. + * m4/sanity.m4 (AM_SANITY_CHECK): Abort configure if `pwd` or + $srcdir contain shell meta-characters that cannot be handled; + space and tab are allowed in the former only. + * tests/sanity.test: New test. + * tests/Makefile.am: Adjust. + * NEWS: Update. + Reports by Jim Meyering and others. + 2008-11-24 Ralf Wildenhues Let `missing' also work with versioned and prefixed programs. diff --git a/Makefile.in b/Makefile.in index 7f8b81088..375bf9b2a 100644 --- a/Makefile.in +++ b/Makefile.in @@ -172,6 +172,7 @@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ am_AUTOCONF = @am_AUTOCONF@ +am_AUTOHEADER = @am_AUTOHEADER@ am__leading_dot = @am__leading_dot@ am__tar = @am__tar@ am__untar = @am__untar@ diff --git a/NEWS b/NEWS index 8e0d0270a..e566172cd 100644 --- a/NEWS +++ b/NEWS @@ -127,6 +127,17 @@ New in 1.10a: - The `missing' script works better with versioned tool names. + - Automake's early configure-time sanity check now diagnoses an + unsafe absolute source directory name and makes configure fail. + + - The Automake macros and rules cope better with whitespace in the + current directory name, as long as the relative path to `configure' + does not contain whitespace. To this end, the values of `$(MISSING)' + and `$(install_sh)' may contain suitable quoting, and their expansion + might need `eval'uation if used outside of a makefile. These + undocumented variables may be used in several documented macros such + as $(AUTOCONF) or $(MAKEINFO). + Bugs fixed in 1.10a: * Long standing bugs: diff --git a/configure b/configure index 73994bd03..8247805d1 100755 --- a/configure +++ b/configure @@ -637,6 +637,7 @@ am__isrc INSTALL_DATA INSTALL_SCRIPT INSTALL_PROGRAM +am_AUTOHEADER am_AUTOCONF build_os build_vendor @@ -1839,9 +1840,11 @@ case $build_os in *\ *) build_os=`echo "$build_os" | sed 's/ /-/g'`;; esac # Save the AUTOCONF setting before AM_INIT_AUTOMAKE overrides it; this # way we can run Autoconf tests from configure (or from the test -# suite) without being bothered by `missing'. +# suite) without being bothered by `missing'. Likewise for autoheader. am_AUTOCONF="${AUTOCONF-autoconf}" +am_AUTOHEADER="${AUTOHEADER-autoheader}" + am__api_version='1.10a' @@ -1943,16 +1946,33 @@ $as_echo_n "checking whether build environment is sane... " >&6; } # Just in case sleep 1 echo timestamp > conftest.file +# Reject unsafe characters in $srcdir or the absolute working directory +# name. Accept space and tab only in the latter. +am_lf=' +' +case `pwd` in + *[\\\"\#\$\&\'\`$am_lf]*) + { { $as_echo "$as_me:$LINENO: error: unsafe absolute working directory name" >&5 +$as_echo "$as_me: error: unsafe absolute working directory name" >&2;} + { (exit 1); exit 1; }; };; +esac +case $srcdir in + *[\\\"\#\$\&\'\`$am_lf\ \ ]*) + { { $as_echo "$as_me:$LINENO: error: unsafe srcdir value: \`$srcdir'" >&5 +$as_echo "$as_me: error: unsafe srcdir value: \`$srcdir'" >&2;} + { (exit 1); exit 1; }; };; +esac + # Do `set' in a subshell so we don't clobber the current shell's # arguments. Must try -L first in case configure is actually a # symlink; some systems play weird games with the mod time of symlinks # (eg FreeBSD returns the mod time of the symlink's containing # directory). if ( - set X `ls -Lt $srcdir/configure conftest.file 2> /dev/null` + set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` if test "$*" = "X"; then # -L didn't work. - set X `ls -t $srcdir/configure conftest.file` + set X `ls -t "$srcdir/configure" conftest.file` fi rm -f conftest.file if test "$*" != "X $srcdir/configure conftest.file" \ @@ -1996,7 +2016,14 @@ program_transform_name=`$as_echo "$program_transform_name" | sed "$ac_script"` # expand $ac_aux_dir to an absolute path am_aux_dir=`cd $ac_aux_dir && pwd` -test x"${MISSING+set}" = xset || MISSING="\${SHELL} $am_aux_dir/missing" +if test x"${MISSING+set}" != xset; then + case $am_aux_dir in + *\ * | *\ *) + MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;; + *) + MISSING="\${SHELL} $am_aux_dir/missing" ;; + esac +fi # Use eval to expand $SHELL if eval "$MISSING --run true"; then am_missing_run="$MISSING --run " @@ -2188,7 +2215,14 @@ AUTOHEADER=${AUTOHEADER-"${am_missing_run}autoheader"} MAKEINFO=${MAKEINFO-"${am_missing_run}makeinfo"} -install_sh=${install_sh-"\$(SHELL) $am_aux_dir/install-sh"} +if test x"${install_sh}" != xset; then + case $am_aux_dir in + *\ * | *\ *) + install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;; + *) + install_sh="\${SHELL} $am_aux_dir/install-sh" + esac +fi # Installed binaries are usually stripped using `strip' when the user # run `make install-strip'. However `strip' might not be the right diff --git a/configure.ac b/configure.ac index 3ede8535d..7073d6aa0 100644 --- a/configure.ac +++ b/configure.ac @@ -25,8 +25,9 @@ AC_CANONICAL_BUILD # Save the AUTOCONF setting before AM_INIT_AUTOMAKE overrides it; this # way we can run Autoconf tests from configure (or from the test -# suite) without being bothered by `missing'. +# suite) without being bothered by `missing'. Likewise for autoheader. AC_SUBST([am_AUTOCONF], ["${AUTOCONF-autoconf}"]) +AC_SUBST([am_AUTOHEADER], ["${AUTOHEADER-autoheader}"]) AM_INIT_AUTOMAKE([1.10a dist-bzip2 filename-length-max=99 color-tests]) diff --git a/doc/Makefile.in b/doc/Makefile.in index a64f13cdc..e692797b0 100644 --- a/doc/Makefile.in +++ b/doc/Makefile.in @@ -143,6 +143,7 @@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ am_AUTOCONF = @am_AUTOCONF@ +am_AUTOHEADER = @am_AUTOHEADER@ am__leading_dot = @am__leading_dot@ am__tar = @am__tar@ am__untar = @am__untar@ diff --git a/lib/Automake/Makefile.in b/lib/Automake/Makefile.in index d6498b380..0df41128a 100644 --- a/lib/Automake/Makefile.in +++ b/lib/Automake/Makefile.in @@ -159,6 +159,7 @@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ am_AUTOCONF = @am_AUTOCONF@ +am_AUTOHEADER = @am_AUTOHEADER@ am__leading_dot = @am__leading_dot@ am__tar = @am__tar@ am__untar = @am__untar@ diff --git a/lib/Automake/tests/Makefile.in b/lib/Automake/tests/Makefile.in index 9675112b8..efe081166 100644 --- a/lib/Automake/tests/Makefile.in +++ b/lib/Automake/tests/Makefile.in @@ -112,6 +112,7 @@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ am_AUTOCONF = @am_AUTOCONF@ +am_AUTOHEADER = @am_AUTOHEADER@ am__leading_dot = @am__leading_dot@ am__tar = @am__tar@ am__untar = @am__untar@ diff --git a/lib/Makefile.in b/lib/Makefile.in index 173e13fdc..2e3c4d882 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -162,6 +162,7 @@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ am_AUTOCONF = @am_AUTOCONF@ +am_AUTOHEADER = @am_AUTOHEADER@ am__leading_dot = @am__leading_dot@ am__tar = @am__tar@ am__untar = @am__untar@ diff --git a/lib/am/Makefile.in b/lib/am/Makefile.in index ee54090fa..dbaf398d3 100644 --- a/lib/am/Makefile.in +++ b/lib/am/Makefile.in @@ -122,6 +122,7 @@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ am_AUTOCONF = @am_AUTOCONF@ +am_AUTOHEADER = @am_AUTOHEADER@ am__leading_dot = @am__leading_dot@ am__tar = @am__tar@ am__untar = @am__untar@ diff --git a/lib/am/install.am b/lib/am/install.am index 885ad0b9f..c114fa59b 100644 --- a/lib/am/install.am +++ b/lib/am/install.am @@ -1,5 +1,5 @@ ## automake - create Makefile.in from Makefile.am -## Copyright (C) 2001, 2002, 2003, 2004, 2006 Free Software Foundation, Inc. +## Copyright (C) 2001, 2002, 2003, 2004, 2006, 2008 Free Software Foundation, Inc. ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -78,7 +78,7 @@ install-am: all-am ## directory. .MAKE .PHONY: install-strip install-strip: -## Beware that they are two variables used to install programs: +## Beware that there are two variables used to install programs: ## INSTALL_PROGRAM is used for ordinary *_PROGRAMS ## install_sh_PROGRAM is used for nobase_*_PROGRAMS (because install-sh ## creates directories) diff --git a/m4/Makefile.in b/m4/Makefile.in index 1e2de16c4..a15fd1b3f 100644 --- a/m4/Makefile.in +++ b/m4/Makefile.in @@ -122,6 +122,7 @@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ am_AUTOCONF = @am_AUTOCONF@ +am_AUTOHEADER = @am_AUTOHEADER@ am__leading_dot = @am__leading_dot@ am__tar = @am__tar@ am__untar = @am__untar@ diff --git a/m4/install-sh.m4 b/m4/install-sh.m4 index 32c2ebb2b..b15371521 100644 --- a/m4/install-sh.m4 +++ b/m4/install-sh.m4 @@ -1,5 +1,5 @@ ## -*- Autoconf -*- -# Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc. +# Copyright (C) 2001, 2003, 2005, 2008 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -10,5 +10,12 @@ # Define $install_sh. AC_DEFUN([AM_PROG_INSTALL_SH], [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl -install_sh=${install_sh-"\$(SHELL) $am_aux_dir/install-sh"} +if test x"${install_sh}" != xset; then + case $am_aux_dir in + *\ * | *\ *) + install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;; + *) + install_sh="\${SHELL} $am_aux_dir/install-sh" + esac +fi AC_SUBST(install_sh)]) diff --git a/m4/missing.m4 b/m4/missing.m4 index 26fab2aab..136399cd5 100644 --- a/m4/missing.m4 +++ b/m4/missing.m4 @@ -1,13 +1,13 @@ # Fake the existence of programs that GNU maintainers use. -*- Autoconf -*- -# Copyright (C) 1997, 1999, 2000, 2001, 2003, 2004, 2005 +# Copyright (C) 1997, 1999, 2000, 2001, 2003, 2004, 2005, 2008 # Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. -# serial 5 +# serial 6 # AM_MISSING_PROG(NAME, PROGRAM) # ------------------------------ @@ -24,7 +24,14 @@ AC_SUBST($1)]) AC_DEFUN([AM_MISSING_HAS_RUN], [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl AC_REQUIRE_AUX_FILE([missing])dnl -test x"${MISSING+set}" = xset || MISSING="\${SHELL} $am_aux_dir/missing" +if test x"${MISSING+set}" != xset; then + case $am_aux_dir in + *\ * | *\ *) + MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;; + *) + MISSING="\${SHELL} $am_aux_dir/missing" ;; + esac +fi # Use eval to expand $SHELL if eval "$MISSING --run true"; then am_missing_run="$MISSING --run " diff --git a/m4/sanity.m4 b/m4/sanity.m4 index 2e76b10d7..3d2f30432 100644 --- a/m4/sanity.m4 +++ b/m4/sanity.m4 @@ -1,13 +1,13 @@ # Check to make sure that the build environment is sane. -*- Autoconf -*- -# Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005 +# Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005, 2008 # Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. -# serial 4 +# serial 5 # AM_SANITY_CHECK # --------------- @@ -16,16 +16,29 @@ AC_DEFUN([AM_SANITY_CHECK], # Just in case sleep 1 echo timestamp > conftest.file +# Reject unsafe characters in $srcdir or the absolute working directory +# name. Accept space and tab only in the latter. +am_lf=' +' +case `pwd` in + *[[\\\"\#\$\&\'\`$am_lf]]*) + AC_MSG_ERROR([unsafe absolute working directory name]);; +esac +case $srcdir in + *[[\\\"\#\$\&\'\`$am_lf\ \ ]]*) + AC_MSG_ERROR([unsafe srcdir value: `$srcdir']);; +esac + # Do `set' in a subshell so we don't clobber the current shell's # arguments. Must try -L first in case configure is actually a # symlink; some systems play weird games with the mod time of symlinks # (eg FreeBSD returns the mod time of the symlink's containing # directory). if ( - set X `ls -Lt $srcdir/configure conftest.file 2> /dev/null` + set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` if test "$[*]" = "X"; then # -L didn't work. - set X `ls -t $srcdir/configure conftest.file` + set X `ls -t "$srcdir/configure" conftest.file` fi rm -f conftest.file if test "$[*]" != "X $srcdir/configure conftest.file" \ diff --git a/tests/Makefile.am b/tests/Makefile.am index 9f9dc32d3..2a8e847e3 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -522,6 +522,7 @@ req.test \ reqd.test \ reqd2.test \ rulepat.test \ +sanity.test \ scripts.test \ seenc.test \ sinclude.test \ diff --git a/tests/Makefile.in b/tests/Makefile.in index 64668e09a..c1c67a65e 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -113,6 +113,7 @@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ am_AUTOCONF = @am_AUTOCONF@ +am_AUTOHEADER = @am_AUTOHEADER@ am__leading_dot = @am__leading_dot@ am__tar = @am__tar@ am__untar = @am__untar@ @@ -675,6 +676,7 @@ req.test \ reqd.test \ reqd2.test \ rulepat.test \ +sanity.test \ scripts.test \ seenc.test \ sinclude.test \ diff --git a/tests/defs.in b/tests/defs.in index e7d9d3935..de0c68248 100644 --- a/tests/defs.in +++ b/tests/defs.in @@ -69,7 +69,7 @@ export SHELL test -z "$PERL" && PERL='@PERL@' test -z "$MAKE" && MAKE=make test -z "$AUTOCONF" && AUTOCONF="@am_AUTOCONF@" -test -z "$AUTOHEADER" && AUTOHEADER="@AUTOHEADER@" +test -z "$AUTOHEADER" && AUTOHEADER="@am_AUTOHEADER@" test -z "$AUTOUPDATE" && AUTOUPDATE=autoupdate test -z "$MISSING" && MISSING=`pwd`/../lib/missing # Use -Werror because this also turns some Perl warnings into error. diff --git a/tests/sanity.test b/tests/sanity.test new file mode 100755 index 000000000..0d3830d4f --- /dev/null +++ b/tests/sanity.test @@ -0,0 +1,49 @@ +#! /bin/sh +# Copyright (C) 2008 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Unsafe absolute directory names should be diagnosed. + +. ./defs || Exit 1 + +set -e + +mkdir 'unsafe$' +cd 'unsafe$' + +cat > configure.in << 'END' +AC_INIT([sanity], [1.0]) +AM_INIT_AUTOMAKE([foreign]) +AC_OUTPUT(Makefile) +END + +cp ../install-sh ../missing . + +: > Makefile.am + +$ACLOCAL +$AUTOCONF +$AUTOMAKE +./configure 2>stderr && { cat stderr >&2; Exit 1; } +cat stderr +grep 'unsafe absolute working directory' stderr + +cd .. +mkdir build +cd build +../unsafe$/configure 2>stderr && { cat stderr >&2; Exit 1; } +cat stderr +grep 'unsafe srcdir' stderr +: -- 2.47.2