igrr / axtls-8266

axTLS port for ESP8266
Other
79 stars 33 forks source link

realloc fail in more_comps() (bigint.c:1072) cause fatal exception 29 #32

Open Palatis opened 7 years ago

Palatis commented 7 years ago

i think we should handle memory allocation fail more gracefully.....

The problem is probably that by the time we try to realloc(), we don't have large enough continues memory block.

https://github.com/igrr/axtls-8266/blob/master/crypto/bigint.c#L1072

fatal exception 29(StoreProhibitedCause):
epc1=0x40218dae, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000004, depc=0x00000000

Exception (29):
epc1=0x40218dae epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000004 depc=0x00000000

ctx: sys 
sp: 3ffffa70 end: 3fffffb0 offset: 01a0
0x4024aeba: more_comps at bigint.c:1072
0x4024b04c: alloc at bigint.c:1106
0x4024b2ed: regular_multiply at bigint.c:822
0x4024b04c: alloc at bigint.c:1106
0x4024be2a: bi_barrett at bigint.c:1289
0x4604e78f: ?? ??:0
0x4024c080: bi_mod_power at bigint.c:1414
0x4024af1c: trim at bigint.c:1197
0x4024d1a1: RSA_public at rsa.c:242
0x402490e6: send_client_key_xchg at tls1_clnt.c:361
0x402494d1: do_clnt_handshake at tls1_clnt.c:126
0x4022b476: pbuf_copy_partial at pbuf.c:1025
0x4010020c: _umm_free at umm_malloc.c:1287
0x4010068c: free at umm_malloc.c:?
0x4020ba6e: ax_port_read at tcp_axtls.c:581
0x40248ed2: do_handshake at tls1.c:1545
0x4010068c: free at umm_malloc.c:?
0x40249038: ssl_read at tls1.c:271
0x4020b811: tcp_ssl_read at tcp_axtls.c:378
0x4020add9: _ZN11AsyncClient5_recvEP7tcp_pcbP4pbufa at ESPAsyncTCP.cpp:388
0x4022d21a: tcp_output at tcp_out.c:925
0x4020ae0b: _ZN11AsyncClient7_s_recvEPvP7tcp_pcbP4pbufa at ESPAsyncTCP.cpp:478
0x40231f08: tcp_input at tcp_in.c:394 (discriminator 1)
0x40100f7b: free at umm_malloc.c:?
0x4022f5b5: ip_input at ip.c:559
0x4022e9b1: ethernet_input at etharp.c:1379
0x40104062: free at umm_malloc.c:?
0x401009c6: free at umm_malloc.c:?
0x402389e8: umm_free_heap_size at umm_malloc.c:1740
0x40100793: free at umm_malloc.c:?
0x401007ce: free at umm_malloc.c:?
0x4023860b: umm_free_heap_size at umm_malloc.c:1740
0x40000f49: ?? ??:0
0x40000f49: ?? ??:0