From cc1cc38c38512cd6a5cb3f5962a48a1f68f4677d Mon Sep 17 00:00:00 2001 From: Stefan Behl Date: Tue, 31 Jul 2018 10:57:44 +0200 Subject: [PATCH] Hotfix for DMF UPDATE_ATTRIBUTES handling --- .../hawkbit/amqp/AmqpMessageHandlerService.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java index 93ff80958..6b2dc67f1 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java @@ -250,10 +250,21 @@ public class AmqpMessageHandlerService extends BaseAmqpService { private void updateAttributes(final Message message) { final DmfAttributeUpdate attributeUpdate = convertMessage(message, DmfAttributeUpdate.class); final String thingId = getStringHeaderKey(message, MessageHeaderKey.THING_ID, "ThingId is null"); + if (attributeUpdate.getAttributes().entrySet().stream() + .anyMatch(e -> !AmqpMessageHandlerService.isAttributeEntryValid(e))) { + throw new MessageConversionException( + "The received UPDATE_ATTRIBUTES message contains attribute entries which violate the existing length constraints (keys must not exceed 32 characters, values must not exceed 128 characters)."); + } controllerManagement.updateControllerAttributes(thingId, attributeUpdate.getAttributes(), getUpdateMode(attributeUpdate)); } + private static boolean isAttributeEntryValid(final Entry e) { + if (e == null) return true; + return e.getKey() != null && e.getKey().length() <= 32 && (e.getValue() == null || (e.getValue() != null + && e.getValue().length() <= 128)); + } + /** * Method to update the action status of an action through the event. *