From: Jay Satiro Date: Thu, 1 Oct 2020 17:34:59 +0000 (-0400) Subject: strerror: fix null deref on winapi out-of-memory X-Git-Tag: curl-7_73_0~28 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9a13f7c2a7ca5fca99622a6feeb29abc3b05d713;p=thirdparty%2Fcurl.git strerror: fix null deref on winapi out-of-memory Follow-up to bed5f84 from several days ago. Ref: https://github.com/curl/curl/pull/6005 --- diff --git a/lib/strerror.c b/lib/strerror.c index fef5c2bcac..0a3b73844c 100644 --- a/lib/strerror.c +++ b/lib/strerror.c @@ -670,9 +670,11 @@ get_winapi_error(int err, char *buf, size_t buflen) FORMAT_MESSAGE_IGNORE_INSERTS), NULL, err, LANG_NEUTRAL, wbuf, sizeof(wbuf)/sizeof(TCHAR), NULL)) { char *msg = curlx_convert_tchar_to_UTF8(wbuf); - strncpy(buf, msg, buflen - 1); - buf[buflen-1] = '\0'; - curlx_unicodefree(msg); + if(msg) { + strncpy(buf, msg, buflen - 1); + buf[buflen-1] = '\0'; + curlx_unicodefree(msg); + } } }