From bad4507664d3c68ad602e15ad3820e4ce11aa13f Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 1 Feb 2019 12:32:01 +0300 Subject: =?UTF-8?q?=D0=A1=20magic=20removed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mir_app/src/netlibsecurity.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/mir_app/src/netlibsecurity.cpp b/src/mir_app/src/netlibsecurity.cpp index b30146e7ca..46c4d9fa0d 100644 --- a/src/mir_app/src/netlibsecurity.cpp +++ b/src/mir_app/src/netlibsecurity.cpp @@ -244,21 +244,16 @@ char* NtlmCreateResponseFromChallenge(HANDLE hSecurity, const char *szChallenge, // Negotiate ANSI? if yes, convert the ANSI name to unicode if ((pkt->flags & 1) == 0) { int bufsz = MultiByteToWideChar(CP_ACP, 0, (char*)domainName, domainLen, nullptr, 0); - wchar_t* buf = (wchar_t*)alloca(bufsz * sizeof(wchar_t)); + wchar_t* buf = (wchar_t*)alloca((bufsz+1) * sizeof(wchar_t)); domainLen = MultiByteToWideChar(CP_ACP, 0, (char*)domainName, domainLen, buf, bufsz) - 1; + buf[domainLen] = 0; domainName = buf; } else domainLen /= sizeof(wchar_t); if (domainLen) { - size_t newLoginLen = mir_wstrlen(login) + domainLen + 1; - wchar_t *newLogin = (wchar_t*)alloca(newLoginLen * sizeof(wchar_t)); - - wcsncpy(newLogin, domainName, domainLen); - newLogin[domainLen] = '\\'; - mir_wstrcpy(newLogin + domainLen + 1, login); - - char* szChl = NtlmCreateResponseFromChallenge(hSecurity, nullptr, newLogin, psw, http, complete); + CMStringW wszNewLogin(FORMAT, L"%s\\%s", domainName, login); + char* szChl = NtlmCreateResponseFromChallenge(hSecurity, nullptr, wszNewLogin, psw, http, complete); mir_free(szChl); } } -- cgit v1.2.3