wincred: avoid memory corruption
`wcsncpy_s()` wants to write the terminating null character so we need to allocate one more space for it in the target memory block. This should fix crashes when trying to read passwords. When this happened, the password/token wouldn't print out and Git would therefore ask for a new password every time. Signed-off-by: David Macek <david.macek.0@gmail.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
David Macek committed
Nov 17, 2025 at 20:39 UTC
d22a488482092da64ad19fda82edde199bed2466
1 file changed
+1
-1
contrib/credential/wincred/git-credential-wincred.c
+1
-1
@@ -165,7 +165,7 @@ static void get_credential(void)
165
write_item("username", creds[i]->UserName,
166
creds[i]->UserName ? wcslen(creds[i]->UserName) : 0);
167
if (creds[i]->CredentialBlobSize > 0) {
168
- secret = xmalloc(creds[i]->CredentialBlobSize);
168
+ secret = xmalloc(creds[i]->CredentialBlobSize + sizeof(WCHAR));
169
wcsncpy_s(secret, creds[i]->CredentialBlobSize, (LPCWSTR)creds[i]->CredentialBlob, creds[i]->CredentialBlobSize / sizeof(WCHAR));
170
line = wcstok_s(secret, L"\r\n", &remaining_lines);
171
write_item("password", line, line ? wcslen(line) : 0);