diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 62682f357..08339465c 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,11 @@ +2004-02-25 Brian Ford , + Corinna Vinschen + + * miscfuncs.cc (check_invalid_virtual_addr): New function. + * winsup.h (check_invalid_virtual_addr): Declare. + * mmap.cc (munmap): Call check_invalid_virtual_addr instead of + IsBadReadPtr. + 2004-02-24 Christopher Faylor * gendef (stabilize_sig_stack): Correctly align this pointer for call diff --git a/winsup/cygwin/miscfuncs.cc b/winsup/cygwin/miscfuncs.cc index 4207c4d1a..7947365f4 100644 --- a/winsup/cygwin/miscfuncs.cc +++ b/winsup/cygwin/miscfuncs.cc @@ -214,6 +214,18 @@ __check_invalid_read_ptr_errno (const void *s, unsigned sz) return set_errno (EFAULT); } +int __stdcall +check_invalid_virtual_addr (const void *s, unsigned sz) +{ + MEMORY_BASIC_INFORMATION mbuf; + void *end; + + for (end = (char *) s + sz; s < end; s = (char *) s + mbuf.RegionSize) + if (!VirtualQuery (s, &mbuf, sizeof mbuf)) + return EINVAL; + return 0; +} + ssize_t check_iovec_for_read (const struct iovec *iov, int iovcnt) { diff --git a/winsup/cygwin/mmap.cc b/winsup/cygwin/mmap.cc index 4f8ea6e14..cacefea41 100644 --- a/winsup/cygwin/mmap.cc +++ b/winsup/cygwin/mmap.cc @@ -641,7 +641,7 @@ munmap (void *addr, size_t len) /* Error conditions according to SUSv3 */ if (!addr || ((DWORD)addr % getpagesize ()) || !len - || IsBadReadPtr (addr, len)) + || check_invalid_virtual_addr (addr, len)) { set_errno (EINVAL); syscall_printf ("-1 = munmap(): Invalid parameters"); diff --git a/winsup/cygwin/winsup.h b/winsup/cygwin/winsup.h index 93cdceed2..a7e38d772 100644 --- a/winsup/cygwin/winsup.h +++ b/winsup/cygwin/winsup.h @@ -276,6 +276,7 @@ int __stdcall __check_null_invalid_struct (void *s, unsigned sz) __attribute__ ( int __stdcall __check_null_invalid_struct_errno (void *s, unsigned sz) __attribute__ ((regparm(2))); int __stdcall __check_invalid_read_ptr (const void *s, unsigned sz) __attribute__ ((regparm(2))); int __stdcall __check_invalid_read_ptr_errno (const void *s, unsigned sz) __attribute__ ((regparm(2))); +int __stdcall check_invalid_virtual_addr (const void *s, unsigned sz) __attribute__ ((regparm(2))); #define check_null_invalid_struct(s) \ __check_null_invalid_struct ((s), sizeof (*(s)))