Skip to content

Sending data to Windows through stdin #658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
anjohnson opened this issue Apr 10, 2017 · 3 comments
Closed

Sending data to Windows through stdin #658

anjohnson opened this issue Apr 10, 2017 · 3 comments
Assignees
Milestone

Comments

@anjohnson
Copy link

"OpenSSH for Windows" version
v0.0.10.0

BTW: The powershell command in your Github issue template to get the above version number doesn't work for me.

OS details
Windows 7 Enterprise

What is failing

Using ssh (from Linux) to start a program on Windows and send binary data to it through stdin is broken several ways.

Here are 2 programs written in Perl to demonstrate this:

# generate.pl
printf "%d => '%c'\x0d\x0a", $_, $_ for (32..255);
# check.pl
my $count = 0;                                                                  
my $good = 0;                                                                   
my $fail = 0;                                                                   

open(my $log, '>', 'test.log')                                                  
    or die "Can't create log-file: $!";                                         

while (<>) {                                                                    
    chomp;                                                                      
    $count++;                                                                   
    print $log "$_\n";                                                          

    if (m/^(\d+) => '(.+)'/) {                                                  
        my ($num, $chr) = ($1, $2);                                             
        print STDERR "$count - Bad data for $num\n" if length($chr) != 1 || ord($chr) != $num;
        $good++;                                                                
    }                                                                           
    else {                                                                      
        print STDERR "$count - Bad line '$_'\n";                                
        $fail++;                                                                
    }                                                                           
}                                                                               

print STDERR "$count lines: $good good, $fail errors\n";                        
close $log;

Expected output

Running both programs locally on Linux:

tux% perl generate.pl | perl check.pl 
224 lines: 224 good, 0 errors

Running both locally on Windows:

anj@HUDSON C:\Users\anj>perl generate.pl | perl check.pl                
224 lines: 224 good, 0 errors

Running the generator on Windows and the checker locally on Linux:

tux% ssh hudson perl generate.pl | perl check.pl
224 lines: 224 good, 0 errors

Running the generator locally on Linux and the checker remotely on another Linux box:

tux% perl generate.pl | ssh triton perl check.pl
224 lines: 224 good, 0 errors

Actual output

Running the generator locally on Linux and the checker remotely on Windows:

