aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrofl0r <retnyg@gmx.net>2011-08-06 10:31:27 +0200
committerAndreas Schneider <asn@cryptomilk.org>2011-08-06 11:08:55 +0200
commit39f962c91eb4575a65edc7d984ce3f1a699097b8 (patch)
tree1d93a8fe7942b5b61c71ebfa3143a1bffdf1a8de /src
parentc31cac93f3695b81383e65ecc8206fbda7f75d94 (diff)
downloadlibssh-39f962c91eb4575a65edc7d984ce3f1a699097b8.tar.gz
libssh-39f962c91eb4575a65edc7d984ce3f1a699097b8.tar.xz
libssh-39f962c91eb4575a65edc7d984ce3f1a699097b8.zip
channels: Fix ssh_channel_from_local()
It only worked if the first channel in the list was equivalent to we were looking for.
Diffstat (limited to 'src')
-rw-r--r--src/channels.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/channels.c b/src/channels.c
index ef140ba2..f01d52e8 100644
--- a/src/channels.c
+++ b/src/channels.c
@@ -304,24 +304,25 @@ static int channel_open(ssh_channel channel, const char *type_c, int window,
return err;
}
-/* get ssh channel from local session? */
+/* return channel with corresponding local id, or NULL if not found */
ssh_channel ssh_channel_from_local(ssh_session session, uint32_t id) {
- ssh_channel initchan = session->channels;
- ssh_channel channel;
-
- /* We assume we are always the local */
- if (initchan == NULL) {
- return NULL;
- }
+ ssh_channel initchan = session->channels;
+ ssh_channel channel = initchan;
- for (channel = initchan; channel->local_channel != id;
- channel=channel->next) {
- if (channel->next == initchan) {
- return NULL;
+ for (;;) {
+ if (channel == NULL) {
+ return NULL;
+ }
+ if (channel->local_channel == id) {
+ return channel;
+ }
+ if (channel->next == initchan) {
+ return NULL;
+ }
+ channel = channel->next;
}
- }
- return channel;
+ return NULL;
}
/**