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
585 stars 739 forks source link

Fix check on output of vsnprintf #2562

Closed vaavva closed 7 months ago

vaavva commented 7 months 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 The snprintf() API function returns the total length of the string it tried to create; if the attacker is able to craft input so that `count` becomes larger than the available space in ´buffer` and if the return value is used unsafely such as in the `AdvanceCountersAfterWrite()` function, memory corruption might occur. # Description of the solution Checked that the return value of snprintf is not >= count instead of just != count