summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTaylor Blau <me@ttaylorr.com>2025-05-28 14:33:35 -0400
committerTaylor Blau <me@ttaylorr.com>2025-05-28 14:33:35 -0400
commit32c93d5935f9afe4c2a48803b2e50700b5913b6a (patch)
tree97215e07f9d4df5e05f7ea1e685bf5f73a0acbe9
parent2d22f0cd07c308d7ff25bbf4ec8f1bb53b4bcda7 (diff)
parent9de345cb273cc7faaeda279c7e07149d8a15a319 (diff)
Merge branch 'tb/wincred-buffer-overflow' into maint-2.43
This merges in the fix for CVE-2025-48386. * tb/wincred-buffer-overflow: wincred: avoid buffer overflow in wcsncat() Signed-off-by: Taylor Blau <me@ttaylorr.com>
-rw-r--r--contrib/credential/wincred/git-credential-wincred.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/contrib/credential/wincred/git-credential-wincred.c b/contrib/credential/wincred/git-credential-wincred.c
index 4cd56c42e2..ceff44207a 100644
--- a/contrib/credential/wincred/git-credential-wincred.c
+++ b/contrib/credential/wincred/git-credential-wincred.c
@@ -37,6 +37,14 @@ static void *xmalloc(size_t size)
static WCHAR *wusername, *password, *protocol, *host, *path, target[1024],
*password_expiry_utc;
+static void target_append(const WCHAR *src)
+{
+ size_t avail = ARRAY_SIZE(target) - wcslen(target) - 1; /* -1 for NUL */
+ if (avail < wcslen(src))
+ die("target buffer overflow");
+ wcsncat(target, src, avail);
+}
+
static void write_item(const char *what, LPCWSTR wbuf, int wlen)
{
char *buf;
@@ -294,17 +302,17 @@ int main(int argc, char *argv[])
/* prepare 'target', the unique key for the credential */
wcscpy(target, L"git:");
- wcsncat(target, protocol, ARRAY_SIZE(target));
- wcsncat(target, L"://", ARRAY_SIZE(target));
+ target_append(protocol);
+ target_append(L"://");
if (wusername) {
- wcsncat(target, wusername, ARRAY_SIZE(target));
- wcsncat(target, L"@", ARRAY_SIZE(target));
+ target_append(wusername);
+ target_append(L"@");
}
if (host)
- wcsncat(target, host, ARRAY_SIZE(target));
+ target_append(host);
if (path) {
- wcsncat(target, L"/", ARRAY_SIZE(target));
- wcsncat(target, path, ARRAY_SIZE(target));
+ target_append(L"/");
+ target_append(path);
}
if (!strcmp(argv[1], "get"))