ARMmbed

When input a wrong pk_cert ,the mbedtls_pk_parse_key() will cause a coredump?

HELLO!
I am working on something like this:
when I input correct cert,it works well.

but now,if i change some chars of the cert,then I input the cert,when connect,the MCU will cause a coredump.
I analyze the coredump file,and the stack ,are:
assert()
vportfree()
rsa_free_wrap()
mbedtls_pk_free()
mbedtls_pk_parse_key()

and my corrent pk cert is:
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEA8SZr5Py7GsieeUV2evT10TfCw/vbmln7Qxn5zFtM4jBndV7z
4mXx6rUmVqQmfP42lzJioKj7wvadju6N7NyxkxTQQc9MHYEhH1bPgzSaAiFcOWBg
irQi9Dwqj7L+aR4VTg4Bc88DAa+jYgRnE1UalY0b7uc/DYXVa8ne3PsgQxgHMwDx
6gKLUgSos7pODH+j529YgTJc5ibTD69F37Ey/7Voh5quq+lYl/j1ph1DoYrgai9r
Mwcro56fM1uxVpJ3dbEW/Dcy9RMvystjVlELhoW2GtLCBOwfIubHASN3BtR7+5iD
VRN+KfTJhty3xpXgXc2vuUE+GFg6HDtzo3g25QIDAQABAoIBAB9RpZ6iQiya1JYc
cuRKLyjCbK2mZqF3wT24QGyNiQExVyZztAn5wn8Akt+axxLhszZUyWFjQPtTqyfW
jKEwEnHvOJLreM+2JxaaYC4CpWPUcFVVUoSBG68Lp11tWkRNr2epQwAG6TWNWZNP
zhFBMsgsgO24o8Q+Vvb+S0744HpGApM/8qAAH0bVdrOHuLgIaWAzSguRZcXhE+xv
BbpiZ+jyVeYpDHjZrIoQTXhYY86FLvdTRAVRx0P1iF9sRtKcnNqmlxpeUB0/vnha
adTnX1HEWQQU0By9eOCPSPWVHrnIjkK3iMvt7KGxAGHEAu37F5D6UTXyh6XLHJAd
Dbed/tECgYEA+bXiJLASj5No7XQlrDk3MG0BOUNApZerwr65u4E6f9FkG6tg1xYs
g1RpUULxZSDEWRg7neSCP40osm4hVQMa5x/jKlUMhh3BoAiOa/LQ/cCAb9qeAgpg
Ka8u+c8FsaUQD4g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Pn1EwdiVdxb+Y3LQmO5dRkkiEmgQvLT+sHBu95IkPBzL+8s9jft05cGg
JItZAoGBAOgBS8HttLXEcCqfhtmy8MoZY49vKGUa3lB372Sc7W5bVYGf5qV/kbPG
wdpZrsDz+exp7GpK1QhfFtLpgDcfRz0dboGjB+NwrXyaueaSNmVcrLihgSDMsxaV
TpuIDgHzI3pasl3Fo6AT028LQBZS8qB4Vh8gF7cvbFBKmKzNsVaJ
-----END RSA PRIVATE KEY-----

I think wrong cert should return a error,but not a coredump,I don’t want coredump
the test engineer think this is a big BUG,
can some nice man help me?
please help me avoid the coredump when input a wrong cert,very thanks !

Hi @cqcsdzmt
Thank you for your question!
Note that this isn’t a certificate, but a private key, which should be known only to you. When do you expect it to get corrupted?
Your wrong private key sample is identical to your correct private key. You probably have a copy error.

I wouldn’t say this is a big bug, since as mentioned before, the private key should not be accessible by anything but your application, so it shouldn’t get corrupted.
Please update your wrong key to understand where the crash happens. This could be an issue of bad input which causes undefined behaviour, as sending corrupted data to a free function might result in a coredump, no matter what measures you make.
Regards,
Mbed TLS Team member
Ron

I have find the reason why it cause a coredump.
it’s my MCU code have a bug.
thanks for reply.