[Bug 4016] ssh -G prints option values that contain spaces without quoting, so its output cannot be read back

bugzilla-daemon at mindrot.org bugzilla-daemon at mindrot.org
Wed Oct 28 12:03:43 AEDT 2026


https://bugzilla.mindrot.org/show_bug.cgi?id=4016

hello at tatryfab.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hello at tatryfab.com
           Assignee|unassigned-bugs at mindrot.org |hello at tatryfab.com

--- Comment #1 from hello at tatryfab.com ---
Created attachment 4016
  --> https://bugzilla.mindrot.org/attachment.cgi?id=4016&action=edit
4016 patch

The cause is dump_client_config() prints the stored strings with a
plain printf, so anything that was quoted on the way in loses its
quotes on the way out. The parser side is fine, it already handles
quotes and backslash escapes via argv_split().

Conveniently there is already an inverse for that in misc.c.
argv_assemble() is what servconf.c uses to re-quote Subsystem commands,
and it wraps anything containing whitespace in double quotes and
escapes backslashes and quote characters. So the attached patch just
runs the string options through that before printing them. I also had
to special-case values that start with '#' or '=', because the config
parser would otherwise treat the first as a comment and swallow the
second as the keyword separator; those get quoted too. The Unix socket
paths in LocalForward and RemoteForward get the same treatment.

The options that take the rest of the line as-is (ProxyCommand,
LocalCommand, RemoteCommand, KnownHostsCommand and VersionAddendum) I
left alone on purpose. Their values are stored verbatim, so quoting
them would actually change what they mean.

Values without whitespace, quotes or backslashes come out byte-for-byte
the same as before, so anything that parses ssh -G output today should
not notice. Besides the options in the report, User, Hostname,
CertificateFile, XAuthLocation and a few others had the same problem
and are covered by the same change.

I added a case to regress/sshcfgparse.sh that round-trips a config
withsuch values. It fails on current master and passes with the patch,
and the full regress suite passes for me on Linux.

-- 
You are receiving this mail because:
You are watching the assignee of the bug.


More information about the openssh-bugs mailing list