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

templates: add checks for payload length and array size #19

Closed
wants to merge 3 commits into from

Conversation

bugobliterator
Copy link
Collaborator

No description provided.

@bugobliterator bugobliterator force-pushed the pr-check-payload-array-size branch from 5ccba23 to dbb67a9 Compare February 10, 2024 09:00
@@ -166,7 +169,9 @@ void _@(msg_underscored_name)_decode(const CanardRxTransfer* transfer, uint32_t*
@(ind)(void)bit_ofs;
@(ind)(void)msg;
@(ind)(void)tao;

@(ind)if (tao && (transfer->payload_len > @(msg_define_name.upper())_MAX_SIZE)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need this to be in the function above so we can return true to indicate a bad decode. Note that relying on bit_ofs to detect that we haven't decoded is not sufficient

@@ -232,6 +237,9 @@ void _@(msg_underscored_name)_decode(const CanardRxTransfer* transfer, uint32_t*
@[ end if]@
@{indent += 1}@{ind = ' '*indent}@
@[ end if]@
@(ind)if (msg->@(field.name).len > @(field.type.max_size)) {
@(ind) msg->@(field.name).len = @(field.type.max_size);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we should change these void functions to bool. Unfortunately the convention is return true on invalid decode (that is completely crazy btw)

Copy link
Collaborator Author

@bugobliterator bugobliterator Feb 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we should change these void functions to bool. Unfortunately the convention is return true on invalid decode (that is completely crazy btw)

The return true is to match the older version of the compiler.

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.

2 participants