From 2817e0dc89f74ae714e863eeff94c31041e05e6e Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Mon, 11 Mar 2002 20:23:09 +0000 Subject: [PATCH] * mmap.cc (msync): Check area given by addr and len for being a contigeous mmap'd region. --- winsup/cygwin/ChangeLog | 5 +++++ winsup/cygwin/mmap.cc | 13 +++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index fa15f2ce1..e0c7e88ca 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,8 @@ +2002-03-11 Corinna Vinschen + + * mmap.cc (msync): Check area given by addr and len for being a + contigeous mmap'd region. + 2002-03-11 Corinna Vinschen * fork.cc (fork_child): Call fixup_mmaps_after_fork() before diff --git a/winsup/cygwin/mmap.cc b/winsup/cygwin/mmap.cc index dae80e4d6..2a81d8d3c 100644 --- a/winsup/cygwin/mmap.cc +++ b/winsup/cygwin/mmap.cc @@ -674,8 +674,12 @@ msync (caddr_t addr, size_t len, int flags) for (int li = 0; li < l->nrecs; ++li) { mmap_record *rec = l->recs + li; - if (rec->get_address () == addr) + if (rec->access (addr)) { + /* Check whole area given by len. */ + for (DWORD i = getpagesize (); i < len; ++i) + if (!rec->access (addr + i)) + goto invalid_address_range; fhandler_base *fh = rec->alloc_fh (); int ret = fh->msync (rec->get_handle (), addr, len, flags); rec->free_fh (fh); @@ -688,10 +692,11 @@ msync (caddr_t addr, size_t len, int flags) ReleaseResourceLock(LOCK_MMAP_LIST, WRITE_LOCK | READ_LOCK, "msync"); return 0; } - } - } - } + } + } + } +invalid_address_range: /* SUSv2: Return code if indicated memory was not mapped is ENOMEM. */ set_errno (ENOMEM); syscall_printf ("-1 = msync(): ENOMEM");