On Thu, 22 May 2025 10:11:58 -0700 (PDT)
Jeremy Drake wrote:
> The RegionSize member of the MEMORY_BASIC_INFORMATION struct is of type
> SIZE_T, and it may be larger than will fit in a DWORD (I observed
> 0x200000000).  This resulted in an error due to trying to reserve 0
> bytes from VirtualAlloc.
> 
> Fixes: 8d777a13fcf4 ("* dll_init.cc (reserve_at, release_at): New functions.")
> Addresses: https://cygwin.com/pipermail/cygwin/2025-May/258154.html
> Reported-by: Yuyi Wang <[email protected]>
> Signed-off-by: Jeremy Drake <[email protected]>
> ---
>  winsup/cygwin/dll_init.cc   | 2 +-
>  winsup/cygwin/release/3.6.2 | 3 +++
>  2 files changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/winsup/cygwin/dll_init.cc b/winsup/cygwin/dll_init.cc
> index b8f38b56de..e5953ca9f6 100644
> --- a/winsup/cygwin/dll_init.cc
> +++ b/winsup/cygwin/dll_init.cc
> @@ -633,7 +633,7 @@ dll_list::track_self ()
>  static PVOID
>  reserve_at (PCWCHAR name, PVOID here, PVOID dll_base, DWORD dll_size)
>  {
> -  DWORD size;
> +  size_t size;
>    MEMORY_BASIC_INFORMATION mb;
> 
>    if (!VirtualQuery (here, &mb, sizeof (mb)))
> diff --git a/winsup/cygwin/release/3.6.2 b/winsup/cygwin/release/3.6.2
> index 3b1944d99f..16a4fee156 100644
> --- a/winsup/cygwin/release/3.6.2
> +++ b/winsup/cygwin/release/3.6.2
> @@ -28,3 +28,6 @@ Fixes:
> 
>  - Fix infinite exception loop on segmentation fault when strace-ing
>    Addresses: https://cygwin.com/pipermail/cygwin/2025-May/258144.html
> +
> +- Fix size truncation in dll_init reserve_at function.
> +  Addresses: https://cygwin.com/pipermail/cygwin/2025-May/258154.html
> -- 
> 2.49.0.windows.1
> 

Nice cache!
Question is: Isn't it better to declare size as SIZE_T rather
than size_t because the 2nd arg (size) of VirtualAlloc() is
declared as SIZE_T?

Other than that LGTM. If you think size_t is better, please push
as is.

-- 
Takashi Yano <[email protected]>

Reply via email to