Azure / azure-iot-sdk-c

A C99 SDK for connecting devices to Microsoft Azure IoT services
https://azure.github.io/azure-iot-sdk-c
Other
587 stars 739 forks source link

Change message_queue indexing from pointer address to uint32_t #2497

Closed ewertons closed 1 year ago

ewertons commented 1 year ago
# Checklist - [x] I have read the [contribution guidelines] (https://github.com/Azure/azure-iot-sdk-c/blob/main/.github/CONTRIBUTING.md). - [x] I added or modified the existing tests to cover the change (we do not allow our test coverage to go down). - If this is a modification that impacts the behavior of a public API - [ ] I edited the corresponding document in the `devdoc` folder and added or modified requirements. - I submitted this PR against the correct branch: - [x] This pull-request is submitted against the `main` branch. - [x] I have merged the latest `main` branch prior to submission and re-merged as needed after I took any feedback. - [x] I have squashed my changes into one with a clear description of the change. # Reference/Link to the issue solved with this PR (if any) # Description of the problem

This change fixes a memory corruption caused by message queue when the following scenario occurs: MESSAGE1 is enqueued (address #0001) MESSAGE1 is put in progress by mq MESSAGE1 is destroyed by the app MESSAGE2 is enqueued (re-using address #0001, which was made available by the previous step) MESSAGE2 is put in progress by the mq MESSAGE2 processing is marked as completed by the app

Here the message queue searches the list of in-progress messages by the message address in memory. Since MESSAGE2 now has the same address of MESSAGE1 (which was freed), message_queue picks the entry for MESSAGE1 for removing from the in-progress list, leaving MESSAGE2 behind.

Description of the solution

Please see description above.