Skip to content

Commit f624600

Browse files
oyvindronningstadnvlsianpu
authored andcommitted
boot_serial: Update cddl-gen version
To bring in bugfixes. Regenerate code. Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no> (cherry picked from commit 1e63e8f) Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
1 parent 9ab84e5 commit f624600

11 files changed

+41
-26
lines changed

boot/boot_serial/src/cbor_common.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file has been copied from the cddl-gen submodule.
3-
* Commit 8f9358a0b4b0e9b0cd579f0988056ef0b60760e4
3+
* Commit 9f77837f9950da1633d22abf6181a830521a6688
44
*/
55

66
/*

boot/boot_serial/src/cbor_common.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file has been copied from the cddl-gen submodule.
3-
* Commit 8f9358a0b4b0e9b0cd579f0988056ef0b60760e4
3+
* Commit 9f77837f9950da1633d22abf6181a830521a6688
44
*/
55

66
/*

boot/boot_serial/src/cbor_decode.c

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file has been copied from the cddl-gen submodule.
3-
* Commit 8f9358a0b4b0e9b0cd579f0988056ef0b60760e4
3+
* Commit 9f77837f9950da1633d22abf6181a830521a6688
44
*/
55

66
/*
@@ -126,6 +126,7 @@ static bool value_extract(cbor_state_t *state,
126126

127127
static bool int32_decode(cbor_state_t *state, int32_t *result)
128128
{
129+
FAIL_IF(state->payload >= state->payload_end);
129130
uint8_t major_type = MAJOR_TYPE(*state->payload);
130131
uint32_t uint_result;
131132
int32_t int_result;
@@ -155,6 +156,7 @@ static bool int32_decode(cbor_state_t *state, int32_t *result)
155156

156157
bool intx32_decode(cbor_state_t *state, int32_t *result)
157158
{
159+
FAIL_IF(state->payload >= state->payload_end);
158160
uint8_t major_type = MAJOR_TYPE(*state->payload);
159161

160162
if (major_type != CBOR_MAJOR_TYPE_PINT
@@ -197,6 +199,7 @@ static bool uint32_decode(cbor_state_t *state, uint32_t *result)
197199

198200
bool uintx32_decode(cbor_state_t *state, uint32_t *result)
199201
{
202+
FAIL_IF(state->payload >= state->payload_end);
200203
uint8_t major_type = MAJOR_TYPE(*state->payload);
201204

202205
if (major_type != CBOR_MAJOR_TYPE_PINT) {
@@ -233,6 +236,7 @@ bool uintx32_expect_union(cbor_state_t *state, uint32_t result)
233236
static bool strx_start_decode(cbor_state_t *state,
234237
cbor_string_type_t *result, cbor_major_type_t exp_major_type)
235238
{
239+
FAIL_IF(state->payload >= state->payload_end);
236240
uint8_t major_type = MAJOR_TYPE(*state->payload);
237241

238242
if (major_type != exp_major_type) {
@@ -243,10 +247,10 @@ static bool strx_start_decode(cbor_state_t *state,
243247
FAIL();
244248
}
245249

246-
if ((state->payload + result->len) > state->payload_end) {
250+
if (result->len > (state->payload_end - state->payload)) {
247251
cbor_print("error: 0x%x > 0x%x\r\n",
248-
(uint32_t)(state->payload + result->len),
249-
(uint32_t)state->payload_end);
252+
(uint32_t)result->len,
253+
(uint32_t)(state->payload_end - state->payload));
250254
FAIL_RESTORE();
251255
}
252256

@@ -264,6 +268,7 @@ bool bstrx_cbor_start_decode(cbor_state_t *state, cbor_string_type_t *result)
264268
FAIL_RESTORE();
265269
}
266270

271+
/* Overflow is checked in strx_start_decode() */
267272
state->payload_end = result->value + result->len;
268273
return true;
269274
}
@@ -290,6 +295,7 @@ bool strx_decode(cbor_state_t *state, cbor_string_type_t *result,
290295
FAIL();
291296
}
292297

