Skip to content

Commit f6b2216

Browse files
mike-scottnashif
authored andcommitted
net: lwm2m: fix out-of-bounds access in put_s8()
Per Coverity report, oma_tlv_put() does pointer arithmetic accessing the data as an array of u8_t. In put_bool() we get a singleton pointer from the evaluation of: "value != 0 ? 1 : 0" which is passed to put_s8() which in turn passes it to oma_tlv_put(). To avoid misinterpretation, let's create a temporary s8_t variable to pass into oma_tlv_put instead. Fixes: #12312 Signed-off-by: Michael Scott <[email protected]>
1 parent 95f21d5 commit f6b2216

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

subsys/net/lib/lwm2m/lwm2m_rw_oma_tlv.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,9 @@ static size_t put_float64fix(struct lwm2m_output_context *out,
554554
static size_t put_bool(struct lwm2m_output_context *out,
555555
struct lwm2m_obj_path *path, bool value)
556556
{
557-
return put_s8(out, path, value != 0 ? 1 : 0);
557+
s8_t value_s8 = (value != 0 ? 1 : 0);
558+
559+
return put_s8(out, path, value_s8);
558560
}
559561

560562
static size_t get_number(struct lwm2m_input_context *in, s64_t *value,

0 commit comments

Comments
 (0)