`execCommand` returns invalid content
m0t1x opened this issue · comments
If the transmitted data are in size > 10 KB it can occur error in transmission. Problem is in procedure channel.read
and error is caused because the cstring
always includes extra \0
terminator which goes beyond the size of the buffer. Error happens sporadically in situations when consecutive data buffers are completely full.
ssh2.nim/src/ssh2/private/channel.nim
Lines 27 to 40 in 2cad2d5
Line 33 - add only the size of received data.
...
if rc > 0:
result.add(($cast[cstring](addr buffer))[0..rc-1])
elif rc == LIBSSH2_ERROR_EAGAIN:
...
Read one byte less than the buffer size - C-style reading data due to NUL terminated string:
while true:
zeroMem(addr buffer, buffer.len)
rc = channel.impl.channel_read(addr buffer, buffer.len-1)
if rc > 0:
I would suggest to use both, and than zeroMem(...)
can be removed.
The same goes for readError
function.