Skip to content

Commit

Permalink
net: lwm2m: Fix overlapping buffers from Portfolio object
Browse files Browse the repository at this point in the history
Portfolio object created string buffers for Identity resources
that was overlapping on some cases.

Don't calculate pointers by hand, allow compiler to calculate it.

Fixes #64634

Signed-off-by: Seppo Takalo <[email protected]>
  • Loading branch information
SeppoTakalo authored and carlescufi committed Nov 2, 2023
1 parent 2eb804a commit b6ab302
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions subsys/net/lib/lwm2m/lwm2m_obj_portfolio.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,14 @@ static struct lwm2m_engine_obj_field fields[] = {
static struct lwm2m_engine_obj_inst inst[MAX_INSTANCE_COUNT];
static struct lwm2m_engine_res res[MAX_INSTANCE_COUNT][PORTFOLIO_MAX_ID];
static struct lwm2m_engine_res_inst res_inst[MAX_INSTANCE_COUNT][RESOURCE_INSTANCE_COUNT];
static char identity[MAX_INSTANCE_COUNT*PORTFOLIO_IDENTITY_MAX][DEFAULT_IDENTITY_BUFFER_LENGTH];
static char identity[MAX_INSTANCE_COUNT][PORTFOLIO_IDENTITY_MAX][DEFAULT_IDENTITY_BUFFER_LENGTH];

static struct lwm2m_engine_obj_inst *portfolio_create(uint16_t obj_inst_id)
{
int index, avail = -1, i = 0, j = 0, indentity_buffer_start = 0;
int index, avail = -1, i = 0, j = 0;

/* Check that there is no other instance with this ID */
for (index = 0; index < ARRAY_SIZE(inst); index++) {
if (index) {
indentity_buffer_start += PORTFOLIO_IDENTITY_MAX;
}
if (inst[index].obj && inst[index].obj_inst_id == obj_inst_id) {
LOG_ERR("Can not create instance - "
"already existing: %u",
Expand All @@ -95,7 +92,7 @@ static struct lwm2m_engine_obj_inst *portfolio_create(uint16_t obj_inst_id)

/* initialize instance resource data */
INIT_OBJ_RES_MULTI_DATA_LEN(PORTFOLIO_IDENTITY_ID, res[avail], i, res_inst[avail], j,
PORTFOLIO_IDENTITY_MAX, false, identity[indentity_buffer_start],
PORTFOLIO_IDENTITY_MAX, false, identity[avail],
DEFAULT_IDENTITY_BUFFER_LENGTH, 0);
INIT_OBJ_RES_EXECUTE(PORTFOLIO_GET_AUTH_DATA_ID, res[avail], i, NULL);
INIT_OBJ_RES_MULTI_OPTDATA(PORTFOLIO_AUTH_DATA_ID, res[avail], i, res_inst[avail], j,
Expand Down

0 comments on commit b6ab302

Please sign in to comment.