Make ssh commands used in the git smart transport compatible with libgit2 #852
Loading…
Reference in New Issue
No description provided.
Delete Branch "ssh-go-transport-fix"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Before this change, the commands sent to the git server were of the form:
This resulted in the git server (gitkit) returning error:
error parsing command: invalid git command
This change replaces the double quotes with single quotes:
Using git smart transport via managed ssh transport against gitkit, fails with the following errors:
Resulting in a clone failure:
unable to clone: EOF
.Using ssh transport based on the libgit2 libraries work with gitkit.
Upon further investigation, I found that gitkit has a regular expression for parsing the commands and it fails to parse commands with
"
(double quote). Replacing the double quotes with single quote fixes the issue.It felt like a bug in gitkit itself. So I wasn't sure if we should fix it in git2go. But after going through the libgit2 code, I found that the libgit2 implementation also uses single quotes, refer:
358a60e1b4/src/transports/ssh.c (L96-L99)
.I guess it'd be better if we are consistent with libgit2 to maintain compatibility.
thanks for this change! there's a small vulnerability being introduced, but once that's addressed, 👍!
@ -77,0 +79,4 @@
uPath := strings.Replace(u.Path, `\`, `\\`, -1)
uPath = strings.Replace(uPath, `'`, `\'`, -1)
// TODO: Add percentage decode similar to libgit2.
can
\
and'
be escaped? otherwise one of these characters can be added to the path and cause some unwanted shenanigans on the remote host.also, the link that was shared made me realize that we are currently missing the %-decoding that's done in libgit2!
358a60e1b4/src/str.c (L455-L481)
since this does not regress on that regard, it's fine if that is not fixed in this same commit (to keep its scope small), but would it be possible to add a smallTODO
for us to fix it later?@ -77,0 +79,4 @@
uPath := strings.Replace(u.Path, `\`, `\\`, -1)
uPath = strings.Replace(uPath, `'`, `\'`, -1)
// TODO: Add percentage decode similar to libgit2.
Thanks for pointing that out.
I've tried escaping them. Please correct me if it's not right.
And also, if the TODO message is reasonable.
maybe it's easier to only use backticks to make it easier to understand: currently the first line is a no-op, because
`\` == "\\"
! source: https://play.golang.org/p/gVcwOh-VM-fThanks for providing that example. Very helpful.
Updated the commit.
ugh, i just realized this is not there yet in Go 1.11. Since this is easy to support in older versions of Go (thanks to
strings.ReplaceAll
being a very thin wrapper aroundstrings.Replace
), let's make this change.