]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
strerror: fix null deref on winapi out-of-memory
authorJay Satiro <raysatiro@yahoo.com>
Thu, 1 Oct 2020 17:34:59 +0000 (13:34 -0400)
committerJay Satiro <raysatiro@yahoo.com>
Thu, 1 Oct 2020 17:34:59 +0000 (13:34 -0400)
Follow-up to bed5f84 from several days ago.

Ref: https://github.com/curl/curl/pull/6005

lib/strerror.c

index fef5c2bcac29747087babc8f9ebea2c3865981dc..0a3b73844c3ff4b19e5bc4a396933750aa70b17c 100644 (file)
@@ -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);
+      }
     }
   }