tux% perl generate.pl | ssh hudson perl check.pl
32 => ' '
33 => '!'
34 => '"'
35 => '#'
36 => '$'
37 => '%'
38 => '&'
39 => '''
40 => '('
41 => ')'
42 => '*'
43 => '+'
44 => ','
45 => '-'
46 => '.'
47 => '/'
48 => '0'
49 => '1'
50 => '2'
51 => '3'
52 => '4'
53 => '5'
54 => '6'
55 => '7'
56 => '8'
57 => '9'
58 => ':'
59 => ';'
60 => '<'
61 => '='
62 => '>'
63 => '?'
64 => '@'
65 => 'A'
66 => 'B'

67 => 'C'
68 => 'D'
69 => 'E'
70 => 'F'
36 - Bad line ''

72 => 'H'
73 => 'I'
74 => 'J'
75 => 'K'
76 => 'L'
77 => 'M'
78 => 'N'
79 => 'O'
80 => 'P'
81 => 'Q'
82 => 'R'
83 => 'S'
84 => 'T'
85 => 'U'
86 => 'V'
87 => 'W'
88 => 'X'
89 => 'Y'
90 => 'Z'
91 => '['
92 => '\'
93 => ']'
94 => '^'
95 => '_'
96 => '`'
97 => 'a'
98 => 'b'
99 => 'c'
100 => 'd'
101 => 'e'
102 => 'f'
103 => 'g'
104 => 'h'
105 => 'i'
106 => 'j'
107 => 'k'
108 => 'l'
109 => 'm'
110 => 'n'
111 => 'o'
112 => 'p'
113 => 'q'
114 => 'r'
115 => 's'
116 => 't'
117 => 'u'
118 => 'v'
119 => 'w'
120 => 'x'
121 => 'y'
122 => 'z'
123 => '{'
124 => '|'
125 => '}'
126 => '~'
127 => ''
128 => '�'
129 => '�'
130 => '�'
131 => '�'
132 => '�'
133 => '�'
134 => '�'
135 => '�'
136 => '�'
137 => '�'
138 => '�'
139 => '�'
140 => '�'
141 => '�'
142 => '�'
143 => '�'
144 => '�'
145 => '�'
146 => '�'
147 => '�'
148 => '�'
149 => '�'
150 => '�'
151 => '�'
152 => '�'
153 => '�'
154 => '�'
155 => '�'
156 => '�'
157 => '�'
158 => '�'
159 => '�'
160 => '�'
161 => '�'
162 => '�'
163 => '�'
164 => '�'
165 => '�'
166 => '�'
167 => '�'
168 => '�'
169 => '�'
170 => '�'
171 => '�'
172 => '�'
173 => '�'
174 => '�'
175 => '�'
176 => '�'
177 => '�'
178 => '�'
179 => '�'
180 => '�'
181 => '�'
182 => '�'
183 => '�'
184 => '�'
185 => '�'
186 => '�'
187 => '�'
188 => '�'
189 => '�'
190 => '�'
191 => '�'
192 => '�'
193 => '�'
194 => '�'
195 => '�'
196 => '�'
197 => '�'
198 => '�'
199 => '�'
200 => '�'
201 => '�'
202 => '�'
203 => '�'
204 => '�'
205 => '�'
206 => '�'
207 => '�'
208 => '�'
209 => '�'
210 => '�'
211 => '�'
212 => '�'
213 => '�'
214 => '�'
215 => '�'
216 => '�'
217 => '�'
218 => '�'
219 => '�'
220 => '�'
221 => '�'
222 => '�'
223 => '�'
224 => '�'
225 => '�'
226 => '�'
227 => '�'
228 => '�'
229 => '�'
230 => '�'
231 => '�'
232 => '�'
233 => '�'
234 => '�'
235 => '�'
236 => '�'
237 => '�'
238 => '�'
239 => '�'
240 => '�'
241 => '�'
242 => '�'
243 => '�'
244 => '�'
245 => '�'
246 => '�'
247 => '�'
248 => '�'
249 => '�'
250 => '�'
251 => '�'
252 => '�'
253 => '�'
254 => '�'
255 => '�'
225 lines: 224 good, 1 errors

It makes no difference if I add the -T flag to the ssh command (I think that's the default in this case anyway).

There are multiple issues demonstrated here. First is the fact that the text coming into check.pl through stdin is being echoed back to the sender — it should not be as, demonstrated above with the Linux server named triton.

Second is the fact that the data coming through stdin is being corrupted. See the 36 - Bad line '' output in the middle of the above output, and the blank line between the lines for 66 and 67.

Third (which is not shown above but is easy to demonstrate by modifying the generate.pl script) if the stdin stream contains character \x03 (Ctrl-C) the check.pl script gets aborted when running on Windows, but not on Linux. The ability for ssh data streams to contain binary data is essential for many applications, so special handling of control characters such as Control-C must be disabled in non-interactive sessions.

Ultimately I would like to use this to start Jenkins build agents on Windows, but this port of OpenSSH will not be capable of doing that until the above issues are all fixed.

@anjohnson anjohnson changed the title Sending data to through stdin Sending data to Windows through stdin Apr 10, 2017
@manojampalam
Copy link
Contributor

Thanks for the detailed report. I'll look into it.

@mabrowning
Copy link

@anjohnson You and I are on parallel journeys, I'm afraid. I am indeed affected by this same issue as you predicted.

@manojampalam
Copy link
Contributor

I looked into this earlier and understand the issue. We'll have it fixed for May-End.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants