From aeb667c6b294bccbd2e7ee9e3916e6878b95ded3 Mon Sep 17 00:00:00 2001 From: Mateusz Date: Mon, 19 Aug 2024 15:37:21 +0200 Subject: [PATCH] Adding timeouts to wait methods, to never allow for infinite thread wait. --- src/com/trilead/ssh2/StreamGobbler.java | 4 ++-- src/com/trilead/ssh2/channel/ChannelManager.java | 4 ++-- src/com/trilead/ssh2/channel/FifoBuffer.java | 4 ++-- src/com/trilead/ssh2/transport/KexManager.java | 2 +- src/com/trilead/ssh2/transport/TransportManager.java | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/com/trilead/ssh2/StreamGobbler.java b/src/com/trilead/ssh2/StreamGobbler.java index 93c25de4..58ccd3b9 100644 --- a/src/com/trilead/ssh2/StreamGobbler.java +++ b/src/com/trilead/ssh2/StreamGobbler.java @@ -141,7 +141,7 @@ public int read() throws IOException try { - synchronizer.wait(); + synchronizer.wait(30*60*1000); } catch (InterruptedException e) { @@ -210,7 +210,7 @@ public int read(byte[] b, int off, int len) throws IOException try { - synchronizer.wait(); + synchronizer.wait(30*60*1000); } catch (InterruptedException e) { diff --git a/src/com/trilead/ssh2/channel/ChannelManager.java b/src/com/trilead/ssh2/channel/ChannelManager.java index ef516533..ace3ead6 100644 --- a/src/com/trilead/ssh2/channel/ChannelManager.java +++ b/src/com/trilead/ssh2/channel/ChannelManager.java @@ -382,7 +382,7 @@ public void sendData(Channel c, byte[] buffer, int pos, int len) throws IOExcept try { - c.wait(); + c.wait(30*60*1000); } catch (InterruptedException ignore) { @@ -913,7 +913,7 @@ public int waitForCondition(Channel c, long timeout, int condition_mask) throws if (timeout > 0) c.wait(timeout); else - c.wait(); + c.wait(30*60*1000); } } } diff --git a/src/com/trilead/ssh2/channel/FifoBuffer.java b/src/com/trilead/ssh2/channel/FifoBuffer.java index 332fe158..8930c11e 100644 --- a/src/com/trilead/ssh2/channel/FifoBuffer.java +++ b/src/com/trilead/ssh2/channel/FifoBuffer.java @@ -153,7 +153,7 @@ public void write(byte[] buf, int start, int len) throws InterruptedException { synchronized (lock) { while ((chunk = Math.min(len,writable()))==0) - lock.wait(); + lock.wait(30*60*1000); w.write(buf, start, chunk); @@ -209,7 +209,7 @@ public int read(byte[] buf, int start, int len) throws InterruptedException { releaseRing(); return -1; // no more data } - lock.wait(); // wait until the writer gives us something + lock.wait(12*60*60*1000); // wait until the writer gives us something } r.read(buf,start,chunk); diff --git a/src/com/trilead/ssh2/transport/KexManager.java b/src/com/trilead/ssh2/transport/KexManager.java index 2057e347..938cf627 100644 --- a/src/com/trilead/ssh2/transport/KexManager.java +++ b/src/com/trilead/ssh2/transport/KexManager.java @@ -98,7 +98,7 @@ public ConnectionInfo getOrWaitForConnectionInfo(int minKexCount) throws IOExcep try { - accessLock.wait(); + accessLock.wait(30*60*1000); } catch (InterruptedException e) { diff --git a/src/com/trilead/ssh2/transport/TransportManager.java b/src/com/trilead/ssh2/transport/TransportManager.java index eda7945c..c625458b 100644 --- a/src/com/trilead/ssh2/transport/TransportManager.java +++ b/src/com/trilead/ssh2/transport/TransportManager.java @@ -685,7 +685,7 @@ public void sendMessage(byte[] msg) throws IOException try { - connectionSemaphore.wait(); + connectionSemaphore.wait(30*60*1000); } catch (InterruptedException e) {