298+
/* Overflow is checked in strx_start_decode() */
293299
(state->payload) += result->len;
294300
return true;
295301
}
@@ -338,8 +344,9 @@ bool tstrx_expect(cbor_state_t *state, cbor_string_type_t *result)
338344
static bool list_map_start_decode(cbor_state_t *state,
339345
cbor_major_type_t exp_major_type)
340346
{
341-
uint32_t new_elem_count;
347+
FAIL_IF(state->payload >= state->payload_end);
342348
uint8_t major_type = MAJOR_TYPE(*state->payload);
349+
uint32_t new_elem_count;
343350

344351
if (major_type != exp_major_type) {
345352
FAIL();
@@ -400,6 +407,7 @@ bool map_end_decode(cbor_state_t *state)
400407

401408
static bool primx_decode(cbor_state_t *state, uint32_t *result)
402409
{
410+
FAIL_IF(state->payload >= state->payload_end);
403411
uint8_t major_type = MAJOR_TYPE(*state->payload);
404412

405413
if (major_type != CBOR_MAJOR_TYPE_PRIM) {
@@ -468,6 +476,7 @@ bool boolx_expect(cbor_state_t *state, bool result)
468476

469477
bool double_decode(cbor_state_t *state, double *result)
470478
{
479+
FAIL_IF(state->payload >= state->payload_end);
471480
uint8_t major_type = MAJOR_TYPE(*state->payload);
472481

473482
if (major_type != CBOR_MAJOR_TYPE_PRIM) {
@@ -501,6 +510,7 @@ bool any_decode(cbor_state_t *state, void *result)
501510
cbor_assert(result == NULL,
502511
"'any' type cannot be returned, only skipped.\n");
503512

513+
FAIL_IF(state->payload >= state->payload_end);
504514
uint8_t major_type = MAJOR_TYPE(*state->payload);
505515
uint32_t value;
506516
uint32_t num_decode;
@@ -545,6 +555,7 @@ bool any_decode(cbor_state_t *state, void *result)
545555

546556
bool tag_decode(cbor_state_t *state, uint32_t *result)
547557
{
558+
FAIL_IF(state->payload >= state->payload_end);
548559
uint8_t major_type = MAJOR_TYPE(*state->payload);
549560

550561
if (major_type != CBOR_MAJOR_TYPE_TAG) {

boot/boot_serial/src/cbor_decode.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file has been copied from the cddl-gen submodule.
3-
* Commit 8f9358a0b4b0e9b0cd579f0988056ef0b60760e4
3+
* Commit 9f77837f9950da1633d22abf6181a830521a6688
44
*/
55

66
/*
@@ -19,7 +19,8 @@
1919
/** The cbor_decode library provides functions for decoding CBOR data elements.
2020
*
2121
* This library is primarily meant to be called from code generated by
22-
* $CDDL_GEN_BASE/scripts/cddl_gen.py
22+
* $CDDL_GEN_BASE/cddl_gen/cddl_gen.py script, or its equivalent cddl_gen
23+
* command line executable.
2324
*
2425
* Some details to notice about this library:
2526
* - Integers are all 32 bits (uint32_t). This means that CBOR's 64 bit values

boot/boot_serial/src/cbor_encode.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file has been copied from the cddl-gen submodule.
3-
* Commit 8f9358a0b4b0e9b0cd579f0988056ef0b60760e4
3+
* Commit 9f77837f9950da1633d22abf6181a830521a6688
44
*/
55

66
/*
@@ -239,6 +239,9 @@ static bool strx_encode(cbor_state_t *state,
239239
if (!strx_start_encode(state, input, major_type)) {
240240
FAIL();
241241
}
242+
if (input->len > (state->payload_end - state->payload)) {
243+
FAIL();
244+
}
242245
if (state->payload_mut != input->value) {
243246
memmove(state->payload_mut, input->value, input->len);
244247
}

boot/boot_serial/src/cbor_encode.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file has been copied from the cddl-gen submodule.
3-
* Commit 8f9358a0b4b0e9b0cd579f0988056ef0b60760e4
3+
* Commit 9f77837f9950da1633d22abf6181a830521a6688
44
*/
55

66
/*
@@ -55,10 +55,10 @@ bool bstrx_encode(cbor_state_t *state, const cbor_string_type_t *result);
5555
bool tstrx_encode(cbor_state_t *state, const cbor_string_type_t *result);
5656

5757
#define tstrx_put(state, string) \
58-
tstrx_encode(state, &(cbor_string_type_t){.value = (const uint8_t *)string, .len = (sizeof(string) - 1)})
58+
tstrx_encode(state, &(cbor_string_type_t){.value = string, len = (sizeof(string) - 1)})
5959

6060
#define tstrx_put_term(state, string) \
61-
tstrx_encode(state, &(cbor_string_type_t){.value = (const uint8_t *)string, .len = strlen((const char *)string)})
61+
tstrx_encode(state, &(cbor_string_type_t){.value = string, len = strlen(string)})
6262

6363
/** Encode a LIST header.
6464
*

boot/boot_serial/src/regenerate_serial_recovery_cbor.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ copy_with_copy_notice ../../../ext/cddl-gen/include/cbor_encode.h cbor_encode.h
3030
copy_with_copy_notice ../../../ext/cddl-gen/include/cbor_common.h cbor_common.h
3131

3232
echo "Generating serial_recovery_cbor.c|h"
33-
python3 ../../../ext/cddl-gen/scripts/cddl_gen.py -c serial_recovery.cddl code -d -t Upload --oc serial_recovery_cbor.c --oh serial_recovery_cbor.h --time-header
33+
python3 ../../../ext/cddl-gen/cddl_gen/cddl_gen.py -c serial_recovery.cddl code -d -t Upload --oc serial_recovery_cbor.c --oh serial_recovery_cbor.h --time-header
3434

3535
add_copyright() {
3636
echo "$(printf '/*

boot/boot_serial/src/serial_recovery_cbor.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file has been generated from the cddl-gen submodule.
3-
* Commit 8f9358a0b4b0e9b0cd579f0988056ef0b60760e4
3+
* Commit 9f77837f9950da1633d22abf6181a830521a6688
44
*/
55

66
/*
@@ -11,7 +11,7 @@
1111

1212
/*
1313
* Generated with cddl_gen.py (https://github.com/NordicSemiconductor/cddl-gen)
14-
* at: 2021-05-10 09:40:43
14+
* at: 2021-08-02 17:09:42
1515
* Generated with a default_max_qty of 3
1616
*/
1717

@@ -34,19 +34,19 @@ static bool decode_Member(
3434
cbor_string_type_t tmp_str;
3535
bool int_res;
3636

37-
bool tmp_result = (((union_start_code(state) && (int_res = (((((tstrx_expect(state, ((tmp_str.value = (const uint8_t *)"image",
37+
bool tmp_result = (((union_start_code(state) && (int_res = (((((tstrx_expect(state, ((tmp_str.value = "image",
3838
tmp_str.len = sizeof("image") - 1, &tmp_str)))))
3939
&& (intx32_decode(state, (&(*result)._Member_image)))) && (((*result)._Member_choice = _Member_image) || 1))
40-
|| (union_elem_code(state) && ((((tstrx_expect(state, ((tmp_str.value = (const uint8_t *)"data",
40+
|| (union_elem_code(state) && ((((tstrx_expect(state, ((tmp_str.value = "data",
4141
tmp_str.len = sizeof("data") - 1, &tmp_str)))))
4242
&& (bstrx_decode(state, (&(*result)._Member_data)))) && (((*result)._Member_choice = _Member_data) || 1)))
43-
|| (union_elem_code(state) && ((((tstrx_expect(state, ((tmp_str.value = (const uint8_t *)"len",
43+
|| (union_elem_code(state) && ((((tstrx_expect(state, ((tmp_str.value = "len",
4444
tmp_str.len = sizeof("len") - 1, &tmp_str)))))
4545
&& (intx32_decode(state, (&(*result)._Member_len)))) && (((*result)._Member_choice = _Member_len) || 1)))
46-
|| (union_elem_code(state) && ((((tstrx_expect(state, ((tmp_str.value = (const uint8_t *)"off",
46+
|| (union_elem_code(state) && ((((tstrx_expect(state, ((tmp_str.value = "off",
4747
tmp_str.len = sizeof("off") - 1, &tmp_str)))))
4848
&& (intx32_decode(state, (&(*result)._Member_off)))) && (((*result)._Member_choice = _Member_off) || 1)))
49-
|| (union_elem_code(state) && ((((tstrx_expect(state, ((tmp_str.value = (const uint8_t *)"sha",
49+
|| (union_elem_code(state) && ((((tstrx_expect(state, ((tmp_str.value = "sha",
5050
tmp_str.len = sizeof("sha") - 1, &tmp_str)))))
5151
&& (bstrx_decode(state, (&(*result)._Member_sha)))) && (((*result)._Member_choice = _Member_sha) || 1)))), union_end_code(state), int_res))));
5252

boot/boot_serial/src/serial_recovery_cbor.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file has been generated from the cddl-gen submodule.
3-
* Commit 8f9358a0b4b0e9b0cd579f0988056ef0b60760e4
3+
* Commit 9f77837f9950da1633d22abf6181a830521a6688
44
*/
55

66
/*
@@ -11,7 +11,7 @@
1111

1212
/*
1313
* Generated with cddl_gen.py (https://github.com/NordicSemiconductor/cddl-gen)
14-
* at: 2021-05-10 09:40:43
14+
* at: 2021-08-02 17:09:42
1515
* Generated with a default_max_qty of 3
1616
*/
1717

boot/boot_serial/src/types_serial_recovery_cbor.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
22
* This file has been generated from the cddl-gen submodule.
3-
* Commit 8f9358a0b4b0e9b0cd579f0988056ef0b60760e4
3+
* Commit 9f77837f9950da1633d22abf6181a830521a6688
44
*/
55

66
/*
77
* Generated with cddl_gen.py (https://github.com/NordicSemiconductor/cddl-gen)
8-
* at: 2021-05-10 09:40:43
8+
* at: 2021-08-02 17:09:42
99
* Generated with a default_max_qty of 3
1010
*/
1111

ext/cddl-gen

0 commit comments

Comments
 (0)