Skip to content

Commit

Permalink
Fix Win32 p11_dl_error crash
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tomsci authored and ueno committed Mar 10, 2019
1 parent 4a92517 commit cbe95e3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion common/compat.c
Expand Up @@ -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 |
Expand All @@ -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
Expand Down

0 comments on commit cbe95e3

Please sign in to comment.