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

Fix potential type size mismatch through pointers #432

Merged
merged 1 commit into from
Nov 13, 2020

Conversation

sbertin-telular
Copy link
Contributor

size_t can be 64-bits while unsigned int is smaller. This causes issues
when option_length is accessed through the pointer x in
coap_parse_message(). The option length and delta are at most a 16-bit
unsigned integer plus 269 according to RFC 7252. Changing
option_number, option_delta, and option_length to uint32_t and x to
uint32_t * fixes #429. This also ensures sufficient size even if used
on a platform with smaller integers.

Signed-off-by: Scott Bertin sbertin@telular.com

@sbertin-telular
Copy link
Contributor Author

@rettichschnidi please review.

@sbertin-telular
Copy link
Contributor Author

Rebased

uint32_t option_number = 0;
uint32_t option_delta = 0;
uint32_t option_length = 0;
uint32_t *x;
Copy link
Contributor

Choose a reason for hiding this comment

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

The casts on line 699 should to be adjusted too.

Rest is looking good to me.

@sbertin-telular
Copy link
Contributor Author

Amended to fix casts

@sbertin-telular
Copy link
Contributor Author

Wait a minute, the casts shouldn't be necessary now.

size_t can be 64-bits while unsigned int is smaller. This causes issues
when option_length is accessed through the pointer x in
coap_parse_message(). The option length and delta are at most a 16-bit
unsigned integer plus 269 according to RFC 7252. Changing
option_number, option_delta, and option_length to uint32_t and x to
uint32_t * fixes eclipse-wakaama#429. This also ensures sufficient size even if used
on a platform with smaller integers.

Signed-off-by: Scott Bertin <sbertin@telular.com>
@sbertin-telular
Copy link
Contributor Author

Amended to remove unnecessary type casts.

@sbernard31 sbernard31 merged commit 6094b1e into eclipse-wakaama:master Nov 13, 2020
@sbertin-telular sbertin-telular deleted the fix_249 branch November 13, 2020 15:22
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.

Typecasting causing undefined behavior
3 participants