Skip to content

Commit aba6f78

Browse files
committed
net: lwm2m: Do not enforce canonical CBOR decoding
Our decoder can handle decoding of non-deterministic CBOR just fine. There is no need to block valid CBOR if the server does not produce length-first deterministic CBOR. Signed-off-by: Seppo Takalo <[email protected]>
1 parent d8edd78 commit aba6f78

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

subsys/net/lib/lwm2m/lwm2m_rw_cbor.c

+18
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ static int get_s64(struct lwm2m_input_context *in, int64_t *value)
237237
{
238238
ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1, 0);
239239

240+
states->constant_state->enforce_canonical = false;
241+
240242
if (!zcbor_int64_decode(states, value)) {
241243
LOG_WRN("unable to decode a 64-bit integer value");
242244
return -EBADMSG;
@@ -253,6 +255,8 @@ static int get_s32(struct lwm2m_input_context *in, int32_t *value)
253255
{
254256
ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1, 0);
255257

258+
states->constant_state->enforce_canonical = false;
259+
256260
if (!zcbor_int32_decode(states, value)) {
257261
LOG_WRN("unable to decode a 32-bit integer value, err: %d",
258262
states->constant_state->error);
@@ -270,6 +274,8 @@ static int get_float(struct lwm2m_input_context *in, double *value)
270274
{
271275
ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1, 0);
272276

277+
states->constant_state->enforce_canonical = false;
278+
273279
if (!zcbor_float_decode(states, value)) {
274280
LOG_ERR("unable to decode a floating-point value");
275281
return -EBADMSG;
@@ -289,6 +295,8 @@ static int get_string(struct lwm2m_input_context *in, uint8_t *value, size_t buf
289295

290296
ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1, 0);
291297

298+
states->constant_state->enforce_canonical = false;
299+
292300
if (!zcbor_tstr_decode(states, &hndl)) {
293301
LOG_WRN("unable to decode a string");
294302
return -EBADMSG;
@@ -318,6 +326,8 @@ static int get_time_string(struct lwm2m_input_context *in, int64_t *value)
318326

319327
ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1, 0);
320328

329+
states->constant_state->enforce_canonical = false;
330+
321331
if (!zcbor_tstr_decode(states, &hndl)) {
322332
return -EBADMSG;
323333
}
@@ -336,6 +346,8 @@ static int get_time_numerical(struct lwm2m_input_context *in, int64_t *value)
336346
{
337347
ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1, 0);
338348

349+
states->constant_state->enforce_canonical = false;
350+
339351
if (!zcbor_int64_decode(states, value)) {
340352
LOG_WRN("unable to decode seconds since Epoch");
341353
return -EBADMSG;
@@ -355,6 +367,8 @@ static int get_time(struct lwm2m_input_context *in, time_t *value)
355367

356368
ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1, 0);
357369

370+
states->constant_state->enforce_canonical = false;
371+
358372
success = zcbor_tag_decode(states, &tag);
359373

360374
if (success) {
@@ -405,6 +419,8 @@ static int get_bool(struct lwm2m_input_context *in, bool *value)
405419
{
406420
ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1, 0);
407421

422+
states->constant_state->enforce_canonical = false;
423+
408424
if (!zcbor_bool_decode(states, value)) {
409425
LOG_WRN("unable to decode a boolean value");
410426
return -EBADMSG;
@@ -425,6 +441,8 @@ static int get_opaque(struct lwm2m_input_context *in, uint8_t *value, size_t buf
425441

426442
ZCBOR_STATE_D(states, 1, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1, 0);
427443

444+
states->constant_state->enforce_canonical = false;
445+
428446
/* Get the CBOR header only on first read. */
429447
if (opaque->offset == 0) {
430448
ret = zcbor_bstr_start_decode_fragment(states, &hndl);

subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.c

+2
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ static bool decode_lwm2m_senml(zcbor_state_t *state, struct lwm2m_senml *result)
212212
{
213213
zcbor_log("%s\r\n", __func__);
214214

215+
state->constant_state->enforce_canonical = false;
216+
215217
bool res =
216218
(((zcbor_list_start_decode(state) &&
217219
((zcbor_multi_decode(

0 commit comments

Comments
 (0)