Skip to contentSkip to conversation

wincred: avoid memory corruption

PATCH New Johannes Schindelin via GitGitGadget 1 participant 1 message Nov 17, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wincred: avoid memory corruption

From: David Macek <[email protected]>

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.

---
wincred: Avoid memory corruption

This patch wants to be upstreamed...

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2005%2Fdscho%2Fwincred-Avoid-memory-corruption-5856--v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2005/dscho/wincred-Avoid-memory-corruption-5856--v1
Pull-Request: https://github.com/gitgitgadget/git/pull/2005

 contrib/credential/wincred/git-credential-wincred.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
contrib/credential/wincred/git-credential-wincred.c +1 -1
index 5683846b4b..73c2b9b72a 100644
@@ -165,7 +165,7 @@ static void get_credential(void)
 			write_item("username", creds[i]->UserName,
 				creds[i]->UserName ? wcslen(creds[i]->UserName) : 0);
 			if (creds[i]->CredentialBlobSize > 0) {
-				secret = xmalloc(creds[i]->CredentialBlobSize);
+				secret = xmalloc(creds[i]->CredentialBlobSize + sizeof(WCHAR));
 				wcsncpy_s(secret, creds[i]->CredentialBlobSize, (LPCWSTR)creds[i]->CredentialBlob, creds[i]->CredentialBlobSize / sizeof(WCHAR));
 				line = wcstok_s(secret, L"\r\n", &remaining_lines);
 				write_item("password", line, line ? wcslen(line) : 0);

base-commit: 9a2fb147f2c61d0cab52c883e7e26f5b7948e3ed

Signature · 1 line
gitgitgadget