Skip to content

Commit 6411a23

Browse files
committed
Fixes to Unicode issues in scp and sftp
1 parent 5c02287 commit 6411a23

File tree

6 files changed

+39
-29
lines changed

6 files changed

+39
-29
lines changed

contrib/win32/openssh/version.rc

0 Bytes
Binary file not shown.

contrib/win32/win32compat/shell-host.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ void SizeWindow(HANDLE hInput) {
398398
matchingFont.FontWeight = FW_NORMAL;
399399
wcscpy(matchingFont.FaceName, L"Consolas");
400400

401-
bSuccess = SetCurrentConsoleFontEx(child_out, FALSE, &matchingFont);
401+
bSuccess = __SetCurrentConsoleFontEx(child_out, FALSE, &matchingFont);
402402

403403
// This information is the live screen
404404
ZeroMemory(&consoleInfo, sizeof(consoleInfo));
@@ -1069,6 +1069,15 @@ int start_with_pty(int ac, wchar_t **av) {
10691069
HANDLE hEventHook = NULL;
10701070
HMODULE hm_kernel32 = NULL, hm_user32 = NULL;
10711071

1072+
if ((hm_kernel32 = LoadLibraryW(L"kernel32.dll")) == NULL ||
1073+
(hm_user32 = LoadLibraryW(L"user32.dll")) == NULL ||
1074+
(__SetCurrentConsoleFontEx = (__t_SetCurrentConsoleFontEx)GetProcAddress(hm_kernel32, "SetCurrentConsoleFontEx")) == NULL ||
1075+
(__UnhookWinEvent = (__t_UnhookWinEvent)GetProcAddress(hm_user32, "UnhookWinEvent")) == NULL ||
1076+
(__SetWinEventHook = (__t_SetWinEventHook)GetProcAddress(hm_user32, "SetWinEventHook")) == NULL) {
1077+
printf("cannot support a pseudo terminal. \n");
1078+
return -1;
1079+
}
1080+
10721081
pipe_in = GetStdHandle(STD_INPUT_HANDLE);
10731082
pipe_out = GetStdHandle(STD_OUTPUT_HANDLE);
10741083
pipe_err = GetStdHandle(STD_ERROR_HANDLE);
@@ -1093,7 +1102,7 @@ int start_with_pty(int ac, wchar_t **av) {
10931102

10941103
InitializeCriticalSection(&criticalSection);
10951104

1096-
hEventHook = SetWinEventHook(EVENT_CONSOLE_CARET, EVENT_CONSOLE_LAYOUT, NULL,
1105+
hEventHook = __SetWinEventHook(EVENT_CONSOLE_CARET, EVENT_CONSOLE_LAYOUT, NULL,
10971106
ConsoleEventProc, 0, 0, WINEVENT_OUTOFCONTEXT);
10981107

10991108
memset(&si, 0, sizeof(STARTUPINFO));
@@ -1168,7 +1177,7 @@ int start_with_pty(int ac, wchar_t **av) {
11681177
if (ux_thread != INVALID_HANDLE_VALUE)
11691178
TerminateThread(ux_thread, S_OK);
11701179
if (hEventHook)
1171-
UnhookWinEvent(hEventHook);
1180+
__UnhookWinEvent(hEventHook);
11721181

11731182
FreeConsole();
11741183

progressmeter.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ refresh_progress_meter(void)
240240
#ifdef WINDOWS
241241
wchar_t* wtmp = utf8_to_utf16(buf);
242242
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), wtmp, wcslen(wtmp), 0, 0);
243-
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), L"\n", 1, 0, 0);
244243
free(wtmp);
245244
#else
246245
atomicio(vwrite, STDOUT_FILENO, buf, win_size - 1);

scp.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,9 @@ main(int argc, char **argv)
924924
*/
925925

926926
w32posix_initialize();
927-
ConInit(STD_OUTPUT_HANDLE, TRUE);
927+
/*scp is invoked on client side*/
928+
if (!(argc >= 2 && ( strcmp(argv[1], "-f" ) == 0 || strcmp(argv[1], "-t") == 0 )))
929+
ConInit(STD_OUTPUT_HANDLE, TRUE);
928930
#endif
929931

930932
/* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
@@ -2037,7 +2039,7 @@ int start_process_io(char *exename, char **argv, char **envv,
20372039
char *homedir, char *lpDesktop)
20382040
{
20392041
UNREFERENCED_PARAMETER(envv);
2040-
STARTUPINFO sui;
2042+
STARTUPINFOW sui;
20412043
DWORD ret;
20422044
char cmdbuf[2048];
20432045
int ctr;
@@ -2047,7 +2049,7 @@ int start_process_io(char *exename, char **argv, char **envv,
20472049
*/
20482050
sui.cb = sizeof(STARTUPINFO);
20492051
sui.lpReserved = 0;
2050-
sui.lpDesktop = lpDesktop;
2052+
sui.lpDesktop = utf8_to_utf16(lpDesktop);
20512053
sui.lpTitle = NULL; /* NULL means use exe name as title */
20522054
sui.dwX = 0;
20532055
sui.dwY = 0;
@@ -2076,17 +2078,17 @@ int start_process_io(char *exename, char **argv, char **envv,
20762078
ctr++;
20772079
}
20782080

2079-
ret = CreateProcess(
2080-
exename, // given in form like "d:\\util\\cmd.exe"
2081-
cmdbuf, /* in "arg0 arg1 arg2" form command line */
2081+
ret = CreateProcessW(
2082+
utf8_to_utf16(exename), // given in form like "d:\\util\\cmd.exe"
2083+
utf8_to_utf16(cmdbuf), /* in "arg0 arg1 arg2" form command line */
20822084
NULL, /* process security */
20832085
NULL, /* thread security */
20842086
TRUE, /* inherit handles is YES */
20852087
CreateFlags,
20862088
/* give new proc a new screen, suspend it for debugging also */
20872089
NULL, /* in "E1=a0E2=b0E3=c00" form environment,
20882090
NULL means use parent's */
2089-
homedir, /* Current Directory, NULL means use whats for parent */
2091+
utf8_to_utf16(homedir), /* Current Directory, NULL means use whats for parent */
20902092
&sui, /* start up info */
20912093
pi); /* process created info kept here */
20922094

sftp-common.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ typedef struct _REPARSE_DATA_BUFFER {
444444
};
445445
} REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER;
446446

447-
BOOL ResolveLink(char * tLink, char *ret, DWORD * plen, DWORD Flags)
447+
BOOL ResolveLink(wchar_t * tLink, wchar_t *ret, DWORD * plen, DWORD Flags)
448448
{
449449
HANDLE fileHandle;
450450
BYTE reparseBuffer[MAX_REPARSE_SIZE];
@@ -455,7 +455,7 @@ BOOL ResolveLink(char * tLink, char *ret, DWORD * plen, DWORD Flags)
455455

456456
if (Flags & FILE_ATTRIBUTE_DIRECTORY)
457457
{
458-
fileHandle = CreateFile(tLink, 0,
458+
fileHandle = CreateFileW(tLink, 0,
459459
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
460460
OPEN_EXISTING,
461461
FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, 0);
@@ -466,18 +466,18 @@ BOOL ResolveLink(char * tLink, char *ret, DWORD * plen, DWORD Flags)
466466
//
467467
// Open the file
468468
//
469-
fileHandle = CreateFile(tLink, 0,
469+
fileHandle = CreateFileW(tLink, 0,
470470
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
471471
OPEN_EXISTING,
472472
FILE_FLAG_OPEN_REPARSE_POINT, 0);
473473
}
474474
if (fileHandle == INVALID_HANDLE_VALUE)
475475
{
476-
sprintf_s(ret, *plen, "%s", tLink);
476+
swprintf_s(ret, *plen, L"%ls", tLink);
477477
return TRUE;
478478
}
479479

480-
if (GetFileAttributes(tLink) & FILE_ATTRIBUTE_REPARSE_POINT) {
480+
if (GetFileAttributesW(tLink) & FILE_ATTRIBUTE_REPARSE_POINT) {
481481

482482
if (DeviceIoControl(fileHandle, FSCTL_GET_REPARSE_POINT,
483483
NULL, 0, reparseInfo, sizeof(reparseBuffer),
@@ -496,11 +496,11 @@ BOOL ResolveLink(char * tLink, char *ret, DWORD * plen, DWORD Flags)
496496
(PWCHAR)(reparseData + msReparseInfo->MountPointReparseBuffer.SubstituteNameOffset),
497497
(size_t)msReparseInfo->MountPointReparseBuffer.SubstituteNameLength);
498498
temp[msReparseInfo->MountPointReparseBuffer.SubstituteNameLength] = 0;
499-
sprintf_s(ret, *plen, "%S", &temp[4]);
499+
swprintf_s(ret, *plen, L"%ls", &temp[4]);
500500
}
501501
else
502502
{
503-
sprintf_s(ret, *plen, "%s", tLink);
503+
swprintf_s(ret, *plen, L"%ls", tLink);
504504
return FALSE;
505505
}
506506

@@ -512,7 +512,7 @@ BOOL ResolveLink(char * tLink, char *ret, DWORD * plen, DWORD Flags)
512512
}
513513
}
514514
else {
515-
sprintf_s(ret, *plen, "%s", tLink);
515+
swprintf_s(ret, *plen, L"%ls", tLink);
516516
}
517517

518518
CloseHandle(fileHandle);
@@ -521,30 +521,30 @@ BOOL ResolveLink(char * tLink, char *ret, DWORD * plen, DWORD Flags)
521521

522522
char * get_inside_path(char * opath, BOOL bResolve, BOOL bMustExist)
523523
{
524-
BOOL ResolveLink(char * tLink, char *ret, DWORD * plen, DWORD Flags);
525-
526524
char * ipath;
527525
char * temp_name;
528-
char temp[1024];
529-
DWORD templen = sizeof(temp);
526+
wchar_t temp[1024];
527+
DWORD templen = 1024;
530528
WIN32_FILE_ATTRIBUTE_DATA FileInfo;
531529

532-
533-
if (!GetFileAttributesEx(opath, GetFileExInfoStandard, &FileInfo) && bMustExist)
530+
wchar_t* opath_w = utf8_to_utf16(opath);
531+
if (!GetFileAttributesExW(opath_w, GetFileExInfoStandard, &FileInfo) && bMustExist)
534532
{
533+
free(opath_w);
535534
return NULL;
536535
}
537536

538537
if (bResolve)
539538
{
540-
ResolveLink(opath, temp, &templen, FileInfo.dwFileAttributes);
541-
ipath = xstrdup(temp);
539+
ResolveLink(opath_w, temp, &templen, FileInfo.dwFileAttributes);
540+
ipath = utf16_to_utf8(temp);
542541
}
543542
else
544543
{
545544
ipath = xstrdup(opath);
546545
}
547546

547+
free(opath_w);
548548
return ipath;
549549
}
550550

sftp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2393,7 +2393,7 @@ connect_to_server(char *path, char **args, int *in, int *out)
23932393
char fullCmd[MAX_PATH] = { 0 };
23942394
char ioArg[1024] = { 0 };
23952395
PROCESS_INFORMATION pi = { 0 };
2396-
STARTUPINFO si = { 0 };
2396+
STARTUPINFOW si = { 0 };
23972397

23982398
debug3("Generating ssh-client command...");
23992399
fullCmd[0] = '\0';
@@ -2428,7 +2428,7 @@ connect_to_server(char *path, char **args, int *in, int *out)
24282428

24292429
debug("Executing ssh client: \"%.500s\"...\n", fullCmd);
24302430

2431-
if (CreateProcessA(NULL, fullCmd, NULL, NULL, TRUE,
2431+
if (CreateProcessW(NULL, utf8_to_utf16(fullCmd), NULL, NULL, TRUE,
24322432
NORMAL_PRIORITY_CLASS, NULL,
24332433
NULL, &si, &pi) == TRUE) {
24342434
sshpid = pi.dwProcessId;

0 commit comments

Comments
 (0)