Skip to content

Commit 726f6ea

Browse files
committed
fix: check if last char if null terminator before exclude
1 parent a1d0dcf commit 726f6ea

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

packages/passkeys/passkeys_windows/windows/webauthn_helper.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,24 @@ namespace passkeys_windows
9494
}
9595

9696
std::string base64(base64_size, 0);
97+
DWORD written_size = base64_size;
9798
if (!CryptBinaryToStringA(data, static_cast<DWORD>(size),
9899
CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF,
99-
&base64[0], &base64_size))
100+
&base64[0], &written_size))
100101
{
101102
throw std::runtime_error("Failed to encode base64");
102103
}
103104

104-
// Remove null terminator
105-
base64.resize(base64_size - 1);
105+
// Resize to actual content length (excluding null terminator if present)
106+
// CryptBinaryToStringA writes 'written_size' chars which may include null terminator
107+
if (written_size > 0 && base64[written_size - 1] == '\0')
108+
{
109+
base64.resize(written_size - 1);
110+
}
111+
else
112+
{
113+
base64.resize(written_size);
114+
}
106115

107116
// Base64 to Base64url conversion
108117
for (char &c : base64)

0 commit comments

Comments
 (0)