Fix/ai http ca use after free - #719
Merged
Merged
Conversation
http_session_send() freed the CA buffer returned by tuya_iotdns_query_domain_certs() right after TUYA_TRANSPORTER_SET_TLS_CONFIG, but the TLS layer only keeps the pointer: tuya_tls_config_set() memcpy-s the config struct, not the certificate data, and mbedtls_x509_crt_parse() does not run until tuya_transporter_connect(). The freed DER block is typically reused by the allocations inside connect (socket, mbedtls contexts), so mbedtls reads garbage and fails with MBEDTLS_ERR_X509_INVALID_FORMAT (-0x2180) -- the outer SEQUENCE tag is no longer 0x30. TLS connections to CDN hosts then fail, e.g. the US-region *.cdn5th.com TTS download, while CN region often survives because the block happens to stay intact. Free cacert after connect returns instead, and reject an empty CA up front the way http_session.c already does.
yingtao450
approved these changes
Sep 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR 描述/PR description
[在此详细描述 PR 的内容]/[Describe the PR content in detail here]
代码质量/Code Quality:
在本次拉取请求中,我已考虑以下事项 As part of this pull request, I've considered the following: