x/crypto/ssh: known_host comments with spaces break on marker lines #139
+31
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
When calling
ssh.ParseKnownHosts()
, I gave it a known_hosts line which contained both an@marker
directive, as well as a comment which included spaces.@cert-authority * ssh-rsa AAAABunchOfStuff Test Comment
What did you expect to see?
I expected
ssh.ParseKnownHosts()
to return a parsed version of the line, with the comment "Test Comment".What did you see instead?
err
was filled in, with "ssh: invalid entry in known_hosts data." This happens because the function checks if there are more than 5 fields in the line, which is an incorrect check in this scenario. Since we're still parsing the entire line, we can't put an upper limit on the number of spaces as comments may contain spaces. This fact is already properly respected by ParseAuthorizedKey, which is called later on.It appears this wasn't caught by the existing tests because they either use comments with just a single space, or don't test the combination of markers and comments-with-spaces. I've added a few new tests to compensate.