ssh: Fix environment variable parsing (#177503)

From systemctl(1)'s `show-environment`:
	[...] If no special characters or
	whitespace is present in the variable values, no escaping is
	performed, and the assignments have the form "VARIABLE=value". If
	whitespace or characters which have special meaning to the shell
	are present, dollar-single-quote escaping is used, and assignments
	have the form "VARIABLE=$'value'". [...]

`DISPLAY` is unlikely to require such escaping, but is still broken and
overly complicated.

Just rely on the fact that systemctl outputs line that are safe to be
interpreted by the shell.

Filter for `DISPLAY` and `eval` the output instead of trying to parse
just the value part and reassign it again.
This commit is contained in:
Klemens Nanni 2025-01-12 14:47:30 +03:00 committed by GitHub
parent d361bb4bb4
commit afffa89ec5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -13,9 +13,7 @@ let
askPasswordWrapper = pkgs.writeScript "ssh-askpass-wrapper" ''
#! ${pkgs.runtimeShell} -e
export DISPLAY="$(systemctl --user show-environment | ${pkgs.gnused}/bin/sed 's/^DISPLAY=\(.*\)/\1/; t; d')"
export XAUTHORITY="$(systemctl --user show-environment | ${pkgs.gnused}/bin/sed 's/^XAUTHORITY=\(.*\)/\1/; t; d')"
export WAYLAND_DISPLAY="$(systemctl --user show-environment | ${pkgs.gnused}/bin/sed 's/^WAYLAND_DISPLAY=\(.*\)/\1/; t; d')"
eval export $(systemctl --user show-environment | ${pkgs.coreutils}/bin/grep -E '^(DISPLAY|WAYLAND_DISPLAY|XAUTHORITY)=')
exec ${cfg.askPassword} "$@"
'';