]> granicus.if.org Git - p11-kit/commitdiff
Fix Win32 p11_dl_error crash
authorTom Sutcliffe <tomsci@me.com>
Sat, 9 Mar 2019 13:41:22 +0000 (13:41 +0000)
committerDaiki Ueno <ueno@gnu.org>
Sun, 10 Mar 2019 10:02:12 +0000 (11:02 +0100)
Caused by returning a buffer that wasn't allocated with malloc and
needed to be freed with LocalFree() instead. The fix is to strdup
msg_buf so what's returned can be free()d.

common/compat.c

index 48614faac778e6f4203a993a6ddc6f39decee899..5f475342dab97c8d409d5cf216a29796fa42a1c4 100644 (file)
@@ -270,6 +270,7 @@ p11_dl_error (void)
 {
        DWORD code = GetLastError();
        LPVOID msg_buf;
+       char *result;
 
        FormatMessageA (FORMAT_MESSAGE_ALLOCATE_BUFFER |
                        FORMAT_MESSAGE_FROM_SYSTEM |
@@ -278,7 +279,9 @@ p11_dl_error (void)
                        MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
                        (LPSTR)&msg_buf, 0, NULL);
 
-       return msg_buf;
+       result = strdup (msg_buf);
+       LocalFree (msg_buf);
+       return result;
 }
 
 int