[commit: ghc] master: Paranoid integer overflow check in osGetMBlocks (1247dff)

git at git.haskell.org git at git.haskell.org
Fri Aug 30 00:17:14 CEST 2013


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/1247dff7b852d45dc5006ae8be33ac991cc76c74/ghc

>---------------------------------------------------------------

commit 1247dff7b852d45dc5006ae8be33ac991cc76c74
Author: Reid Barton <rwbarton at gmail.com>
Date:   Wed Aug 28 17:13:41 2013 -0400

    Paranoid integer overflow check in osGetMBlocks
    
    Signed-off-by: Austin Seipp <aseipp at pobox.com>


>---------------------------------------------------------------

1247dff7b852d45dc5006ae8be33ac991cc76c74
 rts/posix/OSMem.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/rts/posix/OSMem.c b/rts/posix/OSMem.c
index cbc76f8..76b863e 100644
--- a/rts/posix/OSMem.c
+++ b/rts/posix/OSMem.c
@@ -184,7 +184,8 @@ osGetMBlocks(nat n)
 
   // Compute size = MBLOCK_SIZE * (W_)n,
   // while testing for integer overflow.
-  // We assume that W_ is at least as large a type as nat.
+  if (n > (nat)((W_)-1))
+      barf("osGetMBlocks: impossibly large MBlock count %d; nat larger than W_?", n);
   if ((W_)n > ((W_)-1) / MBLOCK_SIZE) {
       // We tried to allocate, say, 4 GB or more on a 32-bit system.
       errorBelch("out of memory (requested %d MBlocks)", n);





More information about the ghc-commits mailing list