autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 4/10] Proper config.status --file/--header and $srcdir escapi


From: Ralf Wildenhues
Subject: Re: [PATCH 4/10] Proper config.status --file/--header and $srcdir escaping.
Date: Thu, 6 Dec 2007 22:54:29 +0100
User-agent: Mutt/1.5.13 (2006-08-11)

* lib/autoconf/status.m4 (_AC_OUTPUT_MAIN_LOOP): Quote special
characters in $ac_file_inputs.
(_AC_OUTPUT_FILE, _AC_OUTPUT_HEADER): eval $ac_file_inputs
accordingly.
* tests/torture.at (datarootdir workaround): Adjust.
(AC_CONFIG_FILES, HEADERS, LINKS and COMMANDS): Extend test.
---

Hi Paul,

* Paul Eggert wrote on Wed, Dec 05, 2007 at 12:17:54AM CET:
> Ralf Wildenhues <address@hidden> writes:
> 
> > -case `sed -n '/datarootdir/ {
> > +case `eval cat "$ac_file_inputs" | sed -n '/datarootdir/ {
[...]
> I'd rather not turn one subprocess into two just to overcome some
> shell quoting issue.  How about doing it this way instead?
> 
>         sed_program='/datarootdir/ {
>            ...
>         '
>         case `eval sed -n \"\$sed_program\" "$ac_file_inputs"` in
> 
> Similarly for the other introductions of "eval cat ...".

Yep, good idea, thanks.  Updated patch (that otherwise still requires
AC_CONFIG_{FILES,HEADERS} to be stable under eval).

Cheers,
Ralf

 lib/autoconf/status.m4 |   43 ++++++++++++++++++++++++++++---------------
 tests/torture.at       |   17 ++++++++++++++++-
 2 files changed, 44 insertions(+), 16 deletions(-)

diff --git a/lib/autoconf/status.m4 b/lib/autoconf/status.m4
index 3372a8b..8afa9ba 100644
--- a/lib/autoconf/status.m4
+++ b/lib/autoconf/status.m4
@@ -601,13 +601,15 @@ m4_ifndef([AC_DATAROOTDIR_CHECKED],
 ac_datarootdir_hack=; ac_datarootdir_seen=
 m4_define([_AC_datarootdir_vars],
          [datadir, docdir, infodir, localedir, mandir])
-case `sed -n '/datarootdir/ {
+ac_sed_dataroot='
+/datarootdir/ {
   p
   q
 }
 m4_foreach([_AC_Var], m4_defn([_AC_datarootdir_vars]),
           [/@_AC_Var@/p
-])' $ac_file_inputs` in
+])'
+case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in
 *datarootdir*) ac_datarootdir_seen=yes;;
 address@hidden(address@hidden|address@hidden, _AC_datarootdir_vars)@*)
   AC_MSG_WARN([$ac_file_inputs seems to ignore the --datarootdir setting])
@@ -626,7 +628,7 @@ _ACEOF
 # Shell code in configure.ac might set extrasub.
 # FIXME: do we really want to maintain this feature?
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
-  sed "$ac_vpsub
+ac_sed_extra="$ac_vpsub
 $extrasub
 _ACEOF
 cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
@@ -645,7 +647,8 @@ m4_foreach([_AC_Var], [srcdir, abs_srcdir, top_srcdir, 
abs_top_srcdir,
 ])dnl
 m4_ifndef([AC_DATAROOTDIR_CHECKED], [$ac_datarootdir_hack
 ])dnl
-" $ac_file_inputs m4_defn([_AC_SUBST_CMDS]) >$tmp/out \
+"
+eval sed \"\$ac_sed_extra\" "$ac_file_inputs" m4_defn([_AC_SUBST_CMDS]) 
>$tmp/out \
   || AC_MSG_ERROR([could not create $ac_file])
 
 m4_ifndef([AC_DATAROOTDIR_CHECKED],
@@ -659,14 +662,14 @@ which seems to be undefined.  Please make sure it is 
defined.])
   rm -f "$tmp/stdin"
   case $ac_file in
   -) cat "$tmp/out" && rm -f "$tmp/out";;
-  *) rm -f "$ac_file" && mv "$tmp/out" $ac_file;;
+  *) rm -f "$ac_file" && mv "$tmp/out" "$ac_file";;
   esac \
   || AC_MSG_ERROR([could not create $ac_file])
 dnl This would break Makefile dependencies:
-dnl  if diff $ac_file "$tmp/out" >/dev/null 2>&1; then
+dnl  if diff "$ac_file" "$tmp/out" >/dev/null 2>&1; then
 dnl    echo "$ac_file is unchanged"
 dnl  else
-dnl     rm -f $ac_file; mv "$tmp/out" $ac_file
+dnl     rm -f "$ac_file"; mv "$tmp/out" "$ac_file"
 dnl  fi
 ])# _AC_OUTPUT_FILE
 
