Skip to content

Commit cc40bc3

Browse files
broglep-workfabiobaltieri
authored andcommitted
net: lwm2m: fix senml max name size
base name or name can contain up to two shorts. (object id & object intstance or resource id & resource instance id) Signed-off-by: Pascal Brogle <[email protected]>
1 parent 136f032 commit cc40bc3

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
3333
#include "lwm2m_senml_cbor_types.h"
3434
#include "lwm2m_util.h"
3535

36+
#define SENML_MAX_NAME_SIZE sizeof("/65535/65535/")
37+
3638
struct cbor_out_fmt_data {
3739
/* Data */
3840
struct lwm2m_senml input;
3941

40-
/* Storage for basenames and names ~ sizeof("/65535/999/") */
42+
/* Storage for basenames and names ~ sizeof("/65535/65535/") */
4143
struct {
42-
char names[CONFIG_LWM2M_RW_SENML_CBOR_RECORDS][sizeof("/65535/999/")];
44+
char names[CONFIG_LWM2M_RW_SENML_CBOR_RECORDS][SENML_MAX_NAME_SIZE];
4345
size_t name_sz; /* Name buff size */
4446
uint8_t name_cnt;
4547
};
@@ -93,7 +95,7 @@ static void setup_out_fmt_data(struct lwm2m_message *msg)
9395

9496
(void)memset(fd, 0, sizeof(*fd));
9597
engine_set_out_user_data(&msg->out, fd);
96-
fd->name_sz = sizeof("/65535/999/");
98+
fd->name_sz = SENML_MAX_NAME_SIZE;
9799
fd->basetime = 0;
98100
fd->objlnk_sz = sizeof("65535:65535");
99101
}
@@ -160,7 +162,7 @@ static int put_basename(struct lwm2m_output_context *out, struct lwm2m_obj_path
160162
record->_record_bn._record_bn.len = len;
161163
record->_record_bn_present = 1;
162164

163-
if ((len < sizeof("0/0") - 1) || (len >= sizeof("65535/999"))) {
165+
if ((len < sizeof("/0/0") - 1) || (len >= SENML_MAX_NAME_SIZE)) {
164166
__ASSERT_NO_MSG(false);
165167
return -EINVAL;
166168
}
@@ -307,7 +309,7 @@ static int put_begin_ri(struct lwm2m_output_context *out, struct lwm2m_obj_path
307309
}
308310

309311
/* Forms name from resource id and resource instance id */
310-
int len = snprintk(name, sizeof("65535/999"),
312+
int len = snprintk(name, SENML_MAX_NAME_SIZE,
311313
"%" PRIu16 "/%" PRIu16 "",
312314
path->res_id, path->res_inst_id);
313315

@@ -709,7 +711,7 @@ static int do_write_op_item(struct lwm2m_message *msg, struct record *rec)
709711
uint8_t created = 0U;
710712
struct cbor_in_fmt_data *fd;
711713
/* Composite op - name with basename */
712-
char name[sizeof("65535/999")] = { 0 }; /* Null terminated name */
714+
char name[SENML_MAX_NAME_SIZE] = { 0 }; /* Null terminated name */
713715
int len = 0;
714716
char fqn[MAX_RESOURCE_LEN + 1] = {0};
715717

0 commit comments

Comments
 (0)