Skip to content

Commit adf8346

Browse files
authored
fix(NODE-2129): fix sporadic AcquireCredentialsHandle error (#133)
1 parent cd6f6a0 commit adf8346

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/win32/kerberos_sspi.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ auth_sspi_client_init(WCHAR* service,
5454
WCHAR* mechoid,
5555
sspi_client_state* state) {
5656
SECURITY_STATUS status;
57-
SEC_WINNT_AUTH_IDENTITY_W authIdentity;
57+
SEC_WINNT_AUTH_IDENTITY_W authIdentity{};
5858
TimeStamp ignored;
5959

6060
state->response = NULL;

src/win32/kerberos_win32.cc

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
#define GSS_C_REPLAY_FLAG 4
1313
#define GSS_C_SEQUENCE_FLAG 8
1414

15-
const wchar_t* to_wstring(const char *bytes) {
16-
unsigned int sizeOfStr = MultiByteToWideChar(CP_UTF8, 0, bytes, -1, NULL, 0);
17-
wchar_t *output = new wchar_t[sizeOfStr];
18-
MultiByteToWideChar(CP_UTF8, 0, bytes, -1, output, sizeOfStr);
19-
return output;
15+
const std::wstring to_wstring(const char *bytes) {
16+
DWORD sizeOfStr = MultiByteToWideChar(CP_UTF8, 0, bytes, -1, NULL, 0);
17+
assert(sizeOfStr > 0);
18+
std::wstring arg(sizeOfStr, '\0');
19+
DWORD result = MultiByteToWideChar(CP_UTF8, 0, bytes, -1, &arg[0], sizeOfStr);
20+
assert(result > 0);
21+
arg.resize(result - 1);
22+
return arg;
2023
}
2124

2225
NAN_INLINE std::wstring WStringOptionValue(v8::Local<v8::Object> options, const char* _key) {
@@ -31,7 +34,7 @@ NAN_INLINE std::wstring WStringOptionValue(v8::Local<v8::Object> options, const
3134
return std::wstring();
3235
}
3336

34-
return std::wstring(to_wstring(*(Nan::Utf8String(value))));
37+
return to_wstring(*(Nan::Utf8String(value)));
3538
}
3639

3740
/// KerberosClient
@@ -137,7 +140,7 @@ NAN_METHOD(KerberosServer::Step) {
137140

138141
/// Global Methods
139142
NAN_METHOD(InitializeClient) {
140-
std::wstring service(to_wstring(*(Nan::Utf8String(info[0]))));
143+
std::wstring service = to_wstring(*(Nan::Utf8String(info[0])));
141144
v8::Local<v8::Object> options = Nan::To<v8::Object>(info[1]).ToLocalChecked();
142145
Nan::Callback* callback = new Nan::Callback(Nan::To<v8::Function>(info[2]).ToLocalChecked());
143146

0 commit comments

Comments
 (0)