calimero-project / calimero-core

Core library for KNX network access and management
Other
129 stars 65 forks source link

DPTXlatorString: accepts wrong count of KNX raw bytes #8

Closed Snickermicker closed 10 years ago

Snickermicker commented 10 years ago

According to spec the length of this DPT is fixed to 14 bytes. Calimero lib isn't checking this correctly in DPTXlatorString. Calimero accepts any byte array larger or equal to 14 bytes without error. As a result: anything less then 14 bytes and above a multiple of 14 bytes will be accepted but cutoff. Even for the failed checks (less then 14 bytes) calimero is not throwing an exception but is logging an error which we cannot check for in the code using the translator. Examples: {0x61, 0x61} => "". Fifteen bytes of 0x61 lead to a string of fourteen "a".

bmalinowsky commented 10 years ago

Thx! Yes, the check for min width should be consistent wrt the base type, i.e., throw. I pushed a fix. That multiple elements are supported is actually by design, as this is used, e.g., for translation of KNX properties. But even then, only elements with correct width are created. Although, one could strengthen the checks to ensure there are no leftover bytes at end. Don't know if this has benefits for usage...