Skip to content

emcute: fix payload copy error for emcute_pub#11957

Merged
miri64 merged 1 commit intoRIOT-OS:masterfrom
miri64:emcute/fix/payload-copy-error
Oct 7, 2019
Merged

emcute: fix payload copy error for emcute_pub#11957
miri64 merged 1 commit intoRIOT-OS:masterfrom
miri64:emcute/fix/payload-copy-error

Conversation

@miri64
Copy link
Copy Markdown
Member

@miri64 miri64 commented Aug 5, 2019

Contribution description

len is used with the memcpy() to copy the payload to tbuf. With a payload provided that is just long enough to fill tbuf, len += 6 leads to the memcpy() overriding data after tbuf (e.g. the mutex that is unlocked right after) and thus resulting in potential segmentation faults.

Additionally + 6 can only be applied if the total packet length is below 256 (see spec), so len + pos is what needs to be provided to the corresponding send functions instead (pos adapts to the header length of the PUBLISH message).

Testing procedure

Merge #11823 and run its testing procedure.

Issues/PRs references

Split out of #11823 to stream-line the review.

@miri64 miri64 added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Area: network Area: Networking labels Aug 5, 2019
@miri64 miri64 added this to the Release 2019.10 milestone Aug 5, 2019
@miri64 miri64 requested a review from haukepetersen August 5, 2019 11:07
@miri64 miri64 changed the title emcute: fix payload copy error for emcude_pub emcute: fix payload copy error for emcute_pub Aug 5, 2019
`len` is used with the `memcpy()` to copy the payload to `tbuf`. With a
payload provided that is just long enough to fill `tbuf`, `len += 6`
leads to the `memcpy()` overriding data after `tbuf` (e.g. the
`mutex` that is unlocked right after) and thus resulting in potential
segmentation faults.
Additionally `+ 6` can only be applied if the total packet length is
below 256 (see spec), so `len + pos` is what needs to be provided to the
corresponding send functions instead (`pos` adapts to the header length
of the PUBLISH message).
@miri64 miri64 force-pushed the emcute/fix/payload-copy-error branch from 5917475 to 10a3f3e Compare August 5, 2019 11:07
@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Aug 5, 2019

Fixed some typos in commit message 😅

@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Oct 1, 2019
@benpicco
Copy link
Copy Markdown
Contributor

benpicco commented Oct 1, 2019

I guess the original code was based on the same false assumption as the one fixed in #11958
All those magic numbers make it a bit scary though.

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Oct 1, 2019

I guess the original code was based on the same false assumption as the one fixed in #11958
All those magic numbers make it a bit scary though.

Yeah.. before I lost interest in this due to missing reviews, I planned to replace those too 😅

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Oct 7, 2019

Ping @benpicco?

Copy link
Copy Markdown
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

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

Code makes more sense now and pos ends up being 6 in the end anyway.

@miri64 miri64 added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Oct 7, 2019
@miri64 miri64 merged commit 9d0faa9 into RIOT-OS:master Oct 7, 2019
@miri64 miri64 deleted the emcute/fix/payload-copy-error branch October 7, 2019 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: network Area: Networking CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants