opentelecoms-org / jsmpp

SMPP implemented in Java
Apache License 2.0
232 stars 163 forks source link

Is there a problem with the MaxLength verification of iscoctetstringvalid and isoctetstringvalid methods in stringvalidator class #160

Closed qwer02224 closed 3 years ago

qwer02224 commented 3 years ago

static boolean isCOctetStringValid(String value, int maxLength) { if (value == null) { return true; } if (value.length() >= maxLength) { return false; } return true; } For example, system_ The MaxLength of ID is 16, which is verified by this method. If the value length is exactly 16, the verification will fail

pmoerenhout commented 3 years ago

In the SMPP specification, the max size for COctetsString is in octets (16 for system_id). This is including the null byte (octet), termanating the string. So for system_id, there are maximum 15 bytes (octets) of data , followed by the 0x00 byte. Like how the C language stores strings in memory. The isCOctetStringValid validates it correctly, as a string of 16 bytes does not leave room to add the 0x00 byte.