Repository : ssh://[email protected]/ghc On branch : master Link : http://ghc.haskell.org/trac/ghc/changeset/48865521de6638240819b3979edbb3d33401dc8e/ghc
>--------------------------------------------------------------- commit 48865521de6638240819b3979edbb3d33401dc8e Author: Reid Barton <[email protected]> Date: Wed Aug 28 17:08:19 2013 -0400 Check for integer overflow in osGetMBlocks Fixes Trac #5188. Signed-off-by: Austin Seipp <[email protected]> >--------------------------------------------------------------- 48865521de6638240819b3979edbb3d33401dc8e rts/posix/OSMem.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/rts/posix/OSMem.c b/rts/posix/OSMem.c index 26aebc2..000ad63 100644 --- a/rts/posix/OSMem.c +++ b/rts/posix/OSMem.c @@ -177,7 +177,18 @@ void * osGetMBlocks(nat n) { caddr_t ret; - W_ size = MBLOCK_SIZE * (W_)n; + W_ size; + + // 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 ((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); + stg_exit(EXIT_FAILURE); + } else { + size = MBLOCK_SIZE * (W_)n; + } if (next_request == 0) { // use gen_map_mblocks the first time. _______________________________________________ ghc-commits mailing list [email protected] http://www.haskell.org/mailman/listinfo/ghc-commits