@@ -855,19 +858,19 @@ m4_define([_AC_OUTPUT_HEADER],
   if test x"$ac_file" != x-; then
     {
       AS_ECHO(["/* $configure_input  */"]) \
-      && $AWK -f "$tmp/defines.awk" $ac_file_inputs
+      && eval '$AWK -f "$tmp/defines.awk"' "$ac_file_inputs"
     } >"$tmp/config.h" \
       || AC_MSG_ERROR([could not create $ac_file])
     if diff $ac_file "$tmp/config.h" >/dev/null 2>&1; then
       AC_MSG_NOTICE([$ac_file is unchanged])
     else
       rm -f $ac_file
-      mv "$tmp/config.h" $ac_file \
+      mv "$tmp/config.h" "$ac_file" \
        || AC_MSG_ERROR([could not create $ac_file])
     fi
   else
     AS_ECHO(["/* $configure_input  */"]) \
-      && $AWK -f "$tmp/defines.awk" $ac_file_inputs \
+      && eval '$AWK -f "$tmp/defines.awk"' "$ac_file_inputs" \
       || AC_MSG_ERROR([could not create -])
   fi
 dnl If running for Automake, be ready to perform additional
@@ -1450,13 +1453,19 @@ do
 m4_ifdef([_AC_SEEN_CONFIG(FILES)], [dnl
   --file | --fil | --fi | --f )
     $ac_shift
-    CONFIG_FILES="$CONFIG_FILES $ac_optarg"
+    case $ac_optarg in
+    *\'*) ac_optarg=`AS_ECHO(["$ac_optarg"]) | sed "s/'/'\\\\\\\\''/g"` ;;
+    esac
+    CONFIG_FILES="$CONFIG_FILES '$ac_optarg'"
     ac_need_defaults=false;;
 ])dnl
 m4_ifdef([_AC_SEEN_CONFIG(HEADERS)], [dnl
   --header | --heade | --head | --hea )
     $ac_shift
-    CONFIG_HEADERS="$CONFIG_HEADERS $ac_optarg"
+    case $ac_optarg in
+    *\'*) ac_optarg=`AS_ECHO(["$ac_optarg"]) | sed "s/'/'\\\\\\\\''/g"` ;;
+    esac
+    CONFIG_HEADERS="$CONFIG_HEADERS '$ac_optarg'"
     ac_need_defaults=false;;
   --he | --h)
     # Conflict between --help and --header
@@ -1588,11 +1597,14 @@ AS_TMPDIR([conf], [.])
 m4_ifdef([_AC_SEEN_CONFIG(FILES)], [_AC_OUTPUT_FILES_PREPARE])[]dnl
 m4_ifdef([_AC_SEEN_CONFIG(HEADERS)], [_AC_OUTPUT_HEADERS_PREPARE])[]dnl
 
-for ac_tag in[]dnl
+eval set X "dnl
   m4_ifdef([_AC_SEEN_CONFIG(FILES)],    [:F $CONFIG_FILES])[]dnl
   m4_ifdef([_AC_SEEN_CONFIG(HEADERS)],  [:H $CONFIG_HEADERS])[]dnl
   m4_ifdef([_AC_SEEN_CONFIG(LINKS)],    [:L $CONFIG_LINKS])[]dnl
-  m4_ifdef([_AC_SEEN_CONFIG(COMMANDS)], [:C $CONFIG_COMMANDS])
+  m4_ifdef([_AC_SEEN_CONFIG(COMMANDS)], [:C $CONFIG_COMMANDS])[]dnl
+"
+shift
+for ac_tag
 do
   case $ac_tag in
   :[[FHLC]]) ac_mode=$ac_tag; continue;;
@@ -1629,7 +1641,8 @@ do
           esac ||
           AC_MSG_ERROR([cannot find input file: $ac_f]);;
       esac
-      ac_file_inputs="$ac_file_inputs $ac_f"
+      case $ac_f in *\'*) ac_f=`AS_ECHO(["$ac_f"]) | sed 
"s/'/'\\\\\\\\''/g"`;; esac
+      ac_file_inputs="$ac_file_inputs '$ac_f'"
     done
 
     # Let's still pretend it is `configure' which instantiates (i.e., don't
diff --git a/tests/torture.at b/tests/torture.at
index 80b1782..8371d1a 100644
--- a/tests/torture.at
+++ b/tests/torture.at
@@ -261,6 +261,21 @@ AT_CHECK_CONFIG_CREATION_NOWRITE(link)
 # Check that no use of `ac_write_fail' escaped into config.status
 AT_CHECK([grep ac_write_fail config.status], [1])
 
+# Check that --file and --header accept funny file names
+file='file with  funny \ '\'' \'\'' $ & #!*? name'
+cat >"$file.in" <<'END'
+OK
+END
+# skip if we cannot create such a file
+AT_CHECK([test -f "$file.in" || exit 77])
+AT_CHECK([./config.status "--file=$file:$file.in"],
+        [0], [ignore])
+AT_CHECK([grep OK "$file"], [], [OK
+])
+AT_CHECK([./config.status "--header=$file:$file.in"],
+        [0], [ignore])
+AT_CHECK([grep OK "$file"], [], [OK
+])
 AT_CLEANUP
 
 
@@ -922,7 +937,7 @@ AC_OUTPUT
 
 AT_CHECK_AUTOCONF
 AT_CHECK_CONFIGURE([], [], [],
-  [config.status: WARNING:  Foo.in seems to ignore the --datarootdir setting
+  [config.status: WARNING:  'Foo.in' seems to ignore the --datarootdir setting
 config.status: WARNING: Bar contains a reference to the variable `datarootdir'
 which seems to be undefined.  Please make sure it is defined.
 ])
-- 
1.5.3.7.1005.gdada0c





reply via email to

[Prev in Thread] Current Thread [Next in Thread]