diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2002-08-02 14:43:16 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2002-08-02 14:43:16 +0000 |
commit | 00795ba1dbecae1566b3c4be1cf26a171ce3c930 (patch) | |
tree | 646a22550661c9ece1d191268015f557f8087a8c /usr.bin/ssh | |
parent | 51b3f066f858155932ae1548a6eb89a6a7d9aeef (diff) |
Change mm_zalloc() sanity checks to be more in line with what
we do in calloc() and add a check to monitor_mm.c.
OK provos@ and markus@
Diffstat (limited to 'usr.bin/ssh')
-rw-r--r-- | usr.bin/ssh/monitor.c | 6 | ||||
-rw-r--r-- | usr.bin/ssh/monitor_mm.c | 6 |
2 files changed, 7 insertions, 5 deletions
diff --git a/usr.bin/ssh/monitor.c b/usr.bin/ssh/monitor.c index 7c4f3c0de79..e25360f941b 100644 --- a/usr.bin/ssh/monitor.c +++ b/usr.bin/ssh/monitor.c @@ -25,7 +25,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: monitor.c,v 1.22 2002/07/22 17:32:56 stevesk Exp $"); +RCSID("$OpenBSD: monitor.c,v 1.23 2002/08/02 14:43:15 millert Exp $"); #include <openssl/dh.h> @@ -1419,10 +1419,10 @@ mm_get_keystate(struct monitor *pmonitor) void * mm_zalloc(struct mm_master *mm, u_int ncount, u_int size) { - int len = size * ncount; + size_t len = size * ncount; void *address; - if (len <= 0 || size > 65535 || ncount > 65535) + if (len == 0 || ncount > SIZE_T_MAX / size) fatal("%s: mm_zalloc(%u, %u)", __func__, ncount, size); address = mm_malloc(mm, len); diff --git a/usr.bin/ssh/monitor_mm.c b/usr.bin/ssh/monitor_mm.c index acd90ff1309..6eb84041a25 100644 --- a/usr.bin/ssh/monitor_mm.c +++ b/usr.bin/ssh/monitor_mm.c @@ -24,7 +24,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: monitor_mm.c,v 1.7 2002/06/28 01:49:31 millert Exp $"); +RCSID("$OpenBSD: monitor_mm.c,v 1.8 2002/08/02 14:43:15 millert Exp $"); #include <sys/mman.h> @@ -160,8 +160,10 @@ mm_malloc(struct mm_master *mm, size_t size) if (size == 0) fatal("mm_malloc: try to allocate 0 space"); + if (size > SIZE_T_MAX - MM_MINSIZE + 1) + fatal("mm_malloc: size too big"); - size = ((size + MM_MINSIZE - 1) / MM_MINSIZE) * MM_MINSIZE; + size = ((size + (MM_MINSIZE - 1)) / MM_MINSIZE) * MM_MINSIZE; RB_FOREACH(mms, mmtree, &mm->rb_free) { if (mms->size >= size) |