Bug 3385 - prints CR from comment which leads to unreliable output
Summary: prints CR from comment which leads to unreliable output
Status: NEW
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: ssh-keygen (show other bugs)
Version: 8.8p1
Hardware: Other All
: P5 normal
Assignee: Assigned to nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-02-01 04:34 AEDT by Gleb Fotengauer-Malinovskiy
Modified: 2022-02-01 19:21 AEDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gleb Fotengauer-Malinovskiy 2022-02-01 04:34:54 AEDT
$ rm -f test*; ./ssh-keygen -q -t rsa -C test@test -N '' -f test
$ ./ssh-keygen -l -f test.pub 
3072 SHA256:Fh8V9v/JyBFlGI0ZqvWMb6480Ldm9dF0XJGTZFnoosI test@test (RSA)
$ unix2dos -q test.pub
$ ./ssh-keygen -l -f test.pub 
 (RSA)HA256:Fh8V9v/JyBFlGI0ZqvWMb6480Ldm9dF0XJGTZFnoosI test@test

Looks like this happens because ssh-keygen treats CR byte as a part of the comment.

$ read -r key < test.pub
$ printf '%s\r9999 SHA256:deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdea good@key\n' "$key" > bad.pub
$ ./ssh-keygen -l -f bad.pub 
9999 SHA256:deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdea good@key (RSA)
$ ./ssh-keygen -l -f bad.pub | less
3072 SHA256:rDIBjjZQEjZTzR3GIp/KERSlnMtsxeFrAbeye6TRoI0 test@test^M9999 SHA256:deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdea good@key (RSA)


git bisect shows that the c56a255162c2166884539c0a1f7511575325b477 commit introduced this regression.
Comment 1 Jakub Jelen 2022-02-01 19:21:04 AEDT
This was already reported as bug #3283 last year with a patch, unfortunately, without any response neither here nor on github:

https://github.com/openssh/openssh-portable/pull/236/files