-
Notifications
You must be signed in to change notification settings - Fork 754
[lts_03_2025] Use safe_add_size_t when sizing DPS transport response buffers (backport of #2738) #2746
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
base: lts_03_2025
Are you sure you want to change the base?
[lts_03_2025] Use safe_add_size_t when sizing DPS transport response buffers (backport of #2738) #2746
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1090,6 +1090,31 @@ BEGIN_TEST_SUITE(prov_transport_http_client_ut) | |
| prov_dev_http_transport_destroy(handle); | ||
| } | ||
|
|
||
| TEST_FUNCTION(prov_transport_http_reply_recv_invalid_content_len_fail) | ||
| { | ||
| //arrange | ||
| PROV_DEVICE_TRANSPORT_HANDLE handle = prov_dev_http_transport_create(TEST_URI_VALUE, TRANSPORT_HSM_TYPE_TPM, TEST_SCOPE_ID_VALUE, TEST_DPS_API_VALUE, on_transport_error, NULL); | ||
| (void)prov_dev_http_transport_open(handle, TEST_REGISTRATION_ID_VALUE, TEST_BUFFER_VALUE, TEST_BUFFER_VALUE, on_transport_register_data_cb, NULL, on_transport_status_cb, NULL, on_transport_challenge_callback, NULL); | ||
| (void)prov_dev_http_transport_register_device(handle, on_transport_json_parse, on_transport_create_json_payload, NULL); | ||
| g_on_http_open(g_http_open_ctx, HTTP_CALLBACK_REASON_OK); | ||
| prov_dev_http_transport_dowork(handle); | ||
| umock_c_reset_all_calls(); | ||
|
|
||
| // A Content-Length of SIZE_MAX would wrap (content_len + 1) to 0; the transport must | ||
| // reject it instead of allocating a zero-length buffer and copying gigabytes past it. | ||
|
Comment on lines
+1103
to
+1104
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same conclusion as the log-message thread, and the comment is genuinely misleading. The test drives Not changing it here only to keep this backport a clean cherry-pick of For the record, the test itself is sound — I verified it fails against the unfixed source: reverting the three |
||
| STRICT_EXPECTED_CALL(HTTPHeaders_FindHeaderValue(IGNORED_PTR_ARG, IGNORED_PTR_ARG)).SetReturn(NULL); | ||
|
|
||
| //act | ||
| g_on_http_reply_recv(g_http_execute_ctx, HTTP_CALLBACK_REASON_OK, (const unsigned char*)TEST_JSON_CONTENT, (size_t)-1, TEST_SUCCESS_STATUS_CODE, TEST_HTTP_HANDLE_VALUE); | ||
|
|
||
| //assert | ||
| ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); | ||
|
|
||
| //cleanup | ||
| (void)prov_dev_http_transport_close(handle); | ||
| prov_dev_http_transport_destroy(handle); | ||
| } | ||
|
|
||
| TEST_FUNCTION(prov_transport_http_reply_recv_transient_error_succeed) | ||
| { | ||
| //arrange | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed on the substance; not changing it in this PR.
You are right that the value is not caller-specified.
content_lenis the length reported by the receive callback — in azure-uhttp-c it isBUFFER_length(recv_msg.msg_body), i.e. bytes actually received and buffered, not theContent-Lengthheader. That distinction is exactly why this is hardening rather than a remotely reachable overflow, so the wording is worth correcting.The reason not to do it here: this string is byte-identical to
main, and "the threeprovisioning_client/srcfiles are byte-identical tomainat the allocation sites" is the main safety argument for this backport. Changing it would make the branches diverge and leave the same wording wrong onmain.Better fixed on
mainand allowed to flow down. Happy to open that PR.