Part of the patch for CVE-2018-9988. Cherry-pick of 027f84c69f Ref. https://github.com/espressif/esp-idf/issues/1860
027f84c69f