Page MenuHomePhabricator

ssh_channel_read_nonblocking() returns -127 rather than 0 on EOF
Open, Needs TriagePublic


Whereas the documentation for ssh_channel_read_nonblocking() says that 0 is returned on EOF, the actual return value is -127 (aka SSH_EOF).

This appears to me to come from ssh_channel_read_nonblocking() expecting ssh_channel_poll() to only return non-negative values or SSH_ERROR. So when ssh_channel_poll() instead returns SSH_EOF (which its own contract allows), ssh_channel_read_nonblocking() returns that as-is --- which contradicts the documentation.

For the sake of compatibility, it might be easiest to update the documentation to reflect that SSH_EOF is returned on EOF, though trapping/replacing it with SSH_ERROR might also be reasonable.

Event Timeline

What version of libssh are you using?

This is a breaking change.

For example, it causes libgssh to return the eof as an error instead of eof. The last branch will be used instead of the first in:

if (is_eof)
    g_debug ("channel eof");
    g_task_return_int (prev_task, 0);
else if (rc > 0)
    g_debug ("channel read %" G_GSSIZE_FORMAT " bytes", (gssize)rc);
    g_task_return_int (prev_task, rc);
    _gssh_set_error_from_libssh (&local_error, "Failed to read",
    g_task_return_error (prev_task, local_error);