+/* $OpenBSD: monitor_mm.c,v 1.15 2006/08/03 03:34:42 deraadt Exp $ */
/*
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
* All rights reserved.
*/
#include "includes.h"
-RCSID("$OpenBSD: monitor_mm.c,v 1.7 2002/06/28 01:49:31 millert Exp $");
+#include <sys/types.h>
#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
#endif
+#include <sys/param.h>
+#include "openbsd-compat/sys-tree.h"
+
+#include <errno.h>
+#include <stdarg.h>
+#include <string.h>
-#include "ssh.h"
#include "xmalloc.h"
+#include "ssh.h"
#include "log.h"
#include "monitor_mm.h"
mm->mmalloc = mmalloc;
address = xmmap(size);
- if (address == MAP_FAILED)
+ if (address == (void *)MAP_FAILED)
fatal("mmap(%lu): %s", (u_long)size, strerror(errno));
mm->address = address;
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)