Skip to content

Commit 1c51883

Browse files
committed
Fix for storing user name
1 parent e75ef6a commit 1c51883

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

Common/unicode.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,9 +556,9 @@ BSTR __stdcall MyStringToBSTR(
556556
CMyStringW& string)
557557
{
558558
#ifdef OLE2ANSI
559-
return ::SysAllocStringLen(string, (UINT) string.GetLengthA());
559+
return ::SysAllocStringLen(string.IsEmpty() ? "" : string, (UINT) string.GetLengthA());
560560
#else
561-
return ::SysAllocStringLen(string, (UINT) string.GetLength());
561+
return ::SysAllocStringLen(string.IsEmpty() ? L"" : string, (UINT)string.GetLength());
562562
#endif
563563
}
564564

ShellDLL/Auth.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ AuthReturnType CAuthentication::SSHAuthenticate(IEasySFTPAuthentication2* pAuth,
189189
::SysFreeString(bstr);
190190
size_t nUserLen = 0;
191191
auto* pUser = reinterpret_cast<LPCSTR>(strUserName.AllocUTF8String(&nUserLen));
192+
if (!pUser)
193+
{
194+
pUser = "";
195+
nUserLen = 0;
196+
}
192197
switch (mode)
193198
{
194199
case EasySFTPAuthenticationMode::None:
@@ -365,6 +370,11 @@ AuthReturnType CAuthentication::SSHAuthenticateWithAgent(IEasySFTPAuthentication
365370
{
366371
size_t nUserLen = 0;
367372
auto* lpszUser = reinterpret_cast<LPCSTR>(strUserName.AllocUTF8String(&nUserLen));
373+
if (!lpszUser)
374+
{
375+
lpszUser = "";
376+
nUserLen = 0;
377+
}
368378

369379
CAuthSession* pAuthSession = NULL;
370380
{

ShellDLL/AuthPage.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,14 @@ LRESULT CHostAuthPage::OnApply(WPARAM wParam, LPARAM lParam)
228228
}
229229
if (bAutoLogin)
230230
{
231+
if (strUserName.IsEmpty())
232+
{
233+
_SecureStringW::SecureEmptyString(strPassword);
234+
::MyMessageBoxW(m_hWnd, MAKEINTRESOURCEW(IDS_NO_USER_NAME), NULL, MB_ICONEXCLAMATION);
235+
GetParentSheet()->SetCurSel(this);
236+
return PSNRET_INVALID_NOCHANGEPAGE;
237+
}
238+
231239
CMyStringW strPKey;
232240
if (nAuthType == EasySFTPAuthenticationMode::PrivateKey)
233241
{
@@ -303,6 +311,7 @@ LRESULT CHostAuthPage::OnApply(WPARAM wParam, LPARAM lParam)
303311
else
304312
{
305313
m_pSettings->ClearCredentials();
314+
m_pSettings->strUserName = strUserName;
306315
}
307316
}
308317
else

0 commit comments

Comments
 (0)