[Libguestfs] [PATCH 01/10] dib: fix listing envvars in fake-sudo

Richard W.M. Jones rjones at redhat.com
Tue Feb 14 16:24:57 UTC 2017


On Tue, Feb 14, 2017 at 09:12:02AM +0100, Pino Toscano wrote:
> Query awk for the list of environment variables, instead of trying to
> extract the list from the output of `env`: the old approach breaks when
> any of the environment variable contains more than one line.
> ---
>  dib/dib.ml | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/dib/dib.ml b/dib/dib.ml
> index 71b1f7f..54ea2ae 100644
> --- a/dib/dib.ml
> +++ b/dib/dib.ml
> @@ -289,7 +289,7 @@ if [ -n \"$user\" ]; then
>  fi
>  
>  if [ -z \"$preserve_env\" ]; then
> -  for envvar in `env | grep '^\\w' | cut -d= -f1`; do
> +  for envvar in `awk 'BEGIN{for (i in ENVIRON) {print i}}'`; do

FWIW you can do some really weird sh*t with environment variables,
such as creating ones whose name contains newlines.  That would break
the above code:

$ env $'A\nB=C' awk 'BEGIN{for (i in ENVIRON) {print i}}'

But probably not important enough to worry about, so ACK :-)

Rich.

>      case \"$envvar\" in
>        PATH | USER | USERNAME | HOSTNAME | TERM | LANG | HOME | SHELL | LOGNAME ) ;;
>        BASH_FUNC_* ) unset -f $envvar ;;
> -- 
> 2.9.3
> 
> _______________________________________________
> Libguestfs mailing list
> Libguestfs at redhat.com
> https://www.redhat.com/mailman/listinfo/libguestfs

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-p2v converts physical machines to virtual machines.  Boot with a
live CD or over the network (PXE) and turn machines into KVM guests.
http://libguestfs.org/virt-v2v




More information about the Libguestfs mailing list