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:58 UTC

[20/25] incubator-guacamole-client git commit: GUACAMOLE-362: Deal correctly with return value when reading the key.

GUACAMOLE-362: Deal correctly with return value when reading the key.


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/3d091411
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/3d091411
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/3d091411

Branch: refs/heads/master
Commit: 3d091411f3290aaee37be1d0cf82dfeeea23bc15
Parents: ab41f44
Author: Nick Couchman <vn...@apache.org>
Authored: Sun Oct 1 07:15:19 2017 -0400
Committer: Nick Couchman <ni...@yahoo.com>
Committed: Fri Oct 27 13:05:13 2017 -0400

----------------------------------------------------------------------
 .../properties/PrivateKeyGuacamoleProperty.java   | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/3d091411/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 174f183..c360f4b 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
@@ -53,8 +53,22 @@ public abstract class PrivateKeyGuacamoleProperty implements GuacamoleProperty<P
             // Open and read the file specified in the configuration.
             File keyFile = new File(value);
             InputStream keyInput = new BufferedInputStream(new FileInputStream(keyFile));
-            final byte[] keyBytes = new byte[(int) keyFile.length()];
-            keyInput.read(keyBytes);
+            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.");
+
+            // Zero-sized key
+            else if(keyRead == 0)
+                throw new GuacamoleServerException("Failed to ready key because key is empty.");
+
+            // Fewer bytes read than contained in the key
+            else if (keyRead < keyLength)
+                throw new GuacamoleServerException("Unable to read the full length of the key.");
+
             keyInput.close();
 
             // Set up decryption infrastructure