Skip to content

Commit

Permalink
windows: fix CommandLineToArgvW ASLR crash
Browse files Browse the repository at this point in the history
  • Loading branch information
lieff committed Aug 31, 2017
1 parent 2da9033 commit 0951d89
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lvg.c
Original file line number Diff line number Diff line change
Expand Up @@ -913,14 +913,20 @@ int open_lvg(const char *file_name)

#ifdef __MINGW32__
#include <windows.h>
#include <shellapi.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
int argc;
int argc = 0;
LPWSTR *argvw = CommandLineToArgvW(GetCommandLineW(), &argc);
int size_needed = WideCharToMultiByte(CP_UTF8, 0, argvw[1], -1, NULL, 0, NULL, NULL);
char *arg = alloca(size_needed);
WideCharToMultiByte(CP_UTF8, 0, argvw[1], -1, arg, size_needed, NULL, NULL);
char *argv[3] = { (char*)"", arg, 0 };
char *argv[3] = { (char*)"", 0, 0 };
if (argvw && argc > 1)
{
int size_needed = WideCharToMultiByte(CP_UTF8, 0, argvw[1], -1, NULL, 0, NULL, NULL);
argv[1] = alloca(size_needed + 1);
WideCharToMultiByte(CP_UTF8, 0, argvw[1], -1, argv[1], size_needed, NULL, NULL);
argv[1][size_needed] = 0;
LocalFree(argvw);
}
#else
int main(int argc, char **argv)
{
Expand Down

0 comments on commit 0951d89

Please sign in to comment.