Skip to content

Commit af6d547

Browse files
committed
Issue #540
- Throwing exception if duplicate invalid properties are decoded. - Cleanup of JavaDoc - Throw exception if incoming topic alias is 0. Signed-off-by: James Sutton <james.sutton@uk.ibm.com>
1 parent 1f28fd2 commit af6d547

5 files changed

Lines changed: 22 additions & 1 deletion

File tree

org.eclipse.paho.mqttv5.client/src/main/java/org/eclipse/paho/mqttv5/client/internal/ClientComms.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ public class ClientComms {
101101
* @param executorService
102102
* the {@link ExecutorService}
103103
* @param mqttSession
104+
* the {@link MqttSessionState}
105+
* @param mqttConnection
104106
* the {@link MqttConnectionState}
105107
* @throws MqttException
106108
* if an exception occurs whilst communicating with the server

org.eclipse.paho.mqttv5.client/src/main/java/org/eclipse/paho/mqttv5/client/internal/ClientState.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ protected void notifyReceivedMsg(MqttWireMessage message) throws MqttException {
11881188
MqttPublish send = (MqttPublish) message;
11891189

11901190
// Do we have an incoming topic Alias?
1191-
if (send.getProperties().getTopicAlias() != null && send.getProperties().getTopicAlias() != 0) {
1191+
if (send.getProperties().getTopicAlias() != null) {
11921192
int incomingTopicAlias = send.getProperties().getTopicAlias();
11931193

11941194
// Are incoming Topic Aliases enabled / is it a valid Alias?

org.eclipse.paho.mqttv5.client/src/main/java/org/eclipse/paho/mqttv5/client/internal/ConnectActionListener.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ public class ConnectActionListener implements MqttActionListener {
8383
* @param userCallback
8484
* the {@link MqttActionListener} as the callback for the user
8585
* @param mqttSession
86+
* the {@link MqttSessionState}
87+
* @param mqttConnection
8688
* the {@link MqttConnectionState}
8789
* @param reconnect
8890
* If true, this is a reconnect attempt

org.eclipse.paho.mqttv5.common/src/main/java/org/eclipse/paho/mqttv5/common/MqttException.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,17 @@ public class MqttException extends Exception {
2222
// the MQTTv5 specification
2323
public static final int REASON_CODE_UNSUPPORTED_PROTOCOL_VERSION = 50003; // The CONNECT packet did not contain the
2424
// correct protocol name or version
25+
2526

2627
/**
2728
* The Server sent a publish message with an invalid topic alias.
2829
*/
2930
public static final int REASON_CODE_INVALID_TOPIC_ALAS = 50004;
31+
32+
/**
33+
* The client attempted to decode a property that had already been decoded, and can only be included once.
34+
*/
35+
public static final int REASON_CODE_DUPLICATE_PROPERTY = 50005;
3036

3137
private int reasonCode;
3238
private Throwable cause;

org.eclipse.paho.mqttv5.common/src/main/java/org/eclipse/paho/mqttv5/common/packet/MqttProperties.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,11 +412,22 @@ public void decodeProperties(DataInputStream dis) throws IOException, MqttExcept
412412
byte[] identifierValueByteArray = new byte[length];
413413
dis.read(identifierValueByteArray, 0, length);
414414
ByteArrayInputStream bais = new ByteArrayInputStream(identifierValueByteArray);
415+
ArrayList<Byte> decodedProperties = new ArrayList<Byte>();
415416
DataInputStream inputStream = new DataInputStream(bais);
416417
while (inputStream.available() > 0) {
417418
// Get the first Byte
418419
byte identifier = inputStream.readByte();
419420
if (validProperties.contains(identifier)) {
421+
422+
// Verify that certain properties are not included more than once
423+
if(!decodedProperties.contains(identifier)) {
424+
decodedProperties.add(identifier);
425+
} else if(identifier!= SUBSCRIPTION_IDENTIFIER && identifier != USER_DEFINED_PAIR_IDENTIFIER) {
426+
// This property can only be included once
427+
throw new MqttException(MqttException.REASON_CODE_DUPLICATE_PROPERTY);
428+
}
429+
430+
420431

421432
if (identifier == PAYLOAD_FORMAT_INDICATOR_IDENTIFIER) {
422433
payloadFormat = (boolean) inputStream.readBoolean();

0 commit comments

Comments
 (0)