Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update decoding pattern to avoid possible assert in TinyCBOR #245

Closed
jphickey opened this issue Sep 20, 2023 · 0 comments · Fixed by #254
Closed

Update decoding pattern to avoid possible assert in TinyCBOR #245

jphickey opened this issue Sep 20, 2023 · 0 comments · Fixed by #254
Assignees
Labels
bug Something isn't working

Comments

@jphickey
Copy link
Collaborator

Describe the bug
TinyCBOR may assert when decoding if it gets out of sync with the end of a container. This was discovered when attempting to decode an endpoint that used the "dtn" scheme as opposed to the "ipn" scheme. BPLib does not currently support the dtn scheme, and the internal decoding error flag was set as expected, but it still tried to "close" the container in the TinyCBOR state. This caused TinyCBOR to assert.

To Reproduce
Pass in a bundle from the CLA that uses a "dtn" scheme endpoint ID.

Expected behavior
Should not assert

Code snips
This is the line that asserted:

if (!cbor_value_at_end(&content))
{
dec->error = true;
}
/* return to parent scope */
if (cbor_value_leave_container(parent, &content) != CborNoError)

In this case the dec->error flag was already set due to the decode issue, but the cbor_value_leave_container() is still called. This caused TinyCBOR to assert because it wasn't at the end of the container.

System observed on:
Debian with TinyCBOR 0.60

Additional context
The code must not make any additional calls into TinyCBOR once the error flag is set, as it will be out of sync.

Reporter Info
Joseph Hickey, Vantage Systems, Inc.

@jphickey jphickey self-assigned this Sep 20, 2023
@jphickey jphickey added the bug Something isn't working label Sep 20, 2023
jphickey added a commit to jphickey/bplib that referenced this issue Sep 20, 2023
Implement the encoding and decoding of CBOR containers as a loop.  This
permits the "error" flag to be easily polled after each iteration, and
if it is ever set, the operation should exit safely.

This is important because after any encode/decode issue, the tiny CBOR
state will no longer be in sync with the data, and this library may
assert if invoked with a bad state object.
jphickey added a commit to jphickey/bplib that referenced this issue Sep 20, 2023
Implement the encoding and decoding of CBOR containers as a loop.  This
permits the "error" flag to be easily polled after each iteration, and
if it is ever set, the operation should exit safely.

This is important because after any encode/decode issue, the tiny CBOR
state will no longer be in sync with the data, and this library may
assert if invoked with a bad state object.
jphickey added a commit that referenced this issue Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant