public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
From: "Petrovski, Roman" <RPetrovski@illumina.com>
To: "cygwin-patches@cygwin.com" <cygwin-patches@cygwin.com>
Subject: RE: RtlFillMemory fails on block sizes over 0x7fffffff
Date: Wed, 29 Jul 2015 16:28:00 -0000	[thread overview]
Message-ID: <3BD89E0BA5F96349B765DE1100906A6D016FC0276D@UKCH-PRD-EXMB01.illumina.com> (raw)
In-Reply-To: <20150729162135.GA20388@calimero.vinschen.de>

Sure, in case you decide to go with the patch meanwhile, please use the one attached to this email. The original wrongly uses n instead of size for copying the memory.

As this is fairly critical issue, do you know when users should expect a  fix to become available in the binary release?

Roman.


From 3ba2e2feaf785c213d2f3db16efab74e25347b43 Mon Sep 17 00:00:00 2001
From: Roman Petrovski <rpetrovski@illumina.com>
Date: Wed, 29 Jul 2015 09:20:19 -0700
Subject: [PATCH] RtlFillMemory fails on block sizes over 0x7fffffff

---
 winsup/cygwin/miscfuncs.cc | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/winsup/cygwin/miscfuncs.cc b/winsup/cygwin/miscfuncs.cc
index 4a7a1b8..2c38de3 100644
--- a/winsup/cygwin/miscfuncs.cc
+++ b/winsup/cygwin/miscfuncs.cc
@@ -904,17 +904,35 @@ err:
 extern "C" void NTAPI RtlFillMemory (PVOID, SIZE_T, BYTE);
 extern "C" void NTAPI RtlCopyMemory (PVOID, const VOID *, SIZE_T);

+
+static const size_t RTL_MAX_SIZE = 0x7fffffff;
 extern "C" void *
 memset (void *s, int c, size_t n)
 {
-  RtlFillMemory (s, n, c);
+  char *p = (char*)s;
+  while (n)
+  {
+    size_t size = min(RTL_MAX_SIZE, n);
+    RtlFillMemory (p, size, c);
+    p += size;
+    n -= size;
+  }
   return s;
 }

 extern "C" void *
 memcpy(void *__restrict dest, const void *__restrict src, size_t n)
 {
-  RtlCopyMemory (dest, src, n);
+  char *d = (char*)dest;
+  char *s = (char*)src;
+  while (n)
+  {
+    size_t size = min(RTL_MAX_SIZE, n);
+    RtlCopyMemory (d, s, size);
+    d += size;
+    s += size;
+    n -= size;
+  }
   return dest;
 }
 #endif
--
2.4.5


-----Original Message-----
From: cygwin-patches-owner@cygwin.com [mailto:cygwin-patches-owner@cygwin.com] On Behalf Of Corinna Vinschen
Sent: 29 July 2015 17:22
To: cygwin-patches@cygwin.com
Subject: Re: RtlFillMemory fails on block sizes over 0x7fffffff

On Jul 29 14:11, Petrovski, Roman wrote:
> Hi, just ran into a problem which boils down to the following at least with Windows 7:
> 
> char *p = (char*)malloc(0x80000000UL);	//works fine, allocates memory as requested
> memset(p, 0, 0x80000000UL);			//Watch process segfault.
> 
> The RtlFillMemory either crashes or underfills the buffer depending on the size given.
> Looks like internally it treats size as a signed 4-byte integer.
> 
> Please apply the patch below or implement an alternative.

Thanks for the patch, but I'll rather be looking into an assembler alternative.  I'm planning to pull in the NetBSD implementation, with the tweaks required for MS ABI.


Thanks,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

  reply	other threads:[~2015-07-29 16:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-29 14:10 Petrovski, Roman
2015-07-29 16:21 ` Corinna Vinschen
2015-07-29 16:28   ` Petrovski, Roman [this message]
2015-07-29 20:21     ` Corinna Vinschen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3BD89E0BA5F96349B765DE1100906A6D016FC0276D@UKCH-PRD-EXMB01.illumina.com \
    --to=rpetrovski@illumina.com \
    --cc=cygwin-patches@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).