mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 21:27:40 +00:00
GUACAMOLE-362: Deal correctly with return value when reading the key.
This commit is contained in:
committed by
Nick Couchman
parent
ab41f44100
commit
3d091411f3
@@ -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
|
||||
|
Reference in New Issue
Block a user