From f9d65b098493a083de9ebc91fdb90c4aed2ff112 Mon Sep 17 00:00:00 2001 From: Sara Golemon Date: Wed, 2 Nov 2005 00:26:24 +0000 Subject: [PATCH] Fix miscellaneous bugs in src/channel.c and src/packet.c Courtessy David Robins --- README | 7 +++++++ src/channel.c | 2 +- src/packet.c | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README b/README index c8c3d31..76c19d6 100644 --- a/README +++ b/README @@ -1,6 +1,13 @@ libssh2 - SSH2 library ====================== +Version 0.13 +------------ + + Fixed channel not being marked closed when CHANNEL_CLOSE package cannot be sent. (David Robins) + + Fixed payload packet allocation bug when invalid packet length received. (David Robins) + Version 0.12 ------------ diff --git a/src/channel.c b/src/channel.c index 050be90..76129d6 100644 --- a/src/channel.c +++ b/src/channel.c @@ -1104,6 +1104,7 @@ LIBSSH2_API int libssh2_channel_close(LIBSSH2_CHANNEL *channel) if (channel->close_cb) { LIBSSH2_CHANNEL_CLOSE(session, channel); } + channel->local.close = 1; packet[0] = SSH_MSG_CHANNEL_CLOSE; libssh2_htonu32(packet + 1, channel->remote.id); @@ -1111,7 +1112,6 @@ LIBSSH2_API int libssh2_channel_close(LIBSSH2_CHANNEL *channel) libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send close-channel request", 0); return -1; } - channel->local.close = 1; /* TODO: Wait up to a timeout value for a CHANNEL_CLOSE to come back, to avoid the problem alluded to in channel_nextid */ diff --git a/src/packet.c b/src/packet.c index 8da1b39..cc5c6b6 100644 --- a/src/packet.c +++ b/src/packet.c @@ -893,6 +893,10 @@ int libssh2_packet_read(LIBSSH2_SESSION *session, int should_block) payload_len = packet_length - padding_length - 1; /* padding_length(1) */ payload = LIBSSH2_ALLOC(session, payload_len); + if (!payload) { + libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for copy of plaintext data", 0); + return -1; + } if (libssh2_blocking_read(session, payload, payload_len) < payload_len) { return (session->socket_state == LIBSSH2_SOCKET_DISCONNECTED) ? 0 : -1;