summaryrefslogtreecommitdiff
path: root/lib/strerror.c
diff options
context:
space:
mode:
authorJay Satiro <raysatiro@yahoo.com>2020-10-01 13:34:59 -0400
committerJay Satiro <raysatiro@yahoo.com>2020-10-01 13:34:59 -0400
commit9a13f7c2a7ca5fca99622a6feeb29abc3b05d713 (patch)
tree440d08f6d9f3f5af19a6743e3c91c5d54b699bc1 /lib/strerror.c
parent7920be94738e0d84f7aa30c3605d29ec4274c714 (diff)
downloadcurl-9a13f7c2a7ca5fca99622a6feeb29abc3b05d713.tar.gz
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
Diffstat (limited to 'lib/strerror.c')
-rw-r--r--lib/strerror.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/strerror.c b/lib/strerror.c
index fef5c2bca..0a3b73844 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);
+ }
}
}