Skip to content

Commit 0a2ff7c

Browse files
committed
Merge branch 'js/mingw-use-utf8'
Windows update. * js/mingw-use-utf8: mingw: fix possible buffer overrun when calling `GetUserNameW()` mingw: use Unicode functions explicitly mingw: get pw_name in UTF-8 format
2 parents e1cee0b + 697bdd2 commit 0a2ff7c

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

compat/mingw.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,7 +1407,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
14071407
do_unset_environment_variables();
14081408

14091409
/* Determine whether or not we are associated to a console */
1410-
cons = CreateFile("CONOUT$", GENERIC_WRITE,
1410+
cons = CreateFileW(L"CONOUT$", GENERIC_WRITE,
14111411
FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
14121412
FILE_ATTRIBUTE_NORMAL, NULL);
14131413
if (cons == INVALID_HANDLE_VALUE) {
@@ -1949,13 +1949,19 @@ struct passwd *getpwuid(int uid)
19491949
static unsigned initialized;
19501950
static char user_name[100];
19511951
static struct passwd *p;
1952+
wchar_t buf[100];
19521953
DWORD len;
19531954

19541955
if (initialized)
19551956
return p;
19561957

1957-
len = sizeof(user_name);
1958-
if (!GetUserName(user_name, &len)) {
1958+
len = ARRAY_SIZE(buf);
1959+
if (!GetUserNameW(buf, &len)) {
1960+
initialized = 1;
1961+
return NULL;
1962+
}
1963+
1964+
if (xwcstoutf(user_name, buf, sizeof(user_name)) < 0) {
19591965
initialized = 1;
19601966
return NULL;
19611967
}

compat/poll/poll.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ win32_compute_revents (HANDLE h, int *p_sought)
150150
if (!once_only)
151151
{
152152
NtQueryInformationFile = (PNtQueryInformationFile)(void (*)(void))
153-
GetProcAddress (GetModuleHandle ("ntdll.dll"),
153+
GetProcAddress (GetModuleHandleW (L"ntdll.dll"),
154154
"NtQueryInformationFile");
155155
once_only = TRUE;
156156
}

compat/winansi.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ int winansi_isatty(int fd)
608608
void winansi_init(void)
609609
{
610610
int con1, con2;
611-
char name[32];
611+
wchar_t name[32];
612612

613613
/* check if either stdout or stderr is a console output screen buffer */
614614
con1 = is_console(1);
@@ -628,13 +628,15 @@ void winansi_init(void)
628628
}
629629

630630
/* create a named pipe to communicate with the console thread */
631-
xsnprintf(name, sizeof(name), "\\\\.\\pipe\\winansi%lu", GetCurrentProcessId());
632-
hwrite = CreateNamedPipe(name, PIPE_ACCESS_OUTBOUND,
631+
if (swprintf(name, ARRAY_SIZE(name) - 1, L"\\\\.\\pipe\\winansi%lu",
632+
GetCurrentProcessId()) < 0)
633+
die("Could not initialize winansi pipe name");
634+
hwrite = CreateNamedPipeW(name, PIPE_ACCESS_OUTBOUND,
633635
PIPE_TYPE_BYTE | PIPE_WAIT, 1, BUFFER_SIZE, 0, 0, NULL);
634636
if (hwrite == INVALID_HANDLE_VALUE)
635637
die_lasterr("CreateNamedPipe failed");
636638

637-
hread = CreateFile(name, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
639+
hread = CreateFileW(name, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
638640
if (hread == INVALID_HANDLE_VALUE)
639641
die_lasterr("CreateFile for named pipe failed");
640642

0 commit comments

Comments
 (0)