Skip to content

Commit 2637167

Browse files
Jeremy Drake via Cygwin-patchestyan0
authored andcommitted
Cygwin: cygwin_conv_path: don't write to to before size is validated.
In the CCP_POSIX_TO_WIN_W path, when `from` is a device, cygwin_conv_path would attempt to write to the `to` buffer before the validation of the `size`. This resulted in an EFAULT error in the common use-case of passing `to` as NULL and `size` as 0 to get the required size of `to` for the conversion (as used in cygwin_create_path). Instead, set a boolean and write to `to` after validation. Fixes: 43f65cd ("* Makefile.in (DLL_OFILES): Add fhandler_procsys.o.") Addresses: https://cygwin.com/pipermail/cygwin/2025-April/258068.html Signed-off-by: Jeremy Drake <[email protected]> (cherry picked from commit 5dd3d58)
1 parent 60da503 commit 2637167

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

winsup/cygwin/path.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3911,6 +3911,7 @@ cygwin_conv_path (cygwin_conv_path_t what, const void *from, void *to,
39113911
int how = what & CCP_CONVFLAGS_MASK;
39123912
what &= CCP_CONVTYPE_MASK;
39133913
int ret = -1;
3914+
bool prependglobalroot = false;
39143915

39153916
__try
39163917
{
@@ -4019,7 +4020,7 @@ cygwin_conv_path (cygwin_conv_path_t what, const void *from, void *to,
40194020
{
40204021
/* Device name points to somewhere else in the NT namespace.
40214022
Use GLOBALROOT prefix to convert to Win32 path. */
4022-
to = (void *) wcpcpy ((wchar_t *) to, ro_u_globalroot.Buffer);
4023+
prependglobalroot = true;
40234024
lsiz += ro_u_globalroot.Length / sizeof (WCHAR);
40244025
}
40254026
/* TODO: Same ".\\" band-aid as in CCP_POSIX_TO_WIN_A case. */
@@ -4075,6 +4076,8 @@ cygwin_conv_path (cygwin_conv_path_t what, const void *from, void *to,
40754076
stpcpy ((char *) to, buf);
40764077
break;
40774078
case CCP_POSIX_TO_WIN_W:
4079+
if (prependglobalroot)
4080+
to = (void *) wcpcpy ((PWCHAR) to, ro_u_globalroot.Buffer);
40784081
wcpcpy ((PWCHAR) to, path);
40794082
break;
40804083
}

winsup/cygwin/release/3.6.2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ Fixes:
1313

1414
- Fix setting DOS attributes on devices.
1515
Addresse: https://cygwin.com/pipermail/cygwin/2025-April/257940.html
16+
17+
- Fix cygwin_conv_path writing to 'to' pointer before size is checked.
18+
Addresses: https://cygwin.com/pipermail/cygwin/2025-April/258068.html

0 commit comments

Comments
 (0)