Skip to content

Commit 32c93d5

Browse files
committed
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 <[email protected]>
2 parents 2d22f0c + 9de345c commit 32c93d5

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

contrib/credential/wincred/git-credential-wincred.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ static void *xmalloc(size_t size)
3737
static WCHAR *wusername, *password, *protocol, *host, *path, target[1024],
3838
*password_expiry_utc;
3939

40+
static void target_append(const WCHAR *src)
41+
{
42+
size_t avail = ARRAY_SIZE(target) - wcslen(target) - 1; /* -1 for NUL */
43+
if (avail < wcslen(src))
44+
die("target buffer overflow");
45+
wcsncat(target, src, avail);
46+
}
47+
4048
static void write_item(const char *what, LPCWSTR wbuf, int wlen)
4149
{
4250
char *buf;
@@ -294,17 +302,17 @@ int main(int argc, char *argv[])
294302

295303
/* prepare 'target', the unique key for the credential */
296304
wcscpy(target, L"git:");
297-
wcsncat(target, protocol, ARRAY_SIZE(target));
298-
wcsncat(target, L"://", ARRAY_SIZE(target));
305+
target_append(protocol);
306+
target_append(L"://");
299307
if (wusername) {
300-
wcsncat(target, wusername, ARRAY_SIZE(target));
301-
wcsncat(target, L"@", ARRAY_SIZE(target));
308+
target_append(wusername);
309+
target_append(L"@");
302310
}
303311
if (host)
304-
wcsncat(target, host, ARRAY_SIZE(target));
312+
target_append(host);
305313
if (path) {
306-
wcsncat(target, L"/", ARRAY_SIZE(target));
307-
wcsncat(target, path, ARRAY_SIZE(target));
314+
target_append(L"/");
315+
target_append(path);
308316
}
309317

310318
if (!strcmp(argv[1], "get"))

0 commit comments

Comments
 (0)