[lts_03_2025] Use safe_add_size_t when sizing DPS transport response buffers (backport of #2738) - #2746
Conversation
* Use safe_add_size_t when sizing DPS transport response buffers The DPS HTTP, MQTT and AMQP transports sized their response buffers with malloc(len + 1). Compute the allocation size with safe_add_size_t (as already done elsewhere in the tree, e.g. uhttp) and fail the request if the addition saturates, instead of allocating a mis-sized buffer. Add a regression unit test per transport covering the saturating-length path. * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Address review feedback - prov_transport_mqtt_common: drop duplicate http_proxy_io.h include - prov_transport_http_client: correct payload-allocation error message - amqp unit test: assert the error is surfaced to the register callback --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> (cherry picked from commit 70f9fa2)
The cherry-picked regression tests use IGNORED_ARG, which is only defined in newer umock-c. lts_03_2025 pins umock-c 504193e6 (Mar 2020), where that macro does not exist, so the three provisioning UT suites would fail to compile. Replace IGNORED_ARG with IGNORED_PTR_ARG, matching the macro already used throughout these test files on this branch. All nine occurrences are pointer arguments, so IGNORED_PTR_ARG is the correct substitution. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: Successfully started running 1 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
CI on this PR is blocked by broken infrastructure on
|
Backports #2738 to
lts_03_2025, the only LTS branch still in maintenance (end date 2026-10-07 per the LTS schedule inreadme.md).Why
The DPS transports size their response buffers with
malloc(len + 1), so alenofSIZE_MAXwould wrap tomalloc(0)and the followingmemcpywould run off the allocation. #2738 fixed this onmainon 2026-07-23 but was not ported to the LTS branch, which still carries the unhardened pattern in all three files.Contents
70f9fa28cherry-picked unchanged. The threeprovisioning_client/srcfiles are byte-identical tomainat the allocation sites.IGNORED_ARG, which does not exist in the umock-c pinned by this branch (504193e6, March 2020); it was added later. Without this change the three provisioning UT suites fail to compile. All nine occurrences are pointer arguments, so they becomeIGNORED_PTR_ARG, matching the macro already used throughout these files on this branch.Notes
lts_03_2025(772a4f8b) already providessafe_add_size_tinsafe_math.h, with a macro definition identical to the one onmain.payload_datais now set toNULLafter thefree(), so the malloc-failure branch no longer leaves a dangling pointer behind.http_proxy_io.hinclude removed fromprov_transport_mqtt_common.cwas genuinely duplicated on this branch too (lines 17 and 19); one include remains.