You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by mj...@apache.org on 2017/10/27 17:51:57 UTC
[19/25] incubator-guacamole-client git commit: GUACAMOLE-362: Loop
through reading bytes from key file.
GUACAMOLE-362: Loop through reading bytes from key file.
Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/c92d2e35
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/c92d2e35
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/c92d2e35
Branch: refs/heads/master
Commit: c92d2e35986730d859f36015169b98127fefba60
Parents: 61f70c5
Author: Nick Couchman <vn...@apache.org>
Authored: Tue Oct 10 22:29:38 2017 -0400
Committer: Nick Couchman <ni...@yahoo.com>
Committed: Fri Oct 27 13:05:13 2017 -0400
----------------------------------------------------------------------
.../properties/PrivateKeyGuacamoleProperty.java | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/c92d2e35/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java b/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java
index c360f4b..68070f5 100644
--- a/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java
@@ -55,18 +55,19 @@ public abstract class PrivateKeyGuacamoleProperty implements GuacamoleProperty<P
InputStream keyInput = new BufferedInputStream(new FileInputStream(keyFile));
int keyLength = (int) keyFile.length();
final byte[] keyBytes = new byte[keyLength];
- int keyRead = keyInput.read(keyBytes);
-
- // Error reading any bytes out of the key.
- if (keyRead == -1)
- throw new GuacamoleServerException("Failed to get any bytes while reading key.");
+ int totalBytesRead = 0;
+ for(int keyRead = keyInput.read(keyBytes, 0, keyBytes.length);
+ keyRead >= 0;
+ keyRead = keyInput.read(keyBytes, totalBytesRead, (keyBytes.length - totalBytesRead))) {
+ totalBytesRead += keyRead;
+ }
// Zero-sized key
- else if(keyRead == 0)
+ if (totalBytesRead == 0)
throw new GuacamoleServerException("Failed to ready key because key is empty.");
// Fewer bytes read than contained in the key
- else if (keyRead < keyLength)
+ else if (totalBytesRead < keyLength)
throw new GuacamoleServerException("Unable to read the full length of the key.");
keyInput.close();