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 misalignment issue during STUN data reading #233

Merged
merged 2 commits into from
Jan 15, 2024

Conversation

Abeja27
Copy link
Contributor

@Abeja27 Abeja27 commented Jan 14, 2024

src/stun.c Outdated
@@ -908,7 +908,8 @@ int stun_read_attr(const void *data, size_t size, stun_message_t *msg, uint8_t *
JLOG_DEBUG("STUN ICE controlling attribute length invalid, length=%zu", length);
return -1;
}
msg->ice_controlling = ntohll(*((uint64_t *)attr->value));
uint32_t* value32 = (uint32_t *)attr->value;
msg->ice_controlling = ntohll(((uint64_t)value32[1] << 32) | value32[0]);
Copy link
Owner

Choose a reason for hiding this comment

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

There is actually an issue with endianess, as it reads the two 32-bit blocks reversed and expects ntohll to reverse them again. This works only if the architecture is little-endian.

In order to work on big endian architectures too, where ntoh* are no-ops, the conversion should be:

Suggested change
msg->ice_controlling = ntohll(((uint64_t)value32[1] << 32) | value32[0]);
msg->ice_controlling = ((uint64_t)ntohl(value32[0]) << 32) | ntohl(value32[1]);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah my bad. I always get that wrong. I've committed the fix.

Copy link
Owner

@paullouisageneau paullouisageneau left a comment

Choose a reason for hiding this comment

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

It looks perfect now, thank you for the fix!

@paullouisageneau paullouisageneau changed the title #232 Fixed misalignment issue during STUN data reading Fix misalignment issue during STUN data reading Jan 15, 2024
@paullouisageneau paullouisageneau linked an issue Jan 15, 2024 that may be closed by this pull request
@paullouisageneau paullouisageneau merged commit 0a7e4ec into paullouisageneau:master Jan 15, 2024
3 checks passed
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.

Misalignment issue during STUN data reading
2 participants