This is a patch for CVE-2017-18187. Cherry-picked from 83c9f495ff Ref. https://github.com/espressif/esp-idf/issues/1730
83c9f495ff