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

decoder/nanocbor_leave_container(): reject (some) invalid arguments #92

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mguetschow
Copy link
Contributor

The documentation of nanocbor_leave_container() states the following preconditions:

This must be called with the same @ref nanocbor_value_t struct that was used to enter the container (1). Furthermore, the @p container must be at the end of the container (2).

This PR adds a check to the implementation to (partly) ensure these preconditions and otherwise return an error code. To this end, the API is changed in a backwards-compatible manner with int as return type instead of void.

The check ensures that container is actually a container and that it has been consumed up to the end (precondition (2)). It also adds a plausibility check for (1) by ensuring that container->curr is between it->curr and it->end.

I'm not sure whether the selected error value NANOCBOR_ERR_INVALID_TYPE is the appropriate one, maybe it would make sense to add NANOCBOR_ERR_INVALID_ARGUMENT or something similar to nanocbor_error_t.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant