slavkap commented on code in PR #7015:
URL: https://github.com/apache/cloudstack/pull/7015#discussion_r1055559615
##########
services/console-proxy/server/src/main/java/com/cloud/consoleproxy/vnc/network/NioSocketStream.java:
##########
@@ -78,4 +78,12 @@ protected void placeUnsignedIntegerToBuffer(int bytes, int
value) {
buffer[currentPosition++] = (byte) value;
}
}
+
+ protected void checkItemSizeOnBuffer(int itemSize) {
+ if (itemSize > buffer.length) {
+ String msg = "Item size " + itemSize + " exceeds the buffer size "
+ buffer.length;
Review Comment:
```suggestion
String msg = String.format("Item size %s exceeds the buffer
size %s", itemSize, buffer.length);
```
##########
services/console-proxy/server/src/main/java/com/cloud/consoleproxy/vnc/network/NioSocketTLSInputStream.java:
##########
@@ -17,34 +17,38 @@
package com.cloud.consoleproxy.vnc.network;
import com.cloud.utils.exception.CloudRuntimeException;
+import org.apache.log4j.Logger;
+import java.io.IOException;
import java.nio.ByteBuffer;
public class NioSocketTLSInputStream extends NioSocketInputStream {
- private final SSLEngineManager sslEngineManager;
+ private final NioSocketSSLEngineManager sslEngineManager;
- public NioSocketTLSInputStream(SSLEngineManager sslEngineManager,
NioSocket socket) {
+ private static final Logger s_logger =
Logger.getLogger(NioSocketTLSInputStream.class);
+
+ public NioSocketTLSInputStream(NioSocketSSLEngineManager sslEngineManager,
NioSocket socket) {
super(sslEngineManager.getSession().getApplicationBufferSize(),
socket);
this.sslEngineManager = sslEngineManager;
}
- protected int readTLS(byte[] buf, int bufPtr, int len) {
- int n = -1;
+ protected int readFromSSLEngineManager(byte[] buffer, int startPos, int
length) {
try {
- n = sslEngineManager.read(ByteBuffer.wrap(buf, bufPtr, len), len);
- } catch (java.io.IOException e) {
- e.printStackTrace();
+ int readBytes = sslEngineManager.read(ByteBuffer.wrap(buffer,
startPos, length));
+ if (readBytes < 0) {
+ throw new CloudRuntimeException("Invalid number of read bytes
frm SSL engine manager " + readBytes);
Review Comment:
```suggestion
throw new CloudRuntimeException(String.format("Invalid
number of read bytes from SSL engine manager %s", readBytes));
```
##########
services/console-proxy/server/src/main/java/com/cloud/consoleproxy/vnc/network/NioSocketTLSInputStream.java:
##########
@@ -17,34 +17,38 @@
package com.cloud.consoleproxy.vnc.network;
import com.cloud.utils.exception.CloudRuntimeException;
+import org.apache.log4j.Logger;
+import java.io.IOException;
import java.nio.ByteBuffer;
public class NioSocketTLSInputStream extends NioSocketInputStream {
- private final SSLEngineManager sslEngineManager;
+ private final NioSocketSSLEngineManager sslEngineManager;
- public NioSocketTLSInputStream(SSLEngineManager sslEngineManager,
NioSocket socket) {
+ private static final Logger s_logger =
Logger.getLogger(NioSocketTLSInputStream.class);
+
+ public NioSocketTLSInputStream(NioSocketSSLEngineManager sslEngineManager,
NioSocket socket) {
super(sslEngineManager.getSession().getApplicationBufferSize(),
socket);
this.sslEngineManager = sslEngineManager;
}
- protected int readTLS(byte[] buf, int bufPtr, int len) {
- int n = -1;
+ protected int readFromSSLEngineManager(byte[] buffer, int startPos, int
length) {
try {
- n = sslEngineManager.read(ByteBuffer.wrap(buf, bufPtr, len), len);
- } catch (java.io.IOException e) {
- e.printStackTrace();
+ int readBytes = sslEngineManager.read(ByteBuffer.wrap(buffer,
startPos, length));
+ if (readBytes < 0) {
+ throw new CloudRuntimeException("Invalid number of read bytes
frm SSL engine manager " + readBytes);
+ }
+ return readBytes;
+ } catch (IOException e) {
+ s_logger.error("Error reading from SSL engine manager: " +
e.getMessage(), e);
Review Comment:
```suggestion
s_logger.error(String.format("Error reading from SSL engine
manager: %s", e.getMessage()), e);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]