Skip to content

Commit 6bfeb4f

Browse files
rlubosfabiobaltieri
authored andcommitted
net: lwm2m: senml_cbor: Verify data len before calling memcpy
Check if there actually is data to copy before calling memcpy() to prevent potentially calling memcpy() with NULL value pointer. Signed-off-by: Robert Lubos <[email protected]>
1 parent 779d852 commit 6bfeb4f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,9 @@ static int get_string(struct lwm2m_input_context *in, uint8_t *buf, size_t bufle
644644
}
645645

646646
len = MIN(buflen-1, fd->current->record_union.union_vs.len);
647-
648-
memcpy(buf, fd->current->record_union.union_vs.value, len);
647+
if (len > 0) {
648+
memcpy(buf, fd->current->record_union.union_vs.value, len);
649+
}
649650
buf[len] = '\0';
650651

651652
fd->current = NULL;

0 commit comments

Comments
 (0)