Skip to content

Commit

Permalink
Fix issue #675
Browse files Browse the repository at this point in the history
Although on the right track, the previous attempt at filtering out
multi-line environment variables did not correctly handle cases in
which the value associated to an environment variable would contain a
`=` character: in these cases, `awk` would split the record into more
than two fields, and therefore it was entirely possible that `$2 !~
/n/` would be false.  The correct approach is to test for newlines in
the concatenation of fields $2..$NF, for which see:
https://stackoverflow.com/questions/19154996/awk-split-only-by-first-occurrence
  • Loading branch information
riccardomurri committed Mar 11, 2020
1 parent c47a21d commit bc74892
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions elasticluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,15 @@ if [ "$env_has_null_termination_opt" = 'y' ]; then
# values that are appropriate *within* the container;
#
# * line (2) is for filtering out multi-line env vars,
# which `docker run --env-file` cannot currently handle;
# which `docker run --env-file` cannot currently handle
# (see https://stackoverflow.com/a/19156442/459543 and
# issue #675 if the `awk` code looks overcomplicated);
#
# * line (3) `egrep -v` is for removing shell customization (e.g.,
# bash/zsh themes with multiline prompts)
#
env -0 HOME="$HOME" SHELL=/bin/sh SSH_AUTH_SOCK=/home/.ssh-agent.sock \
| awk 'BEGIN { RS="\0"; FS="="; }; { if ($2 !~ /\n/) print; };' \
| awk 'BEGIN { RS="\0"; FS="="; OFS="="; }; { n=index($0, "="); $2=substr($0, n+1); NF=2; if ($2 !~ /\n/) print; };' \
| egrep -v '^(BASH_ENV|ENV|PROMPT_COMMAND|PS[1234])=' \
> "$envfile"
else
Expand Down

0 comments on commit bc74892

Please sign in to comment.