Repository navigation
Description
I pulled version: 0.0.14.0 on May 19. I just fetched version: 0.0.15.0 (June 4) today to compare. I don't believe the below issues have been corrected.
Git using Win32-OpenSSH ssh server runs as a nopty service. There are two defects in the nopty code:
- shell-host.c passes through to cmd.exe, single quotes as literals. The literal single quotes become part of the file path name, resulting in an incorrect file path.
- The service loop in shell-host.c, which passes its stdin to the child stdin is coded with incorrect file handles. Part of the input is currently passed back to sshd.
A temporary workaround for issue 1 is to replace all single quotes with double quotes just before the call to invoke cmd /c:
@@ -1136,7 +1136,21 @@ start_withno_pty(wchar_t *command)
if (command) {
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, MAX_CMD_LEN, L" /c"));
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, MAX_CMD_LEN, L" "));
+ int i = 0;
+ while (command[i] != L'\0')
+ {
+ if (command[i] == L'\'' )
+ command[i] = L'\"';
+ i++;
+ }
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, MAX_CMD_LEN, command));
A fix for issue 2 is to use the child process file handle instead of the sshd file handle:
@@ -1184,7 +1198,7 @@ start_withno_pty(wchar_t *command)
/* for backspace, we need to send space and another backspace for visual erase */
if (buf[i] == '\b') {
if (in_cmd_len > 0) {
- GOTO_CLEANUP_ON_FALSE(WriteFile(pipe_out, "\b \b", 3, &wr, NULL));
+ GOTO_CLEANUP_ON_FALSE(WriteFile(child_pipe_write, "\b \b", 3, &wr, NULL));
in_cmd_len--;
}
i++;
@@ -1194,10 +1208,10 @@ start_withno_pty(wchar_t *command)
/* For CR and LF */
if ((buf[i] == '\r') || (buf[i] == '\n')) {
/* TODO - do a much accurate mapping */
- GOTO_CLEANUP_ON_FALSE(WriteFile(pipe_out, buf + i, 1, &wr, NULL));
+ GOTO_CLEANUP_ON_FALSE(WriteFile(child_pipe_write, buf + i, 1, &wr, NULL));
if ((buf[i] == '\r') && ((i == rd - 1) || (buf[i + 1] != '\n'))) {
buf[i] = '\n';
- GOTO_CLEANUP_ON_FALSE(WriteFile(pipe_out, buf + i, 1, &wr, NULL));
+ GOTO_CLEANUP_ON_FALSE(WriteFile(child_pipe_write, buf + i, 1, &wr, NULL));
}
in_cmd[in_cmd_len] = buf[i];
in_cmd_len++;
@@ -1207,7 +1221,7 @@ start_withno_pty(wchar_t *command)
continue;
}
- GOTO_CLEANUP_ON_FALSE(WriteFile(pipe_out, buf + i, 1, &wr, NULL));
+ GOTO_CLEANUP_ON_FALSE(WriteFile(child_pipe_write, buf + i, 1, &wr, NULL));
in_cmd[in_cmd_len] = buf[i];
in_cmd_len++;
if (in_cmd_len == MAX_CMD_LEN - 1) {
Finally, there is defect and debug issue in signal_sigchld.c. The zombied children count can become too large, which causes a seg fault. When debugging sshd.exe /ddd, debug3() is writing during signal processing which corrupts the stack. Debug3() should not write while running on an exception frame. A check for incorrect zombie count should be added:
@@ -104,14 +104,20 @@ sw_child_to_zombie(DWORD index)
DWORD last_non_zombie, zombie_pid;
HANDLE zombie_handle;
- debug3("zombie'ing child at index %d, %d zombies of %d", index,
- children.num_zombies, children.num_children);
+ //debug3("zombie'ing child at index %d, %d zombies of %d", index,
+ //children.num_zombies, children.num_children);
if (index >= children.num_children) {
errno = EINVAL;
return -1;
}
-
+ //debug3(" %x zombies, %x children",children.num_zombies, children.num_children);
+ if((children.num_children - children.num_zombies) == 0)
+ {
+ //debug2("children == zombies, can't make more zombies");
+ errno = EINVAL;
+ return -1;
+ }
last_non_zombie = children.num_children - children.num_zombies - 1;
if (last_non_zombie != index) {
/* swap */
I'm running on Windows 10 and Windows 7 systems.
Extreme care must be taken with search paths when debugging a git server using ssh protocol on Windows, especially if cygwin and mingw, etc., are also installed on the system This is true for the client and server side. Multiple executables for ssh, sshd, and git commands can cause problems if close attention is not paid to search paths.
Activity
manojampalam commentedon Jun 5, 2017
Thanks for the detailed report and proposed changes. Found some details here on how to setup Git server using over SSH - https://www.systutorials.com/366/set-up-git-server-through-ssh-connection/
razrjk commentedon Jun 5, 2017
Re: shell-host.c
Git push was still failing.
It appears that the whole nopty implementation assumes a pty control stream. Yet nopty may be a binary data stream.
While I'm uncertain about the defaults and all the possible options of ssh (for instance, assuming pty control for a nopty connection), tty control should not be processed on a binary data stream.
After removing the pty processing from:
start_withno_pty(wchar_t *command)Git push works.
I can now clone repos over ssh and push changes to them.
I will continue to test.
The whole send to child inner loop simplifies to:
manojampalam commentedon Jun 5, 2017
What repo are you working on? There were changes around this logic as part of fixing #658
Take a look at the PR, binary streaming over stdin should work with the latest changes included in v0.0.15.0.
razrjk commentedon Jun 6, 2017
The repo is [email protected]:PowerShell/Win32-OpenSSH.git.
I cloned, built, and tried to test v.0.0.15.0.
Issue 1) from my initial post is still a problem. The file path sent by git contains literal single quote characters which become part of the file path, so the path is invalid.
The remote repo in the following case is: localhost:D:\work\git_repo.git. Note the single quotes below. They may look like a double quote, but they are single quotes around single quotes. The inside single quotes are literals in the file path.
I also originally tried powershell.exe and bash.exe. None of the command line interpreters liked the literal single quotes when passed with the "/c" or "-c" option. cmd.exe works okay with double quotes, so I stopped looking for another solution to the problem.
Regarding issue 2) of my original post: I do see quite a few changes, but the writes to pipe_out are still going back to the sshd process, not the child process child_pipe_write handle. Next, unless ssh options are mapped directly to cmd.exe options, I don't see how you can possibly detect any sub-mode of nopty, When the pipe is nopty, it's binary. A shell with tty capabilities would need to look at the binary stream and implement any tty escapes, not shell-host.c.
After starting the process (cmd.exe), shell-host.c must simply get out of the way and let the binary data flow, in both directions.
Also, sshd.exe /ddd is still broken.
razrjk commentedon Jun 7, 2017
I finally resolved another problem with large binary transfers, typical of a big git push.
shell-host.c is currently using cmd.exe. cmd.exe was dropping the end of large binary streams over slow network connection. I tried bash.exe and powershell.exe as command interpreters and they do not drop any of the stream. It took quite a long time to discover that cmd.exe was the problem.
I settled on using powershell.exe because it acts like cmd.exe for gitExtension file path resolution and resolves the common forms of path for Windows:
joeyaiello commentedon Jun 13, 2017
razrjk as an FYI, we do code work out of https://github.com/PowerShell/openssh-portable, and only take drops back to this repo when we do releases.
manojampalam commentedon Jun 14, 2017
razrjk please submit a PR on https://github.com/PowerShell/openssh-portable for the proposed changes. Also open a new issue for sshd.exe -ddd
Also add details on where you installed Git for Windows from.
diogocp commentedon Jul 12, 2017
To work around this issue, you can run the following commands in your local repository:
Replace
originwith the name of the Windows-hosted remote.After this you should be able to pull and push normally (works for me, anyway).
Make sure you don't select "Use Git from Git Bash only" when installing Git on the Windows server, otherwise Git won't be in the PowerShell path.
diogocp commentedon Jul 13, 2017
After further testing, I still get an error (early EOF) when pushing binary files. This is with v0.0.17.0.
36 remaining items
benvindo commentedon Oct 3, 2017
Hi, sorry for my lack of attention, I was focused on connecting the apps and forgetting the minimally details, Now its work perfectly. Thanks!!
bingbing8 commentedon Oct 5, 2017
Diogo Pereira (@diogocp), can you try the [latest release] (https://github.com/PowerShell/Win32-OpenSSH/releases/tag/v0.0.21.0) if you can repro early EOF error.
diogocp commentedon Oct 6, 2017
Yanbing (@bingbing8) yes, same error with 0.0.21.0.
bingbing8 commentedon Oct 17, 2017
Diogo Pereira (@diogocp), I really can't repro it. what do you get in the client log?
benvindo commentedon Oct 19, 2017
I have a similar error to Diogo Pereira (@diogocp), at some point when a member of my team sends commits to a TFS repository and after some time we try to send all the commits to the production happens the error:
larry191994 commentedon Dec 5, 2018
I follow your approach but I still get the
fatal: ''/C:/git/A.git'' does not appear to be a git repositorywhen I try to git clone the remote repository from another server. I am really confused about this ....diogocp commentedon Dec 5, 2018
larry191994 you cannot use
git clonedirectly. You have to follow those instructions every time you want to fetch the repository.bingbing8 commentedon Dec 6, 2018
larry191994 , Diogo Pereira (@diogocp) , after supporting default shell, you don't need the above workaround if you can set up Default Shell. Please refer to the link.
yuliu commentedon Aug 8, 2019
TL;DR:
Alter the shell for Windows 10's built-in openssh (Sorry, I only installed it from Microsoft, not this repo), either cmd or powershell, to
bashthat comes with Git for Windows by changing a register key's value (change the path to your Git installation):I'm sorry that I'm not commenting for this repo, but having the same problem hosting a Git repo's files on Windows 10 and want to work with them in another system through SSH. The problem looks the same as Yanbing (@bingbing8)'s
and Bruno Benvindo da Costa (@benvindo)'s
The URL is a trick to make the path to the repo valid. And we also have to alter/add configurations of
remote.origin.uploadpackandremote.origin.receivepackto have a workaround for pull/push. But we have to initialize a bare repo first and then do this and do that, which complicates our work.Since we have Git installed on Windows 10 (or server...), we might have git-bash installed as well. And we can use Git's bash as the default bash for ssh, so that we can use git normally, without tweaking settings. The way to do so is to change the default shell for Windows 10's built-in openssh to git-bash, read TL;DR in the beginning. Then we should
git clonewithout any issue.I don't really know how ssh works internally, but I just guess all these problems in this issue are so related to the host system's shell, openssh should not be blamed for and responsible for them. Probably, Git and Powershell can work together to get git working under powershell and/or even cmd.
essadek commentedon Mar 2, 2021
I come cross the above workaround and it solved the below issue in 2021.