Closed kglowacki closed 7 years ago
if I skip mbedtls_ssl_close_notify(&ssl_ctx) it crashes and occasionally give me a coredump:
`================== CURRENT THREAD REGISTERS ===================
pc 0x40140e77 0x40140e77 <mbedtls_mpi_zeroize+11>
lbeg 0x400014fd 1073747197
lend 0x4000150d 1073747213
lcount 0xfffffffe 4294967294
sar 0x4 4
ps 0x60a20 395808
threadptr
==================== CURRENT THREAD STACK =====================
idf/components/mbedtls/library/bignum.c:104
check return code of mbedtls_ssl_close_notify?
mbedtls_ssl_close_notify ends with ESP_OK.
mbedtls_ssl_free crashes while trying to release memory allocated during handshake at ssl_context.handshake->dhm_ctx.pX.p, I commented out everything between handshake and ssl_free, and it still crashes. Also tried with disabled hardware acceleration for mbedtls, no luck.
rookie mistake - I've passed mbedtls_ssl_context by value instead of a pointer so handshake() modified a copy.
Thanks for letting us know, glad you got this working correctly.
handshake() modified a copy
BTW, if passed by value instead of pointer in C then mbedtls_ssl_context will actually treat the first 4 bytes of the structure contents as the pointer. The first 4 bytes of mbedtls_ssl_context struct is a pointer to mbedtls_ssl_config, so the handshake would have treated the config structure as if it was the context and probably totally corrupted it. Yay memory unsafe languages? At least the compiler can warn for this particular one.
I'm trying to rework 'https' example to use a client certificate and make a POST to AWS-Iot. Request itself actually succeeds, but I'm unable to release ssl resources afterwards. mbedtls_ssl_free() hangs (or, rarely, crashes). I see similar effect with mbedtls_ssl_session_reset.
code available here (last line fails) [https://github.com/openairproject/sensor-esp32/blob/aws-iot/components/awsiot/awsiot_rest.c]