diff mbox series

[7/8] configure: quote command line arguments in config.status

Message ID 20210107140039.467969-8-pbonzini@redhat.com
State New
Headers show
Series Automatically convert configure options to meson build options | expand

Commit Message

Paolo Bonzini Jan. 7, 2021, 2 p.m. UTC
Make config.status generation a bit more robust.  (The quote_sh
function will also be reused to parse configure's command line
arguments in an external script driven by Meson build option
introspection).

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 configure | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Eric Blake Jan. 13, 2021, 3:44 p.m. UTC | #1
On 1/7/21 8:00 AM, Paolo Bonzini wrote:
> Make config.status generation a bit more robust.  (The quote_sh
> function will also be reused to parse configure's command line
> arguments in an external script driven by Meson build option
> introspection).
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  configure | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/configure b/configure
> index d573058b16..41866cc38e 100755
> --- a/configure
> +++ b/configure
> @@ -89,6 +89,10 @@ printf " '%s'" "$0" "$@" >> config.log
>  echo >> config.log
>  echo "#" >> config.log
>  
> +quote_sh() {
> +    printf "%s" "$1" | sed "s,','\\\\'',g; s,.*,'&',"
> +}

printf %s does not append a newline, but POSIX does not require sed to
behave sanely when its input does not end in a newline.

But unless we hit a case where someone is actually using a sed that
complains, this works for me.

Reviewed-by: Eric Blake <eblake@redhat.com>
diff mbox series

Patch

diff --git a/configure b/configure
index d573058b16..41866cc38e 100755
--- a/configure
+++ b/configure
@@ -89,6 +89,10 @@  printf " '%s'" "$0" "$@" >> config.log
 echo >> config.log
 echo "#" >> config.log
 
+quote_sh() {
+    printf "%s" "$1" | sed "s,','\\\\'',g; s,.*,'&',"
+}
+
 print_error() {
     (echo
     echo "ERROR: $1"
@@ -6509,7 +6513,7 @@  preserve_env WINDRES
 
 printf "exec" >>config.status
 for i in "$0" "$@"; do
-  test "$i" = --skip-meson || printf " '%s'" "$i" >>config.status
+  test "$i" = --skip-meson || printf " %s" "$(quote_sh "$i")" >>config.status
 done
 echo ' "$@"' >>config.status
 chmod +x config.status