{"thread":{"id":"64497","subject":"[PATCH] wincred: avoid memory corruption","startedAt":"2025-11-17T20:39:47Z","lastAt":"2025-11-17T20:39:47Z","messageCount":1,"participants":["Johannes Schindelin via GitGitGadget"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"530836","messageId":"pull.2005.git.1763411984773.gitgitgadget@gmail.com","threadId":"64497","inReplyTo":null,"subject":"[PATCH] wincred: avoid memory corruption","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2025-11-17T20:39:44Z","receivedAt":"2025-11-17T20:39:47Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: David Macek <david.macek.0@gmail.com>\n\n`wcsncpy_s()` wants to write the terminating null character so we need\nto allocate one more space for it in the target memory block.\n\nThis should fix crashes when trying to read passwords.  When this\nhappened, the password/token wouldn't print out and Git would therefore\nask for a new password every time.\n\nSigned-off-by: David Macek <david.macek.0@gmail.com>\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n    wincred: Avoid memory corruption\n    \n    This patch wants to be upstreamed...\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2005%2Fdscho%2Fwincred-Avoid-memory-corruption-5856--v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2005/dscho/wincred-Avoid-memory-corruption-5856--v1\nPull-Request: https://github.com/gitgitgadget/git/pull/2005\n\n contrib/credential/wincred/git-credential-wincred.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/contrib/credential/wincred/git-credential-wincred.c b/contrib/credential/wincred/git-credential-wincred.c\nindex 5683846b4b..73c2b9b72a 100644\n--- a/contrib/credential/wincred/git-credential-wincred.c\n+++ b/contrib/credential/wincred/git-credential-wincred.c\n@@ -165,7 +165,7 @@ static void get_credential(void)\n \t\t\twrite_item(\"username\", creds[i]->UserName,\n \t\t\t\tcreds[i]->UserName ? wcslen(creds[i]->UserName) : 0);\n \t\t\tif (creds[i]->CredentialBlobSize > 0) {\n-\t\t\t\tsecret = xmalloc(creds[i]->CredentialBlobSize);\n+\t\t\t\tsecret = xmalloc(creds[i]->CredentialBlobSize + sizeof(WCHAR));\n \t\t\t\twcsncpy_s(secret, creds[i]->CredentialBlobSize, (LPCWSTR)creds[i]->CredentialBlob, creds[i]->CredentialBlobSize / sizeof(WCHAR));\n \t\t\t\tline = wcstok_s(secret, L\"\\r\\n\", &remaining_lines);\n \t\t\t\twrite_item(\"password\", line, line ? wcslen(line) : 0);\n\nbase-commit: 9a2fb147f2c61d0cab52c883e7e26f5b7948e3ed\n-- \ngitgitgadget\n"}]}