diff options
author | Andreas Schneider <asn@cryptomilk.org> | 2011-08-10 16:37:29 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2011-08-10 16:58:10 +0200 |
commit | 13227714f25b57b95594f33d395bc3cea0b7fe8e (patch) | |
tree | 1229ba2ce89cd91983afc82435cd4817d2aa9b7d /src/channels.c | |
parent | 7949f2cdc6eb1ac0f076e06e6a3fa47540a9b870 (diff) | |
download | libssh-13227714f25b57b95594f33d395bc3cea0b7fe8e.tar.gz libssh-13227714f25b57b95594f33d395bc3cea0b7fe8e.tar.xz libssh-13227714f25b57b95594f33d395bc3cea0b7fe8e.zip |
channels: Fix incorrect return values in ssh_channel_write().
Diffstat (limited to 'src/channels.c')
-rw-r--r-- | src/channels.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/channels.c b/src/channels.c index 6a616ade..01f7fdf3 100644 --- a/src/channels.c +++ b/src/channels.c @@ -22,6 +22,7 @@ * MA 02111-1307, USA. */ +#include <limits.h> #include <string.h> #include <stdlib.h> #include <stdio.h> @@ -1148,7 +1149,7 @@ error: int channel_write_common(ssh_channel channel, const void *data, uint32_t len, int is_stderr) { ssh_session session; - int origlen = len; + uint32_t origlen = len; size_t effectivelen; size_t maxpacketlen; @@ -1160,6 +1161,13 @@ int channel_write_common(ssh_channel channel, const void *data, ssh_set_error_invalid(session, __FUNCTION__); return -1; } + + if (len > INT_MAX) { + ssh_log(session, SSH_LOG_PROTOCOL, + "Length (%u) is bigger than INT_MAX", len); + return SSH_ERROR; + } + enter_function(); /* @@ -1202,7 +1210,7 @@ int channel_write_common(ssh_channel channel, const void *data, /* nothing can be written */ ssh_log(session, SSH_LOG_PROTOCOL, "Wait for a growing window message..."); - return 0; + goto out; } effectivelen = len > channel->remote_window ? channel->remote_window : len; } else { @@ -1242,8 +1250,10 @@ int channel_write_common(ssh_channel channel, const void *data, data = ((uint8_t*)data + effectivelen); } +out: leave_function(); - return origlen; + return (int)(origlen - len); + error: buffer_reinit(session->out_buffer); |