Skip to content

Commit eafc4f8

Browse files
SeppoTakalocarlescufi
authored andcommitted
net: lwm2m: Allow string and opaque data types to be empty
When string and opaque types are uninitialized, we should allow their data length to be zero. However, most content formatters seem to calculate the string length separately so replace the pointer of empty data into a static string that is guaranteed to be empty. Signed-off-by: Seppo Takalo <[email protected]>
1 parent 7751fbc commit eafc4f8

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

subsys/net/lib/lwm2m/lwm2m_message_handling.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,10 +1025,22 @@ static int lwm2m_read_handler(struct lwm2m_engine_obj_inst *obj_inst, struct lwm
10251025
res->res_instances[i].res_inst_id, &data_len);
10261026
}
10271027

1028-
if (!data_ptr || data_len == 0) {
1028+
if (!data_ptr && data_len) {
10291029
return -ENOENT;
10301030
}
10311031

1032+
if (!data_len) {
1033+
if (obj_field->data_type != LWM2M_RES_TYPE_OPAQUE &&
1034+
obj_field->data_type != LWM2M_RES_TYPE_STRING) {
1035+
return -ENOENT;
1036+
}
1037+
/* Only opaque and string types can be empty, and when
1038+
* empty, we should not give pointer to potentially uninitialized
1039+
* data to a content formatter. Give pointer to empty string instead.
1040+
*/
1041+
data_ptr = "";
1042+
}
1043+
10321044
switch (obj_field->data_type) {
10331045

10341046
case LWM2M_RES_TYPE_OPAQUE:

0 commit comments

Comments
 (0)